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
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include "crires_recipe.h"
00037
00038 #include "crires_wlcalib.h"
00039
00040
00041
00042
00043
00044 #define RECIPE_STRING "crires_util_wlassign"
00045
00046
00047
00048
00049
00050 static int crires_util_wlassign_save(const cpl_table **,
00051 const cpl_parameterlist *, cpl_frameset *) ;
00052
00053 static char crires_util_wlassign_description[] =
00054 "This recipe accepts 2 parameters:\n"
00055 "First parameter: the table of the extracted spectrum in pixels\n"
00056 " (PRO TYPE = "CRIRES_PROTYPE_SPEC_PIX")\n"
00057 "Second parameter: the table with the wavelength solution(s)\n"
00058 " (PRO TYPE = "CRIRES_PROTYPE_WL_POLY")\n"
00059 "\n"
00060 "This recipe produces 1 file:\n"
00061 "First product: the table with the extracted spectrum in wavelength.\n"
00062 " (PRO TYPE = "CRIRES_PROTYPE_SPEC_WL")\n" ;
00063
00064 CRIRES_RECIPE_DEFINE(crires_util_wlassign,
00065 CRIRES_PARAM_DISPLAY,
00066 "Put the wavelength in the extracted table",
00067 crires_util_wlassign_description) ;
00068
00069
00070
00071
00072
00073 static struct {
00074
00075 int display ;
00076
00077 } crires_util_wlassign_config ;
00078
00079
00080
00081
00082
00083
00090
00091 static int crires_util_wlassign(
00092 cpl_frameset * frameset,
00093 const cpl_parameterlist * parlist)
00094 {
00095 cpl_frame * fr ;
00096 cpl_table * ext_tab[CRIRES_NB_DETECTORS] ;
00097 cpl_polynomial * wl_pol[CRIRES_NB_DETECTORS] ;
00098 cpl_table * wl_sol ;
00099 int nbrows ;
00100 double wl ;
00101 int i, j ;
00102
00103
00104 crires_util_wlassign_config.display = crires_parameterlist_get_int(parlist,
00105 RECIPE_STRING, CRIRES_PARAM_DISPLAY) ;
00106
00107
00108 if (crires_dfs_set_groups(frameset, NULL)) {
00109 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00110 return -1 ;
00111 }
00112
00113
00114 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00115 cpl_msg_info(__func__, "Wavelength assignment for chip %d", i+1) ;
00116
00117
00118 ext_tab[i] = NULL ;
00119 wl_pol[i] = NULL ;
00120
00121
00122 cpl_msg_info(__func__, "Load the table") ;
00123 cpl_msg_indent_more() ;
00124 fr = cpl_frameset_get_frame(frameset, 0);
00125 if ((ext_tab[i] = crires_load_table_check(cpl_frame_get_filename(fr),
00126 i+1, CRIRES_PROTYPE_SPEC_PIX, -1, -1, 0)) == NULL) {
00127 cpl_msg_warning(__func__, "Empty extension") ;
00128 cpl_msg_indent_less() ;
00129 continue ;
00130 }
00131 cpl_msg_indent_less() ;
00132
00133
00134 cpl_msg_info(__func__, "Wavelength retrieval") ;
00135 cpl_msg_indent_more() ;
00136 fr = cpl_frameset_get_frame(frameset, 1);
00137 if ((wl_sol = crires_load_table_check(cpl_frame_get_filename(fr), i+1,
00138 CRIRES_PROTYPE_WL_POLY, -1, -1, 0)) == NULL) {
00139 cpl_msg_error(__func__, "No wavelength solution found") ;
00140 cpl_msg_indent_less() ;
00141 for (j=0 ; j<i ; j++) {
00142 if (ext_tab[j] != NULL) cpl_table_delete(ext_tab[j]) ;
00143 }
00144 return -1 ;
00145 }
00146 cpl_msg_indent_less() ;
00147
00148
00149 cpl_msg_info(__func__, "Solution polynomial generation") ;
00150 wl_pol[i]=crires_wlcalib_gen_wlpoly(wl_sol) ;
00151 cpl_table_delete(wl_sol) ;
00152
00153
00154 cpl_msg_info(__func__, "Wavelength column computation") ;
00155 cpl_table_new_column(ext_tab[i], CRIRES_COL_WAVELENGTH,CPL_TYPE_DOUBLE);
00156 cpl_table_new_column(ext_tab[i], CRIRES_COL_WAVELENGTH_MODEL,
00157 CPL_TYPE_DOUBLE);
00158 nbrows = cpl_table_get_nrow(ext_tab[i]) ;
00159 for (j=0 ; j<nbrows ; j++) {
00160 if (wl_pol[i] != NULL) {
00161 wl = cpl_polynomial_eval_1d(wl_pol[i], (double)(j+1), NULL) ;
00162 } else {
00163 wl = 0.0 ;
00164 }
00165 cpl_table_set_double(ext_tab[i], CRIRES_COL_WAVELENGTH, j, wl);
00166 cpl_table_set_double(ext_tab[i], CRIRES_COL_WAVELENGTH_MODEL, j,
00167 0.0);
00168 }
00169 if (wl_pol[i] != NULL) cpl_polynomial_delete(wl_pol[i]) ;
00170
00171
00172 if(crires_util_wlassign_config.display == i+1) {
00173 irplib_table_plot(
00174 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Intensity OPT (ADU/sec)';",
00175 "t 'Extracted spectrum OPT' w lines", "", ext_tab[i],
00176 CRIRES_COL_WAVELENGTH, CRIRES_COL_EXTRACT_INT_OPT) ;
00177 irplib_table_plot(
00178 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Intensity RECT (ADU/sec)';",
00179 "t 'Extracted spectrum RECT' w lines", "", ext_tab[i],
00180 CRIRES_COL_WAVELENGTH, CRIRES_COL_EXTRACT_INT_RECT) ;
00181 }
00182 }
00183
00184
00185 cpl_msg_info(__func__, "Save the product") ;
00186 cpl_msg_indent_more() ;
00187 if (crires_util_wlassign_save((const cpl_table **)ext_tab, parlist,
00188 frameset)) {
00189 cpl_msg_error(__func__, "Cannot save the product") ;
00190 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00191 if (ext_tab[i] != NULL) cpl_table_delete(ext_tab[i]) ;
00192 }
00193 cpl_msg_indent_less() ;
00194 return -1 ;
00195 }
00196 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00197 if (ext_tab[i] != NULL) cpl_table_delete(ext_tab[i]) ;
00198 }
00199 cpl_msg_indent_less() ;
00200
00201
00202 if (cpl_error_get_code()) return -1 ;
00203 else return 0 ;
00204 }
00205
00206
00214
00215 static int crires_util_wlassign_save(
00216 const cpl_table ** out,
00217 const cpl_parameterlist * parlist,
00218 cpl_frameset * set)
00219 {
00220 const char * recipe_name = "crires_util_wlassign" ;
00221
00222
00223 crires_table_save(set,
00224 parlist,
00225 set,
00226 out,
00227 recipe_name,
00228 CRIRES_OBS_EXTRACT_WL_TAB,
00229 CRIRES_PROTYPE_SPEC_WL,
00230 NULL,
00231 NULL,
00232 PACKAGE "/" PACKAGE_VERSION,
00233 "crires_util_wlassign.fits") ;
00234
00235 return 0;
00236 }