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
00035
00038
00039
00040
00041
00042 #include <tests.h>
00043
00044 #include <xsh_data_pre.h>
00045 #include <xsh_data_order.h>
00046 #include <xsh_data_wavesol.h>
00047 #include <xsh_data_spectralformat.h>
00048 #include <xsh_error.h>
00049 #include <xsh_msg.h>
00050 #include <xsh_data_instrument.h>
00051 #include <xsh_drl.h>
00052 #include <xsh_pfits.h>
00053
00054
00055 #include <cpl.h>
00056 #include <math.h>
00057
00058
00059
00060
00061
00062 #define MODULE_ID "XSH_DATA_WAVEMAP"
00063
00064 #define SYNTAX "Test the wavemap (work only for vis for now)\n"\
00065 "use : ./test_xsh_data_wavemap [OPTIONS] ORDER_TAB WAVESOL WAVEMAP"\
00066 " SPECTRALFORMAT\n"\
00067 "ORDER_TAB => the order table\n"\
00068 "WAVESOL => the wavesolution table\n"\
00069 "WAVEMAP => the wavemap frame\n"\
00070 "SPECTRALFORMAT => the spectral format table\n"
00071
00072
00073
00074
00075
00083 int main( int argc, char **argv)
00084 {
00085
00086 int ret = 0 ;
00087 xsh_instrument* instrument = NULL;
00088 XSH_INSTRCONFIG* iconfig = NULL;
00089
00090 char* order_tab_name = NULL;
00091 char* wavesol_name = NULL;
00092 char* wavemap_name = NULL;
00093 char* spectralformat_name = NULL;
00094
00095 cpl_frame *order_tab_frame = NULL;
00096 cpl_frame *wavesol_frame = NULL;
00097 cpl_frame *wavemap_frame = NULL;
00098 cpl_frame *spectralformat_frame = NULL;
00099
00100
00101
00102 TESTS_INIT( MODULE_ID);
00103 cpl_msg_set_level( CPL_MSG_DEBUG);
00104 xsh_debug_level_set( XSH_DEBUG_LEVEL_MEDIUM);
00105
00106
00107 if ( (argc ) >= 4 ) {
00108 order_tab_name = argv[1];
00109 wavesol_name = argv[2];
00110 wavemap_name = argv[3];
00111 spectralformat_name = argv[4];
00112 }
00113 else{
00114 printf(SYNTAX);
00115 exit(0);
00116 }
00117 xsh_msg(" order tab frame name %s",order_tab_name);
00118 xsh_msg(" wave sol frame name %s", wavesol_name);
00119 xsh_msg(" wave map frame name %s",wavemap_name);
00120 xsh_msg(" spectral format frame name %s",spectralformat_name);
00121
00122 TESTS_XSH_FRAME_CREATE( order_tab_frame, "ORDER_TAB_EDGES_arm",
00123 order_tab_name);
00124 TESTS_XSH_FRAME_CREATE( wavesol_frame, "WAVE_TAB_2D_arm", wavesol_name);
00125 TESTS_XSH_FRAME_CREATE( wavemap_frame, "WAVE_MAP_arm", wavemap_name);
00126 TESTS_XSH_FRAME_CREATE( spectralformat_frame, "SPECTRAL_FORMAT_TAB_arm",
00127 spectralformat_name);
00128
00129
00130 instrument = xsh_instrument_new() ;
00131
00132 instrument = xsh_instrument_new();
00133 xsh_instrument_set_arm( instrument, XSH_ARM_VIS);
00134
00135 xsh_instrument_set_mode( instrument, XSH_MODE_SLIT ) ;
00136 xsh_instrument_set_lamp( instrument, XSH_LAMP_QTH_D2) ;
00137 iconfig = xsh_instrument_get_config( instrument);
00138
00139
00140 {
00141 cpl_image* wavemap = NULL;
00142 float * wavemap_data = NULL;
00143 int nx, ny;
00144 xsh_order_list *order_list= NULL;
00145 xsh_wavesol *wavesol = NULL;
00146 xsh_spectralformat_list *spectralformat_list= NULL;
00147 int iorder=0, nblines=0;
00148 cpl_table *table = NULL;
00149
00150 check( wavemap = cpl_image_load( cpl_frame_get_filename( wavemap_frame),
00151 CPL_TYPE_FLOAT, 0, 0));
00152 check (nx = cpl_image_get_size_x( wavemap));
00153 check (ny = cpl_image_get_size_y( wavemap));
00154 check( wavemap_data = cpl_image_get_data_float( wavemap));
00155 check( order_list = xsh_order_list_load( order_tab_frame, instrument));
00156 check( wavesol = xsh_wavesol_load( wavesol_frame, instrument ));
00157 check( table = cpl_table_new( 6));
00158 XSH_TABLE_NEW_COL(table, "absorder", "",CPL_TYPE_INT);
00159 XSH_TABLE_NEW_COL(table, "wavelength", "",CPL_TYPE_DOUBLE);
00160 XSH_TABLE_NEW_COL(table, "wavemap_x", "",CPL_TYPE_DOUBLE);
00161 XSH_TABLE_NEW_COL(table, "wavemap_y", "",CPL_TYPE_DOUBLE);
00162 XSH_TABLE_NEW_COL(table, "wavesol_x", "",CPL_TYPE_DOUBLE);
00163 XSH_TABLE_NEW_COL(table, "wavesol_y", "",CPL_TYPE_DOUBLE);
00164 check(cpl_table_set_size( table, order_list->size*ny));
00165
00166 for( iorder= 0; iorder < order_list->size; iorder++) {
00167 int abs_order, start_y, end_y, y;
00168
00169 abs_order = order_list->list[iorder].absorder;
00170 check( start_y = xsh_order_list_get_starty( order_list, iorder));
00171 check( end_y = xsh_order_list_get_endy( order_list, iorder));
00172
00173 for(y=start_y; y < end_y; y++){
00174 double x, x_center, y_center;
00175 int int_x;
00176 double lambda_wavemap;
00177
00178 check( x= cpl_polynomial_eval_1d( order_list->list[iorder].cenpoly,
00179 y, NULL));
00180 int_x = floor(x);
00181 lambda_wavemap = wavemap_data[int_x+y*nx];
00182 check( x_center = xsh_wavesol_eval_polx( wavesol, lambda_wavemap, abs_order,
00183 0.0));
00184 check( y_center = xsh_wavesol_eval_poly( wavesol, lambda_wavemap, abs_order,
00185 0.0));
00186 check(cpl_table_set_int(table, "absorder", nblines, abs_order));
00187 check(cpl_table_set_double(table, "wavelength", nblines, lambda_wavemap));
00188 check(cpl_table_set_double(table, "wavemap_x", nblines, int_x));
00189 check(cpl_table_set_double(table, "wavemap_y", nblines, y));
00190 check(cpl_table_set_double(table, "wavesol_x", nblines, x_center));
00191 check(cpl_table_set_double(table, "wavesol_y", nblines, y_center));
00192 nblines++;
00193 }
00194 }
00195 check( cpl_table_save(table, NULL, NULL, "result.fits", CPL_IO_DEFAULT));
00196 }
00197 cleanup:
00198 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00199 xsh_error_dump(CPL_MSG_ERROR);
00200 return 1;
00201 }
00202 else return ret ;
00203 }
00204