35 #include "muse_scibasic_z.h"
88 static const char *muse_scibasic_help =
89 "Processing 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&), optionally detects cosmic rays (note that by default cosmic ray rejection is handled in the post processing recipes while the data is reformatted into a datacube, so that the default setting is cr=&none& here), converts the images from adu to count, subtracts the dark, divides by the flat-field, and (optionally) propagates the integrated flux value from the twilight-sky cube. [For special cases, users can choose to combine all input files at the image level, so that the pixel table is only created once, for the combined data. This is not recommended for science data, where the combination should take place after correcting for atmospheric effects, before the creation of the final cube.] The reduced image is then saved (if --saveimage=true). 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 for each exposure. If --skylines contains one or more wavelengths for (bright and isolated) sky emission lines, these lines are used to correct the wavelength calibration using an offset. The data is then cut to a useful wavelength range (if --crop=true). 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 is multiplied by the normalized median flux of that slice in the ILLUM exposure. As last step, the data is divided by the normalized twilight cube (if given), using the 3D coordinate of each pixel in the pixel table to interpolate the twilight correction onto the data. This pre-reduced pixel table for each exposure is then saved to disk.";
91 static const char *muse_scibasic_help_esorex =
92 "\n\nInput frames for raw frame tag \"OBJECT\":\n"
93 "\n Frame tag Type Req #Fr Description"
94 "\n -------------------- ---- --- --- ------------"
95 "\n OBJECT raw . Raw exposure of a science target"
96 "\n STD raw . Raw exposure of a standard star field"
97 "\n SKY raw . Raw exposure of an (almost) empty sky field"
98 "\n ASTROMETRY raw . Raw exposure of an astrometric field"
99 "\n ILLUM raw . 1 Single optional raw attached-field field exposure"
100 "\n MASTER_BIAS calib Y 1 Master bias"
101 "\n MASTER_DARK calib . 1 Master dark"
102 "\n MASTER_FLAT calib Y 1 Master flat"
103 "\n TRACE_TABLE calib Y 1 Trace table"
104 "\n WAVECAL_TABLE calib Y 1 Wavelength calibration table"
105 "\n GEOMETRY_TABLE calib Y 1 Relative positions of the slices in the field of view"
106 "\n TWILIGHT_CUBE calib . Smoothed cube of twilight sky"
107 "\n BADPIX_TABLE calib . 1 Known bad pixels"
108 "\n\nProduct frames for raw frame tag \"OBJECT\":\n"
109 "\n Frame tag Level Description"
110 "\n -------------------- -------- ------------"
111 "\n OBJECT_RED intermed Pre-processed CCD-based images for OBJECT input (if --saveimage=true)"
112 "\n OBJECT_RESAMPLED intermed Resampled 2D image for OBJECT input (if --resample=true)"
113 "\n PIXTABLE_OBJECT intermed Output pixel table for OBJECT input"
114 "\n STD_RED intermed Pre-processed CCD-based images for STD input (if --saveimage=true)"
115 "\n STD_RESAMPLED intermed Resampled 2D image for STD input (if --resample=true)"
116 "\n PIXTABLE_STD intermed Output pixel table for STD input"
117 "\n SKY_RED intermed Pre-processed CCD-based images for SKY input (if --saveimage=true)"
118 "\n SKY_RESAMPLED intermed Resampled 2D image for SKY input (if --resample=true)"
119 "\n PIXTABLE_SKY intermed Output pixel table for SKY input"
120 "\n ASTROMETRY_RED intermed Pre-processed CCD-based images for ASTROMETRY input (if --saveimage=true)"
121 "\n ASTROMETRY_RESAMPLED intermed Resampled 2D image for ASTROMETRY input (if --resample=true)"
122 "\n PIXTABLE_ASTROMETRY intermed Output pixel table for ASTROMETRY input" "\n\nInput frames for raw frame tag \"REDUCED\":\n"
123 "\n Frame tag Type Req #Fr Description"
124 "\n -------------------- ---- --- --- ------------"
125 "\n REDUCED raw Y Reduced CCD image"
126 "\n TRACE_TABLE calib Y 1 Trace table"
127 "\n WAVECAL_TABLE calib Y 1 Wavelength calibration table"
128 "\n GEOMETRY_TABLE calib Y 1 Relative positions of the slices in the field of view"
129 "\n\nProduct frames for raw frame tag \"REDUCED\":\n"
130 "\n Frame tag Level Description"
131 "\n -------------------- -------- ------------"
132 "\n REDUCED_RESAMPLED intermed Resampled 2D image (if --resample=true)"
133 "\n PIXTABLE_REDUCED intermed Output pixel table";
144 static cpl_recipeconfig *
145 muse_scibasic_new_recipeconfig(
void)
147 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
151 cpl_recipeconfig_set_tag(recipeconfig, tag, -1, -1);
153 cpl_recipeconfig_set_tag(recipeconfig, tag, -1, -1);
155 cpl_recipeconfig_set_tag(recipeconfig, tag, -1, -1);
157 cpl_recipeconfig_set_tag(recipeconfig, tag, -1, -1);
159 cpl_recipeconfig_set_tag(recipeconfig, tag, -1, 1);
160 cpl_recipeconfig_set_input(recipeconfig, tag,
"MASTER_BIAS", 1, 1);
161 cpl_recipeconfig_set_input(recipeconfig, tag,
"MASTER_DARK", -1, 1);
162 cpl_recipeconfig_set_input(recipeconfig, tag,
"MASTER_FLAT", 1, 1);
163 cpl_recipeconfig_set_input(recipeconfig, tag,
"TRACE_TABLE", 1, 1);
164 cpl_recipeconfig_set_input(recipeconfig, tag,
"WAVECAL_TABLE", 1, 1);
165 cpl_recipeconfig_set_input(recipeconfig, tag,
"GEOMETRY_TABLE", 1, 1);
166 cpl_recipeconfig_set_input(recipeconfig, tag,
"TWILIGHT_CUBE", -1, -1);
167 cpl_recipeconfig_set_input(recipeconfig, tag,
"BADPIX_TABLE", -1, 1);
168 cpl_recipeconfig_set_output(recipeconfig, tag,
"OBJECT_RED");
169 cpl_recipeconfig_set_output(recipeconfig, tag,
"OBJECT_RESAMPLED");
170 cpl_recipeconfig_set_output(recipeconfig, tag,
"PIXTABLE_OBJECT");
171 cpl_recipeconfig_set_output(recipeconfig, tag,
"STD_RED");
172 cpl_recipeconfig_set_output(recipeconfig, tag,
"STD_RESAMPLED");
173 cpl_recipeconfig_set_output(recipeconfig, tag,
"PIXTABLE_STD");
174 cpl_recipeconfig_set_output(recipeconfig, tag,
"SKY_RED");
175 cpl_recipeconfig_set_output(recipeconfig, tag,
"SKY_RESAMPLED");
176 cpl_recipeconfig_set_output(recipeconfig, tag,
"PIXTABLE_SKY");
177 cpl_recipeconfig_set_output(recipeconfig, tag,
"ASTROMETRY_RED");
178 cpl_recipeconfig_set_output(recipeconfig, tag,
"ASTROMETRY_RESAMPLED");
179 cpl_recipeconfig_set_output(recipeconfig, tag,
"PIXTABLE_ASTROMETRY");
182 cpl_recipeconfig_set_tag(recipeconfig, tag, 1, -1);
183 cpl_recipeconfig_set_input(recipeconfig, tag,
"TRACE_TABLE", 1, 1);
184 cpl_recipeconfig_set_input(recipeconfig, tag,
"WAVECAL_TABLE", 1, 1);
185 cpl_recipeconfig_set_input(recipeconfig, tag,
"GEOMETRY_TABLE", 1, 1);
186 cpl_recipeconfig_set_output(recipeconfig, tag,
"REDUCED_RESAMPLED");
187 cpl_recipeconfig_set_output(recipeconfig, tag,
"PIXTABLE_REDUCED");
203 static cpl_error_code
204 muse_scibasic_prepare_header(
const char *aFrametag, cpl_propertylist *aHeader)
206 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
207 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
208 if (!strcmp(aFrametag,
"OBJECT_RED")) {
211 "Number of saturated pixels in output data");
212 }
else if (!strcmp(aFrametag,
"OBJECT_RESAMPLED")) {
213 }
else if (!strcmp(aFrametag,
"PIXTABLE_OBJECT")) {
216 "Number of saturated pixels in output data");
219 "[Angstrom] Shift in wavelength applied to the data using sky emission line(s)");
220 }
else if (!strcmp(aFrametag,
"STD_RED")) {
223 "Number of saturated pixels in output data");
224 }
else if (!strcmp(aFrametag,
"STD_RESAMPLED")) {
225 }
else if (!strcmp(aFrametag,
"PIXTABLE_STD")) {
228 "Number of saturated pixels in output data");
229 }
else if (!strcmp(aFrametag,
"SKY_RED")) {
232 "Number of saturated pixels in output data");
233 }
else if (!strcmp(aFrametag,
"SKY_RESAMPLED")) {
234 }
else if (!strcmp(aFrametag,
"PIXTABLE_SKY")) {
237 "Number of saturated pixels in output data");
238 }
else if (!strcmp(aFrametag,
"ASTROMETRY_RED")) {
241 "Number of saturated pixels in output data");
242 }
else if (!strcmp(aFrametag,
"ASTROMETRY_RESAMPLED")) {
243 }
else if (!strcmp(aFrametag,
"PIXTABLE_ASTROMETRY")) {
246 "Number of saturated pixels in output data");
247 }
else if (!strcmp(aFrametag,
"REDUCED_RESAMPLED")) {
248 }
else if (!strcmp(aFrametag,
"PIXTABLE_REDUCED")) {
250 cpl_msg_warning(__func__,
"Frame tag %s is not defined", aFrametag);
251 return CPL_ERROR_ILLEGAL_INPUT;
253 return CPL_ERROR_NONE;
266 static cpl_frame_level
267 muse_scibasic_get_frame_level(
const char *aFrametag)
270 return CPL_FRAME_LEVEL_NONE;
272 if (!strcmp(aFrametag,
"OBJECT_RED")) {
273 return CPL_FRAME_LEVEL_INTERMEDIATE;
275 if (!strcmp(aFrametag,
"OBJECT_RESAMPLED")) {
276 return CPL_FRAME_LEVEL_INTERMEDIATE;
278 if (!strcmp(aFrametag,
"PIXTABLE_OBJECT")) {
279 return CPL_FRAME_LEVEL_INTERMEDIATE;
281 if (!strcmp(aFrametag,
"STD_RED")) {
282 return CPL_FRAME_LEVEL_INTERMEDIATE;
284 if (!strcmp(aFrametag,
"STD_RESAMPLED")) {
285 return CPL_FRAME_LEVEL_INTERMEDIATE;
287 if (!strcmp(aFrametag,
"PIXTABLE_STD")) {
288 return CPL_FRAME_LEVEL_INTERMEDIATE;
290 if (!strcmp(aFrametag,
"SKY_RED")) {
291 return CPL_FRAME_LEVEL_INTERMEDIATE;
293 if (!strcmp(aFrametag,
"SKY_RESAMPLED")) {
294 return CPL_FRAME_LEVEL_INTERMEDIATE;
296 if (!strcmp(aFrametag,
"PIXTABLE_SKY")) {
297 return CPL_FRAME_LEVEL_INTERMEDIATE;
299 if (!strcmp(aFrametag,
"ASTROMETRY_RED")) {
300 return CPL_FRAME_LEVEL_INTERMEDIATE;
302 if (!strcmp(aFrametag,
"ASTROMETRY_RESAMPLED")) {
303 return CPL_FRAME_LEVEL_INTERMEDIATE;
305 if (!strcmp(aFrametag,
"PIXTABLE_ASTROMETRY")) {
306 return CPL_FRAME_LEVEL_INTERMEDIATE;
308 if (!strcmp(aFrametag,
"REDUCED_RESAMPLED")) {
309 return CPL_FRAME_LEVEL_INTERMEDIATE;
311 if (!strcmp(aFrametag,
"PIXTABLE_REDUCED")) {
312 return CPL_FRAME_LEVEL_INTERMEDIATE;
314 return CPL_FRAME_LEVEL_NONE;
328 muse_scibasic_get_frame_mode(
const char *aFrametag)
333 if (!strcmp(aFrametag,
"OBJECT_RED")) {
336 if (!strcmp(aFrametag,
"OBJECT_RESAMPLED")) {
339 if (!strcmp(aFrametag,
"PIXTABLE_OBJECT")) {
342 if (!strcmp(aFrametag,
"STD_RED")) {
345 if (!strcmp(aFrametag,
"STD_RESAMPLED")) {
348 if (!strcmp(aFrametag,
"PIXTABLE_STD")) {
351 if (!strcmp(aFrametag,
"SKY_RED")) {
354 if (!strcmp(aFrametag,
"SKY_RESAMPLED")) {
357 if (!strcmp(aFrametag,
"PIXTABLE_SKY")) {
360 if (!strcmp(aFrametag,
"ASTROMETRY_RED")) {
363 if (!strcmp(aFrametag,
"ASTROMETRY_RESAMPLED")) {
366 if (!strcmp(aFrametag,
"PIXTABLE_ASTROMETRY")) {
369 if (!strcmp(aFrametag,
"REDUCED_RESAMPLED")) {
372 if (!strcmp(aFrametag,
"PIXTABLE_REDUCED")) {
390 muse_scibasic_create(cpl_plugin *aPlugin)
394 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
395 recipe = (cpl_recipe *)aPlugin;
403 muse_scibasic_new_recipeconfig(),
404 muse_scibasic_prepare_header,
405 muse_scibasic_get_frame_level,
406 muse_scibasic_get_frame_mode);
411 cpl_msg_set_time_on();
415 recipe->parameters = cpl_parameterlist_new();
420 p = cpl_parameter_new_range(
"muse.muse_scibasic.nifu",
422 "IFU to handle. If set to 0, all IFUs are processed serially. If set to -1, all IFUs are processed in parallel.",
423 "muse.muse_scibasic",
427 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nifu");
428 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nifu");
430 cpl_parameterlist_append(recipe->parameters, p);
433 p = cpl_parameter_new_value(
"muse.muse_scibasic.overscan",
435 "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.",
436 "muse.muse_scibasic",
437 (
const char *)
"vpoly");
438 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"overscan");
439 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"overscan");
441 cpl_parameterlist_append(recipe->parameters, p);
444 p = cpl_parameter_new_value(
"muse.muse_scibasic.ovscreject",
446 "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\").",
447 "muse.muse_scibasic",
448 (
const char *)
"dcr");
449 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscreject");
450 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscreject");
452 cpl_parameterlist_append(recipe->parameters, p);
455 p = cpl_parameter_new_value(
"muse.muse_scibasic.ovscsigma",
457 "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\".",
458 "muse.muse_scibasic",
460 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscsigma");
461 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscsigma");
463 cpl_parameterlist_append(recipe->parameters, p);
466 p = cpl_parameter_new_value(
"muse.muse_scibasic.ovscignore",
468 "The number of pixels of the overscan adjacent to the data region of the CCD that are ignored when computing statistics or fits.",
469 "muse.muse_scibasic",
471 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscignore");
472 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscignore");
474 cpl_parameterlist_append(recipe->parameters, p);
477 p = cpl_parameter_new_value(
"muse.muse_scibasic.crop",
479 "Automatically crop the output pixel tables in wavelength depending on the expected useful wavelength range of the observation mode used (4750-9350 Angstrom for nominal mode, 4600-9350 Angstrom for extended mode).",
480 "muse.muse_scibasic",
482 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"crop");
483 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"crop");
485 cpl_parameterlist_append(recipe->parameters, p);
488 p = cpl_parameter_new_enum(
"muse.muse_scibasic.cr",
490 "Type of cosmic ray cleaning to use (for quick-look data processing).",
491 "muse.muse_scibasic",
492 (
const char *)
"none",
494 (
const char *)
"none",
495 (
const char *)
"dcr");
496 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"cr");
497 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"cr");
499 cpl_parameterlist_append(recipe->parameters, p);
502 p = cpl_parameter_new_value(
"muse.muse_scibasic.xbox",
504 "Search box size in x. Only used if cr=dcr.",
505 "muse.muse_scibasic",
507 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"xbox");
508 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"xbox");
510 cpl_parameterlist_append(recipe->parameters, p);
513 p = cpl_parameter_new_value(
"muse.muse_scibasic.ybox",
515 "Search box size in y. Only used if cr=dcr.",
516 "muse.muse_scibasic",
518 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ybox");
519 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ybox");
521 cpl_parameterlist_append(recipe->parameters, p);
524 p = cpl_parameter_new_value(
"muse.muse_scibasic.passes",
526 "Maximum number of cleaning passes. Only used if cr=dcr.",
527 "muse.muse_scibasic",
529 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"passes");
530 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"passes");
532 cpl_parameterlist_append(recipe->parameters, p);
535 p = cpl_parameter_new_value(
"muse.muse_scibasic.thres",
537 "Threshold for detection gap in factors of standard deviation. Only used if cr=dcr.",
538 "muse.muse_scibasic",
540 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"thres");
541 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"thres");
543 cpl_parameterlist_append(recipe->parameters, p);
546 p = cpl_parameter_new_enum(
"muse.muse_scibasic.combine",
548 "Type of combination to use. Note that in most cases, science exposures cannot easily be combined on the CCD level, so this should usually be kept as \"none\"! This does not pay attention about the type of input data, and will combine all raw inputs!",
549 "muse.muse_scibasic",
550 (
const char *)
"none",
552 (
const char *)
"none",
553 (
const char *)
"average",
554 (
const char *)
"median",
555 (
const char *)
"minmax",
556 (
const char *)
"sigclip");
557 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"combine");
558 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"combine");
560 cpl_parameterlist_append(recipe->parameters, p);
563 p = cpl_parameter_new_value(
"muse.muse_scibasic.nlow",
565 "Number of minimum pixels to reject with minmax",
566 "muse.muse_scibasic",
568 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nlow");
569 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nlow");
571 cpl_parameterlist_append(recipe->parameters, p);
574 p = cpl_parameter_new_value(
"muse.muse_scibasic.nhigh",
576 "Number of maximum pixels to reject with minmax",
577 "muse.muse_scibasic",
579 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nhigh");
580 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nhigh");
582 cpl_parameterlist_append(recipe->parameters, p);
585 p = cpl_parameter_new_value(
"muse.muse_scibasic.nkeep",
587 "Number of pixels to keep with minmax",
588 "muse.muse_scibasic",
590 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nkeep");
591 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nkeep");
593 cpl_parameterlist_append(recipe->parameters, p);
596 p = cpl_parameter_new_value(
"muse.muse_scibasic.lsigma",
598 "Low sigma for pixel rejection with sigclip",
599 "muse.muse_scibasic",
601 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"lsigma");
602 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"lsigma");
604 cpl_parameterlist_append(recipe->parameters, p);
607 p = cpl_parameter_new_value(
"muse.muse_scibasic.hsigma",
609 "High sigma for pixel rejection with sigclip",
610 "muse.muse_scibasic",
612 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"hsigma");
613 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"hsigma");
615 cpl_parameterlist_append(recipe->parameters, p);
618 p = cpl_parameter_new_value(
"muse.muse_scibasic.scale",
620 "Scale the individual images to a common exposure time before combining them.",
621 "muse.muse_scibasic",
623 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"scale");
624 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"scale");
626 cpl_parameterlist_append(recipe->parameters, p);
629 p = cpl_parameter_new_value(
"muse.muse_scibasic.saveimage",
631 "Save the pre-processed CCD-based image of each input exposure before it is transformed into a pixel table.",
632 "muse.muse_scibasic",
634 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"saveimage");
635 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"saveimage");
637 cpl_parameterlist_append(recipe->parameters, p);
640 p = cpl_parameter_new_value(
"muse.muse_scibasic.skylines",
642 "List of wavelengths of sky emission lines (in Angstrom) to use as reference for wavelength offset correction using a Gaussian fit. It can contain multiple (isolated) lines, as comma-separated list, individual shifts are then combined into one weighted average offset. Set to \"none\" to deactivate.",
643 "muse.muse_scibasic",
644 (
const char *)
"5577.339,6300.304");
645 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"skylines");
646 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"skylines");
648 cpl_parameterlist_append(recipe->parameters, p);
651 p = cpl_parameter_new_value(
"muse.muse_scibasic.skyhalfwidth",
653 "Half-width of the extraction box (in Angstrom) around each sky emission line.",
654 "muse.muse_scibasic",
656 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"skyhalfwidth");
657 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"skyhalfwidth");
659 cpl_parameterlist_append(recipe->parameters, p);
662 p = cpl_parameter_new_value(
"muse.muse_scibasic.skybinsize",
664 "Size of the bins (in Angstrom per pixel) for the intermediate spectrum to do the Gaussian fit to each sky emission line.",
665 "muse.muse_scibasic",
667 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"skybinsize");
668 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"skybinsize");
670 cpl_parameterlist_append(recipe->parameters, p);
673 p = cpl_parameter_new_value(
"muse.muse_scibasic.resample",
675 "Resample the input science data into 2D spectral images using tracing and wavelength calibration solutions for a visual check. Note that the image produced will show small wiggles even when the input calibrations are good and were applied successfully!",
676 "muse.muse_scibasic",
678 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"resample");
679 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"resample");
681 cpl_parameterlist_append(recipe->parameters, p);
684 p = cpl_parameter_new_value(
"muse.muse_scibasic.dlambda",
686 "Wavelength step (in Angstrom per pixel) to use for resampling.",
687 "muse.muse_scibasic",
689 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"dlambda");
690 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"dlambda");
692 cpl_parameterlist_append(recipe->parameters, p);
695 p = cpl_parameter_new_value(
"muse.muse_scibasic.merge",
697 "Merge output products from different IFUs into a common file.",
698 "muse.muse_scibasic",
700 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"merge");
701 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"merge");
703 cpl_parameterlist_append(recipe->parameters, p);
723 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
724 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
727 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.nifu");
728 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
729 aParams->
nifu = cpl_parameter_get_int(p);
731 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.overscan");
732 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
733 aParams->
overscan = cpl_parameter_get_string(p);
735 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.ovscreject");
736 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
737 aParams->
ovscreject = cpl_parameter_get_string(p);
739 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.ovscsigma");
740 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
741 aParams->
ovscsigma = cpl_parameter_get_double(p);
743 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.ovscignore");
744 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
745 aParams->
ovscignore = cpl_parameter_get_int(p);
747 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.crop");
748 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
749 aParams->
crop = cpl_parameter_get_bool(p);
751 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.cr");
752 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
753 aParams->
cr_s = cpl_parameter_get_string(p);
755 (!strcasecmp(aParams->
cr_s,
"none")) ? MUSE_SCIBASIC_PARAM_CR_NONE :
756 (!strcasecmp(aParams->
cr_s,
"dcr")) ? MUSE_SCIBASIC_PARAM_CR_DCR :
757 MUSE_SCIBASIC_PARAM_CR_INVALID_VALUE;
758 cpl_ensure_code(aParams->
cr != MUSE_SCIBASIC_PARAM_CR_INVALID_VALUE,
759 CPL_ERROR_ILLEGAL_INPUT);
761 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.xbox");
762 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
763 aParams->
xbox = cpl_parameter_get_int(p);
765 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.ybox");
766 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
767 aParams->
ybox = cpl_parameter_get_int(p);
769 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.passes");
770 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
771 aParams->
passes = cpl_parameter_get_int(p);
773 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.thres");
774 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
775 aParams->
thres = cpl_parameter_get_double(p);
777 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.combine");
778 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
779 aParams->
combine_s = cpl_parameter_get_string(p);
781 (!strcasecmp(aParams->
combine_s,
"none")) ? MUSE_SCIBASIC_PARAM_COMBINE_NONE :
782 (!strcasecmp(aParams->
combine_s,
"average")) ? MUSE_SCIBASIC_PARAM_COMBINE_AVERAGE :
783 (!strcasecmp(aParams->
combine_s,
"median")) ? MUSE_SCIBASIC_PARAM_COMBINE_MEDIAN :
784 (!strcasecmp(aParams->
combine_s,
"minmax")) ? MUSE_SCIBASIC_PARAM_COMBINE_MINMAX :
785 (!strcasecmp(aParams->
combine_s,
"sigclip")) ? MUSE_SCIBASIC_PARAM_COMBINE_SIGCLIP :
786 MUSE_SCIBASIC_PARAM_COMBINE_INVALID_VALUE;
787 cpl_ensure_code(aParams->
combine != MUSE_SCIBASIC_PARAM_COMBINE_INVALID_VALUE,
788 CPL_ERROR_ILLEGAL_INPUT);
790 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.nlow");
791 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
792 aParams->
nlow = cpl_parameter_get_int(p);
794 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.nhigh");
795 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
796 aParams->
nhigh = cpl_parameter_get_int(p);
798 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.nkeep");
799 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
800 aParams->
nkeep = cpl_parameter_get_int(p);
802 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.lsigma");
803 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
804 aParams->
lsigma = cpl_parameter_get_double(p);
806 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.hsigma");
807 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
808 aParams->
hsigma = cpl_parameter_get_double(p);
810 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.scale");
811 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
812 aParams->
scale = cpl_parameter_get_bool(p);
814 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.saveimage");
815 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
816 aParams->
saveimage = cpl_parameter_get_bool(p);
818 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.skylines");
819 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
820 aParams->
skylines = cpl_parameter_get_string(p);
822 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.skyhalfwidth");
823 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
826 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.skybinsize");
827 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
828 aParams->
skybinsize = cpl_parameter_get_double(p);
830 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.resample");
831 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
832 aParams->
resample = cpl_parameter_get_bool(p);
834 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.dlambda");
835 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
836 aParams->
dlambda = cpl_parameter_get_double(p);
838 p = cpl_parameterlist_find(aParameters,
"muse.muse_scibasic.merge");
839 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
840 aParams->
merge = cpl_parameter_get_bool(p);
854 muse_scibasic_exec(cpl_plugin *aPlugin)
856 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
859 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
860 cpl_msg_set_threadid_on();
862 cpl_frameset *usedframes = cpl_frameset_new(),
863 *outframes = cpl_frameset_new();
865 muse_scibasic_params_fill(¶ms, recipe->parameters);
867 cpl_errorstate prestate = cpl_errorstate_get();
869 if (params.
nifu < -1 || params.
nifu > kMuseNumIFUs) {
870 cpl_msg_error(__func__,
"Please specify a valid IFU number (between 1 and "
871 "%d), 0 (to process all IFUs consecutively), or -1 (to "
872 "process all IFUs in parallel) using --nifu.", kMuseNumIFUs);
876 cpl_boolean donotmerge = CPL_FALSE;
878 if (params.
nifu > 0) {
881 rc = muse_scibasic_compute(proc, ¶ms);
882 cpl_frameset_join(usedframes, proc->
usedframes);
883 cpl_frameset_join(outframes, proc->
outframes);
885 donotmerge = CPL_TRUE;
886 }
else if (params.
nifu < 0) {
887 int *rcs = cpl_calloc(kMuseNumIFUs,
sizeof(
int));
889 #pragma omp parallel for default(none) \
890 shared(outframes, params, rcs, recipe, usedframes)
891 for (nifu = 1; nifu <= kMuseNumIFUs; nifu++) {
897 int *rci = rcs + (nifu - 1);
898 *rci = muse_scibasic_compute(proc, pars);
899 if (rci && cpl_error_get_code() == MUSE_ERROR_CHIP_NOT_LIVE) {
903 #pragma omp critical(muse_processing_used_frames)
904 cpl_frameset_join(usedframes, proc->
usedframes);
905 #pragma omp critical(muse_processing_output_frames)
906 cpl_frameset_join(outframes, proc->
outframes);
911 for (nifu = 1; nifu <= kMuseNumIFUs; nifu++) {
912 if (rcs[nifu-1] != 0) {
918 for (params.
nifu = 1; params.
nifu <= kMuseNumIFUs && !rc; params.
nifu++) {
921 rc = muse_scibasic_compute(proc, ¶ms);
922 if (rc && cpl_error_get_code() == MUSE_ERROR_CHIP_NOT_LIVE) {
925 cpl_frameset_join(usedframes, proc->
usedframes);
926 cpl_frameset_join(outframes, proc->
outframes);
930 UNUSED_ARGUMENT(donotmerge);
932 if (!cpl_errorstate_is_equal(prestate)) {
936 cpl_msg_set_level(CPL_MSG_INFO);
943 if (params.
merge && !donotmerge) {
944 muse_utils_frameset_merge_frames(outframes);
952 cpl_frameset_join(recipe->frames, usedframes);
953 cpl_frameset_join(recipe->frames, outframes);
954 cpl_frameset_delete(usedframes);
955 cpl_frameset_delete(outframes);
968 muse_scibasic_destroy(cpl_plugin *aPlugin)
972 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
973 recipe = (cpl_recipe *)aPlugin;
979 cpl_parameterlist_delete(recipe->parameters);
996 cpl_plugin_get_info(cpl_pluginlist *aList)
998 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
999 cpl_plugin *plugin = &recipe->interface;
1003 helptext = cpl_sprintf(
"%s%s", muse_scibasic_help,
1004 muse_scibasic_help_esorex);
1006 helptext = cpl_sprintf(
"%s", muse_scibasic_help);
1010 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
1011 CPL_PLUGIN_TYPE_RECIPE,
1013 "Remove the instrumental signature from the data of each CCD and convert them from an image into a pixel table.",
1018 muse_scibasic_create,
1020 muse_scibasic_destroy);
1021 cpl_pluginlist_append(aList, plugin);
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
int nkeep
Number of pixels to keep with minmax.
double hsigma
High sigma for pixel rejection with sigclip.
muse_cplframework_type muse_cplframework(void)
Return the CPL framework the recipe is run under.
int passes
Maximum number of cleaning passes. Only used if cr=dcr.
double ovscsigma
If the deviation of mean overscan levels between a raw input image and the reference image is higher ...
const char * combine_s
Type of combination to use. Note that in most cases, science exposures cannot easily be combined on t...
double dlambda
Wavelength step (in Angstrom per pixel) to use for resampling.
double lsigma
Low sigma for pixel rejection with sigclip.
int combine
Type of combination to use. Note that in most cases, science exposures cannot easily be combined on t...
int scale
Scale the individual images to a common exposure time before combining them.
cpl_frameset * usedframes
muse_processing * muse_processing_new(const char *aName, cpl_recipe *aRecipe)
Create a new processing structure.
int saveimage
Save the pre-processed CCD-based image of each input exposure before it is transformed into a pixel t...
const char * muse_get_license(void)
Get the pipeline copyright and license.
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.
int cr
Type of cosmic ray cleaning to use (for quick-look data processing).
int resample
Resample the input science data into 2D spectral images using tracing and wavelength calibration solu...
int merge
Merge output products from different IFUs into a common file.
int nifu
IFU to handle. If set to 0, all IFUs are processed serially. If set to -1, all IFUs are processed in ...
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
void muse_processinginfo_delete(cpl_recipe *)
Clear all information from the processing info and from the recipe config.
double skyhalfwidth
Half-width of the extraction box (in Angstrom) around each sky emission line.
int crop
Automatically crop the output pixel tables in wavelength depending on the expected useful wavelength ...
const char * ovscreject
This influences how values are rejected when computing overscan statistics. Either no rejection at al...
int xbox
Search box size in x. Only used if cr=dcr.
int nhigh
Number of maximum pixels to reject with minmax.
cpl_error_code muse_cplframeset_erase_duplicate(cpl_frameset *aFrames)
Erase all duplicate frames from a frameset.
int ybox
Search box size in y. Only used if cr=dcr.
double thres
Threshold for detection gap in factors of standard deviation. Only used if cr=dcr.
Structure to hold the parameters of the muse_scibasic recipe.
double skybinsize
Size of the bins (in Angstrom per pixel) for the intermediate spectrum to do the Gaussian fit to each...
cpl_error_code muse_cplframeset_erase_all(cpl_frameset *aFrames)
Erase all frames in a frameset.
const char * cr_s
Type of cosmic ray cleaning to use (for quick-look data processing). (as string)
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.
const char * skylines
List of wavelengths of sky emission lines (in Angstrom) to use as reference for wavelength offset cor...
int ovscignore
The number of pixels of the overscan adjacent to the data region of the CCD that are ignored when com...
int nlow
Number of minimum pixels to reject with minmax.
cpl_error_code muse_processing_prepare_property(cpl_propertylist *, const char *, cpl_type, const char *)
Prepare and check the specified property.