00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030
00036
00039
00040
00041
00042
00043
00044 #include <xsh_data_pre.h>
00045 #include <xsh_error.h>
00046 #include <xsh_msg.h>
00047 #include <xsh_data_instrument.h>
00048 #include <xsh_parameters.h>
00049 #include <xsh_dfs.h>
00050 #include <xsh_pfits.h>
00051 #include <tests.h>
00052 #include <cpl.h>
00053 #include <math.h>
00054 #include <string.h>
00055
00056
00057
00058
00059 #define MODULE_ID "XSH_CREATE_MASTER_BIAS"
00060
00061
00062
00063
00064
00071
00072
00073 int main(void)
00074 {
00075 xsh_instrument* instrument = NULL;
00076 cpl_frame* frame = NULL;
00077 cpl_frame* med_frame = NULL;
00078 cpl_frame* mbias = NULL;
00079 cpl_frameset* set = NULL;
00080 xsh_pre* pre = NULL;
00081 float mean = 0.0,median = 0.0, stdev = 0.0;
00082 xsh_clipping_param crh_clipping = {4, 2, 0.7, 0};
00083 xsh_hot_cold_pix_param hp_clip_param = {3.0, 3.0, 3};
00084 xsh_fpn_param fpn_param = {-1,-1,-1,-1,4,10};
00085 xsh_ron_param ron_param = {"ALL",
00086 4,100,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,25};
00087 xsh_struct_param struct_param = {-1,-1};
00088 cpl_parameterlist* parameters=NULL;
00089 const char* RECIPE_ID="xsh_mbias";
00090
00091
00092
00093
00094 TESTS_INIT(MODULE_ID);
00095
00096
00097 instrument = xsh_instrument_new() ;
00098 xsh_instrument_set_mode( instrument, XSH_MODE_IFU ) ;
00099 xsh_instrument_set_arm( instrument, XSH_ARM_UVB ) ;
00100 xsh_instrument_set_lamp( instrument, XSH_LAMP_QTH ) ;
00101 xsh_instrument_set_recipe_id(instrument, "xsh_mbias");
00102
00103
00104 frame = xsh_test_create_frame("frame.fits",10,10,
00105 XSH_LINEARITY_UVB,CPL_FRAME_GROUP_RAW, instrument);
00106 set = cpl_frameset_new();
00107 cpl_frameset_insert(set,frame);
00108
00109
00110
00111 parameters = cpl_parameterlist_new();
00112 check(xsh_parameters_generic( RECIPE_ID, parameters ));
00113
00114
00115 check(xsh_parameters_clipping_crh_create(RECIPE_ID,parameters,crh_clipping));
00116
00117 check(xsh_parameters_hot_cold_pix_create(RECIPE_ID,parameters,hp_clip_param));
00118
00119
00120 check(xsh_parameters_fpn_create(RECIPE_ID,parameters,fpn_param));
00121 check(xsh_parameters_ron_create(RECIPE_ID,parameters,ron_param));
00122 check(xsh_parameters_struct_create(RECIPE_ID,parameters,struct_param));
00123
00124
00125
00126
00127 check(xsh_prepare(set,NULL, NULL, "PRE",instrument,0));
00128
00129
00130 check (med_frame = xsh_remove_crh_multiple( set, "remove_crh.fits",
00131 &crh_clipping, instrument,
00132 NULL,NULL ));
00133
00134 check(mbias = xsh_create_master_bias(set,med_frame,instrument,parameters));
00135
00136
00137 check(pre = xsh_pre_load(mbias,instrument));
00138
00139
00140 assure( strcmp(xsh_pfits_get_pcatg(pre->data_header),"MASTER_BIAS_UVB")
00141 == 0,CPL_ERROR_ILLEGAL_OUTPUT,"Wrong pcatg keyword");
00142
00143 check(mean = xsh_pfits_get_qc_mbiasavg (pre->data_header));
00144 check(median = xsh_pfits_get_qc_mbiasmed(pre->data_header));
00145 check(stdev = xsh_pfits_get_qc_mbiasrms (pre->data_header));
00146
00147 assure( mean - cpl_image_get_mean(pre->data) < XSH_FLOAT_PRECISION,
00148 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong mean value in QC");
00149 assure( median - cpl_image_get_median(pre->data) < XSH_FLOAT_PRECISION,
00150 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong median value in QC");
00151 assure( stdev - cpl_image_get_stdev(pre->data) < XSH_FLOAT_PRECISION,
00152 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong rms value in QC");
00153 xsh_msg("header is ok");
00154
00155
00156 assure(cpl_frame_get_group(mbias) == CPL_FRAME_GROUP_CALIB,
00157 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong group for MASTER BIAS frame");
00158 assure(strcmp(cpl_frame_get_tag(mbias),XSH_MASTER_BIAS_UVB) == 0,
00159 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong tag (%s) for MASTER BIAS frame ",
00160 cpl_frame_get_tag(mbias));
00161 xsh_msg("frame is ok");
00162 cleanup:
00163 xsh_free_parameterlist(¶meters);
00164 xsh_free_frame(&med_frame);
00165 xsh_pre_free(&pre);
00166 xsh_free_frameset(&set);
00167 xsh_free_frame(&mbias);
00168 xsh_instrument_free(&instrument);
00169 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00170 xsh_error_dump(CPL_MSG_ERROR);
00171 return 1;
00172 } else {
00173 return 0;
00174 }
00175 }
00176