66#define MODULE_ID "XSH_EXTRACT_CLEAN_SYM"
75 {
"debug", required_argument, 0,
DEBUG_OPT},
82 puts(
"Unitary test of xsh_extract_clean");
83 puts(
"Usage: test_xsh_extract_clean [options] <input_files>");
86 puts(
" --decode-bp=<n> : Integer representation of the bits to be considered bad when decoding the bad pixel mask pixel values.");
87 puts(
" --method=<n> : method for extraction CLEAN | LOCALIZATION | FULL | NOD");
88 puts(
" --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
89 puts(
" --help : What you see" ) ;
90 puts(
"\nInput Files" ) ;
91 puts(
"The input files argument MUST be in this order:" ) ;
92 puts(
" 1. Rectified frame 2D" ) ;
93 puts(
" 2. Localization table");
103 int option_index = 0;
105 while (( opt = getopt_long (argc, argv,
"slit_position:slit_height:method",
123 xsh_msg(
"WRONG method %s", optarg);
128 if ( strcmp( optarg,
"LOW")==0){
131 else if ( strcmp( optarg,
"HIGH")==0){
136 *decode_bp=atoi(optarg);
150cpl_error_code
xsh_set_wcs(cpl_propertylist* header,
const double crpix1,
151 const double crval1,
const double cdelt1,
const double crpix2,
152 const double crval2,
const double cdelt2) {
153 cpl_propertylist_append_double(header,
"CRPIX1", crpix1);
154 cpl_propertylist_append_double(header,
"CRVAL1", crval1);
155 cpl_propertylist_append_double(header,
"CDELT1", cdelt1);
156 cpl_propertylist_append_string(header,
"CTYPE1",
"LINEAR");
158 cpl_propertylist_append_double(header,
"CRPIX2", crpix2);
159 cpl_propertylist_append_double(header,
"CRVAL2", crval2);
160 cpl_propertylist_append_double(header,
"CDELT2", cdelt2);
161 cpl_propertylist_append_string(header,
"CTYPE2",
"LINEAR");
168 return cpl_error_get_code();
177 cpl_frame* extracted=NULL;
187 int mask_size=mask_hsize*2+1;
200 double* res_flux=NULL;
201 double* res_errs=NULL;
202 double* res_lambda=NULL;
217 const char* fname=NULL;
218 cpl_image* ima_data=NULL;
219 cpl_image* ima_errs=NULL;
220 cpl_image* ima_qual=NULL;
225 cpl_propertylist* header=NULL;
228 double crval1 = 533.68;
229 double cdelt1 = 0.04;
232 const char* res_name=
"extracted_signal.fits";
234 cpl_table* res_table=NULL;
238 int slit_min=slit_border;
239 int slit_max=slit_min+2*hslit;
244 fname=cpl_frame_get_filename(frame2D);
245 ima_data=cpl_image_load(fname,CPL_TYPE_FLOAT,0,0);
246 ima_errs=cpl_image_load(fname,CPL_TYPE_FLOAT,0,1);
247 ima_qual=cpl_image_load(fname,CPL_TYPE_INT,0,2);
248 header=cpl_propertylist_load(fname,0);
258 flux=cpl_image_get_data_float(ima_data);
259 errs=cpl_image_get_data_float(ima_errs);
260 check(qual=cpl_image_get_data_int(ima_qual));
262 res_table=cpl_table_new(nlambda);
263 cpl_table_new_column(res_table,
"wave",CPL_TYPE_DOUBLE);
264 cpl_table_new_column(res_table,
"flux",CPL_TYPE_DOUBLE);
265 cpl_table_new_column(res_table,
"errs",CPL_TYPE_DOUBLE);
266 cpl_table_new_column(res_table,
"qual",CPL_TYPE_INT);
268 cpl_table_fill_column_window_double(res_table,
"wave",0,nlambda,0.);
269 cpl_table_fill_column_window_double(res_table,
"flux",0,nlambda,0.);
270 cpl_table_fill_column_window_double(res_table,
"errs",0,nlambda,0.);
271 cpl_table_fill_column_window_int(res_table,
"qual",0,nlambda,0);
273 check(res_lambda=cpl_table_get_data_double(res_table,
"wave"));
274 res_flux=cpl_table_get_data_double(res_table,
"flux");
275 res_errs=cpl_table_get_data_double(res_table,
"errs");
276 res_qual=cpl_table_get_data_int(res_table,
"qual");
278 lambda = cpl_malloc(nlambda *
sizeof(
double));
281 slit_min = nslit / 2 - hslit;
282 slit_max = nslit / 2 + hslit;
289 for (ilambda = 0; ilambda < nlambda; ilambda++) {
293 lambda[ilambda] = (float) (crval1 + cdelt1 * ilambda);
295 xsh_extract_clean_slice(flux,errs,qual,lambda,ilambda,
instrument,slit_min, slit_max,nlambda,nslit,mask_hsize,&fluxval, &errval,&qualval, pima, fima, rima);
297 res_lambda[ilambda] = lambda[ilambda];
298 res_flux[ilambda] = fluxval;
299 res_errs[ilambda] = sqrt(errval);
300 res_qual[ilambda] = qualval;
306 check(cpl_table_save(res_table,NULL,NULL,res_name,CPL_IO_DEFAULT));
308 extracted = cpl_frame_new();
309 cpl_frame_set_filename(extracted, res_name);
310 cpl_frame_set_level(extracted, CPL_FRAME_LEVEL_TEMPORARY);
311 cpl_frame_set_group(extracted, CPL_FRAME_GROUP_RAW ) ;
312 cpl_frame_set_tag(extracted,
"TEST");
333int main(
int argc,
char **argv)
338 cpl_propertylist *header= NULL;
339 const char *tag =
"TELL_SLIT_ORDER2D_VIS";
340 cpl_frame* result = NULL;
343 char* rec_name =
"sym_extract2d.fits";
344 cpl_frame* rec_frame = NULL;
350 const double crpix1=1.;
351 const double crval1=533.68;
352 const double cdelt1=0.04;
354 const double crpix2=1.;
355 const double crval2=-5.3;
356 const double cdelt2=0.16;
357 cpl_image*
data=NULL;
358 cpl_image* errs=NULL;
359 cpl_image* qual=NULL;
369 const int nval=2*rad+1;
370 const float crh=10000.;
376 cpl_msg_set_level(CPL_MSG_DEBUG);
382 xsh_msg(
"argc=%d optind=%d",argc,optind);
396 data=cpl_image_new(sx,sy,CPL_TYPE_FLOAT);
398 qual=cpl_image_new(sx,sy,CPL_TYPE_INT);
399 pdata=cpl_image_get_data_float(
data);
400 pqual=cpl_image_get_data_int(qual);
403 val = cpl_malloc(nval *
sizeof(
float));
412 for (k = -rad; k <= rad; k++) {
414 for (i = 0; i < sx; i++) {
415 pdata[j * sx + i] = val[k + rad];
428 pdata[j * sx + i]=crh;
430 xsh_msg_debug(
"ingest CRH at pix[%d,%d]=pix[%g,%g]",i,j,crval1+i*cdelt1,crval2+j*cdelt2);
437 pdata[j * sx + i]=crh;
441 pdata[j * sx + i]=crh;
447 pdata[j * sx + i]=crh;
450 pdata[j * sx + i]=crh;
456 for (i = 106; i <= 116; i++) {
457 pdata[j * sx + i]=crh;
464 pdata[j * sx + i]=crh;
469 pdata[j * sx + i]=crh;
474 pdata[j * sx + i]=crh;
479 pdata[j * sx + i]=crh;
484 pdata[j * sx + i]=crh;
489 for (k = -rad; k <= rad; k++) {
492 pdata[j * sx + i] = crh;
498 for (j= 0; j < sy; j++) {
500 pdata[j * sx + i] = crh;
507 errs=cpl_image_duplicate(
data);
508 cpl_image_power(errs,0.5);
509 cpl_image_add_scalar(errs,1);
511 header=cpl_propertylist_new();
512 xsh_set_wcs(header, crpix1,crval1, cdelt1, crpix2,crval2, cdelt2);
517 rec_frame = cpl_frame_new();
519 cpl_frame_set_filename( rec_frame, rec_name) ;
521 cpl_frame_set_level( rec_frame, CPL_FRAME_LEVEL_TEMPORARY);
522 cpl_frame_set_group( rec_frame, CPL_FRAME_GROUP_RAW ) ;
523 cpl_frame_set_tag( rec_frame, tag);
548 if (cpl_error_get_code() != CPL_ERROR_NONE) {
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
#define xsh_error_dump(level)
#define XSH_ASSURE_NOT_NULL(pointer)
void xsh_instrument_set_mode(xsh_instrument *i, XSH_MODE mode)
Set a mode on instrument structure.
void xsh_instrument_set_arm(xsh_instrument *i, XSH_ARM arm)
Set an arm on instrument structure.
void xsh_instrument_set_lamp(xsh_instrument *i, XSH_LAMP lamp)
Set a lamp on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
void xsh_instrument_set_decode_bp(xsh_instrument *i, const int decode_bp)
Set bad pixel code.
#define xsh_msg_debug(...)
Print a debug message.
#define xsh_msg(...)
Print a message on info level.
void xsh_pfits_set_cd22(cpl_propertylist *plist, double value)
Write the CD2_2 value.
void xsh_pfits_set_cd21(cpl_propertylist *plist, double value)
Write the CD2_1 value.
double xsh_pfits_get_cdelt1(const cpl_propertylist *plist)
find out the cdelt1
int xsh_pfits_get_naxis1(const cpl_propertylist *plist)
find out the NAXIS1 value
double xsh_pfits_get_crval1(const cpl_propertylist *plist)
find out the crval1
void xsh_pfits_set_cd12(cpl_propertylist *plist, double value)
Write the CD1_2 value.
void xsh_pfits_set_cd11(cpl_propertylist *plist, double value)
Write the CD1_1 value.
int xsh_pfits_get_naxis2(const cpl_propertylist *plist)
find out the NAXIS2 value
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
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_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
#define TESTS_CLEAN_WORKSPACE(DRL_ID)
#define TESTS_INIT_WORKSPACE(DRL_ID)
#define TESTS_INIT(DRL_ID)
#define DECODE_BP_FLAG_DEF
#define EXTRACT_METHOD_PRINT(method)
#define XSH_FREE(POINTER)