35 #include "muse_twilight_z.h" 93 static const char *muse_twilight_help =
94 "Processing first handles each raw input image separately: it trims the raw data and records the overscan statistics, subtracts the bias (taking account of the overscan, if --overscan is not \"none\"), converts the images from adu to count, subtracts the dark, divides by the flat-field and combines all the exposures using input parameters. The input calibrations geometry table, trace table, and wavelength calibration table are used to assign 3D coordinates to each CCD-based pixel, thereby creating a pixel table from the master sky-flat. These pixel tables are then cut in wavelength using the --lambdamin and --lambdamax parameters. The integrated flux in each IFU is computed as the sum of the data in the pixel table, and saved in the header, to be used later as estimate for the relative throughput of each IFU. If an ILLUM exposure was given as input, it is then used to correct the relative illumination between all slices of one IFU. For this, the data of each slice within the pixel table of each IFU is multiplied by the normalized median flux of that slice in the ILLUM exposure. The pixel tables of all IFUs are then merged, using the integrated fluxes as inverse scaling factors, and a cube is reconstructed from the merged dataset, using given parameters. A white-light image is created from the cube. This skyflat cube is then saved to disk, with the white-light image as one extension. To construct a smooth 3D illumination correction, the cube is post-processed in the following way: the white-light image is used to create a mask of the illuminated area. From this area, the optional vignetting mask is removed. The smoothing is then computed for each plane of the cube: the illuminated area is smoothed (by a 5x7 median filter), normalized, fit with a 2D polynomial (of given polynomial orders), and normalized again. A smooth white image is then created by collapsing the smooth cube. If a vignetting mask was given, the corner area given by the mask is used to compute a 2D correction for the vignetted area: the original unsmoothed white-light image is corrected for large scale gradients by dividing it with the smooth white image. The residuals in the corner area then smoothed using input parameters. This smoothed vignetting correction is the multiplied onto each plane of the smooth cube, normalizing each plane again. This twilight cube is then saved to disk.";
96 static const char *muse_twilight_help_esorex =
97 "\n\nInput frames for raw frame tag \"SKYFLAT\":\n" 98 "\n Frame tag Type Req #Fr Description" 99 "\n -------------------- ---- --- --- ------------" 100 "\n SKYFLAT raw Y >=3 Raw twilight skyflat" 101 "\n ILLUM raw . 1 Single optional raw (attached/illumination) flat-field exposure" 102 "\n MASTER_BIAS calib Y 1 Master bias" 103 "\n MASTER_DARK calib . 1 Master dark" 104 "\n MASTER_FLAT calib Y 1 Master flat" 105 "\n BADPIX_TABLE calib . Known bad pixels" 106 "\n TRACE_TABLE calib Y 1 Tracing table for all slices" 107 "\n WAVECAL_TABLE calib Y 1 Wavelength calibration table" 108 "\n GEOMETRY_TABLE calib Y 1 Relative positions of the slices in the field of view" 109 "\n VIGNETTING_MASK calib . 1 Mask to mark vignetted regions in the MUSE field of view" 110 "\n\nProduct frames for raw frame tag \"SKYFLAT\":\n" 111 "\n Frame tag Level Description" 112 "\n -------------------- -------- ------------" 113 "\n DATACUBE_SKYFLAT final Cube of combined twilight skyflat exposures" 114 "\n TWILIGHT_CUBE final Smoothed cube of twilight sky";
125 static cpl_recipeconfig *
126 muse_twilight_new_recipeconfig(
void)
128 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
130 cpl_recipeconfig_set_tag(recipeconfig,
"SKYFLAT", 3, -1);
131 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"MASTER_BIAS", 1, 1);
132 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"MASTER_DARK", -1, 1);
133 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"MASTER_FLAT", 1, 1);
134 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"BADPIX_TABLE", -1, -1);
135 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"TRACE_TABLE", 1, 1);
136 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"WAVECAL_TABLE", 1, 1);
137 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"GEOMETRY_TABLE", 1, 1);
138 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"VIGNETTING_MASK", -1, 1);
139 cpl_recipeconfig_set_output(recipeconfig,
"SKYFLAT",
"DATACUBE_SKYFLAT");
140 cpl_recipeconfig_set_output(recipeconfig,
"SKYFLAT",
"TWILIGHT_CUBE");
141 cpl_recipeconfig_set_tag(recipeconfig,
"ILLUM", -1, 1);
142 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"MASTER_BIAS", 1, 1);
143 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"MASTER_DARK", -1, 1);
144 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"MASTER_FLAT", 1, 1);
145 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"BADPIX_TABLE", -1, -1);
146 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"TRACE_TABLE", 1, 1);
147 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"WAVECAL_TABLE", 1, 1);
148 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"GEOMETRY_TABLE", 1, 1);
149 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"VIGNETTING_MASK", -1, 1);
165 static cpl_error_code
166 muse_twilight_prepare_header(
const char *aFrametag, cpl_propertylist *aHeader)
168 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
169 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
170 if (!strcmp(aFrametag,
"DATACUBE_SKYFLAT")) {
173 "Median value of raw exposure i of IFU m in input list");
176 "Mean value of raw exposure i of IFU m in input list");
179 "Standard deviation of raw exposure i of IFU m in input list");
182 "Minimum value of raw exposure i of IFU m in input list");
185 "Maximum value of raw exposure i of IFU m in input list");
188 "Number of saturated pixels in raw exposure i of IFU m in input list");
191 "Median value of the combined exposures in IFU m");
194 "Mean value of the combined exposures in IFU m");
197 "Standard deviation of the combined exposures in IFU m");
200 "Minimum value of the combined exposures in IFU m");
203 "Maximum value of the combined exposures in IFU m");
206 "Flux integrated over the whole CCD of the combined exposures of IFU m");
209 "Flux integrated over all slices of IFU m. Computed using the pixel table of the exposure.");
210 }
else if (!strcmp(aFrametag,
"TWILIGHT_CUBE")) {
212 cpl_msg_warning(__func__,
"Frame tag %s is not defined", aFrametag);
213 return CPL_ERROR_ILLEGAL_INPUT;
215 return CPL_ERROR_NONE;
228 static cpl_frame_level
229 muse_twilight_get_frame_level(
const char *aFrametag)
232 return CPL_FRAME_LEVEL_NONE;
234 if (!strcmp(aFrametag,
"DATACUBE_SKYFLAT")) {
235 return CPL_FRAME_LEVEL_FINAL;
237 if (!strcmp(aFrametag,
"TWILIGHT_CUBE")) {
238 return CPL_FRAME_LEVEL_FINAL;
240 return CPL_FRAME_LEVEL_NONE;
254 muse_twilight_get_frame_mode(
const char *aFrametag)
259 if (!strcmp(aFrametag,
"DATACUBE_SKYFLAT")) {
262 if (!strcmp(aFrametag,
"TWILIGHT_CUBE")) {
280 muse_twilight_create(cpl_plugin *aPlugin)
284 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
285 recipe = (cpl_recipe *)aPlugin;
293 muse_twilight_new_recipeconfig(),
294 muse_twilight_prepare_header,
295 muse_twilight_get_frame_level,
296 muse_twilight_get_frame_mode);
301 cpl_msg_set_time_on();
305 recipe->parameters = cpl_parameterlist_new();
310 p = cpl_parameter_new_value(
"muse.muse_twilight.overscan",
312 "If this is \"none\", stop when detecting discrepant overscan levels (see ovscsigma), for \"offset\" it assumes that the mean overscan level represents the real offset in the bias levels of the exposures involved, and adjusts the data accordingly; for \"vpoly\", a polynomial is fit to the vertical overscan and subtracted from the whole quadrant.",
313 "muse.muse_twilight",
314 (
const char *)
"vpoly");
315 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"overscan");
316 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"overscan");
318 cpl_parameterlist_append(recipe->parameters, p);
321 p = cpl_parameter_new_value(
"muse.muse_twilight.ovscreject",
323 "This influences how values are rejected when computing overscan statistics. Either no rejection at all (\"none\"), rejection using the DCR algorithm (\"dcr\"), or rejection using an iterative constant fit (\"fit\").",
324 "muse.muse_twilight",
325 (
const char *)
"dcr");
326 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscreject");
327 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscreject");
329 cpl_parameterlist_append(recipe->parameters, p);
332 p = cpl_parameter_new_value(
"muse.muse_twilight.ovscsigma",
334 "If the deviation of mean overscan levels between a raw input image and the reference image is higher than |ovscsigma x stdev|, stop the processing. If overscan=\"vpoly\", this is used as sigma rejection level for the iterative polynomial fit (the level comparison is then done afterwards with |100 x stdev| to guard against incompatible settings). Has no effect for overscan=\"offset\".",
335 "muse.muse_twilight",
337 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscsigma");
338 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscsigma");
340 cpl_parameterlist_append(recipe->parameters, p);
343 p = cpl_parameter_new_value(
"muse.muse_twilight.ovscignore",
345 "The number of pixels of the overscan adjacent to the data section of the CCD that are ignored when computing statistics or fits.",
346 "muse.muse_twilight",
348 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscignore");
349 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscignore");
351 cpl_parameterlist_append(recipe->parameters, p);
354 p = cpl_parameter_new_enum(
"muse.muse_twilight.combine",
356 "Type of combination to use",
357 "muse.muse_twilight",
358 (
const char *)
"sigclip",
360 (
const char *)
"average",
361 (
const char *)
"median",
362 (
const char *)
"minmax",
363 (
const char *)
"sigclip");
364 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"combine");
365 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"combine");
367 cpl_parameterlist_append(recipe->parameters, p);
370 p = cpl_parameter_new_value(
"muse.muse_twilight.nlow",
372 "Number of minimum pixels to reject with minmax",
373 "muse.muse_twilight",
375 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nlow");
376 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nlow");
378 cpl_parameterlist_append(recipe->parameters, p);
381 p = cpl_parameter_new_value(
"muse.muse_twilight.nhigh",
383 "Number of maximum pixels to reject with minmax",
384 "muse.muse_twilight",
386 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nhigh");
387 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nhigh");
389 cpl_parameterlist_append(recipe->parameters, p);
392 p = cpl_parameter_new_value(
"muse.muse_twilight.nkeep",
394 "Number of pixels to keep with minmax",
395 "muse.muse_twilight",
397 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nkeep");
398 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nkeep");
400 cpl_parameterlist_append(recipe->parameters, p);
403 p = cpl_parameter_new_value(
"muse.muse_twilight.lsigma",
405 "Low sigma for pixel rejection with sigclip",
406 "muse.muse_twilight",
408 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"lsigma");
409 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"lsigma");
411 cpl_parameterlist_append(recipe->parameters, p);
414 p = cpl_parameter_new_value(
"muse.muse_twilight.hsigma",
416 "High sigma for pixel rejection with sigclip",
417 "muse.muse_twilight",
419 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"hsigma");
420 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"hsigma");
422 cpl_parameterlist_append(recipe->parameters, p);
425 p = cpl_parameter_new_value(
"muse.muse_twilight.scale",
427 "Scale the individual images to a common exposure time before combining them.",
428 "muse.muse_twilight",
430 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"scale");
431 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"scale");
433 cpl_parameterlist_append(recipe->parameters, p);
436 p = cpl_parameter_new_enum(
"muse.muse_twilight.resample",
438 "The resampling technique to use for the final output cube.",
439 "muse.muse_twilight",
440 (
const char *)
"drizzle",
442 (
const char *)
"nearest",
443 (
const char *)
"linear",
444 (
const char *)
"quadratic",
445 (
const char *)
"renka",
446 (
const char *)
"drizzle",
447 (
const char *)
"lanczos");
448 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"resample");
449 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"resample");
451 cpl_parameterlist_append(recipe->parameters, p);
454 p = cpl_parameter_new_enum(
"muse.muse_twilight.crtype",
456 "Type of statistics used for detection of cosmic rays during final resampling. \"iraf\" uses the variance information, \"mean\" uses standard (mean/stdev) statistics, \"median\" uses median and the median median of the absolute median deviation.",
457 "muse.muse_twilight",
458 (
const char *)
"median",
460 (
const char *)
"iraf",
461 (
const char *)
"mean",
462 (
const char *)
"median");
463 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"crtype");
464 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"crtype");
466 cpl_parameterlist_append(recipe->parameters, p);
469 p = cpl_parameter_new_value(
"muse.muse_twilight.crsigma",
471 "Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative value switches cosmic ray rejection off.",
472 "muse.muse_twilight",
474 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"crsigma");
475 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"crsigma");
477 cpl_parameterlist_append(recipe->parameters, p);
480 p = cpl_parameter_new_value(
"muse.muse_twilight.lambdamin",
482 "Minimum wavelength for twilight reconstruction.",
483 "muse.muse_twilight",
485 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"lambdamin");
486 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"lambdamin");
488 cpl_parameterlist_append(recipe->parameters, p);
491 p = cpl_parameter_new_value(
"muse.muse_twilight.lambdamax",
493 "Maximum wavelength for twilight reconstruction.",
494 "muse.muse_twilight",
496 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"lambdamax");
497 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"lambdamax");
499 cpl_parameterlist_append(recipe->parameters, p);
502 p = cpl_parameter_new_value(
"muse.muse_twilight.dlambda",
504 "Sampling for twilight reconstruction, this should result in planes of equal wavelength coverage.",
505 "muse.muse_twilight",
507 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"dlambda");
508 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"dlambda");
510 cpl_parameterlist_append(recipe->parameters, p);
513 p = cpl_parameter_new_value(
"muse.muse_twilight.xorder",
515 "Polynomial order to use in x direction to fit the full field of view.",
516 "muse.muse_twilight",
518 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"xorder");
519 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"xorder");
521 cpl_parameterlist_append(recipe->parameters, p);
524 p = cpl_parameter_new_value(
"muse.muse_twilight.yorder",
526 "Polynomial order to use in y direction to fit the full field of view.",
527 "muse.muse_twilight",
529 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"yorder");
530 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"yorder");
532 cpl_parameterlist_append(recipe->parameters, p);
535 p = cpl_parameter_new_value(
"muse.muse_twilight.vignmaskedges",
537 "Pixels on edges stronger than this fraction in the normalized image are excluded from the fit to the vignetted area. Set to non-positive number to include them in the fit.",
538 "muse.muse_twilight",
540 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"vignmaskedges");
541 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"vignmaskedges");
543 cpl_parameterlist_append(recipe->parameters, p);
546 p = cpl_parameter_new_enum(
"muse.muse_twilight.vignsmooth",
548 "Type of smoothing to use for the vignetted region given by the VIGNETTING_MASK; gaussian uses (vignxpar + vignypar)/2 as FWHM.",
549 "muse.muse_twilight",
550 (
const char *)
"polyfit",
552 (
const char *)
"polyfit",
553 (
const char *)
"gaussian",
554 (
const char *)
"median");
555 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"vignsmooth");
556 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"vignsmooth");
558 cpl_parameterlist_append(recipe->parameters, p);
561 p = cpl_parameter_new_value(
"muse.muse_twilight.vignxpar",
563 "Parameter used by the vignetting smoothing: x order for polyfit (default, recommended 4), parameter that influences the FWHM for the gaussian (recommended: 10), or x dimension of median filter (recommended 5).",
564 "muse.muse_twilight",
566 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"vignxpar");
567 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"vignxpar");
569 cpl_parameterlist_append(recipe->parameters, p);
572 p = cpl_parameter_new_value(
"muse.muse_twilight.vignypar",
574 "Parameter used by the vignetting smoothing: y order for polyfit (default, recommended 4), parameter that influences the FWHM for the gaussian (recommended: 10), or y dimension of median filter (recommended 5).",
575 "muse.muse_twilight",
577 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"vignypar");
578 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"vignypar");
580 cpl_parameterlist_append(recipe->parameters, p);
600 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
601 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
604 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.overscan");
605 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
606 aParams->
overscan = cpl_parameter_get_string(p);
608 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.ovscreject");
609 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
610 aParams->
ovscreject = cpl_parameter_get_string(p);
612 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.ovscsigma");
613 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
614 aParams->
ovscsigma = cpl_parameter_get_double(p);
616 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.ovscignore");
617 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
618 aParams->
ovscignore = cpl_parameter_get_int(p);
620 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.combine");
621 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
622 aParams->
combine_s = cpl_parameter_get_string(p);
624 (!strcasecmp(aParams->
combine_s,
"average")) ? MUSE_TWILIGHT_PARAM_COMBINE_AVERAGE :
625 (!strcasecmp(aParams->
combine_s,
"median")) ? MUSE_TWILIGHT_PARAM_COMBINE_MEDIAN :
626 (!strcasecmp(aParams->
combine_s,
"minmax")) ? MUSE_TWILIGHT_PARAM_COMBINE_MINMAX :
627 (!strcasecmp(aParams->
combine_s,
"sigclip")) ? MUSE_TWILIGHT_PARAM_COMBINE_SIGCLIP :
628 MUSE_TWILIGHT_PARAM_COMBINE_INVALID_VALUE;
629 cpl_ensure_code(aParams->
combine != MUSE_TWILIGHT_PARAM_COMBINE_INVALID_VALUE,
630 CPL_ERROR_ILLEGAL_INPUT);
632 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.nlow");
633 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
634 aParams->
nlow = cpl_parameter_get_int(p);
636 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.nhigh");
637 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
638 aParams->
nhigh = cpl_parameter_get_int(p);
640 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.nkeep");
641 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
642 aParams->
nkeep = cpl_parameter_get_int(p);
644 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.lsigma");
645 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
646 aParams->
lsigma = cpl_parameter_get_double(p);
648 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.hsigma");
649 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
650 aParams->
hsigma = cpl_parameter_get_double(p);
652 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.scale");
653 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
654 aParams->
scale = cpl_parameter_get_bool(p);
656 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.resample");
657 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
658 aParams->
resample_s = cpl_parameter_get_string(p);
660 (!strcasecmp(aParams->
resample_s,
"nearest")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_NEAREST :
661 (!strcasecmp(aParams->
resample_s,
"linear")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_LINEAR :
662 (!strcasecmp(aParams->
resample_s,
"quadratic")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_QUADRATIC :
663 (!strcasecmp(aParams->
resample_s,
"renka")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_RENKA :
664 (!strcasecmp(aParams->
resample_s,
"drizzle")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_DRIZZLE :
665 (!strcasecmp(aParams->
resample_s,
"lanczos")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_LANCZOS :
666 MUSE_TWILIGHT_PARAM_RESAMPLE_INVALID_VALUE;
667 cpl_ensure_code(aParams->
resample != MUSE_TWILIGHT_PARAM_RESAMPLE_INVALID_VALUE,
668 CPL_ERROR_ILLEGAL_INPUT);
670 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.crtype");
671 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
672 aParams->
crtype_s = cpl_parameter_get_string(p);
674 (!strcasecmp(aParams->
crtype_s,
"iraf")) ? MUSE_TWILIGHT_PARAM_CRTYPE_IRAF :
675 (!strcasecmp(aParams->
crtype_s,
"mean")) ? MUSE_TWILIGHT_PARAM_CRTYPE_MEAN :
676 (!strcasecmp(aParams->
crtype_s,
"median")) ? MUSE_TWILIGHT_PARAM_CRTYPE_MEDIAN :
677 MUSE_TWILIGHT_PARAM_CRTYPE_INVALID_VALUE;
678 cpl_ensure_code(aParams->
crtype != MUSE_TWILIGHT_PARAM_CRTYPE_INVALID_VALUE,
679 CPL_ERROR_ILLEGAL_INPUT);
681 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.crsigma");
682 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
683 aParams->
crsigma = cpl_parameter_get_double(p);
685 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.lambdamin");
686 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
687 aParams->
lambdamin = cpl_parameter_get_double(p);
689 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.lambdamax");
690 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
691 aParams->
lambdamax = cpl_parameter_get_double(p);
693 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.dlambda");
694 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
695 aParams->
dlambda = cpl_parameter_get_double(p);
697 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.xorder");
698 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
699 aParams->
xorder = cpl_parameter_get_int(p);
701 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.yorder");
702 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
703 aParams->
yorder = cpl_parameter_get_int(p);
705 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.vignmaskedges");
706 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
709 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.vignsmooth");
710 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
713 (!strcasecmp(aParams->
vignsmooth_s,
"polyfit")) ? MUSE_TWILIGHT_PARAM_VIGNSMOOTH_POLYFIT :
714 (!strcasecmp(aParams->
vignsmooth_s,
"gaussian")) ? MUSE_TWILIGHT_PARAM_VIGNSMOOTH_GAUSSIAN :
715 (!strcasecmp(aParams->
vignsmooth_s,
"median")) ? MUSE_TWILIGHT_PARAM_VIGNSMOOTH_MEDIAN :
716 MUSE_TWILIGHT_PARAM_VIGNSMOOTH_INVALID_VALUE;
717 cpl_ensure_code(aParams->
vignsmooth != MUSE_TWILIGHT_PARAM_VIGNSMOOTH_INVALID_VALUE,
718 CPL_ERROR_ILLEGAL_INPUT);
720 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.vignxpar");
721 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
722 aParams->
vignxpar = cpl_parameter_get_int(p);
724 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.vignypar");
725 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
726 aParams->
vignypar = cpl_parameter_get_int(p);
740 muse_twilight_exec(cpl_plugin *aPlugin)
742 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
746 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
747 cpl_msg_set_threadid_on();
749 cpl_frameset *usedframes = cpl_frameset_new(),
750 *outframes = cpl_frameset_new();
752 muse_twilight_params_fill(¶ms, recipe->parameters);
754 cpl_errorstate prestate = cpl_errorstate_get();
758 int rc = muse_twilight_compute(proc, ¶ms);
759 cpl_frameset_join(usedframes, proc->
usedframes);
760 cpl_frameset_join(outframes, proc->
outframes);
763 if (!cpl_errorstate_is_equal(prestate)) {
767 cpl_msg_set_level(CPL_MSG_INFO);
778 cpl_frameset_join(recipe->frames, usedframes);
779 cpl_frameset_join(recipe->frames, outframes);
780 cpl_frameset_delete(usedframes);
781 cpl_frameset_delete(outframes);
794 muse_twilight_destroy(cpl_plugin *aPlugin)
798 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
799 recipe = (cpl_recipe *)aPlugin;
805 cpl_parameterlist_delete(recipe->parameters);
822 cpl_plugin_get_info(cpl_pluginlist *aList)
824 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
825 cpl_plugin *plugin = &recipe->interface;
829 helptext = cpl_sprintf(
"%s%s", muse_twilight_help,
830 muse_twilight_help_esorex);
832 helptext = cpl_sprintf(
"%s", muse_twilight_help);
836 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
837 CPL_PLUGIN_TYPE_RECIPE,
839 "Combine several twilight skyflats into one cube, compute correction factors for each IFU, and create a smooth 3D illumination correction.",
844 muse_twilight_create,
846 muse_twilight_destroy);
847 cpl_pluginlist_append(aList, plugin);
double crsigma
Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative va...
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
const char * vignsmooth_s
Type of smoothing to use for the vignetted region given by the VIGNETTING_MASK; gaussian uses (vignxp...
int scale
Scale the individual images to a common exposure time before combining them.
double lsigma
Low sigma for pixel rejection with sigclip.
int nkeep
Number of pixels to keep with minmax.
muse_cplframework_type muse_cplframework(void)
Return the CPL framework the recipe is run under.
double ovscsigma
If the deviation of mean overscan levels between a raw input image and the reference image is higher ...
const char * crtype_s
Type of statistics used for detection of cosmic rays during final resampling. "iraf" uses the varianc...
const char * overscan
If this is "none", stop when detecting discrepant overscan levels (see ovscsigma), for "offset" it assumes that the mean overscan level represents the real offset in the bias levels of the exposures involved, and adjusts the data accordingly; for "vpoly", a polynomial is fit to the vertical overscan and subtracted from the whole quadrant.
cpl_frameset * usedframes
muse_processing * muse_processing_new(const char *aName, cpl_recipe *aRecipe)
Create a new processing structure.
int nhigh
Number of maximum pixels to reject with minmax.
const char * muse_get_license(void)
Get the pipeline copyright and license.
int vignxpar
Parameter used by the vignetting smoothing: x order for polyfit (default, recommended 4)...
double vignmaskedges
Pixels on edges stronger than this fraction in the normalized image are excluded from the fit to the ...
int vignypar
Parameter used by the vignetting smoothing: y order for polyfit (default, recommended 4)...
const char * combine_s
Type of combination to use (as string)
Structure to hold the parameters of the muse_twilight recipe.
double dlambda
Sampling for twilight reconstruction, this should result in planes of equal wavelength coverage...
int vignsmooth
Type of smoothing to use for the vignetted region given by the VIGNETTING_MASK; gaussian uses (vignxp...
int resample
The resampling technique to use for the final output cube.
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
double lambdamin
Minimum wavelength for twilight reconstruction.
void muse_processinginfo_delete(cpl_recipe *)
Clear all information from the processing info and from the recipe config.
int combine
Type of combination to use.
double hsigma
High sigma for pixel rejection with sigclip.
int yorder
Polynomial order to use in y direction to fit the full field of view.
int xorder
Polynomial order to use in x direction to fit the full field of view.
const char * ovscreject
This influences how values are rejected when computing overscan statistics. Either no rejection at al...
cpl_error_code muse_cplframeset_erase_duplicate(cpl_frameset *aFrames)
Erase all duplicate frames from a frameset.
cpl_error_code muse_cplframeset_erase_all(cpl_frameset *aFrames)
Erase all frames in a frameset.
void muse_processinginfo_register(cpl_recipe *, cpl_recipeconfig *, muse_processing_prepare_header_func *, muse_processing_get_frame_level_func *, muse_processing_get_frame_mode_func *)
Register extended functionalities for MUSE recipes.
int ovscignore
The number of pixels of the overscan adjacent to the data section of the CCD that are ignored when co...
double lambdamax
Maximum wavelength for twilight reconstruction.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.
int nlow
Number of minimum pixels to reject with minmax.
int crtype
Type of statistics used for detection of cosmic rays during final resampling. "iraf" uses the varianc...
cpl_error_code muse_processing_prepare_property(cpl_propertylist *, const char *, cpl_type, const char *)
Prepare and check the specified property.
const char * resample_s
The resampling technique to use for the final output cube. (as string)