42 #include "irplib_utils.h"
44 #include "visir_parameter.h"
45 #include "visir_dfs.h"
46 #include "visir_pfits.h"
52 #define visir_plot_manpage \
53 "The recipe can produce a number of predefined plots. " \
54 "Zero means that none of the plots are produced, while " \
55 "increasing values (e.g. 1 or 2) increases the number " \
56 "of plots produced. If the plotting fails a warning is " \
57 "produced, and the recipe continues. " \
58 "The default behaviour of the plotting is to use " \
59 "gnuplot (with option -persist). The recipe currently " \
60 "produces 1D-plots using gnuplot commands. The recipe " \
61 "user can control the actual plotting-command used by " \
62 "the recipe to create the plot by setting the " \
63 "environment variable CPL_PLOTTER. Currently, if " \
65 "is set it must contain the string 'gnuplot'. Setting " \
66 "it to 'cat > my_gnuplot_$$.txt' causes a number of " \
67 "ASCII-files to be created, which each produce a plot " \
68 "when given as standard input to gnuplot (e.g. later " \
69 "or on a different computer). A finer control of the " \
70 "plotting options can be obtained by writing an " \
71 "executable script, e.g. my_gnuplot.pl, that " \
72 "executes gnuplot after setting the desired gnuplot " \
73 "options (e.g. set terminal pslatex color) " \
74 "and then setting CPL_PLOTTER to my_gnuplot.pl. " \
75 "The predefined plots include plotting of images. " \
76 "Images can be plotted not only with gnuplot, but also " \
77 "using the pnm format. This is controlled with the " \
78 "environment variable CPL_IMAGER. If CPL_IMAGER " \
79 "is set to a string that does not contain the word " \
80 "gnuplot, the recipe will generate the plot in pnm " \
81 "format. E.g. setting CPL_IMAGER to " \
82 "'display - &' will produce a gray-scale image " \
83 "using the image viewer display."
88 #define VISIR_PARAMETER_SET(MASK, VARNAME, TYPE, MAN, DEFAULT, SHORT) \
89 if (bitmask & MASK) { \
90 char * paramname = cpl_sprintf(PACKAGE ".%s." VARNAME, recipe); \
92 p = cpl_parameter_new_value(paramname, TYPE, MAN, context, DEFAULT); \
93 cpl_free(paramname); \
94 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, SHORT); \
95 cpl_parameterlist_append(self, p); \
97 (void)cpl_error_set_where(cpl_func); \
102 if (chkmask & MASK) \
103 (void)cpl_error_set(cpl_func, CPL_ERROR_UNSPECIFIED); \
108 #define VISIR_PARAMETER_GET_BOOL(MASK, VARNAME) \
109 if (bitmask & MASK) { \
110 value = irplib_parameterlist_get_bool(self, PACKAGE, recipe, VARNAME); \
112 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
113 return(CPL_FALSE), "mask=0x%llx", MASK); \
120 #define VISIR_PARAMETER_GET_INT(MASK, VARNAME) \
121 if (bitmask & MASK) { \
122 value = irplib_parameterlist_get_int(self, PACKAGE, recipe, VARNAME); \
124 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), return(0), \
125 "mask=0x%llx", MASK); \
133 #define VISIR_PARAMETER_GET_DOUBLE(MASK, VARNAME) \
134 if (bitmask & MASK) { \
135 value = irplib_parameterlist_get_double(self, PACKAGE, recipe, VARNAME); \
137 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), return(0.0), \
138 "mask=0x%llx", MASK); \
146 #define VISIR_PARAMETER_GET_STRING(MASK, VARNAME) \
147 if (bitmask & MASK) { \
148 value = irplib_parameterlist_get_string(self, PACKAGE, recipe, VARNAME); \
150 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), return(NULL),\
151 "mask=0x%llx", MASK); \
182 visir_parameter bitmask)
187 visir_parameter chkmask = 0;
188 cpl_boolean zerodist = CPL_FALSE;
189 cpl_boolean dostrip = CPL_TRUE;
192 cpl_ensure_code(
self, CPL_ERROR_NULL_INPUT);
193 cpl_ensure_code(recipe, CPL_ERROR_NULL_INPUT);
195 context = cpl_sprintf(PACKAGE
".%s", recipe);
198 VISIR_PARAMETER_SET(VISIR_PARAM_NODPOS,
"nodding", CPL_TYPE_STRING,
199 "An optional ASCII specification of the nodding positions "
200 "(in case they are missing from the FITS-file). "
201 "The file must consist of one line per input FITS-file "
202 "and each line must consist of an integer (which is "
203 "ignored) followed by a 0 or 1 (to indicate object or sky). ",
204 VISIR_STR_PAR_EMPTY,
"nod");
207 VISIR_PARAMETER_SET(VISIR_PARAM_AUTOBPM,
"auto_bpm", CPL_TYPE_BOOL,
208 "Automatic detection and correction of bad pixels",
212 VISIR_PARAMETER_SET(VISIR_PARAM_GLITCH,
"rem_glitch", CPL_TYPE_BOOL,
213 "Automatic filtering of glitches", FALSE,
"g");
216 VISIR_PARAMETER_SET(VISIR_PARAM_PURGE,
"purge_bad", CPL_TYPE_BOOL,
217 "Automatic purging of half-cycle images whose median "
218 "deviates more than a factor three from the mean of "
219 "the medians of half-cycle images or whose standard "
220 "deviation deviates more than a factor three from the "
221 "mean of their standard deviations", FALSE,
"p");
224 VISIR_PARAMETER_SET(VISIR_PARAM_UNION,
"union", CPL_TYPE_BOOL,
225 "Combine images using their union, as opposed to their "
226 "intersection (deprecated and ignored, "
227 "see --combine_method)", TRUE,
"union");
230 VISIR_PARAMETER_SET(VISIR_PARAM_REJECT,
"rej", CPL_TYPE_STRING,
231 "Each resulting pixel is the average of the "
232 "corresponding (interpolated) pixel value in each "
233 "jittered image. A positive value, n1, for the first "
234 "of the two integers specifies that for each pixel the "
235 "smallest n1 pixel values shall be ignored in the "
236 "averaging. Similarly, a positive value, n2, for the "
237 "second of the two integers specifies that for each "
238 "pixel the largest n2 pixel values shall be ignored in "
239 "the averaging.",
"0-0",
"rej");
241 VISIR_PARAMETER_SET(VISIR_PARAM_BKG_CORRECT,
"bkgcorrect", CPL_TYPE_BOOL,
242 "Subtract the median from the spectral column before "
243 "extracting the wavelength. This is required when "
244 "the skylines do not correctly cancel due to gratting "
245 "oscillations", FALSE,
"bkgcorrect");
248 VISIR_PARAMETER_SET(VISIR_PARAM_PLOT,
"plot", CPL_TYPE_INT,
249 visir_plot_manpage, 0,
"plot");
251 if (bitmask & VISIR_PARAM_ZERODIST) {
252 bitmask ^= VISIR_PARAM_ZERODIST;
263 VISIR_PARAMETER_SET(VISIR_PARAM_SLITSKEW,
"phi", CPL_TYPE_DOUBLE,
264 "Distortion correction: Skew of slit (degrees) "
265 "(clockwise)", zerodist ? 0.0 : 0.52,
"slit_skew");
270 VISIR_PARAMETER_SET(VISIR_PARAM_SPECSKEW,
"ksi", CPL_TYPE_DOUBLE,
271 "Distortion correction: LMR Skew of spectrum (degrees) "
272 "(counter-clockwise). Not used in High Resolution",
273 zerodist ? 0.0 : 1.73,
"spectrum_skew");
277 VISIR_PARAMETER_SET(VISIR_PARAM_VERTARC,
"eps", CPL_TYPE_DOUBLE,
278 "Distortion correction: LR Detector vertical curvature "
279 "(pixel). Reduced by a factor 4 in MR. Not used in HR "
280 "A-side. Increased by a factor 115/52 in HR B-side",
281 zerodist ? 0.0 : -0.8,
"vert_arc");
285 VISIR_PARAMETER_SET(VISIR_PARAM_HORIARC,
"delta", CPL_TYPE_DOUBLE,
286 "Distortion correction: LMR Detector horizontal "
287 "curvature (pixel). Increased by a factor 1.5 in HR "
288 "A-side. Reduced by a factor 2 in HR B-side",
289 zerodist ? 0.0 : 0,
"hori_arc");
292 VISIR_PARAMETER_SET(VISIR_PARAM_ORDEROFF,
"orderoffset", CPL_TYPE_INT,
293 "Echelle order offset. The offset is relative to the "
294 "main order. The allowed range of offsets depend on "
295 "the selected grism. The offset can never exceed +/-4. "
296 "If the main order is e.g. 8 an order offset of +1 "
297 "will cause the recipe to base the data reduction on "
298 "order 9. With a positive order offset the central "
299 "wavelength becomes smaller while for a negative "
300 "order offset the central wavelength becomes larger.", 0,
304 VISIR_PARAMETER_SET(VISIR_PARAM_OFFSETS,
"offsets", CPL_TYPE_STRING,
305 "An optional ASCII specification of the offsets "
306 "in case those in FITS-headers are missing or wrong. "
307 "The file must consist of one line per input pair of "
308 "FITS-files, and each line must consist of two "
309 "numbers which represent the shift in pixels of that "
310 "image relative to the first image. The first line "
311 "should thus comprise two zeros. Correct FITS-header "
312 "offsets mean that the i'th X offset can be gotten "
313 "from Xoffset_0 - Xoffset_i, where Xoffset_i is the "
314 "value of " VISIR_PFITS_DOUBLE_CUMOFFSETX
" and "
315 "likewise for Y.", VISIR_STR_PAR_EMPTY,
"off");
317 VISIR_PARAMETER_SET(VISIR_PARAM_REFINE,
"refine", CPL_TYPE_BOOL,
318 "User-defined refining of the image offsets. See "
319 "options objs and xcorr", FALSE,
"ref");
321 VISIR_PARAMETER_SET(VISIR_PARAM_OBJECTS,
"objects", CPL_TYPE_STRING,
322 "The shift and add of images needs anchor points that "
323 "typically are bright objects. These are normally "
324 "detected automatically but with user-defined refining "
325 "of offsets enabled, they must be provided by the user "
326 "through an ASCII file containing one line per anchor "
327 "point with each line consisting of its x and y "
328 "coordinate (in pixels). This file is ignored with "
329 "user-defined refining of offsets disabled.",
330 VISIR_STR_PAR_EMPTY,
"objs");
334 VISIR_PARAMETER_SET(VISIR_PARAM_XCORR,
"xcorr", CPL_TYPE_STRING,
335 "If user-defined refining of offsets is enabled a "
336 "cross-correlation of the images is performed. In "
337 "order to speed up this process, this cross-"
338 "correlation is performed only on smaller rectangles "
339 "around the anchor points. The first two parameters "
340 "is the half-size of this rectangle in pixels. The "
341 "second pair is the maximum shift in x and y (pixels) "
342 "evaluated by the cross-correlation on the rectangle. "
343 "Used only if user-defined refining of offsets is enabled.",
344 "10-10-25-25",
"xcorr");
347 VISIR_PARAMETER_SET(VISIR_PARAM_JYVAL,
"jy_val", CPL_TYPE_DOUBLE,
348 "The flux of the standard star in Jansky",
352 VISIR_PARAMETER_SET(VISIR_PARAM_RADII,
"radii", CPL_TYPE_STRING,
353 "Radii : star_max bg_int bg_ext",
354 "20-20-30",
"radii");
357 VISIR_PARAMETER_SET(VISIR_PARAM_LOWLIM,
"low", CPL_TYPE_DOUBLE,
358 "Low threshold for the bad pixel map",
362 VISIR_PARAMETER_SET(VISIR_PARAM_HIGHLIM,
"high", CPL_TYPE_DOUBLE,
363 "High threshold for the bad pixel map",
367 VISIR_PARAMETER_SET(VISIR_PARAM_FIXCOMBI,
"fixcombi", CPL_TYPE_BOOL,
368 "Perform the distortion correction on the combined "
369 "image, and not on each of the jittered images. "
370 "This will reduce excution time and degrade the quality "
371 "of the combined image",
375 VISIR_PARAMETER_SET(VISIR_PARAM_EMIS_TOL,
"emis_tol", CPL_TYPE_DOUBLE,
376 "The computation of the mean and standard deviation "
377 "of the sensitivity is done for wavelengths with an "
378 "atmospheric emissivity of at most "
379 "emis_min + emis_tol * (emis_max - emis_min), where "
380 "emis_min is the minimum emissivity in the observed "
381 "wavelength range and emis_max is the ditto maximum. "
382 "Thus emis_tol = 1 means that all wavelengths are "
387 VISIR_PARAMETER_SET(VISIR_PARAM_QEFF,
"qeff", CPL_TYPE_DOUBLE,
392 VISIR_PARAMETER_SET(VISIR_PARAM_REJBORD,
"rej_bord", CPL_TYPE_STRING,
393 "Rejected left right bottom and top border (pixel)",
397 VISIR_PARAMETER_SET(VISIR_PARAM_HOT_LIM,
"hot_threshold", CPL_TYPE_DOUBLE,
398 "Hot pixel map threshold", 10.0,
"hot_t");
401 VISIR_PARAMETER_SET(VISIR_PARAM_COLD_LIM,
"cold_threshold", CPL_TYPE_DOUBLE,
402 "Cold pixel map threshold", 6.0,
"cold_t");
405 VISIR_PARAMETER_SET(VISIR_PARAM_DEV_LIM,
"dev_threshold", CPL_TYPE_DOUBLE,
406 "Deviant pixel map threshold", 5.0,
"dev_t");
409 VISIR_PARAMETER_SET(VISIR_PARAM_NSAMPLES,
"nsamples", CPL_TYPE_INT,
410 "Number of samples for Read-Out Noise (RON) computation",
414 VISIR_PARAMETER_SET(VISIR_PARAM_HALFSIZE,
"hsize", CPL_TYPE_INT,
415 "Half size of the window for Read-Out Noise (RON) "
416 "computation", 2,
"hsize");
420 VISIR_PARAMETER_SET(VISIR_PARAM_COMBINE,
"comb_meth", CPL_TYPE_STRING,
421 "Combine images using one of: 1) Onto the first image "
422 "(first); 2) Their union (union); 3) Their intersection"
423 " (inter). NB: Only the 'first'-method produces an "
424 "image product with WCS coordinates. A successful "
425 "'first'-method always produces a combined image with "
426 "dimensions equal to those of the input images. "
427 "For the 'union'-method the result image is at least "
428 "as large as the input images while for the 'inter'-"
429 "method the result image is at most as large as the "
430 "input images",
"union",
"combine_method");
432 if (bitmask & VISIR_PARAM_STRIPNON) {
433 bitmask ^= VISIR_PARAM_STRIPNON;
440 VISIR_PARAMETER_SET(VISIR_PARAM_STRIPITE,
"nstripe",
441 CPL_TYPE_INT,
"Max number of destriping iterations "
442 "(0 to disable destriping). Horizontal destriping is "
443 "done first and if no horizontal striping is detected, "
444 "vertical destriping is performed", dostrip ? 15 : 0,
445 "destripe_iterations");
448 VISIR_PARAMETER_SET(VISIR_PARAM_STRIPMOR,
"mstripe", CPL_TYPE_BOOL,
449 "Destripe with morphological cleaning", FALSE,
453 VISIR_PARAMETER_SET(VISIR_PARAM_REJLEFT,
"reject_left", CPL_TYPE_INT,
454 "Reject leftmost columns in spectrum extraction, zero "
455 "means all columns on the left are used. In cross-"
456 "dispersion mode a (small) negative number may be used "
460 VISIR_PARAMETER_SET(VISIR_PARAM_REJRIGHT,
"reject_right", CPL_TYPE_INT,
461 "Reject rightmost columns in spectrum extraction, zero "
462 "means all columns on the right are used. In cross-"
463 "dispersion mode a (small) negative number may be used "
467 VISIR_PARAMETER_SET(VISIR_PARAM_ECCMAX,
"eccmax", CPL_TYPE_DOUBLE,
468 "The maximum eccentricity allowed in the combination "
469 "of the three (in parallel nod/chopping) or four (in "
470 "perpendicular nod/chopping) beams. In parallel mode, "
471 "three perfectly aligned points spaced with the "
472 "chopnod throw will have eccentricity 0, while in "
473 "perpedicular mode a square with the chopnod throw as "
474 "the side length will have eccentricity 0",
479 cpl_ensure_code(!cpl_error_get_code(), cpl_error_get_code());
480 cpl_ensure_code(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE);
482 return CPL_ERROR_NONE;
498 visir_parameter bitmask)
502 cpl_boolean value = CPL_FALSE;
505 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), CPL_FALSE);
506 cpl_ensure(
self, CPL_ERROR_NULL_INPUT, CPL_FALSE);
507 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, CPL_FALSE);
510 VISIR_PARAMETER_GET_BOOL(VISIR_PARAM_AUTOBPM,
"auto_bpm");
513 VISIR_PARAMETER_GET_BOOL(VISIR_PARAM_GLITCH,
"rem_glitch");
516 VISIR_PARAMETER_GET_BOOL(VISIR_PARAM_PURGE,
"purge_bad");
518 VISIR_PARAMETER_GET_BOOL(VISIR_PARAM_REFINE,
"refine");
521 VISIR_PARAMETER_GET_BOOL(VISIR_PARAM_FIXCOMBI,
"fixcombi");
524 VISIR_PARAMETER_GET_BOOL(VISIR_PARAM_STRIPMOR,
"mstripe");
527 VISIR_PARAMETER_GET_BOOL(VISIR_PARAM_BKG_CORRECT,
"bkgcorrect");
530 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, CPL_FALSE);
531 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, CPL_FALSE);
551 visir_parameter bitmask)
558 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), 0);
559 cpl_ensure(
self, CPL_ERROR_NULL_INPUT, 0);
560 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, 0);
564 VISIR_PARAMETER_GET_INT(VISIR_PARAM_PLOT,
"plot");
567 VISIR_PARAMETER_GET_INT(VISIR_PARAM_ORDEROFF,
"orderoffset");
570 VISIR_PARAMETER_GET_INT(VISIR_PARAM_NSAMPLES,
"nsamples");
573 VISIR_PARAMETER_GET_INT(VISIR_PARAM_HALFSIZE,
"hsize");
576 VISIR_PARAMETER_GET_INT(VISIR_PARAM_STRIPITE,
"nstripe");
579 VISIR_PARAMETER_GET_INT(VISIR_PARAM_REJLEFT,
"reject_left");
582 VISIR_PARAMETER_GET_INT(VISIR_PARAM_REJRIGHT,
"reject_right");
585 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, 0);
586 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, 0);
605 visir_parameter bitmask)
609 double value = DBL_MAX;
612 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), 0.0);
613 cpl_ensure(
self, CPL_ERROR_NULL_INPUT, 0.0);
614 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, 0.0);
617 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_SLITSKEW,
"phi");
620 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_SPECSKEW,
"ksi");
623 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_VERTARC,
"eps");
626 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_HORIARC,
"delta");
629 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_JYVAL,
"jy_val");
632 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_LOWLIM,
"low");
635 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_HIGHLIM,
"high");
638 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_EMIS_TOL,
"emis_tol");
641 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_QEFF,
"qeff");
644 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_HOT_LIM,
"hot_threshold");
647 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_COLD_LIM,
"cold_threshold");
650 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_DEV_LIM,
"dev_threshold");
653 VISIR_PARAMETER_GET_DOUBLE(VISIR_PARAM_ECCMAX,
"eccmax");
655 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, 0.0);
656 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, 0.0);
676 visir_parameter bitmask)
680 const char * value = NULL;
681 const cpl_boolean is_combine
682 = bitmask & VISIR_PARAM_COMBINE ? CPL_TRUE : CPL_FALSE;
684 cpl_ensure(
self, CPL_ERROR_NULL_INPUT, NULL);
685 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, NULL);
688 VISIR_PARAMETER_GET_STRING(VISIR_PARAM_NODPOS,
"nodding");
691 VISIR_PARAMETER_GET_STRING(VISIR_PARAM_REJECT,
"rej");
694 VISIR_PARAMETER_GET_STRING(VISIR_PARAM_OFFSETS,
"offsets");
696 VISIR_PARAMETER_GET_STRING(VISIR_PARAM_REFINE,
"refine");
698 VISIR_PARAMETER_GET_STRING(VISIR_PARAM_OBJECTS,
"objects");
701 VISIR_PARAMETER_GET_STRING(VISIR_PARAM_XCORR,
"xcorr");
704 VISIR_PARAMETER_GET_STRING(VISIR_PARAM_RADII,
"radii");
707 VISIR_PARAMETER_GET_STRING(VISIR_PARAM_REJBORD,
"rej_bord");
710 VISIR_PARAMETER_GET_STRING(VISIR_PARAM_COMBINE,
"comb_meth");
712 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, NULL);
713 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, NULL);
715 assert(value != NULL);
719 cpl_ensure(strcmp(value,
"first") == 0 || strcmp(value,
"union") == 0 ||
720 strcmp(value,
"intersect") == 0, CPL_ERROR_UNSUPPORTED_MODE,
double visir_parameterlist_get_double(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR parameter of type double.
cpl_error_code visir_parameter_set(cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Define the specified parameters.
int visir_parameterlist_get_int(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR integer parameter.
cpl_boolean visir_parameterlist_get_bool(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR boolean parameter.
const char * visir_parameterlist_get_string(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR string parameter.