36 #include "visir_recipe.h"
38 #include "visir_spc_distortion.h"
39 #include "visir_destripe.h"
48 #define RECIPE_STRING "visir_old_util_destripe"
50 #define VISIR_UTIL_DESTRIPE_PROCATG "DESTRIPED"
56 cpl_error_code visir_util_destripe_one(cpl_frameset *,
57 irplib_framelist *,
int,
58 const cpl_parameterlist *,
63 #define cpl_plugin_get_info visir_old_util_destripe_get_info
65 cpl_recipe_define(visir_old_util_destripe, VISIR_BINARY_VERSION,
66 "Julian Taylor", PACKAGE_BUGREPORT,
"2012",
67 "Old DRS detector: Attempt to remove stripes in spectral data",
68 "The files listed in the Set Of Frames (sof-file) "
70 "VISIR-chopnod-corrected-file.fits " VISIR_UTIL_CORRECTED
71 "\nThe product(s) will have a FITS card\n"
72 "'HIERARCH ESO PRO CATG' with a value of:\n"
73 VISIR_UTIL_DESTRIPE_PROCATG);
96 visir_old_util_destripe_fill_parameterlist(cpl_parameterlist *
self)
100 VISIR_PARAM_STRIPMOR)
101 ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
113 static int visir_old_util_destripe(cpl_frameset * framelist,
114 const cpl_parameterlist * parlist)
117 cpl_errorstate cleanstate = cpl_errorstate_get();
119 cpl_error_code didfail = CPL_ERROR_NONE;
120 irplib_framelist * allframes = NULL;
121 irplib_framelist * rawframes = NULL;
125 omp_set_num_threads(visir_get_num_threads(CPL_FALSE));
131 VISIR_PARAM_STRIPITE);
134 cpl_boolean morpho_destripe = ndestripe <= 0 ? CPL_FALSE :
136 VISIR_PARAM_STRIPMOR);
141 skip_if(allframes == NULL);
143 VISIR_UTIL_CORRECTED
"|"
144 VISIR_UTIL_UNDISTORT_PROCATG
147 skip_if (rawframes == NULL);
151 #pragma omp parallel for
153 for (cpl_size i = 0; i < n; i++) {
163 if (visir_util_destripe_one(framelist, rawframes, i, parlist,
164 ndestripe, morpho_destripe)) {
165 const cpl_error_code errori = cpl_error_set_where(cpl_func);
169 cpl_errorstate_dump(cleanstate, CPL_FALSE, NULL);
170 cpl_errorstate_set(cleanstate);
171 #pragma omp critical(visir_util_destripe)
178 error_if(didfail, didfail,
"Failed to destripe images in %d frame(s)", n);
185 return cpl_error_get_code();
203 cpl_error_code visir_util_destripe_one(cpl_frameset * framelist,
204 irplib_framelist * rawframes,
int iframe,
205 const cpl_parameterlist * parlist,
207 const cpl_boolean morpho_destripe)
210 cpl_frameset * products = cpl_frameset_new();
211 cpl_frameset * usedframes = cpl_frameset_new();
213 const char * filename = cpl_frame_get_filename(rawframe);
214 cpl_image * img = NULL;
215 char * proname = cpl_sprintf(RECIPE_STRING
"_%d" CPL_DFS_FITS,
217 cpl_propertylist * plist = NULL;
218 visir_data_type dtype;
222 CPL_FRAME_GROUP_RAW);
223 bug_if(cpl_frameset_insert(usedframes, cpl_frame_duplicate
230 skip_if(visir_get_data_type(rawframe, plist, &dtype, &next));
233 VISIR_UTIL_DESTRIPE_PROCATG, plist,
235 visir_pipe_id, proname));
237 for (cpl_size iext = 0; iext < 1 + next; iext++) {
238 cpl_errorstate prestate = cpl_errorstate_get();
240 img = cpl_image_load(filename, CPL_TYPE_FLOAT, 0, iext);
242 cpl_msg_info(cpl_func,
"No image-data in extension %d", (
int)iext);
243 cpl_errorstate_set(prestate);
248 if (visir_data_is_drs(dtype)) {
250 VISIR_DESTRIPE_DETECT,
251 VISIR_DESTRIPE_DETECT_THRESHOLD,
253 cpl_error_set_message(cpl_func,
254 cpl_error_get_code(),
255 "Failure for extension %d/%d",
256 (
int)iext, (
int)next);
261 cpl_image_save(img, proname, CPL_BPP_IEEE_FLOAT,
262 NULL, CPL_IO_EXTEND);
265 FOR_EACH_FRAMESET_C(frame, products) {
266 cpl_frame * copy = cpl_frame_duplicate(frame);
267 cpl_error_code error;
270 #pragma omp critical(visir_util_destripe_one)
272 error = cpl_frameset_insert(framelist, copy);
280 cpl_image_delete(img);
281 cpl_frameset_delete(usedframes);
282 cpl_frameset_delete(products);
285 return cpl_error_get_code();
cpl_error_code visir_parameter_set(cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Define the specified parameters.
cpl_error_code visir_destripe_image(cpl_image *self, int niter, double threshold, double thres_detect, cpl_boolean morpho)
Remove the stripes frome an image using iterations.
cpl_error_code irplib_dfs_save_propertylist(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save a propertylist as a DFS-compliant pipeline product.
int visir_parameterlist_get_int(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR integer parameter.
irplib_framelist * irplib_framelist_extract_regexp(const irplib_framelist *self, const char *regexp, cpl_boolean invert)
Extract the frames with the given tag from a framelist.
cpl_boolean visir_parameterlist_get_bool(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR boolean parameter.
cpl_frame * irplib_framelist_get(irplib_framelist *self, int pos)
Get the specified frame from the framelist.
const cpl_frame * irplib_framelist_get_const(const irplib_framelist *self, int pos)
Get the specified frame from the framelist.
void irplib_framelist_delete(irplib_framelist *self)
Deallocate an irplib_framelist with its frames and properties.
cpl_propertylist * irplib_framelist_get_propertylist(irplib_framelist *self, int pos)
Get the propertylist of the specified frame in the framelist.
cpl_error_code irplib_framelist_load_propertylist(irplib_framelist *self, int pos, int ind, const char *regexp, cpl_boolean invert)
Load the propertylist of the specified frame in the framelist.
irplib_framelist * irplib_framelist_cast(const cpl_frameset *frameset)
Create an irplib_framelist from a cpl_framelist.
int irplib_framelist_get_size(const irplib_framelist *self)
Get the size of a framelist.