35 #include "muse_wavecal_z.h" 82 static const char *muse_wavecal_help =
83 "This recipe detects arc emission lines and fits a wavelength solution to each slice of the instrument. The wavelength calibration table contains polynomials defining the wavelength solution of the slices on the CCD. Processing trims the raw data and records the overscan statistics, subtracts the bias (taking account of the overscan, if --overscan is not \"none\") and converts them from adu to count. Optionally, the dark can be subtracted and the data can be divided by the flat-field, but this is not recommended. The data is then combined using input parameters, into separate images for each lamp. To compute the wavelength solution, arc lines are detected at the center of each slice (using threshold detection on a S/N image) and subsequently assigned wavelengths, using pattern matching to identify lines from the input line catalog. Each line is then traced to the edges of the slice, using Gaussian centering in each CCD column. The Gaussians not only yield center, but also centering error, and line properties (e.g. FWHM). Deviant fits are detected using polynomial fits to each arc line (using the xorder parameter) and rejected. These analysis and measuring steps are carried out separately on images exposed by the different arc lamps, reducing the amount of blending, that can otherwise influence line identification and Gaussian centering. The final two-dimensional fit uses all positions (of all lamps), their wavelengths, and the given polynomial orders to compute the final wavelength solution for each slice, iteratively rejecting outliers. This final fit can be either unweighted (fitweighting=\"uniform\", for fastest processing) or weighted (other values of fitweighting, for higher accuracy).";
85 static const char *muse_wavecal_help_esorex =
86 "\n\nInput frames for raw frame tag \"ARC\":\n" 87 "\n Frame tag Type Req #Fr Description" 88 "\n -------------------- ---- --- --- ------------" 89 "\n ARC raw Y Raw arc lamp exposures" 90 "\n MASTER_BIAS calib Y 1 Master bias" 91 "\n MASTER_DARK calib . 1 Master dark" 92 "\n MASTER_FLAT calib . 1 Master flat" 93 "\n TRACE_TABLE calib Y 1 Trace table" 94 "\n LINE_CATALOG calib Y 1 Arc line catalog" 95 "\n BADPIX_TABLE calib . Known bad pixels" 96 "\n\nProduct frames for raw frame tag \"ARC\":\n" 97 "\n Frame tag Level Description" 98 "\n -------------------- -------- ------------" 99 "\n WAVECAL_TABLE final Wavelength calibration table" 100 "\n WAVECAL_RESIDUALS final Fit residuals of all arc lines (if --residuals=true)" 101 "\n ARC_RED_LAMP final Reduced ARC image, per lamp (if --saveimages=true)";
112 static cpl_recipeconfig *
113 muse_wavecal_new_recipeconfig(
void)
115 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
117 cpl_recipeconfig_set_tag(recipeconfig,
"ARC", 1, -1);
118 cpl_recipeconfig_set_input(recipeconfig,
"ARC",
"MASTER_BIAS", 1, 1);
119 cpl_recipeconfig_set_input(recipeconfig,
"ARC",
"MASTER_DARK", -1, 1);
120 cpl_recipeconfig_set_input(recipeconfig,
"ARC",
"MASTER_FLAT", -1, 1);
121 cpl_recipeconfig_set_input(recipeconfig,
"ARC",
"TRACE_TABLE", 1, 1);
122 cpl_recipeconfig_set_input(recipeconfig,
"ARC",
"LINE_CATALOG", 1, 1);
123 cpl_recipeconfig_set_input(recipeconfig,
"ARC",
"BADPIX_TABLE", -1, -1);
124 cpl_recipeconfig_set_output(recipeconfig,
"ARC",
"WAVECAL_TABLE");
125 cpl_recipeconfig_set_output(recipeconfig,
"ARC",
"WAVECAL_RESIDUALS");
126 cpl_recipeconfig_set_output(recipeconfig,
"ARC",
"ARC_RED_LAMP");
142 static cpl_error_code
143 muse_wavecal_prepare_header(
const char *aFrametag, cpl_propertylist *aHeader)
145 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
146 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
147 if (!strcmp(aFrametag,
"WAVECAL_TABLE")) {
150 "Number of detected arc lines in slice j");
153 "Number of identified arc lines in slice j");
156 "[count] Mean peak count level above background of detected arc lines in slice j");
159 "[count] Standard deviation of peak count level above background of detected arc lines in slice j");
162 "[count] Peak count level above background of the faintest line in slice j");
165 "[count] Peak count level above background of the brightest line in slice j");
168 "[count] Mean peak count level of lines of lamp l above background of detected arc lines in slice j.");
171 "[count] Standard deviation of peak count level of lines of lamp l above background of detected arc lines in slice j.");
174 "[count] Peak count level above background of the brightest line of lamp l in slice j.");
177 "Mean FWHM of detected arc lines in slice j");
180 "Standard deviation of FWHM of detected arc lines in slice j");
183 "Minimum FWHM of detected arc lines in slice j");
186 "Maximum FWHM of detected arc lines in slice j");
189 "Mean spectral resolution R determined in slice j");
192 "Number of arc lines used in calibration solution fit in slice j");
195 "[Angstrom] RMS of the wavelength calibration fit in slice j");
198 "[Angstrom] Difference in wavelength computed for the bottom left and bottom right corners of the slice on the CCD");
201 "[Angstrom] Difference in wavelength computed for the top left and top right corners of the slice on the CCD");
204 "[pix] Position of wavelength given in WLEN in slice j");
207 "[Angstrom] Wavelength associated to WLPOS in slice j");
210 "Number of saturated pixels in output data of lamp l");
211 }
else if (!strcmp(aFrametag,
"WAVECAL_RESIDUALS")) {
212 }
else if (!strcmp(aFrametag,
"ARC_RED_LAMP")) {
215 "Number of saturated pixels in raw arc i in input list");
218 "Number of saturated pixels in output data");
220 cpl_msg_warning(__func__,
"Frame tag %s is not defined", aFrametag);
221 return CPL_ERROR_ILLEGAL_INPUT;
223 return CPL_ERROR_NONE;
236 static cpl_frame_level
237 muse_wavecal_get_frame_level(
const char *aFrametag)
240 return CPL_FRAME_LEVEL_NONE;
242 if (!strcmp(aFrametag,
"WAVECAL_TABLE")) {
243 return CPL_FRAME_LEVEL_FINAL;
245 if (!strcmp(aFrametag,
"WAVECAL_RESIDUALS")) {
246 return CPL_FRAME_LEVEL_FINAL;
248 if (!strcmp(aFrametag,
"ARC_RED_LAMP")) {
249 return CPL_FRAME_LEVEL_FINAL;
251 return CPL_FRAME_LEVEL_NONE;
265 muse_wavecal_get_frame_mode(
const char *aFrametag)
270 if (!strcmp(aFrametag,
"WAVECAL_TABLE")) {
273 if (!strcmp(aFrametag,
"WAVECAL_RESIDUALS")) {
276 if (!strcmp(aFrametag,
"ARC_RED_LAMP")) {
294 muse_wavecal_create(cpl_plugin *aPlugin)
298 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
299 recipe = (cpl_recipe *)aPlugin;
307 muse_wavecal_new_recipeconfig(),
308 muse_wavecal_prepare_header,
309 muse_wavecal_get_frame_level,
310 muse_wavecal_get_frame_mode);
315 cpl_msg_set_time_on();
319 recipe->parameters = cpl_parameterlist_new();
324 p = cpl_parameter_new_range(
"muse.muse_wavecal.nifu",
326 "IFU to handle. If set to 0, all IFUs are processed serially. If set to -1, all IFUs are processed in parallel.",
331 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nifu");
332 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nifu");
334 cpl_parameterlist_append(recipe->parameters, p);
337 p = cpl_parameter_new_value(
"muse.muse_wavecal.overscan",
339 "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.",
341 (
const char *)
"vpoly");
342 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"overscan");
343 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"overscan");
345 cpl_parameterlist_append(recipe->parameters, p);
348 p = cpl_parameter_new_value(
"muse.muse_wavecal.ovscreject",
350 "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\").",
352 (
const char *)
"dcr");
353 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscreject");
354 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscreject");
356 cpl_parameterlist_append(recipe->parameters, p);
359 p = cpl_parameter_new_value(
"muse.muse_wavecal.ovscsigma",
361 "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\".",
364 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscsigma");
365 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscsigma");
367 cpl_parameterlist_append(recipe->parameters, p);
370 p = cpl_parameter_new_value(
"muse.muse_wavecal.ovscignore",
372 "The number of pixels of the overscan adjacent to the data section of the CCD that are ignored when computing statistics or fits.",
375 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"ovscignore");
376 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ovscignore");
378 cpl_parameterlist_append(recipe->parameters, p);
381 p = cpl_parameter_new_enum(
"muse.muse_wavecal.combine",
383 "Type of lampwise image combination to use.",
385 (
const char *)
"sigclip",
387 (
const char *)
"average",
388 (
const char *)
"median",
389 (
const char *)
"minmax",
390 (
const char *)
"sigclip");
391 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"combine");
392 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"combine");
394 cpl_parameterlist_append(recipe->parameters, p);
397 p = cpl_parameter_new_value(
"muse.muse_wavecal.lampwise",
399 "Identify and measure the arc emission lines on images separately for each lamp setup.",
402 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"lampwise");
403 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"lampwise");
404 if (!getenv(
"MUSE_EXPERT_USER")) {
405 cpl_parameter_disable(p, CPL_PARAMETER_MODE_CLI);
408 cpl_parameterlist_append(recipe->parameters, p);
411 p = cpl_parameter_new_value(
"muse.muse_wavecal.sigma",
413 "Sigma level used to detect arc emission lines above the median background level in the S/N image of the central column of each slice",
416 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"sigma");
417 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sigma");
419 cpl_parameterlist_append(recipe->parameters, p);
422 p = cpl_parameter_new_value(
"muse.muse_wavecal.dres",
424 "The allowed range of resolutions for pattern matching (of detected arc lines to line list) in fractions relative to the expected value",
427 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"dres");
428 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"dres");
430 cpl_parameterlist_append(recipe->parameters, p);
433 p = cpl_parameter_new_value(
"muse.muse_wavecal.tolerance",
435 "Tolerance for pattern matching (of detected arc lines to line list)",
438 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"tolerance");
439 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"tolerance");
441 cpl_parameterlist_append(recipe->parameters, p);
444 p = cpl_parameter_new_value(
"muse.muse_wavecal.xorder",
446 "Order of the polynomial for the horizontal curvature within each slice",
449 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"xorder");
450 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"xorder");
452 cpl_parameterlist_append(recipe->parameters, p);
455 p = cpl_parameter_new_value(
"muse.muse_wavecal.yorder",
457 "Order of the polynomial used to fit the dispersion relation",
460 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"yorder");
461 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"yorder");
463 cpl_parameterlist_append(recipe->parameters, p);
466 p = cpl_parameter_new_value(
"muse.muse_wavecal.linesigma",
468 "Sigma level for iterative rejection of deviant fits for each arc line within each slice, a negative value means to use the default (2.5).",
471 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"linesigma");
472 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"linesigma");
474 cpl_parameterlist_append(recipe->parameters, p);
477 p = cpl_parameter_new_value(
"muse.muse_wavecal.residuals",
479 "Create a table containing residuals of the fits to the data of all arc lines. This is useful to assess the quality of the wavelength solution in detail.",
482 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"residuals");
483 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"residuals");
485 cpl_parameterlist_append(recipe->parameters, p);
488 p = cpl_parameter_new_value(
"muse.muse_wavecal.fitsigma",
490 "Sigma level for iterative rejection of deviant datapoints during the final polynomial wavelength solution within each slice, a negative value means to use the default (3.0).",
493 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"fitsigma");
494 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"fitsigma");
496 cpl_parameterlist_append(recipe->parameters, p);
499 p = cpl_parameter_new_enum(
"muse.muse_wavecal.fitweighting",
501 "Type of weighting to use in the final polynomial wavelength solution fit, using centroiding error estimate and/or scatter of each single line as estimates of its accuracy.",
503 (
const char *)
"cerrscatter",
505 (
const char *)
"uniform",
506 (
const char *)
"cerr",
507 (
const char *)
"scatter",
508 (
const char *)
"cerrscatter");
509 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"fitweighting");
510 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"fitweighting");
512 cpl_parameterlist_append(recipe->parameters, p);
515 p = cpl_parameter_new_value(
"muse.muse_wavecal.saveimages",
520 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"saveimages");
521 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"saveimages");
523 cpl_parameterlist_append(recipe->parameters, p);
526 p = cpl_parameter_new_value(
"muse.muse_wavecal.resample",
528 "Resample the input arc images onto 2D images for a visual check using tracing and wavelength calibration solutions. Note that the image produced will show small wiggles even when the calibration was successful!",
531 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"resample");
532 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"resample");
533 if (!getenv(
"MUSE_EXPERT_USER")) {
534 cpl_parameter_disable(p, CPL_PARAMETER_MODE_CLI);
537 cpl_parameterlist_append(recipe->parameters, p);
540 p = cpl_parameter_new_value(
"muse.muse_wavecal.wavemap",
542 "Create a wavelength map of the input images",
545 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"wavemap");
546 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wavemap");
547 if (!getenv(
"MUSE_EXPERT_USER")) {
548 cpl_parameter_disable(p, CPL_PARAMETER_MODE_CLI);
551 cpl_parameterlist_append(recipe->parameters, p);
554 p = cpl_parameter_new_value(
"muse.muse_wavecal.merge",
556 "Merge output products from different IFUs into a common file.",
559 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"merge");
560 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"merge");
562 cpl_parameterlist_append(recipe->parameters, p);
582 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
583 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
586 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.nifu");
587 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
588 aParams->
nifu = cpl_parameter_get_int(p);
590 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.overscan");
591 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
592 aParams->
overscan = cpl_parameter_get_string(p);
594 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.ovscreject");
595 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
596 aParams->
ovscreject = cpl_parameter_get_string(p);
598 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.ovscsigma");
599 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
600 aParams->
ovscsigma = cpl_parameter_get_double(p);
602 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.ovscignore");
603 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
604 aParams->
ovscignore = cpl_parameter_get_int(p);
606 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.combine");
607 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
608 aParams->
combine_s = cpl_parameter_get_string(p);
610 (!strcasecmp(aParams->
combine_s,
"average")) ? MUSE_WAVECAL_PARAM_COMBINE_AVERAGE :
611 (!strcasecmp(aParams->
combine_s,
"median")) ? MUSE_WAVECAL_PARAM_COMBINE_MEDIAN :
612 (!strcasecmp(aParams->
combine_s,
"minmax")) ? MUSE_WAVECAL_PARAM_COMBINE_MINMAX :
613 (!strcasecmp(aParams->
combine_s,
"sigclip")) ? MUSE_WAVECAL_PARAM_COMBINE_SIGCLIP :
614 MUSE_WAVECAL_PARAM_COMBINE_INVALID_VALUE;
615 cpl_ensure_code(aParams->
combine != MUSE_WAVECAL_PARAM_COMBINE_INVALID_VALUE,
616 CPL_ERROR_ILLEGAL_INPUT);
618 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.lampwise");
619 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
620 aParams->
lampwise = cpl_parameter_get_bool(p);
622 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.sigma");
623 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
624 aParams->
sigma = cpl_parameter_get_double(p);
626 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.dres");
627 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
628 aParams->
dres = cpl_parameter_get_double(p);
630 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.tolerance");
631 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
632 aParams->
tolerance = cpl_parameter_get_double(p);
634 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.xorder");
635 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
636 aParams->
xorder = cpl_parameter_get_int(p);
638 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.yorder");
639 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
640 aParams->
yorder = cpl_parameter_get_int(p);
642 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.linesigma");
643 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
644 aParams->
linesigma = cpl_parameter_get_double(p);
646 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.residuals");
647 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
648 aParams->
residuals = cpl_parameter_get_bool(p);
650 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.fitsigma");
651 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
652 aParams->
fitsigma = cpl_parameter_get_double(p);
654 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.fitweighting");
655 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
658 (!strcasecmp(aParams->
fitweighting_s,
"uniform")) ? MUSE_WAVECAL_PARAM_FITWEIGHTING_UNIFORM :
659 (!strcasecmp(aParams->
fitweighting_s,
"cerr")) ? MUSE_WAVECAL_PARAM_FITWEIGHTING_CERR :
660 (!strcasecmp(aParams->
fitweighting_s,
"scatter")) ? MUSE_WAVECAL_PARAM_FITWEIGHTING_SCATTER :
661 (!strcasecmp(aParams->
fitweighting_s,
"cerrscatter")) ? MUSE_WAVECAL_PARAM_FITWEIGHTING_CERRSCATTER :
662 MUSE_WAVECAL_PARAM_FITWEIGHTING_INVALID_VALUE;
663 cpl_ensure_code(aParams->
fitweighting != MUSE_WAVECAL_PARAM_FITWEIGHTING_INVALID_VALUE,
664 CPL_ERROR_ILLEGAL_INPUT);
666 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.saveimages");
667 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
668 aParams->
saveimages = cpl_parameter_get_bool(p);
670 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.resample");
671 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
672 aParams->
resample = cpl_parameter_get_bool(p);
674 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.wavemap");
675 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
676 aParams->
wavemap = cpl_parameter_get_bool(p);
678 p = cpl_parameterlist_find(aParameters,
"muse.muse_wavecal.merge");
679 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
680 aParams->
merge = cpl_parameter_get_bool(p);
694 muse_wavecal_exec(cpl_plugin *aPlugin)
696 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
700 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
701 cpl_msg_set_threadid_on();
703 cpl_frameset *usedframes = cpl_frameset_new(),
704 *outframes = cpl_frameset_new();
706 muse_wavecal_params_fill(¶ms, recipe->parameters);
708 cpl_errorstate prestate = cpl_errorstate_get();
710 if (params.
nifu < -1 || params.
nifu > kMuseNumIFUs) {
711 cpl_msg_error(__func__,
"Please specify a valid IFU number (between 1 and " 712 "%d), 0 (to process all IFUs consecutively), or -1 (to " 713 "process all IFUs in parallel) using --nifu.", kMuseNumIFUs);
717 cpl_boolean donotmerge = CPL_FALSE;
719 if (params.
nifu > 0) {
722 rc = muse_wavecal_compute(proc, ¶ms);
723 cpl_frameset_join(usedframes, proc->
usedframes);
724 cpl_frameset_join(outframes, proc->
outframes);
726 donotmerge = CPL_TRUE;
727 }
else if (params.
nifu < 0) {
728 int *rcs = cpl_calloc(kMuseNumIFUs,
sizeof(
int));
730 #pragma omp parallel for default(none) \ 731 shared(outframes, params, rcs, recipe, usedframes) 732 for (nifu = 1; nifu <= kMuseNumIFUs; nifu++) {
738 int *rci = rcs + (nifu - 1);
739 *rci = muse_wavecal_compute(proc, pars);
740 if (rci && (
int)cpl_error_get_code() == MUSE_ERROR_CHIP_NOT_LIVE) {
744 #pragma omp critical(muse_processing_used_frames) 745 cpl_frameset_join(usedframes, proc->
usedframes);
746 #pragma omp critical(muse_processing_output_frames) 747 cpl_frameset_join(outframes, proc->
outframes);
752 for (nifu = 1; nifu <= kMuseNumIFUs; nifu++) {
753 if (rcs[nifu-1] != 0) {
759 for (params.
nifu = 1; params.
nifu <= kMuseNumIFUs && !rc; params.
nifu++) {
762 rc = muse_wavecal_compute(proc, ¶ms);
763 if (rc && (
int)cpl_error_get_code() == MUSE_ERROR_CHIP_NOT_LIVE) {
766 cpl_frameset_join(usedframes, proc->
usedframes);
767 cpl_frameset_join(outframes, proc->
outframes);
771 UNUSED_ARGUMENT(donotmerge);
773 if (!cpl_errorstate_is_equal(prestate)) {
777 cpl_msg_set_level(CPL_MSG_INFO);
784 if (params.
merge && !donotmerge) {
793 cpl_frameset_join(recipe->frames, usedframes);
794 cpl_frameset_join(recipe->frames, outframes);
795 cpl_frameset_delete(usedframes);
796 cpl_frameset_delete(outframes);
809 muse_wavecal_destroy(cpl_plugin *aPlugin)
813 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
814 recipe = (cpl_recipe *)aPlugin;
820 cpl_parameterlist_delete(recipe->parameters);
837 cpl_plugin_get_info(cpl_pluginlist *aList)
839 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
840 cpl_plugin *plugin = &recipe->interface;
844 helptext = cpl_sprintf(
"%s%s", muse_wavecal_help,
845 muse_wavecal_help_esorex);
847 helptext = cpl_sprintf(
"%s", muse_wavecal_help);
851 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
852 CPL_PLUGIN_TYPE_RECIPE,
854 "Detect arc emission lines and determine the wavelength solution for each slice.",
861 muse_wavecal_destroy);
862 cpl_pluginlist_append(aList, plugin);
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
double fitsigma
Sigma level for iterative rejection of deviant datapoints during the final polynomial wavelength solu...
double linesigma
Sigma level for iterative rejection of deviant fits for each arc line within each slice...
const char * ovscreject
This influences how values are rejected when computing overscan statistics. Either no rejection at al...
double ovscsigma
If the deviation of mean overscan levels between a raw input image and the reference image is higher ...
muse_cplframework_type muse_cplframework(void)
Return the CPL framework the recipe is run under.
int ovscignore
The number of pixels of the overscan adjacent to the data section of the CCD that are ignored when co...
double dres
The allowed range of resolutions for pattern matching (of detected arc lines to line list) in fractio...
cpl_frameset * usedframes
muse_processing * muse_processing_new(const char *aName, cpl_recipe *aRecipe)
Create a new processing structure.
const char * muse_get_license(void)
Get the pipeline copyright and license.
int nifu
IFU to handle. If set to 0, all IFUs are processed serially. If set to -1, all IFUs are processed in ...
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.
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
int wavemap
Create a wavelength map of the input images.
int lampwise
Identify and measure the arc emission lines on images separately for each lamp setup.
int residuals
Create a table containing residuals of the fits to the data of all arc lines. This is useful to asses...
void muse_processinginfo_delete(cpl_recipe *)
Clear all information from the processing info and from the recipe config.
int resample
Resample the input arc images onto 2D images for a visual check using tracing and wavelength calibrat...
int yorder
Order of the polynomial used to fit the dispersion relation.
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.
int fitweighting
Type of weighting to use in the final polynomial wavelength solution fit, using centroiding error est...
const char * combine_s
Type of lampwise image combination to use. (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.
int combine
Type of lampwise image combination to use.
Structure to hold the parameters of the muse_wavecal recipe.
double tolerance
Tolerance for pattern matching (of detected arc lines to line list)
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.
const char * fitweighting_s
Type of weighting to use in the final polynomial wavelength solution fit, using centroiding error est...
cpl_error_code muse_utils_frameset_merge_frames(cpl_frameset *aFrames, cpl_boolean aDelete)
Merge IFU-specific files from a frameset to create multi-IFU outputs.
double sigma
Sigma level used to detect arc emission lines above the median background level in the S/N image of t...
int merge
Merge output products from different IFUs into a common file.
int xorder
Order of the polynomial for the horizontal curvature within each slice.
cpl_error_code muse_processing_prepare_property(cpl_propertylist *, const char *, cpl_type, const char *)
Prepare and check the specified property.