59#define MODULE_ID "XSH_DATA_PRE"
61#define SYNTAX "Test the pre frame\n"\
62 "use : ./test_xsh_data_pre PRE \n"\
63 "PRE => the pre frame\n"
73int main(
int argc,
char** argv)
77 char *pre_name = NULL;
78 cpl_frame *pre_frame = NULL;
81 cpl_propertylist* header = NULL;
83 cpl_image *errs_img = NULL;
84 cpl_image* qual_img = NULL;
87 FILE* pre_file = NULL;
89 double data_mean=0.0, data_stdev=0.0, data_median=0.0;
94 cpl_msg_set_level( CPL_MSG_DEBUG);
108 check (header = cpl_propertylist_load( pre_name, 0));
115 if ( naxis1 == (2048/
binx) ){
118 else if (naxis1 == (2044/
binx) ){
121 else if (naxis1 == (1024/
binx) ){
125 xsh_msg(
" Invalid naxis1 size %d", naxis1);
131 pre_frame = cpl_frame_new();
132 cpl_frame_set_filename( pre_frame, pre_name) ;
133 cpl_frame_set_level( pre_frame, CPL_FRAME_LEVEL_TEMPORARY);
134 cpl_frame_set_group( pre_frame, CPL_FRAME_GROUP_RAW );
135 cpl_frame_set_tag( pre_frame,
"BIAS_UVB");
143 xsh_msg(
"find max at %d %d",a,b);
147 xsh_msg(
" Statistics on DATA: median %f mean %f stdev %f",
148 data_median, data_mean, data_stdev);
152 check ( qual = cpl_image_get_data_int( qual_img));
153 xsh_msg(
"Save order tab in BADPIXEL.reg");
154 pre_file = fopen(
"BADPIXEL.reg",
"w");
155 fprintf( pre_file,
"# Region file format: DS9 version 4.0\n"\
156 "global color=red font=\"helvetica 4 normal\""\
157 "select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 "\
160 for(j=0; j< pre->
ny; j++){
161 for(i=0; i<pre->
nx; i++){
163 fprintf( pre_file,
"point(%f,%f) #point=cross color=red font="\
164 "\"helvetica 4 normal\"\n", i+1.0, j+1.0);
166 else if ( (qual[i+j*pre->
nx] & 16) == 16){
167 fprintf( pre_file,
"point(%f,%f) #point=cross color=green font="\
168 "\"helvetica 4 normal\"\n", i+1.0, j+1.0);
180 if (cpl_error_get_code() != CPL_ERROR_NONE) {
193 xsh_msg(
"Create PRE %s OK",dataname);
197 xsh_msg(
"Save PRE %s OK",pre_name);
201 cpl_frame_set_group(preframe,CPL_FRAME_GROUP_RAW);
205 xsh_msg(
"Load PRE %s OK",dataname);
209 "Can't find conad in header");
211 "Can't find ron in header");
217 "wrong nx in PRE format");
219 "wrong ny in PRE format");
221 CPL_ERROR_ILLEGAL_OUTPUT,
"wrong group in PRE format");
222 assure(pre2->data != NULL,CPL_ERROR_ILLEGAL_OUTPUT,
224 assure(pre2->errs != NULL,CPL_ERROR_ILLEGAL_OUTPUT,
226 assure(pre2->qual != NULL,CPL_ERROR_ILLEGAL_OUTPUT,
232 tdata = cpl_image_get_data_float(pre2->data);
233 terrs = cpl_image_get_data_float(pre2->errs);
234 for(i = 0; i <
nx *
ny; i++){
236 CPL_ERROR_ILLEGAL_OUTPUT,
"WRONG errs part");
248 xsh_msg(
"avg residual = %f ; avg uncertainty = %f",
249 avg_residual, avg_err);
251 assure(avg_residual <= avg_err, CPL_ERROR_ILLEGAL_OUTPUT,
252 "Residual is not zero");
256 tdata = cpl_image_get_data_float(residual->data);
257 terrs = cpl_image_get_data_float(residual->errs);
258 tqual = cpl_image_get_data_int(residual->qual);
259 tdata1 = cpl_image_get_data_float(pre2->data);
260 terrs1 = cpl_image_get_data_float(pre2->errs);
261 tqual1 = cpl_image_get_data_int(pre2->qual);
262 tdata2 = cpl_image_get_data_float(pre3->data);
263 terrs2 = cpl_image_get_data_float(pre3->errs);
264 tqual2 = cpl_image_get_data_int(pre3->qual);
265 for (i = 0; i <
nx *
ny; i++) {
266 assure(tdata[i] <= terrs[i],CPL_ERROR_ILLEGAL_OUTPUT,
267 "Residual is non-zero at %d : ",i);
268 assure(terrs[i] -(sqrt(pow(terrs1[i],2)+pow(terrs2[i],2))) <
270 CPL_ERROR_ILLEGAL_OUTPUT,
271 "Wrong errs at %d : ",i);
272 assure(tqual[i] == (tqual1[i]+tqual2[i]),CPL_ERROR_ILLEGAL_OUTPUT,
275 xsh_msg(
"subtract two PRE OK");
280 tdata = cpl_image_get_data_float(addtest->data);
281 terrs = cpl_image_get_data_float(addtest->errs);
282 tqual = cpl_image_get_data_int(addtest->qual);
283 tdata1 = cpl_image_get_data_float(pre2->data);
284 terrs1 = cpl_image_get_data_float(pre2->errs);
285 tqual1 = cpl_image_get_data_int(pre2->qual);
286 tdata2 = cpl_image_get_data_float(pre3->data);
287 terrs2 = cpl_image_get_data_float(pre3->errs);
288 tqual2 = cpl_image_get_data_int(pre3->qual);
290 for (i = 0; i <
nx *
ny; i++) {
292 CPL_ERROR_ILLEGAL_OUTPUT,
293 "Wrong data at %d : ",i);
294 assure(terrs[i] -(sqrt(pow(terrs1[i],2)+pow(terrs2[i],2))) <
296 CPL_ERROR_ILLEGAL_OUTPUT,
297 "Wrong errs at %d : ",i);
298 assure(tqual[i] == (tqual1[i]+tqual2[i]),CPL_ERROR_ILLEGAL_OUTPUT,
313 if (cpl_error_get_code() != CPL_ERROR_NONE) {
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
cpl_frame * xsh_test_create_frame(const char *name, int nx, int ny, const char *tag, cpl_frame_group group, xsh_instrument *instrument)
void xsh_pre_add(xsh_pre *self, const xsh_pre *right)
Add two PRE images.
cpl_image * xsh_pre_get_data(xsh_pre *pre)
Get data.
xsh_pre * xsh_pre_duplicate(const xsh_pre *pre)
Copy a PRE structure.
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
cpl_frame_group xsh_pre_get_group(const xsh_pre *pre)
Get ny of pre structure.
cpl_image * xsh_pre_get_qual(xsh_pre *pre)
Get qual.
int xsh_pre_get_ny(const xsh_pre *pre)
Get ny of pre structure.
int xsh_pre_window_best_median_flux_pos(xsh_pre *pre, int xcen, int ycen, int search_window_hsize, int running_median_hsize, int *xadj, int *yadj)
Search pixel position of best running median flux in the search window.
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
xsh_pre * xsh_pre_create(cpl_frame *raw, cpl_frame *bpmap, cpl_image *bias_data, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
Create a XSH_PRE from a raw frame.
int xsh_pre_get_nx(const xsh_pre *pre)
Get nx of pre structure.
void xsh_pre_subtract(xsh_pre *self, const xsh_pre *right)
Subtract one PRE image from another The data units are subtracted data = data1 - data2 The error imag...
cpl_image * xsh_pre_get_errs(xsh_pre *pre)
Get errs.
cpl_frame * xsh_pre_save(const xsh_pre *pre, const char *filename, const char *tag, int temp)
Save PRE on disk.
void xsh_pre_median_mean_stdev(xsh_pre *preFrame, double *mean, double *median, double *stdev)
#define assure(CONDITION, ERROR_CODE,...)
#define xsh_error_dump(level)
#define check_msg(COMMAND,...)
#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
#define xsh_msg(...)
Print a message on info level.
double xsh_pfits_get_conad(const cpl_propertylist *plist)
find out the CONAD value
int xsh_pfits_get_binx(const cpl_propertylist *plist)
find out the BINX value
double xsh_pfits_get_ron(const cpl_propertylist *plist)
find out the RON value
int xsh_pfits_get_naxis1(const cpl_propertylist *plist)
find out the NAXIS1 value
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.
#define XSH_FLOAT_PRECISION
#define TESTS_INIT(DRL_ID)
#define XSH_GOOD_PIXEL_LEVEL
#define XSH_LINEARITY_UVB