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