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 #include <tests.h>
00044
00045 #include <xsh_data_pre.h>
00046 #include <xsh_error.h>
00047 #include <xsh_msg.h>
00048 #include <xsh_data_instrument.h>
00049 #include <xsh_data_resid_tab.h>
00050 #include <xsh_drl.h>
00051 #include <xsh_pfits.h>
00052
00053 #include <cpl.h>
00054 #include <math.h>
00055
00056 #include <getopt.h>
00057
00058
00059
00060
00061
00062 #define MODULE_ID "XSH_RESID_TAB"
00063 #define SYNTAX "Test the residual tab\n"\
00064 "use : ./the_xsh_resid_tab RESID_TAB \n"\
00065 "RESID_TAB => the residual table\n"
00066
00067
00068
00069
00070
00071
00079 int main( int argc, char **argv)
00080 {
00081
00082 int ret = 0 ;
00083 xsh_instrument* instrument = NULL;
00084
00085 char* resid_tab_name = NULL;
00086 const char* extracted_tab_name = "redid_not_flagged.fits";
00087 cpl_frame* resid_tab_frame = NULL;
00088 xsh_resid_tab* resid_tab = NULL;
00089 int resid_tab_size = 0;
00090 cpl_table* tab_flagged=NULL;
00091 cpl_table* tab_extract=NULL;
00092 cpl_propertylist* plist=NULL;
00093 int i = 0;
00094 FILE* resid_tab_the_file = NULL;
00095
00096
00097 TESTS_INIT(MODULE_ID);
00098
00099 cpl_msg_set_level(CPL_MSG_DEBUG);
00100 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM) ;
00101
00102
00103 if (argc > 1){
00104 resid_tab_name = argv[1];
00105 }
00106 else{
00107 printf(SYNTAX);
00108 TEST_END();
00109 return 0;
00110 }
00111
00112
00113 instrument = xsh_instrument_new() ;
00114 xsh_instrument_set_mode( instrument, XSH_MODE_IFU );
00115 xsh_instrument_set_arm( instrument, XSH_ARM_VIS);
00116
00117
00118 XSH_ASSURE_NOT_NULL( resid_tab_name);
00119 tab_flagged=cpl_table_load(resid_tab_name,1,0);
00120 plist=cpl_propertylist_load(resid_tab_name,0);
00121 cpl_table_and_selected_int(tab_flagged,"Flag",CPL_EQUAL_TO,0);
00122 tab_extract=cpl_table_extract_selected(tab_flagged);
00123 cpl_table_erase_column(tab_extract,"Flag");
00124 cpl_table_save(tab_extract,plist,NULL,extracted_tab_name,CPL_IO_DEFAULT);
00125
00126
00127 resid_tab_frame = cpl_frame_new();
00128 cpl_frame_set_filename( resid_tab_frame, extracted_tab_name) ;
00129 cpl_frame_set_level( resid_tab_frame, CPL_FRAME_LEVEL_TEMPORARY);
00130 cpl_frame_set_group( resid_tab_frame, CPL_FRAME_GROUP_RAW ) ;
00131
00132 check( resid_tab = xsh_resid_tab_load( resid_tab_frame));
00133 check( resid_tab_size = xsh_resid_tab_get_size( resid_tab));
00134
00135
00136 xsh_msg("Save residual tab in RESID_TAB.reg");
00137 resid_tab_the_file = fopen( "RESID_TAB.reg", "w");
00138
00139 fprintf( resid_tab_the_file, "# Region file format: DS9 version 4.0\n"\
00140 "global color=red font=\"helvetica 10 normal\""\
00141 "select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 "\
00142 "source\nimage\n");
00143 fprintf( resid_tab_the_file, "# RED the_x the_y (pixels)\n"\
00144 "# MAGENTA corr_x corr_y (pixels)\n"\
00145 "# GREEN gauss_x gauss_y (pixels)\n"\
00146 "# BLUE poly_x poly_y (pixels)\n");
00147
00148 if (resid_tab->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY){
00149 xsh_msg("Residual tab compute from POLYNOMIAL");
00150 }
00151 else{
00152 xsh_msg("Residual tab compute from PHYSICAL MODEL");
00153 }
00154 for( i=0; i<resid_tab_size; i++){
00155 double the_x, the_y;
00156 double corr_x, corr_y;
00157 double gauss_x, gauss_y;
00158 double poly_x, poly_y;
00159 double lambda;
00160
00161 lambda = resid_tab->lambda[i];
00162 the_x = resid_tab->thpre_x[i];
00163 the_y = resid_tab->thpre_y[i];
00164 corr_x = resid_tab->thcor_x[i];
00165 corr_y = resid_tab->thcor_y[i];
00166 gauss_x = resid_tab->xgauss[i];
00167 gauss_y = resid_tab->ygauss[i];
00168 if (resid_tab->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY){
00169 poly_x = resid_tab->xpoly[i];
00170 poly_y = resid_tab->ypoly[i];
00171 }
00172 else{
00173 poly_x = resid_tab->thanneal_x[i];
00174 poly_y = resid_tab->thanneal_y[i];
00175 }
00176 fprintf( resid_tab_the_file, "point(%f,%f) #point=cross color=red text={THE %.3f} font="\
00177 "\"helvetica 10 normal\"\n", the_x, the_y, lambda);
00178 fprintf( resid_tab_the_file, "point(%f,%f) #point=diamond color=magenta font="\
00179 "\"helvetica 4 normal\"\n", corr_x, corr_y);
00180 fprintf( resid_tab_the_file, "point(%f,%f) #point=circle color=green font="\
00181 "\"helvetica 4 normal\"\n", gauss_x, gauss_y);
00182 fprintf( resid_tab_the_file, "point(%f,%f) #point=x color=blue font="\
00183 "\"helvetica 4 normal\"\n", poly_x, poly_y);
00184 }
00185 fclose( resid_tab_the_file);
00186 xsh_msg( "Save residual tab in RESID_TAB.dat");
00187 check( xsh_resid_tab_log( resid_tab, "RESID_TAB.dat"));
00188
00189 cleanup:
00190 xsh_instrument_free( &instrument);
00191 xsh_free_frame (&resid_tab_frame);
00192 xsh_resid_tab_free( &resid_tab);
00193 xsh_free_table(&tab_extract);
00194 xsh_free_propertylist(&plist);
00195
00196 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00197 xsh_error_dump(CPL_MSG_ERROR);
00198 ret = 1;
00199 }
00200 TEST_END();
00201 return ret ;
00202 }
00203