38#include "visir_recipe.h"
44#define VISIR_IMG_ACHRO_MIN_DIST 5
46#define RECIPE_STRING "visir_img_achro"
52static cpl_table * visir_img_achro_reduce(
const irplib_framelist *);
53static cpl_error_code visir_img_achro_save(cpl_frameset *,
54 const cpl_parameterlist *,
57VISIR_RECIPE_DEFINE(visir_img_achro, 0,
"Achromatism recipe",
58 "This recipe computes the best transmission wavelength "
60 "positions on the detector.\n"
61 "The files listed in the Set Of Frames (sof-file) "
63 "VISIR-achromatism-file.fits IM_CAL_ACHRO\n"
64 "The results are given in an output table.\n");
84static int visir_img_achro(cpl_frameset * framelist,
85 const cpl_parameterlist * parlist)
87 irplib_framelist * allframes = NULL;
88 irplib_framelist * rawframes = NULL;
89 cpl_table * tab = NULL;
96 allframes = irplib_framelist_cast(framelist);
97 skip_if(allframes == NULL);
98 rawframes = irplib_framelist_extract(allframes, VISIR_IMG_ACHRO_RAW);
99 skip_if (rawframes == NULL);
101 skip_if(irplib_framelist_load_propertylist_all(rawframes, 0,
102 visir_property_regexp,
108 cpl_msg_info(cpl_func,
"Compute the central wavelengths");
109 if ((tab = visir_img_achro_reduce(rawframes)) == NULL) {
110 cpl_msg_error(cpl_func,
"Cannot compute the wavelengths");
115 cpl_msg_info(cpl_func,
"Save the products");
116 skip_if (visir_img_achro_save(framelist, parlist, tab));
120 irplib_framelist_delete(allframes);
121 irplib_framelist_delete(rawframes);
122 cpl_table_delete(tab);
124 return cpl_error_get_code();
134static cpl_table * visir_img_achro_reduce(
const irplib_framelist * rawframes)
136 cpl_imagelist * loaded = NULL;
138 cpl_table * tab = NULL;
139 cpl_table * tab_out = NULL;
146 skip_if (rawframes == NULL);
149 cpl_msg_info(cpl_func,
"Load the input frames");
151 cpl_msg_error(cpl_func,
"Cannot load the input frames");
154 nfiles = cpl_imagelist_get_size(loaded);
155 skip_if (nfiles < 1);
158 cpl_msg_info(cpl_func,
"Get the wavelengths from the input headers");
159 if ((wls = visir_utils_get_wls(rawframes)) == NULL) {
160 cpl_msg_error(cpl_func,
"Cannot get wavelengths");
165 cpl_msg_info(cpl_func,
"Detect the objects and get their flux");
168 tab = visir_table_new_xypos(loaded,
"FLUX");
169 skip_if (tab == NULL);
171 skip_if (cpl_table_wrap_double(tab, wls,
"WAVELENGTH"));
175 skip_if (cpl_table_divide_scalar(tab,
"FLUX",
176 cpl_table_get_column_max(tab,
"FLUX")));
179 cpl_msg_info(cpl_func,
"Group the frames with the same object position");
180 cpl_msg_info(cpl_func,
"Compute the central wavelength at each position");
183 tab_out = cpl_table_new(nfiles);
186 skip_if (cpl_table_copy_structure(tab_out, tab));
187 skip_if (cpl_table_new_column(tab_out,
"NVALS", CPL_TYPE_DOUBLE));
189 skip_if (cpl_table_fill_column_window(tab_out,
"X_POS", 0, nfiles, 0));
190 skip_if (cpl_table_fill_column_window(tab_out,
"Y_POS", 0, nfiles, 0));
191 skip_if (cpl_table_fill_column_window(tab_out,
"WAVELENGTH", 0, nfiles, 0));
192 skip_if (cpl_table_fill_column_window(tab_out,
"FLUX", 0, nfiles, 0));
193 skip_if (cpl_table_fill_column_window(tab_out,
"NVALS", 0, nfiles, 0));
197 for (j=0 ; j < nfiles ; j++) {
198 const double refx = cpl_table_get(tab,
"X_POS", j, NULL);
199 const double refy = cpl_table_get(tab,
"Y_POS", j, NULL);
200 const double flux = cpl_table_get(tab,
"FLUX", j, NULL);
201 const double wlsj = cpl_table_get(tab,
"WAVELENGTH", j, NULL);
205 if (refx <= 0 || refy <= 0 || flux <= 0)
continue;
207 for (i = 0; i < nb_pos; i++) {
208 const double difx = cpl_table_get(tab,
"X_POS", i, NULL) - refx;
209 const double dify = cpl_table_get(tab,
"Y_POS", i, NULL) - refy;
212 if (difx * difx + dify * dify
213 < VISIR_IMG_ACHRO_MIN_DIST * VISIR_IMG_ACHRO_MIN_DIST)
break;
215 if (i == nb_pos) nb_pos++;
218 skip_if (cpl_table_set(tab_out,
"NVALS", i, 1
219 + cpl_table_get(tab_out,
"NVALS", i, NULL)));
220 skip_if (cpl_table_set(tab_out,
"X_POS", i, refx
221 + cpl_table_get(tab_out,
"X_POS", i, NULL)));
222 skip_if (cpl_table_set(tab_out,
"Y_POS", i, refy
223 + cpl_table_get(tab_out,
"Y_POS", i, NULL)));
224 skip_if (cpl_table_set(tab_out,
"FLUX", i, flux
225 + cpl_table_get(tab_out,
"FLUX", i, NULL)));
226 skip_if (cpl_table_set(tab_out,
"WAVELENGTH", i, flux * wlsj
227 + cpl_table_get(tab_out,
"WAVELENGTH", i, NULL)));
231 skip_if (nb_pos < 1);
233 skip_if (cpl_table_set_size(tab_out, nb_pos));
235 skip_if (cpl_table_divide_columns(tab_out,
"X_POS",
"NVALS"));
236 skip_if (cpl_table_divide_columns(tab_out,
"Y_POS",
"NVALS"));
237 skip_if (cpl_table_divide_columns(tab_out,
"WAVELENGTH",
"FLUX"));
239 skip_if (cpl_table_erase_column(tab_out,
"FLUX"));
240 skip_if (cpl_table_erase_column(tab_out,
"NVALS"));
245 cpl_table_delete(tab);
246 cpl_imagelist_delete(loaded);
248 if (cpl_error_get_code()) {
249 cpl_table_delete(tab_out);
265static cpl_error_code visir_img_achro_save(cpl_frameset * set,
266 const cpl_parameterlist * parlist,
267 const cpl_table * tab)
270 skip_if(irplib_dfs_save_table(set, parlist, set, tab, NULL, RECIPE_STRING,
271 VISIR_IMG_ACHRO_TAB_PROCATG, NULL, NULL,
272 visir_pipe_id, RECIPE_STRING CPL_DFS_FITS));
275 return cpl_error_get_code();
cpl_error_code visir_dfs_check_framelist_tag(const irplib_framelist *self)
Check the tags in a frameset (group raw only)
int visir_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.