36 #include "crires_recipe.h"
38 #include "crires_extract.h"
44 #define RECIPE_STRING "crires_util_profile"
50 static int crires_util_profile_save(
const cpl_table **,
51 const cpl_parameterlist *, cpl_frameset *) ;
53 static char crires_util_profile_description[] =
54 "This recipe accepts 1 parameter:\n"
55 "First parameter: the profile produced by the spectrum extraction.\n"
56 " (PRO TYPE = "CRIRES_PROTYPE_PROFILE
")\n"
58 "This recipe produces 1 file:\n"
59 "First product: the table with the FWHMs values of the profile.\n"
60 " (PRO TYPE = "CRIRES_PROTYPE_FWHM
")\n" ;
62 CRIRES_RECIPE_DEFINE(crires_util_profile,
64 "Compute the FWHM of the spectrum along lambda",
65 crires_util_profile_description) ;
76 crires_illum_period period ;
77 } crires_util_profile_config ;
91 static int crires_util_profile(
92 cpl_frameset * frameset,
93 const cpl_parameterlist * parlist)
97 cpl_imagelist * profile ;
98 cpl_propertylist * plist ;
100 cpl_table * tab[CRIRES_NB_DETECTORS] ;
101 cpl_bivector * centers_fwhms ;
106 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
112 crires_util_profile_config.display = crires_parameterlist_get_int(parlist,
113 RECIPE_STRING, CRIRES_PARAM_DISPLAY) ;
116 if (crires_dfs_set_groups(frameset, NULL)) {
117 cpl_msg_error(__func__,
"Cannot identify RAW and CALIB frames") ;
122 fr = cpl_frameset_get_position(frameset, 0);
123 crires_util_profile_config.period =
124 crires_get_detector_illum_period(cpl_frame_get_filename(fr)) ;
125 if (crires_util_profile_config.period == CRIRES_ILLUM_UNKNOWN) {
126 cpl_msg_error(__func__,
127 "Cannot determine the detector illumination period") ;
132 if ((plist=cpl_propertylist_load(cpl_frame_get_filename(fr), 0)) == NULL)
134 sval = crires_pfits_get_ncorrs(plist) ;
135 if (!strcmp(sval,
"FowlerNsampGRstWin")) {
136 crires_util_profile_config.period = CRIRES_ILLUM_FULL_DETECTOR ;
137 crires_util_profile_config.win_mode = 1 ;
139 crires_util_profile_config.win_mode = 0 ;
141 cpl_propertylist_delete(plist) ;
144 crires_display_detector_illum(crires_util_profile_config.period) ;
147 cpl_msg_info(__func__,
"Input image loading") ;
148 fname = cpl_frame_get_filename(fr) ;
149 profile = crires_load_file(fname, crires_util_profile_config.period,
153 cpl_msg_info(__func__,
"FWHM computation") ;
154 cpl_msg_indent_more() ;
155 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
157 if ((i==0 || i==CRIRES_NB_DETECTORS-1) &&
158 (crires_util_profile_config.win_mode == 1)) {
161 cpl_msg_info(__func__,
"Chip number %d", i+1) ;
162 cpl_msg_indent_more() ;
163 if ((centers_fwhms = crires_extract_spatial_fwhm(
164 cpl_imagelist_get(profile, i))) == NULL) {
165 cpl_msg_error(__func__,
166 "Cannot get the FWHM for chip number %d", i+1) ;
169 cpl_msg_indent_less() ;
173 ly = crires_get_detector_ly1(crires_util_profile_config.period) ;
175 ly = crires_get_detector_ly2(crires_util_profile_config.period) ;
177 ly = crires_get_detector_ly3(crires_util_profile_config.period) ;
179 ly = crires_get_detector_ly4(crires_util_profile_config.period) ;
182 cpl_vector_add_scalar(cpl_bivector_get_x(centers_fwhms),(
double)(ly-1));
185 if(crires_util_profile_config.display == i+1) {
187 "set grid;set xlabel 'Position (pixels)';set ylabel 'Y positions (pixels)';",
188 "t 'Y positions' w lines",
"", cpl_bivector_get_x(centers_fwhms));
190 "set grid;set xlabel 'Position (pixels)';set ylabel 'FWHM (pixels)';",
191 "t 'FWHMs' w lines",
"", cpl_bivector_get_y(centers_fwhms));
195 nbrows = cpl_image_get_size_x(cpl_imagelist_get(profile, i)) ;
196 tab[i] = cpl_table_new(nbrows) ;
197 cpl_table_new_column(tab[i], CRIRES_COL_WL_DETPOSX, CPL_TYPE_INT) ;
198 cpl_table_new_column(tab[i], CRIRES_COL_DETPOSY, CPL_TYPE_DOUBLE) ;
199 cpl_table_new_column(tab[i], CRIRES_COL_FWHM, CPL_TYPE_DOUBLE) ;
200 for (j=0 ; j<nbrows ; j++) {
201 cpl_table_set_int(tab[i], CRIRES_COL_WL_DETPOSX, j, j+1) ;
202 cpl_table_set_double(tab[i], CRIRES_COL_DETPOSY, j,
203 cpl_vector_get(cpl_bivector_get_x(centers_fwhms), j));
204 cpl_table_set_double(tab[i], CRIRES_COL_FWHM, j,
205 cpl_vector_get(cpl_bivector_get_y(centers_fwhms), j));
207 cpl_bivector_delete(centers_fwhms) ;
209 cpl_msg_indent_less() ;
210 cpl_imagelist_delete(profile) ;
213 if (crires_util_profile_config.win_mode == 1) {
214 if (tab[1] != NULL) {
215 tab[0] = cpl_table_duplicate(tab[1]) ;
216 cpl_table_set_size(tab[0], 0) ;
217 tab[CRIRES_NB_DETECTORS-1] = cpl_table_duplicate(tab[0]) ;
222 cpl_msg_info(__func__,
"Save the product") ;
223 cpl_msg_indent_more() ;
224 if (crires_util_profile_save((
const cpl_table **)tab, parlist, frameset)) {
225 cpl_msg_error(__func__,
"Cannot save the product") ;
226 cpl_msg_indent_less() ;
227 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) cpl_table_delete(tab[i]) ;
230 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) cpl_table_delete(tab[i]) ;
231 cpl_msg_indent_less() ;
234 if (cpl_error_get_code())
return -1 ;
247 static int crires_util_profile_save(
248 const cpl_table ** out,
249 const cpl_parameterlist * parlist,
252 const char * recipe_name =
"crires_util_profile" ;
255 crires_table_save(set,
264 PACKAGE
"/" PACKAGE_VERSION,
265 "crires_util_profile.fits") ;