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_extract.h"
00039
00040
00041
00042
00043
00044 #define RECIPE_STRING "crires_util_profile"
00045
00046
00047
00048
00049
00050 static int crires_util_profile_save(const cpl_table **,
00051 const cpl_parameterlist *, cpl_frameset *) ;
00052
00053 static char crires_util_profile_description[] =
00054 "This recipe accepts 1 parameter:\n"
00055 "First parameter: the profile produced by the spectrum extraction.\n"
00056 " (PRO TYPE = "CRIRES_PROTYPE_PROFILE")\n"
00057 "\n"
00058 "This recipe produces 1 file:\n"
00059 "First product: the table with the FWHMs values of the profile.\n"
00060 " (PRO TYPE = "CRIRES_PROTYPE_FWHM")\n" ;
00061
00062 CRIRES_RECIPE_DEFINE(crires_util_profile,
00063 CRIRES_PARAM_DISPLAY,
00064 "Compute the FWHM of the spectrum along lambda",
00065 crires_util_profile_description) ;
00066
00067
00068
00069
00070
00071 static struct {
00072
00073 int display ;
00074
00075 crires_illum_period period ;
00076 } crires_util_profile_config ;
00077
00078
00079
00080
00081
00082
00089
00090 static int crires_util_profile(
00091 cpl_frameset * frameset,
00092 const cpl_parameterlist * parlist)
00093 {
00094 cpl_frame * fr ;
00095 const char * fname ;
00096 cpl_imagelist * profile ;
00097 cpl_table * tab[CRIRES_NB_DETECTORS] ;
00098 cpl_bivector * centers_fwhms ;
00099 int nbrows ;
00100 int ly ;
00101 int i, j ;
00102
00103
00104 ly = -1 ;
00105
00106
00107 crires_util_profile_config.display = crires_parameterlist_get_int(parlist,
00108 RECIPE_STRING, CRIRES_PARAM_DISPLAY) ;
00109
00110
00111 if (crires_dfs_set_groups(frameset, NULL)) {
00112 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00113 return -1 ;
00114 }
00115
00116
00117 fr = cpl_frameset_get_frame(frameset, 0);
00118 crires_util_profile_config.period =
00119 crires_get_detector_illum_period(cpl_frame_get_filename(fr)) ;
00120 if (crires_util_profile_config.period == CRIRES_ILLUM_UNKNOWN) {
00121 cpl_msg_error(__func__,
00122 "Cannot determine the detector illumination period") ;
00123 return -1 ;
00124 } else {
00125 crires_display_detector_illum(crires_util_profile_config.period) ;
00126 }
00127
00128
00129 cpl_msg_info(__func__, "Input image loading") ;
00130 fname = cpl_frame_get_filename(fr) ;
00131 profile = crires_load_file(fname, crires_util_profile_config.period,
00132 CPL_TYPE_FLOAT) ;
00133
00134
00135 cpl_msg_info(__func__, "FWHM computation") ;
00136 cpl_msg_indent_more() ;
00137 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00138 cpl_msg_info(__func__, "Chip number %d", i+1) ;
00139 cpl_msg_indent_more() ;
00140 if ((centers_fwhms = crires_extract_spatial_fwhm(
00141 cpl_imagelist_get(profile, i))) == NULL) {
00142 cpl_msg_error(__func__,
00143 "Cannot get the FWHM for chip number %d", i+1) ;
00144 cpl_msg_indent_less() ;
00145 cpl_imagelist_delete(profile) ;
00146 for (j=0 ; j<i ; j++) cpl_table_delete(tab[j]) ;
00147 return -1 ;
00148 }
00149 cpl_msg_indent_less() ;
00150
00151
00152 if (i+1 == 1)
00153 ly = crires_get_detector_ly1(crires_util_profile_config.period) ;
00154 if (i+1 == 2)
00155 ly = crires_get_detector_ly2(crires_util_profile_config.period) ;
00156 if (i+1 == 3)
00157 ly = crires_get_detector_ly3(crires_util_profile_config.period) ;
00158 if (i+1 == 4)
00159 ly = crires_get_detector_ly4(crires_util_profile_config.period) ;
00160 cpl_vector_add_scalar(cpl_bivector_get_x(centers_fwhms), (double)ly) ;
00161
00162
00163 if(crires_util_profile_config.display == i+1) {
00164 irplib_vector_plot(
00165 "set grid;set xlabel 'Position (pixels)';set ylabel 'Y positions (pixels)';",
00166 "t 'Y positions' w lines", "", cpl_bivector_get_x(centers_fwhms));
00167 irplib_vector_plot(
00168 "set grid;set xlabel 'Position (pixels)';set ylabel 'FWHM (pixels)';",
00169 "t 'FWHMs' w lines", "", cpl_bivector_get_y(centers_fwhms));
00170 }
00171
00172
00173 nbrows = cpl_bivector_get_size(centers_fwhms) ;
00174 tab[i] = cpl_table_new(nbrows) ;
00175 cpl_table_new_column(tab[i], CRIRES_COL_WL_DETPOSX, CPL_TYPE_INT) ;
00176 cpl_table_new_column(tab[i], CRIRES_COL_DETPOSY, CPL_TYPE_DOUBLE) ;
00177 cpl_table_new_column(tab[i], CRIRES_COL_FWHM, CPL_TYPE_DOUBLE) ;
00178 for (j=0 ; j<nbrows ; j++) {
00179 cpl_table_set_int(tab[i], CRIRES_COL_WL_DETPOSX, j, j+1) ;
00180 cpl_table_set_double(tab[i], CRIRES_COL_DETPOSY, j,
00181 cpl_vector_get(cpl_bivector_get_x(centers_fwhms), j));
00182 cpl_table_set_double(tab[i], CRIRES_COL_FWHM, j,
00183 cpl_vector_get(cpl_bivector_get_y(centers_fwhms), j));
00184 }
00185 cpl_bivector_delete(centers_fwhms) ;
00186 }
00187 cpl_msg_indent_less() ;
00188
00189
00190 cpl_msg_info(__func__, "Save the product") ;
00191 cpl_msg_indent_more() ;
00192 if (crires_util_profile_save((const cpl_table **)tab, parlist, frameset)) {
00193 cpl_msg_error(__func__, "Cannot save the product") ;
00194 cpl_msg_indent_less() ;
00195 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) cpl_table_delete(tab[i]) ;
00196 return -1 ;
00197 }
00198 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) cpl_table_delete(tab[i]) ;
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_profile_save(
00216 const cpl_table ** out,
00217 const cpl_parameterlist * parlist,
00218 cpl_frameset * set)
00219 {
00220 const char * recipe_name = "crires_util_profile" ;
00221
00222
00223 crires_table_save(set,
00224 parlist,
00225 set,
00226 out,
00227 recipe_name,
00228 CRIRES_FWHM_TAB,
00229 CRIRES_PROTYPE_FWHM,
00230 NULL,
00231 NULL,
00232 PACKAGE "/" PACKAGE_VERSION,
00233 "crires_util_profile.fits") ;
00234
00235 return 0;
00236 }