34#include "cr2res_utils.h"
35#include "cr2res_pfits.h"
36#include "cr2res_dfs.h"
38#include "cr2res_trace.h"
39#include "cr2res_wave.h"
40#include "cr2res_slit_curv.h"
46#define RECIPE_STRING "cr2res_util_trace_map"
52int cpl_plugin_get_info(cpl_pluginlist * list);
58static int cr2res_util_trace_map_create(cpl_plugin *);
59static int cr2res_util_trace_map_exec(cpl_plugin *);
60static int cr2res_util_trace_map_destroy(cpl_plugin *);
61static int cr2res_util_trace_map(cpl_frameset *,
const cpl_parameterlist *);
67static char cr2res_util_trace_map_description[] =
"\
69 Each input TRACE_WAVE file is converted into maps to visualize the \n\
70 traces, wavelengths and the slit curvature \n\
73 raw.fits " CR2RES_TW_DRSTYPE
" [1 to n] \n\
76 <input_name>_slit_curve.fits "
77 CR2RES_UTIL_TRACE_MAP_SLIT_CURVE_PROCATG
"\n\
78 <input_name>_wave.fits "
79 CR2RES_UTIL_TRACE_MAP_WL_PROCATG
"\n\
80 <input_name>_trace.fits "
81 CR2RES_UTIL_TRACE_MAP_TRACE_PROCATG
"\n\
84 loop on input raw frames f: \n\
85 loop on detectors d: \n\
86 Load the trace_wave extension \n\
87 Call cr2res_wave_gen_wave_map() to generate wave_map(d) \n\
88 Call cr2res_trace_gen_image() to generate traces_map(d) \n\
89 Call cr2res_slit_curv_gen_map() to generate slit_curv_map(d) \n\
90 Save wave_map, traces_map and slit_curv_map \n\
92 Library Functions used \n\
93 cr2res_io_load_TRACE_WAVE() \n\
94 cr2res_trace_gen_image() \n\
95 cr2res_slit_curv_gen_map() \n\
96 cr2res_io_save_SLIT_CURV_MAP() \n\
97 cr2res_io_save_WAVE_MAP() \n\
98 cr2res_io_save_TRACE_MAP() \n\
116int cpl_plugin_get_info(cpl_pluginlist * list)
118 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
119 cpl_plugin * plugin = &recipe->interface;
121 if (cpl_plugin_init(plugin,
123 CR2RES_BINARY_VERSION,
124 CPL_PLUGIN_TYPE_RECIPE,
126 "TRACE_WAVE maps creation",
127 cr2res_util_trace_map_description,
128 CR2RES_PIPELINE_AUTHORS,
131 cr2res_util_trace_map_create,
132 cr2res_util_trace_map_exec,
133 cr2res_util_trace_map_destroy)) {
134 cpl_msg_error(cpl_func,
"Plugin initialization failed");
135 (void)cpl_error_set_where(cpl_func);
139 if (cpl_pluginlist_append(list, plugin)) {
140 cpl_msg_error(cpl_func,
"Error adding plugin to list");
141 (void)cpl_error_set_where(cpl_func);
157static int cr2res_util_trace_map_create(cpl_plugin * plugin)
163 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
164 recipe = (cpl_recipe *)plugin;
169 recipe->parameters = cpl_parameterlist_new();
172 p = cpl_parameter_new_value(
"cr2res.cr2res_util_trace_map.detector",
173 CPL_TYPE_INT,
"Only reduce the specified detector",
174 "cr2res.cr2res_util_trace_map", 0);
175 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"detector");
176 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
177 cpl_parameterlist_append(recipe->parameters, p);
179 p = cpl_parameter_new_value(
"cr2res.cr2res_util_trace_map.order",
180 CPL_TYPE_INT,
"Only reduce the specified order",
181 "cr2res.cr2res_util_trace_map", -1);
182 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"order");
183 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
184 cpl_parameterlist_append(recipe->parameters, p);
186 p = cpl_parameter_new_value(
"cr2res.cr2res_util_trace_map.trace_nb",
187 CPL_TYPE_INT,
"Only reduce the specified trace number",
188 "cr2res.cr2res_util_trace_map", -1);
189 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"trace_nb");
190 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
191 cpl_parameterlist_append(recipe->parameters, p);
203static int cr2res_util_trace_map_exec(cpl_plugin * plugin)
208 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
209 recipe = (cpl_recipe *)plugin;
212 return cr2res_util_trace_map(recipe->frames, recipe->parameters);
222static int cr2res_util_trace_map_destroy(cpl_plugin * plugin)
227 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
228 recipe = (cpl_recipe *)plugin;
231 cpl_parameterlist_delete(recipe->parameters);
243static int cr2res_util_trace_map(
244 cpl_frameset * frameset,
245 const cpl_parameterlist * parlist)
247 const cpl_parameter * param;
248 int reduce_det, reduce_order, reduce_trace ;
249 cpl_frameset * rawframes ;
250 cpl_frameset * cur_fset ;
252 cpl_image * img_tmp ;
253 hdrl_image * wl_maps[CR2RES_NB_DETECTORS] ;
254 hdrl_image * trace_maps[CR2RES_NB_DETECTORS] ;
255 hdrl_image * slit_curve_maps[CR2RES_NB_DETECTORS] ;
256 cpl_propertylist * ext_plist[CR2RES_NB_DETECTORS] ;
257 cpl_table * trace_table ;
258 int det_nr, ext_nr, i;
263 param = cpl_parameterlist_find_const(parlist,
264 "cr2res.cr2res_util_trace_map.detector");
265 reduce_det = cpl_parameter_get_int(param);
266 param = cpl_parameterlist_find_const(parlist,
267 "cr2res.cr2res_util_trace_map.order");
268 reduce_order = cpl_parameter_get_int(param);
269 param = cpl_parameterlist_find_const(parlist,
270 "cr2res.cr2res_util_trace_map.trace_nb");
271 reduce_trace = cpl_parameter_get_int(param);
277 cpl_msg_error(__func__,
"Cannot identify RAW and CALIB frames") ;
278 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
286 if (rawframes==NULL || cpl_frameset_get_size(rawframes) <= 0) {
287 cpl_msg_error(__func__,
"Cannot find any RAW file") ;
288 cpl_error_set(__func__, CPL_ERROR_DATA_NOT_FOUND) ;
293 for (i = 0; i < cpl_frameset_get_size(rawframes); i++) {
294 const cpl_frame *cur_frame;
295 const char *cur_fname;
297 cur_frame = cpl_frameset_get_position(rawframes, i) ;
298 cur_fname = cpl_frame_get_filename(cur_frame) ;
299 cpl_msg_info(__func__,
"Reduce Frame %s", cur_fname) ;
300 cpl_msg_indent_more() ;
303 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
306 wl_maps[det_nr-1] = NULL ;
307 trace_maps[det_nr-1] = NULL ;
308 slit_curve_maps[det_nr-1] = NULL ;
312 if (ext_nr < 0) continue ;
315 ext_plist[det_nr-1] = cpl_propertylist_load(cur_fname, ext_nr) ;
318 if (reduce_det != 0 && det_nr != reduce_det) continue ;
320 cpl_msg_info(__func__,
"Process detector number %d", det_nr) ;
321 cpl_msg_indent_more() ;
324 cpl_msg_info(__func__,
"Load the trace table") ;
327 cpl_msg_error(__func__,
328 "Failed to get trace table - skip detector");
330 cpl_msg_indent_less() ;
340 CR2RES_DETECTOR_SIZE, CR2RES_DETECTOR_SIZE) ;
342 cpl_image_delete(img_tmp);
345 slit_curve_maps[det_nr-1] =
347 reduce_trace, 50, 0) ;
349 cpl_table_delete(trace_table) ;
350 cpl_msg_indent_less() ;
354 cur_fset = cpl_frameset_new() ;
355 cpl_frameset_insert(cur_fset, cpl_frame_duplicate(cur_frame)) ;
357 out_file = cpl_sprintf(
"%s_slit_curve.fits",
360 slit_curve_maps, NULL, ext_plist,
361 CR2RES_UTIL_TRACE_MAP_SLIT_CURVE_PROCATG, RECIPE_STRING);
364 out_file = cpl_sprintf(
"%s_wave.fits",
367 NULL, ext_plist, CR2RES_UTIL_TRACE_MAP_WL_PROCATG,
371 out_file = cpl_sprintf(
"%s_trace.fits",
374 trace_maps, NULL, ext_plist,
375 CR2RES_UTIL_TRACE_MAP_TRACE_PROCATG, RECIPE_STRING);
377 cpl_frameset_delete(cur_fset) ;
380 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
381 if (ext_plist[det_nr-1] != NULL)
382 cpl_propertylist_delete(ext_plist[det_nr-1]) ;
383 if (slit_curve_maps[det_nr-1] != NULL)
385 if (trace_maps[det_nr-1] != NULL)
387 if (wl_maps[det_nr-1] != NULL)
390 cpl_msg_indent_less() ;
392 cpl_frameset_delete(rawframes) ;
393 return (
int)cpl_error_get_code();
cpl_error_code cr2res_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
int cr2res_io_save_WAVE_MAP(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **data, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a WAVE_MAP.
int cr2res_io_get_ext_idx(const char *filename, int detector, int data)
Get the wished extension number for a detector.
int cr2res_io_save_TRACE_MAP(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **data, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a TRACE_MAP.
int cr2res_io_save_SLIT_CURV_MAP(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **data, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a SLIT_CURV_MAP.
cpl_table * cr2res_io_load_TRACE_WAVE(const char *filename, int detector)
Load a table from a TRACE_WAVE.
hdrl_image * cr2res_slit_curv_gen_map(const cpl_table *trace_wave, int order, int trace_id, int spacing_pixels, int full_trace)
Compute the slit_curv map from the trace_wave table.
cpl_image * cr2res_trace_gen_image(cpl_table *trace, int nx, int ny)
Make an image out of the trace solution.
char * cr2res_get_root_name(const char *filename)
Find out the root part of a basename (name without extension).
cpl_frameset * cr2res_extract_frameset(const cpl_frameset *in, const char *tag)
Extract the frames with the given tag from a frameset.
char * cr2res_get_base_name(const char *filename)
Find out the base name of a file (i.e. without prefix path)
const char * cr2res_get_license(void)
Get the pipeline copyright and license.
hdrl_image * cr2res_wave_gen_wave_map(const cpl_table *trace_wave)
Compute the wavelength map from the trace_wave table.
hdrl_image * hdrl_image_create(const cpl_image *image, const cpl_image *error)
create a new hdrl_image from to existing images by copying them
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image