1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/*===========================================================================
Copyright (C) 2001 European Southern Observatory (ESO)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the Free
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
MA 02139, USA.
Corresponding concerning ESO-MIDAS should be addressed as follows:
Internet e-mail: midas@eso.org
Postal address: European Southern Observatory
Data Management Division
Karl-Schwarzschild-Strasse 2
D 85748 Garching bei Muenchen
GERMANY
===========================================================================*/
/*-------------------------------------------------------------------------*/
/**
* @defgroup flames_doptimal
*
*/
/*---------------------------------------------------------------------------
Includes
--------------------------------------------------------------------------*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <flames_midas_def.h>
#include <flames_optimal.h>
#include <flames_def_drs_par.h>
#include <flames_uves.h>
#include <flames_ordselect.h>
#include <flames_doptimal.h>
#include <flames_newmatrix.h>
/**@{*/
/*---------------------------------------------------------------------------
Implementation
---------------------------------------------------------------------------*/
/**
@name flames_doptimal()
@short this function performs the actual optimal extraction on a frame
@author G. Mulas - ITAL_FLAMES Consortium. Ported to CPL by A. Modigliani
@param ScienceFrame all fibre frame to be optimally extracted
@param Order fibre-order position table
@param Shifted_FF shifted flat field structure
@param kappa2 square of kappa to be used in kappa-sigma clip
@param mask bad pixel mask frame
@param backframe inter-order background frame
@param normcover array to hold fibre normalization factors
@param orderoffset offset between Slit_FF order tab and fibre-order tab;
@param realfirstorder first order (from fibre-order table) to be extracted
@param reallastorder last order (from fibre-order table) to be extracted
@param minoptitersint minimum number of optimal extraction iterations
@param maxoptitersint maximum number of optimal extraction iterations
@param xkillsize When performing sigma-clipping in the optimal extraction, how many
other adjacent pixels in the x and/or y direction(s) should be
discarded along with the one exceeding the threshold? A cosmic or
cosmetic problem is likely to affect a spot larger than 1 pixel
@param ykillsize see above
@doc loop over orders and the call optimal() function
@return success or failure code
DRS Functions called:
none
Pseudocode:
@note
*/
flames_err
doptimal(
flames_frame *ScienceFrame,
orderpos *Order,
allflats *Shifted_FF,
double kappa2,
frame_mask **mask,
frame_data **backframe,
frame_data **normcover,
int32_t orderoffset,
int32_t realfirstorder,
int32_t reallastorder,
int32_t minoptitersint,
int32_t maxoptitersint,
int32_t xkillsize,
int32_t ykillsize)
{
int32_t ordsta=0, ordend=0, i=0, xysize=0;
char output[100];
int actvals=0;
char drs_verbosity[10];
frame_mask **newmask=0;
frame_mask *fmvecbuf1=0;
memset(drs_verbosity, 0, 10);
if ( SCKGETC(DRS_VERBOSITY, 1, 3, &actvals, drs_verbosity) != 0 ) {
/* the keyword seems undefined, protest... */
return(MAREMMA);
}
newmask=fmmatrix(0,ScienceFrame->subrows-1,0,ScienceFrame->subcols-1);
fmvecbuf1 = newmask[0];
xysize = (ScienceFrame->subrows*ScienceFrame->subcols)-1;
for (i=0; i<=xysize; i++) fmvecbuf1[i] = 0;
for (ordsta=ordend=realfirstorder; ordsta<=reallastorder;
ordsta=++ordend)
{
/* at least we extract from ordsta to ordend */
/* select a set of orders which is disjoint from other orders */
if (ordselect(Order, ScienceFrame, Shifted_FF, &ordend)!=NOERR)
{
SCTPUT("Error selecting an order subset to estract\n");
return flames_midas_error(MAREMMA);
}
/* A little bit of advertising */
sprintf(output, "Extracting orders from nr. %d to nr. %d....",
ordsta, ordend);
SCTPUT(output);
/* let's make the optimal extraction */
switch(optimal(ScienceFrame, Shifted_FF, Order, ordsta, ordend, kappa2,
mask, newmask, backframe, normcover, orderoffset,
minoptitersint, maxoptitersint, xkillsize, ykillsize)) {
case 0:
if ( strcmp(drs_verbosity,"LOW") == 0 ){
} else {
sprintf(output, "Optimal extraction for orders from nr. %d to %d completed\n", ordsta, ordend);
SCTPUT(output);
}
break;
case 1:
sprintf(output, "Error in optimal extraction\n");
SCTPUT(output);
return flames_midas_error(MAREMMA);
break;
case 2:
sprintf(output, "Error in sigma clipping\n");
SCTPUT(output);
return flames_midas_error(MAREMMA);
break;
case 3:
sprintf(output, "Error in covariance calculation\n");
SCTPUT(output);
return flames_midas_error(MAREMMA);
break;
case 4:
sprintf(output, "Error in cross-correlation\n");
SCTPUT(output);
return flames_midas_error(MAREMMA);
break;
default :
sprintf(output, "Unknown error\n");
SCTPUT(output);
return flames_midas_error(MAREMMA);
break;
}
}
free_fmmatrix(newmask, 0,ScienceFrame->subrows-1,0,ScienceFrame->subcols-1);
return NOERR;
}
/**@}*/
|