57#define MODULE_ID "XSH_SUBTRACT_SKY_SINGLE"
59#define SYNTAX "Test the xsh_subtract_sky_single function\n"\
60 "usage :\n test_xsh_subtract_sky_single [<opt>] SCI_FRAME ORDER_TABLE SLITMAP WAVEMAP [LOCALIZATION} \n" \
61 "SCI_FRAME => Science frame NOCOSMIC and flat field [DIV_FF]\n"\
62 "ORDER_TABLE => Order table frame\n"\
63 "SLITMAP => Slit Map Frame\n"\
64 "WAVEMAP => Wave Map frame\n"\
65 "LOCALIZATION => Localization frame (optional)\n\n"\
67 " --nbkpts=<nn> : Number of break points (default 100)\n"\
68 " --method=<n> : 0 => BSPLINE 1 => MEDIAN [BSPLINE]\n"\
69 " --pos1=<n> : Sky position 1 [0]\n"\
70 " --hheight1=<n> : Sky half height 1 [0]\n"\
71 " --pos2=<n> : Sky position 2 [0]\n"\
72 " --hheight2=<n> : Sky half height 2 [0]\n"\
73 " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]\n"\
74 "The output file (after subtraction) is 'SUBTRACTED_FLUX.fits'\n"
92 {
"pos1", required_argument, 0,
POS1_OPT},
94 {
"pos2", required_argument, 0,
POS2_OPT},
96 {
"debug", required_argument, 0,
DEBUG_OPT},
103 int option_index = 0;
105 while( (opt = getopt_long( argc, argv,
Options,
109 sscanf( optarg,
"%64d", &(sky_par->
nbkpts1) ) ;
112 sscanf( optarg,
"%64d", &(sky_par->
method));
115 sky_par->
pos1 = atof( optarg);
121 sky_par->
pos2 = atof( optarg);
127 if ( strcmp( optarg,
"LOW")==0){
130 else if ( strcmp( optarg,
"HIGH")==0){
142 cpl_size
x = 0,
y = 0 ;
148 max = cpl_image_get_max( pre->
data ) ;
149 cpl_image_get_maxpos( pre->
data, &
x, &
y ) ;
150 xsh_msg(
"Maximum value: %lf at %" CPL_SIZE_FORMAT
",%" CPL_SIZE_FORMAT
"",
max,
x,
y ) ;
163int main(
int argc,
char** argv)
165 cpl_frame * sci_frame = NULL ;
166 cpl_frame * order_frame = NULL ;
167 cpl_frame * slitmap_frame = NULL ;
168 cpl_frame * wavemap_frame= NULL ;
169 cpl_frame * local_frame = NULL ;
170 cpl_frame * sky_line_list_frame = NULL ;
172 char * sci_name = NULL, * order_name = NULL, * slitmap_name = NULL,
173 * wavemap_name = NULL, * local_name = NULL , * sky_line_list_name = NULL;
176 cpl_frame * sky_spectrum = NULL ;
177 cpl_frame * sky_spectrum_eso = NULL ;
180 cpl_frame * result = NULL ;
187 cpl_propertylist *plist = NULL;
189 const int decode_bp=2140143615;
191 cpl_msg_set_level(CPL_MSG_DEBUG);
216 nb_frames = argc - optind;
217 xsh_msg(
"Nb of inputs = %d", nb_frames);
218 if ( nb_frames >= 4 ) {
219 sci_name = argv[optind] ;
220 order_name = argv[optind+1] ;
221 slitmap_name = argv[optind+2] ;
222 wavemap_name = argv[optind+3] ;
223 if ( nb_frames >= 5 )
224 sky_line_list_name = argv[optind+4] ;
225 if ( nb_frames == 6 )
226 local_name = argv[optind+5] ;
230 xsh_msg(
"Not enough Input Frames\n" ) ;
236 xsh_msg(
"Sci frame : %s", sci_name);
237 xsh_msg(
"Order frame : %s", order_name);
238 xsh_msg(
"Slit map frame : %s",slitmap_name);
239 xsh_msg(
"Wave map frame : %s",wavemap_name);
240 if (local_name != NULL){
241 xsh_msg(
"Localization frame : %s", local_name);
243 if (sky_line_list_name != NULL){
244 xsh_msg(
"Ref sky line list frame : %s", sky_line_list_name);
256 check( plist = cpl_propertylist_load( sci_name, 0));
282 cpl_frame_set_group( order_frame, CPL_FRAME_GROUP_CALIB ) ;
286 cpl_frame_set_group( slitmap_frame, CPL_FRAME_GROUP_CALIB ) ;
290 cpl_frame_set_group( wavemap_frame, CPL_FRAME_GROUP_CALIB ) ;
292 if ( local_name != NULL ) {
295 cpl_frame_set_group( local_frame, CPL_FRAME_GROUP_CALIB ) ;
298 if ( sky_line_list_name != NULL ) {
301 cpl_frame_set_group( sky_line_list_frame, CPL_FRAME_GROUP_CALIB ) ;
305 slitmap_frame, wavemap_frame,
306 local_frame, sky_line_list_frame,
309 &sky_spectrum,&sky_spectrum_eso,
330 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
331 xsh_msg(
"ERROR in xsh_subtract_sky_single" ) ;
int main()
Unit test of xsh_bspline_interpol.
static const char * Options
static void HandleOptions(int argc, char **argv, xsh_subtract_sky_single_param *sky_par)
static void get_max_pos(cpl_frame *frame, xsh_instrument *instrument)
static struct option LongOptions[]
static xsh_instrument * instrument
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
#define xsh_error_dump(level)
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
void xsh_instrument_set_decode_bp(xsh_instrument *i, const int decode_bp)
Set bad pixel code.
#define xsh_msg(...)
Print a message on info level.
XSH_ARM xsh_pfits_get_arm(const cpl_propertylist *plist)
cpl_frame * xsh_subtract_sky_single(cpl_frame *sci_frame, cpl_frame *order_table_frame, cpl_frame *slitmap_frame, cpl_frame *wavemap_frame, cpl_frame *locTable_frame, cpl_frame *ref_sky_list, cpl_frame *sky_orders_chunks, cpl_frame *usr_defined_break_points_frame, xsh_instrument *instrument, int nbkpts, xsh_subtract_sky_single_param *sky_par, cpl_frame **sky_spectrum, cpl_frame **sky_spectrum_eso, const char *rec_prefix, const int clean_tmp)
Subtract the sky background for single frame. If sky_spectrum is NOT NULL it is saved as a product,...
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
int xsh_debug_level_set(int level)
set debug level
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
enum bspline_sampling bspline_sampling
#define TESTS_XSH_INSTRUMENT_CREATE(instr, mode, arm, lamp, recipe)
#define TESTS_XSH_FRAME_CREATE(frame, tag, name)
#define TESTS_INIT(DRL_ID)
#define XSH_ORDER_TAB_EDGES
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
#define XSH_SKY_LINE_LIST
#define XSH_OBJECT_SLIT_STARE
#define XSH_GET_TAG_FROM_LAMP(TAG, instr)
#define SKY_METHOD_PRINT(method)