35 #include "muse_twilight_z.h" 94 static const char *muse_twilight_help =
95 "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 or NFM data is processed, an area close to the edge of the MUSE field 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 edge area (as defined by the input mask or hardcoded for NRM) are 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.";
97 static const char *muse_twilight_help_esorex =
98 "\n\nInput frames for raw frame tag \"SKYFLAT\":\n" 99 "\n Frame tag Type Req #Fr Description" 100 "\n -------------------- ---- --- --- ------------" 101 "\n SKYFLAT raw Y >=3 Raw twilight skyflat" 102 "\n ILLUM raw . 1 Single optional raw (attached/illumination) flat-field exposure" 103 "\n MASTER_BIAS calib Y 1 Master bias" 104 "\n MASTER_DARK calib . 1 Master dark" 105 "\n MASTER_FLAT calib Y 1 Master flat" 106 "\n BADPIX_TABLE calib . Known bad pixels" 107 "\n TRACE_TABLE calib Y 1 Tracing table for all slices" 108 "\n WAVECAL_TABLE calib Y 1 Wavelength calibration table" 109 "\n GEOMETRY_TABLE calib Y 1 Relative positions of the slices in the field of view" 110 "\n VIGNETTING_MASK calib . 1 Mask to mark vignetted regions in the MUSE field of view" 111 "\n\nProduct frames for raw frame tag \"SKYFLAT\":\n" 112 "\n Frame tag Level Description" 113 "\n -------------------- -------- ------------" 114 "\n DATACUBE_SKYFLAT final Cube of combined twilight skyflat exposures" 115 "\n TWILIGHT_CUBE final Smoothed cube of twilight sky";
126 static cpl_recipeconfig *
127 muse_twilight_new_recipeconfig(
void)
129 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
131 cpl_recipeconfig_set_tag(recipeconfig,
"SKYFLAT", 3, -1);
132 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"MASTER_BIAS", 1, 1);
133 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"MASTER_DARK", -1, 1);
134 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"MASTER_FLAT", 1, 1);
135 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"BADPIX_TABLE", -1, -1);
136 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"TRACE_TABLE", 1, 1);
137 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"WAVECAL_TABLE", 1, 1);
138 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"GEOMETRY_TABLE", 1, 1);
139 cpl_recipeconfig_set_input(recipeconfig,
"SKYFLAT",
"VIGNETTING_MASK", -1, 1);
140 cpl_recipeconfig_set_output(recipeconfig,
"SKYFLAT",
"DATACUBE_SKYFLAT");
141 cpl_recipeconfig_set_output(recipeconfig,
"SKYFLAT",
"TWILIGHT_CUBE");
142 cpl_recipeconfig_set_tag(recipeconfig,
"ILLUM", -1, 1);
143 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"MASTER_BIAS", 1, 1);
144 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"MASTER_DARK", -1, 1);
145 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"MASTER_FLAT", 1, 1);
146 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"BADPIX_TABLE", -1, -1);
147 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"TRACE_TABLE", 1, 1);
148 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"WAVECAL_TABLE", 1, 1);
149 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"GEOMETRY_TABLE", 1, 1);
150 cpl_recipeconfig_set_input(recipeconfig,
"ILLUM",
"VIGNETTING_MASK", -1, 1);
166 static cpl_error_code
167 muse_twilight_prepare_header(
const char *aFrametag, cpl_propertylist *aHeader)
169 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
170 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
171 if (!strcmp(aFrametag,
"DATACUBE_SKYFLAT")) {
174 "Median value of raw exposure i of IFU m in input list");
177 "Mean value of raw exposure i of IFU m in input list");
180 "Standard deviation of raw exposure i of IFU m in input list");
183 "Minimum value of raw exposure i of IFU m in input list");
186 "Maximum value of raw exposure i of IFU m in input list");
189 "Number of saturated pixels in raw exposure i of IFU m in input list");
192 "Median value of the combined exposures in IFU m");
195 "Mean value of the combined exposures in IFU m");
198 "Standard deviation of the combined exposures in IFU m");
201 "Minimum value of the combined exposures in IFU m");
204 "Maximum value of the combined exposures in IFU m");
207 "Flux integrated over the whole CCD of the combined exposures of IFU m");
210 "Flux integrated over all slices of IFU m. Computed using the pixel table of the exposure.");
211 }
else if (!strcmp(aFrametag,
"TWILIGHT_CUBE")) {
213 cpl_msg_warning(__func__,
"Frame tag %s is not defined", aFrametag);
214 return CPL_ERROR_ILLEGAL_INPUT;
216 return CPL_ERROR_NONE;
229 static cpl_frame_level
230 muse_twilight_get_frame_level(
const char *aFrametag)
233 return CPL_FRAME_LEVEL_NONE;
235 if (!strcmp(aFrametag,
"DATACUBE_SKYFLAT")) {
236 return CPL_FRAME_LEVEL_FINAL;
238 if (!strcmp(aFrametag,
"TWILIGHT_CUBE")) {
239 return CPL_FRAME_LEVEL_FINAL;
241 return CPL_FRAME_LEVEL_NONE;
255 muse_twilight_get_frame_mode(
const char *aFrametag)
260 if (!strcmp(aFrametag,
"DATACUBE_SKYFLAT")) {
263 if (!strcmp(aFrametag,
"TWILIGHT_CUBE")) {
281 muse_twilight_create(cpl_plugin *aPlugin)
285 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
286 recipe = (cpl_recipe *)aPlugin;
294 muse_twilight_new_recipeconfig(),
295 muse_twilight_prepare_header,
296 muse_twilight_get_frame_level,
297 muse_twilight_get_frame_mode);
302 cpl_msg_set_time_on();
306 recipe->parameters = cpl_parameterlist_new();
311 p = cpl_parameter_new_value(
"muse.muse_twilight.overscan",
313 "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.",
314 "muse.muse_twilight",
315 (
const char *)
"vpoly");
316 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"overscan");
317 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"overscan");
319 cpl_parameterlist_append(recipe->parameters, p);
322 p = cpl_parameter_new_value(
"muse.muse_twilight.ovscreject",
324 "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\").",
325 "muse.muse_twilight",
326 (
const char *)
"dcr");
327 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscreject");
328 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscreject");
330 cpl_parameterlist_append(recipe->parameters, p);
333 p = cpl_parameter_new_value(
"muse.muse_twilight.ovscsigma",
335 "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\".",
336 "muse.muse_twilight",
338 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscsigma");
339 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscsigma");
341 cpl_parameterlist_append(recipe->parameters, p);
344 p = cpl_parameter_new_value(
"muse.muse_twilight.ovscignore",
346 "The number of pixels of the overscan adjacent to the data section of the CCD that are ignored when computing statistics or fits.",
347 "muse.muse_twilight",
349 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscignore");
350 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscignore");
352 cpl_parameterlist_append(recipe->parameters, p);
355 p = cpl_parameter_new_enum(
"muse.muse_twilight.combine",
357 "Type of combination to use",
358 "muse.muse_twilight",
359 (
const char *)
"sigclip",
361 (
const char *)
"average",
362 (
const char *)
"median",
363 (
const char *)
"minmax",
364 (
const char *)
"sigclip");
365 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"combine");
366 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"combine");
368 cpl_parameterlist_append(recipe->parameters, p);
371 p = cpl_parameter_new_value(
"muse.muse_twilight.nlow",
373 "Number of minimum pixels to reject with minmax",
374 "muse.muse_twilight",
376 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nlow");
377 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nlow");
379 cpl_parameterlist_append(recipe->parameters, p);
382 p = cpl_parameter_new_value(
"muse.muse_twilight.nhigh",
384 "Number of maximum pixels to reject with minmax",
385 "muse.muse_twilight",
387 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nhigh");
388 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nhigh");
390 cpl_parameterlist_append(recipe->parameters, p);
393 p = cpl_parameter_new_value(
"muse.muse_twilight.nkeep",
395 "Number of pixels to keep with minmax",
396 "muse.muse_twilight",
398 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nkeep");
399 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nkeep");
401 cpl_parameterlist_append(recipe->parameters, p);
404 p = cpl_parameter_new_value(
"muse.muse_twilight.lsigma",
406 "Low sigma for pixel rejection with sigclip",
407 "muse.muse_twilight",
409 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"lsigma");
410 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"lsigma");
412 cpl_parameterlist_append(recipe->parameters, p);
415 p = cpl_parameter_new_value(
"muse.muse_twilight.hsigma",
417 "High sigma for pixel rejection with sigclip",
418 "muse.muse_twilight",
420 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"hsigma");
421 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"hsigma");
423 cpl_parameterlist_append(recipe->parameters, p);
426 p = cpl_parameter_new_value(
"muse.muse_twilight.scale",
428 "Scale the individual images to a common exposure time before combining them.",
429 "muse.muse_twilight",
431 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"scale");
432 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"scale");
434 cpl_parameterlist_append(recipe->parameters, p);
437 p = cpl_parameter_new_enum(
"muse.muse_twilight.resample",
439 "The resampling technique to use for the final output cube.",
440 "muse.muse_twilight",
441 (
const char *)
"drizzle",
443 (
const char *)
"nearest",
444 (
const char *)
"linear",
445 (
const char *)
"quadratic",
446 (
const char *)
"renka",
447 (
const char *)
"drizzle",
448 (
const char *)
"lanczos");
449 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"resample");
450 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"resample");
452 cpl_parameterlist_append(recipe->parameters, p);
455 p = cpl_parameter_new_enum(
"muse.muse_twilight.crtype",
457 "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.",
458 "muse.muse_twilight",
459 (
const char *)
"median",
461 (
const char *)
"iraf",
462 (
const char *)
"mean",
463 (
const char *)
"median");
464 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"crtype");
465 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"crtype");
467 cpl_parameterlist_append(recipe->parameters, p);
470 p = cpl_parameter_new_value(
"muse.muse_twilight.crsigma",
472 "Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative value switches cosmic ray rejection off.",
473 "muse.muse_twilight",
475 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"crsigma");
476 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"crsigma");
478 cpl_parameterlist_append(recipe->parameters, p);
481 p = cpl_parameter_new_value(
"muse.muse_twilight.lambdamin",
483 "Minimum wavelength for twilight reconstruction.",
484 "muse.muse_twilight",
486 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"lambdamin");
487 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"lambdamin");
489 cpl_parameterlist_append(recipe->parameters, p);
492 p = cpl_parameter_new_value(
"muse.muse_twilight.lambdamax",
494 "Maximum wavelength for twilight reconstruction.",
495 "muse.muse_twilight",
497 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"lambdamax");
498 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"lambdamax");
500 cpl_parameterlist_append(recipe->parameters, p);
503 p = cpl_parameter_new_value(
"muse.muse_twilight.dlambda",
505 "Sampling for twilight reconstruction, this should result in planes of equal wavelength coverage.",
506 "muse.muse_twilight",
508 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"dlambda");
509 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"dlambda");
511 cpl_parameterlist_append(recipe->parameters, p);
514 p = cpl_parameter_new_value(
"muse.muse_twilight.xorder",
516 "Polynomial order to use in x direction to fit the full field of view.",
517 "muse.muse_twilight",
519 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"xorder");
520 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"xorder");
522 cpl_parameterlist_append(recipe->parameters, p);
525 p = cpl_parameter_new_value(
"muse.muse_twilight.yorder",
527 "Polynomial order to use in y direction to fit the full field of view.",
528 "muse.muse_twilight",
530 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"yorder");
531 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"yorder");
533 cpl_parameterlist_append(recipe->parameters, p);
536 p = cpl_parameter_new_value(
"muse.muse_twilight.vignmaskedges",
538 "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. This has no effect for NFM skyflats.",
539 "muse.muse_twilight",
541 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"vignmaskedges");
542 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"vignmaskedges");
543 if (!getenv(
"MUSE_EXPERT_USER")) {
544 cpl_parameter_disable(p, CPL_PARAMETER_MODE_CLI);
547 cpl_parameterlist_append(recipe->parameters, p);
550 p = cpl_parameter_new_enum(
"muse.muse_twilight.vignsmooth",
552 "Type of smoothing to use for the vignetted region given by the VIGNETTING_MASK (for WFM, or the internal mask, for NFM); gaussian uses (vignxpar + vignypar)/2 as FWHM.",
553 "muse.muse_twilight",
554 (
const char *)
"polyfit",
556 (
const char *)
"polyfit",
557 (
const char *)
"gaussian",
558 (
const char *)
"median");
559 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"vignsmooth");
560 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"vignsmooth");
561 if (!getenv(
"MUSE_EXPERT_USER")) {
562 cpl_parameter_disable(p, CPL_PARAMETER_MODE_CLI);
565 cpl_parameterlist_append(recipe->parameters, p);
568 p = cpl_parameter_new_value(
"muse.muse_twilight.vignxpar",
570 "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). If a negative value is found, the default is taken.",
571 "muse.muse_twilight",
573 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"vignxpar");
574 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"vignxpar");
575 if (!getenv(
"MUSE_EXPERT_USER")) {
576 cpl_parameter_disable(p, CPL_PARAMETER_MODE_CLI);
579 cpl_parameterlist_append(recipe->parameters, p);
582 p = cpl_parameter_new_value(
"muse.muse_twilight.vignypar",
584 "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). If a negative value is found, the default is taken.",
585 "muse.muse_twilight",
587 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"vignypar");
588 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"vignypar");
589 if (!getenv(
"MUSE_EXPERT_USER")) {
590 cpl_parameter_disable(p, CPL_PARAMETER_MODE_CLI);
593 cpl_parameterlist_append(recipe->parameters, p);
596 p = cpl_parameter_new_value(
"muse.muse_twilight.vignnfmmask",
598 "The height of the vignetted region at the top of the MUSE field in NFM. This is the region modeled separately (the final vignetting model might be smaller).",
599 "muse.muse_twilight",
601 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"vignnfmmask");
602 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"vignnfmmask");
603 if (!getenv(
"MUSE_EXPERT_USER")) {
604 cpl_parameter_disable(p, CPL_PARAMETER_MODE_CLI);
607 cpl_parameterlist_append(recipe->parameters, p);
627 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
628 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
631 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.overscan");
632 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
633 aParams->
overscan = cpl_parameter_get_string(p);
635 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.ovscreject");
636 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
637 aParams->
ovscreject = cpl_parameter_get_string(p);
639 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.ovscsigma");
640 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
641 aParams->
ovscsigma = cpl_parameter_get_double(p);
643 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.ovscignore");
644 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
645 aParams->
ovscignore = cpl_parameter_get_int(p);
647 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.combine");
648 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
649 aParams->
combine_s = cpl_parameter_get_string(p);
651 (!strcasecmp(aParams->
combine_s,
"average")) ? MUSE_TWILIGHT_PARAM_COMBINE_AVERAGE :
652 (!strcasecmp(aParams->
combine_s,
"median")) ? MUSE_TWILIGHT_PARAM_COMBINE_MEDIAN :
653 (!strcasecmp(aParams->
combine_s,
"minmax")) ? MUSE_TWILIGHT_PARAM_COMBINE_MINMAX :
654 (!strcasecmp(aParams->
combine_s,
"sigclip")) ? MUSE_TWILIGHT_PARAM_COMBINE_SIGCLIP :
655 MUSE_TWILIGHT_PARAM_COMBINE_INVALID_VALUE;
656 cpl_ensure_code(aParams->
combine != MUSE_TWILIGHT_PARAM_COMBINE_INVALID_VALUE,
657 CPL_ERROR_ILLEGAL_INPUT);
659 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.nlow");
660 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
661 aParams->
nlow = cpl_parameter_get_int(p);
663 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.nhigh");
664 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
665 aParams->
nhigh = cpl_parameter_get_int(p);
667 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.nkeep");
668 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
669 aParams->
nkeep = cpl_parameter_get_int(p);
671 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.lsigma");
672 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
673 aParams->
lsigma = cpl_parameter_get_double(p);
675 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.hsigma");
676 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
677 aParams->
hsigma = cpl_parameter_get_double(p);
679 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.scale");
680 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
681 aParams->
scale = cpl_parameter_get_bool(p);
683 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.resample");
684 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
685 aParams->
resample_s = cpl_parameter_get_string(p);
687 (!strcasecmp(aParams->
resample_s,
"nearest")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_NEAREST :
688 (!strcasecmp(aParams->
resample_s,
"linear")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_LINEAR :
689 (!strcasecmp(aParams->
resample_s,
"quadratic")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_QUADRATIC :
690 (!strcasecmp(aParams->
resample_s,
"renka")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_RENKA :
691 (!strcasecmp(aParams->
resample_s,
"drizzle")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_DRIZZLE :
692 (!strcasecmp(aParams->
resample_s,
"lanczos")) ? MUSE_TWILIGHT_PARAM_RESAMPLE_LANCZOS :
693 MUSE_TWILIGHT_PARAM_RESAMPLE_INVALID_VALUE;
694 cpl_ensure_code(aParams->
resample != MUSE_TWILIGHT_PARAM_RESAMPLE_INVALID_VALUE,
695 CPL_ERROR_ILLEGAL_INPUT);
697 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.crtype");
698 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
699 aParams->
crtype_s = cpl_parameter_get_string(p);
701 (!strcasecmp(aParams->
crtype_s,
"iraf")) ? MUSE_TWILIGHT_PARAM_CRTYPE_IRAF :
702 (!strcasecmp(aParams->
crtype_s,
"mean")) ? MUSE_TWILIGHT_PARAM_CRTYPE_MEAN :
703 (!strcasecmp(aParams->
crtype_s,
"median")) ? MUSE_TWILIGHT_PARAM_CRTYPE_MEDIAN :
704 MUSE_TWILIGHT_PARAM_CRTYPE_INVALID_VALUE;
705 cpl_ensure_code(aParams->
crtype != MUSE_TWILIGHT_PARAM_CRTYPE_INVALID_VALUE,
706 CPL_ERROR_ILLEGAL_INPUT);
708 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.crsigma");
709 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
710 aParams->
crsigma = cpl_parameter_get_double(p);
712 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.lambdamin");
713 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
714 aParams->
lambdamin = cpl_parameter_get_double(p);
716 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.lambdamax");
717 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
718 aParams->
lambdamax = cpl_parameter_get_double(p);
720 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.dlambda");
721 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
722 aParams->
dlambda = cpl_parameter_get_double(p);
724 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.xorder");
725 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
726 aParams->
xorder = cpl_parameter_get_int(p);
728 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.yorder");
729 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
730 aParams->
yorder = cpl_parameter_get_int(p);
732 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.vignmaskedges");
733 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
736 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.vignsmooth");
737 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
740 (!strcasecmp(aParams->
vignsmooth_s,
"polyfit")) ? MUSE_TWILIGHT_PARAM_VIGNSMOOTH_POLYFIT :
741 (!strcasecmp(aParams->
vignsmooth_s,
"gaussian")) ? MUSE_TWILIGHT_PARAM_VIGNSMOOTH_GAUSSIAN :
742 (!strcasecmp(aParams->
vignsmooth_s,
"median")) ? MUSE_TWILIGHT_PARAM_VIGNSMOOTH_MEDIAN :
743 MUSE_TWILIGHT_PARAM_VIGNSMOOTH_INVALID_VALUE;
744 cpl_ensure_code(aParams->
vignsmooth != MUSE_TWILIGHT_PARAM_VIGNSMOOTH_INVALID_VALUE,
745 CPL_ERROR_ILLEGAL_INPUT);
747 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.vignxpar");
748 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
749 aParams->
vignxpar = cpl_parameter_get_int(p);
751 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.vignypar");
752 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
753 aParams->
vignypar = cpl_parameter_get_int(p);
755 p = cpl_parameterlist_find(aParameters,
"muse.muse_twilight.vignnfmmask");
756 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
771 muse_twilight_exec(cpl_plugin *aPlugin)
773 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
777 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
778 cpl_msg_set_threadid_on();
780 cpl_frameset *usedframes = cpl_frameset_new(),
781 *outframes = cpl_frameset_new();
783 muse_twilight_params_fill(¶ms, recipe->parameters);
785 cpl_errorstate prestate = cpl_errorstate_get();
789 int rc = muse_twilight_compute(proc, ¶ms);
790 cpl_frameset_join(usedframes, proc->
usedframes);
791 cpl_frameset_join(outframes, proc->
outframes);
794 if (!cpl_errorstate_is_equal(prestate)) {
798 cpl_msg_set_level(CPL_MSG_INFO);
809 cpl_frameset_join(recipe->frames, usedframes);
810 cpl_frameset_join(recipe->frames, outframes);
811 cpl_frameset_delete(usedframes);
812 cpl_frameset_delete(outframes);
825 muse_twilight_destroy(cpl_plugin *aPlugin)
829 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
830 recipe = (cpl_recipe *)aPlugin;
836 cpl_parameterlist_delete(recipe->parameters);
853 cpl_plugin_get_info(cpl_pluginlist *aList)
855 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
856 cpl_plugin *plugin = &recipe->interface;
860 helptext = cpl_sprintf(
"%s%s", muse_twilight_help,
861 muse_twilight_help_esorex);
863 helptext = cpl_sprintf(
"%s", muse_twilight_help);
867 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
868 CPL_PLUGIN_TYPE_RECIPE,
870 "Combine several twilight skyflats into one cube, compute correction factors for each IFU, and create a smooth 3D illumination correction.",
875 muse_twilight_create,
877 muse_twilight_destroy);
878 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.
int vignnfmmask
The height of the vignetted region at the top of the MUSE field in NFM. This is the region modeled se...
const char * vignsmooth_s
Type of smoothing to use for the vignetted region given by the VIGNETTING_MASK (for WFM...
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 (for WFM...
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)