MUSE Pipeline Reference Manual  2.1.1
muse_exp_combine_z.c
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set sw=2 sts=2 et cin: */
3 /*
4  * This file is part of the MUSE Instrument Pipeline
5  * Copyright (C) 2005-2015 European Southern Observatory
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 /* This file was automatically generated */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 /*----------------------------------------------------------------------------*
29  * Includes *
30  *----------------------------------------------------------------------------*/
31 #include <string.h> /* strcmp(), strstr() */
32 #include <strings.h> /* strcasecmp() */
33 #include <cpl.h>
34 
35 #include "muse_exp_combine_z.h" /* in turn includes muse.h */
36 
37 /*----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------*/
49 /*----------------------------------------------------------------------------*
50  * Static variables *
51  *----------------------------------------------------------------------------*/
52 static const char *muse_exp_combine_help =
53  "Sort reduced pixel tables, one per exposure, by exposure and combine them with applied weights into one final datacube.";
54 
55 static const char *muse_exp_combine_help_esorex =
56  "\n\nInput frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
57  "\n Frame tag Type Req #Fr Description"
58  "\n -------------------- ---- --- --- ------------"
59  "\n PIXTABLE_REDUCED raw Y >=2 Input pixel tables"
60  "\n OFFSET_LIST calib . 1 List of coordinate offsets (and optional flux scale factors)"
61  "\n FILTER_LIST calib . 1 File to be used to create field-of-view images."
62  "\n OUTPUT_WCS calib . 1 WCS to override output cube location / dimensions"
63  "\n\nProduct frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
64  "\n Frame tag Level Description"
65  "\n -------------------- -------- ------------"
66  "\n DATACUBE_FINAL final Output datacube (if --save contains \"cube\")"
67  "\n IMAGE_FOV final Field-of-view images corresponding to the \"filter\" parameter (if --save contains \"cube\")."
68  "\n PIXTABLE_COMBINED intermed Combined pixel table (if --save contains \"combined\")";
69 
70 /*----------------------------------------------------------------------------*/
78 /*----------------------------------------------------------------------------*/
79 static cpl_recipeconfig *
80 muse_exp_combine_new_recipeconfig(void)
81 {
82  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
83 
84  cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_REDUCED", 2, -1);
85  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "OFFSET_LIST", -1, 1);
86  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "FILTER_LIST", -1, 1);
87  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "OUTPUT_WCS", -1, 1);
88  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_REDUCED", "DATACUBE_FINAL");
89  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_REDUCED", "IMAGE_FOV");
90  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_REDUCED", "PIXTABLE_COMBINED");
91 
92  return recipeconfig;
93 } /* muse_exp_combine_new_recipeconfig() */
94 
95 /*----------------------------------------------------------------------------*/
105 /*----------------------------------------------------------------------------*/
106 static cpl_error_code
107 muse_exp_combine_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
108 {
109  cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
110  cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
111  if (!strcmp(aFrametag, "DATACUBE_FINAL")) {
112  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB NDET",
113  CPL_TYPE_INT,
114  "Number of detected sources in combined cube.");
115  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB LAMBDA",
116  CPL_TYPE_FLOAT,
117  "[Angstrom] Wavelength of plane in combined cube that was used for object detection.");
118  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB POS[0-9]+ X",
119  CPL_TYPE_FLOAT,
120  "[pix] Position of source k in x-direction in combined cube. If the FWHM measurement fails, this value will be -1.");
121  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB POS[0-9]+ Y",
122  CPL_TYPE_FLOAT,
123  "[pix] Position of source k in y-direction in combined cube. If the FWHM measurement fails, this value will be -1.");
124  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM[0-9]+ X",
125  CPL_TYPE_FLOAT,
126  "[arcsec] FWHM of source k in x-direction in combined cube. If the FWHM measurement fails, this value will be -1.");
127  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM[0-9]+ Y",
128  CPL_TYPE_FLOAT,
129  "[arcsec] FWHM of source k in y-direction in combined cube. If the FWHM measurement fails, this value will be -1.");
130  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM NVALID",
131  CPL_TYPE_INT,
132  "Number of detected sources with valid FWHM in combined cube.");
133  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM MEDIAN",
134  CPL_TYPE_FLOAT,
135  "[arcsec] Median FWHM of all sources with valid FWHM measurement (in x- and y-direction) in combined cube. If less than three sources with valid FWHM are detected, this value is zero.");
136  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM MAD",
137  CPL_TYPE_FLOAT,
138  "[arcsec] Median absolute deviation of the FWHM of all sources with valid FWHM measurement (in x- and y-direction) in combined cube. If less than three sources with valid FWHM are detected, this value is zero.");
139  } else if (!strcmp(aFrametag, "IMAGE_FOV")) {
140  } else if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
141  } else {
142  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
143  return CPL_ERROR_ILLEGAL_INPUT;
144  }
145  return CPL_ERROR_NONE;
146 } /* muse_exp_combine_prepare_header() */
147 
148 /*----------------------------------------------------------------------------*/
157 /*----------------------------------------------------------------------------*/
158 static cpl_frame_level
159 muse_exp_combine_get_frame_level(const char *aFrametag)
160 {
161  if (!aFrametag) {
162  return CPL_FRAME_LEVEL_NONE;
163  }
164  if (!strcmp(aFrametag, "DATACUBE_FINAL")) {
165  return CPL_FRAME_LEVEL_FINAL;
166  }
167  if (!strcmp(aFrametag, "IMAGE_FOV")) {
168  return CPL_FRAME_LEVEL_FINAL;
169  }
170  if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
171  return CPL_FRAME_LEVEL_INTERMEDIATE;
172  }
173  return CPL_FRAME_LEVEL_NONE;
174 } /* muse_exp_combine_get_frame_level() */
175 
176 /*----------------------------------------------------------------------------*/
185 /*----------------------------------------------------------------------------*/
186 static muse_frame_mode
187 muse_exp_combine_get_frame_mode(const char *aFrametag)
188 {
189  if (!aFrametag) {
190  return MUSE_FRAME_MODE_ALL;
191  }
192  if (!strcmp(aFrametag, "DATACUBE_FINAL")) {
193  return MUSE_FRAME_MODE_MASTER;
194  }
195  if (!strcmp(aFrametag, "IMAGE_FOV")) {
197  }
198  if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
199  return MUSE_FRAME_MODE_MASTER;
200  }
201  return MUSE_FRAME_MODE_ALL;
202 } /* muse_exp_combine_get_frame_mode() */
203 
204 /*----------------------------------------------------------------------------*/
214 /*----------------------------------------------------------------------------*/
215 static int
216 muse_exp_combine_create(cpl_plugin *aPlugin)
217 {
218  /* Check that the plugin is part of a valid recipe */
219  cpl_recipe *recipe;
220  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
221  recipe = (cpl_recipe *)aPlugin;
222  } else {
223  return -1;
224  }
225 
226  /* register the extended processing information (new FITS header creation, *
227  * getting of the frame level for a certain tag) */
229  muse_exp_combine_new_recipeconfig(),
230  muse_exp_combine_prepare_header,
231  muse_exp_combine_get_frame_level,
232  muse_exp_combine_get_frame_mode);
233 
234  /* XXX initialize timing in messages *
235  * since at least esorex is too stupid to turn it on, we have to do it */
237  cpl_msg_set_time_on();
238  }
239 
240  /* Create the parameter list in the cpl_recipe object */
241  recipe->parameters = cpl_parameterlist_new();
242  /* Fill the parameters list */
243  cpl_parameter *p;
244 
245  /* --save: Select output product(s) to save. Can contain one or more of "cube" (output cube and associated images; if this is not given, no resampling is done at all) or "combined" (fully reduced and combined pixel table for the full set of exposures; this is useful, if the final resampling step is to be done again separately). If several options are given, they have to be comma-separated. */
246  p = cpl_parameter_new_value("muse.muse_exp_combine.save",
247  CPL_TYPE_STRING,
248  "Select output product(s) to save. Can contain one or more of \"cube\" (output cube and associated images; if this is not given, no resampling is done at all) or \"combined\" (fully reduced and combined pixel table for the full set of exposures; this is useful, if the final resampling step is to be done again separately). If several options are given, they have to be comma-separated.",
249  "muse.muse_exp_combine",
250  (const char *)"cube");
251  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "save");
252  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "save");
253 
254  cpl_parameterlist_append(recipe->parameters, p);
255 
256  /* --resample: The resampling technique to use for the final output cube. */
257  p = cpl_parameter_new_enum("muse.muse_exp_combine.resample",
258  CPL_TYPE_STRING,
259  "The resampling technique to use for the final output cube.",
260  "muse.muse_exp_combine",
261  (const char *)"drizzle",
262  6,
263  (const char *)"nearest",
264  (const char *)"linear",
265  (const char *)"quadratic",
266  (const char *)"renka",
267  (const char *)"drizzle",
268  (const char *)"lanczos");
269  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "resample");
270  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "resample");
271 
272  cpl_parameterlist_append(recipe->parameters, p);
273 
274  /* --dx: Horizontal step size for resampling (in arcsec or pixel). The following defaults are taken when this value is set to 0.0: 0.2'' for WFM, 0.075'' for NFM, 1.0 if data is in pixel units. */
275  p = cpl_parameter_new_value("muse.muse_exp_combine.dx",
276  CPL_TYPE_DOUBLE,
277  "Horizontal step size for resampling (in arcsec or pixel). The following defaults are taken when this value is set to 0.0: 0.2'' for WFM, 0.075'' for NFM, 1.0 if data is in pixel units.",
278  "muse.muse_exp_combine",
279  (double)0.0);
280  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dx");
281  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dx");
282 
283  cpl_parameterlist_append(recipe->parameters, p);
284 
285  /* --dy: Vertical step size for resampling (in arcsec or pixel). The following defaults are taken when this value is set to 0.0: 0.2'' for WFM, 0.075'' for NFM, 1.0 if data is in pixel units. */
286  p = cpl_parameter_new_value("muse.muse_exp_combine.dy",
287  CPL_TYPE_DOUBLE,
288  "Vertical step size for resampling (in arcsec or pixel). The following defaults are taken when this value is set to 0.0: 0.2'' for WFM, 0.075'' for NFM, 1.0 if data is in pixel units.",
289  "muse.muse_exp_combine",
290  (double)0.0);
291  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dy");
292  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dy");
293 
294  cpl_parameterlist_append(recipe->parameters, p);
295 
296  /* --dlambda: Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0.0 */
297  p = cpl_parameter_new_value("muse.muse_exp_combine.dlambda",
298  CPL_TYPE_DOUBLE,
299  "Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0.0",
300  "muse.muse_exp_combine",
301  (double)0.0);
302  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dlambda");
303  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dlambda");
304 
305  cpl_parameterlist_append(recipe->parameters, p);
306 
307  /* --crtype: 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. */
308  p = cpl_parameter_new_enum("muse.muse_exp_combine.crtype",
309  CPL_TYPE_STRING,
310  "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.",
311  "muse.muse_exp_combine",
312  (const char *)"median",
313  3,
314  (const char *)"iraf",
315  (const char *)"mean",
316  (const char *)"median");
317  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crtype");
318  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crtype");
319 
320  cpl_parameterlist_append(recipe->parameters, p);
321 
322  /* --crsigma: Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative value switches cosmic ray rejection off. */
323  p = cpl_parameter_new_value("muse.muse_exp_combine.crsigma",
324  CPL_TYPE_DOUBLE,
325  "Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative value switches cosmic ray rejection off.",
326  "muse.muse_exp_combine",
327  (double)10.);
328  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crsigma");
329  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crsigma");
330 
331  cpl_parameterlist_append(recipe->parameters, p);
332 
333  /* --rc: Critical radius for the "renka" resampling method. */
334  p = cpl_parameter_new_value("muse.muse_exp_combine.rc",
335  CPL_TYPE_DOUBLE,
336  "Critical radius for the \"renka\" resampling method.",
337  "muse.muse_exp_combine",
338  (double)1.25);
339  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "rc");
340  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "rc");
341 
342  cpl_parameterlist_append(recipe->parameters, p);
343 
344  /* --pixfrac: Pixel down-scaling factor for the "drizzle" resampling method. Up to three, comma-separated, floating-point values can be given. If only one value is given, it applies to all dimensions, two values are interpreted as spatial and spectral direction, respectively, while three are taken as horizontal, vertical, and spectral. */
345  p = cpl_parameter_new_value("muse.muse_exp_combine.pixfrac",
346  CPL_TYPE_STRING,
347  "Pixel down-scaling factor for the \"drizzle\" resampling method. Up to three, comma-separated, floating-point values can be given. If only one value is given, it applies to all dimensions, two values are interpreted as spatial and spectral direction, respectively, while three are taken as horizontal, vertical, and spectral.",
348  "muse.muse_exp_combine",
349  (const char *)"0.6,0.6");
350  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "pixfrac");
351  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "pixfrac");
352 
353  cpl_parameterlist_append(recipe->parameters, p);
354 
355  /* --ld: Number of adjacent pixels to take into account during resampling in all three directions (loop distance); this affects all resampling methods except "nearest". */
356  p = cpl_parameter_new_value("muse.muse_exp_combine.ld",
357  CPL_TYPE_INT,
358  "Number of adjacent pixels to take into account during resampling in all three directions (loop distance); this affects all resampling methods except \"nearest\".",
359  "muse.muse_exp_combine",
360  (int)1);
361  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "ld");
362  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ld");
363 
364  cpl_parameterlist_append(recipe->parameters, p);
365 
366  /* --format: Type of output file format, "Cube" is a standard FITS cube with NAXIS=3 and multiple extensions (for data and variance). The extended "x" formats include the reconstructed image(s) in FITS image extensions within the same file. "sdpCube" does some extra calculations to create FITS keywords for the ESO Science Data Products. */
367  p = cpl_parameter_new_enum("muse.muse_exp_combine.format",
368  CPL_TYPE_STRING,
369  "Type of output file format, \"Cube\" is a standard FITS cube with NAXIS=3 and multiple extensions (for data and variance). The extended \"x\" formats include the reconstructed image(s) in FITS image extensions within the same file. \"sdpCube\" does some extra calculations to create FITS keywords for the ESO Science Data Products.",
370  "muse.muse_exp_combine",
371  (const char *)"Cube",
372  5,
373  (const char *)"Cube",
374  (const char *)"Euro3D",
375  (const char *)"xCube",
376  (const char *)"xEuro3D",
377  (const char *)"sdpCube");
378  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "format");
379  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "format");
380 
381  cpl_parameterlist_append(recipe->parameters, p);
382 
383  /* --weight: Type of weighting scheme to use when combining multiple exposures. "exptime" just uses the exposure time to weight the exposures, "fwhm" uses the best available seeing information from the headers as well, "none" preserves an existing weight column in the input pixel tables without changes. */
384  p = cpl_parameter_new_enum("muse.muse_exp_combine.weight",
385  CPL_TYPE_STRING,
386  "Type of weighting scheme to use when combining multiple exposures. \"exptime\" just uses the exposure time to weight the exposures, \"fwhm\" uses the best available seeing information from the headers as well, \"none\" preserves an existing weight column in the input pixel tables without changes.",
387  "muse.muse_exp_combine",
388  (const char *)"exptime",
389  3,
390  (const char *)"exptime",
391  (const char *)"fwhm",
392  (const char *)"none");
393  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "weight");
394  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "weight");
395 
396  cpl_parameterlist_append(recipe->parameters, p);
397 
398  /* --filter: The filter name(s) to be used for the output field-of-view image. Each name has to correspond to an EXTNAME in an extension of the FILTER_LIST file. If an unsupported filter name is given, creation of the respective image is omitted. If multiple filter names are given, they have to be comma separated. */
399  p = cpl_parameter_new_value("muse.muse_exp_combine.filter",
400  CPL_TYPE_STRING,
401  "The filter name(s) to be used for the output field-of-view image. Each name has to correspond to an EXTNAME in an extension of the FILTER_LIST file. If an unsupported filter name is given, creation of the respective image is omitted. If multiple filter names are given, they have to be comma separated.",
402  "muse.muse_exp_combine",
403  (const char *)"white");
404  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "filter");
405  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "filter");
406 
407  cpl_parameterlist_append(recipe->parameters, p);
408 
409  /* --lambdamin: Cut off the data below this wavelength after loading the pixel table(s). */
410  p = cpl_parameter_new_value("muse.muse_exp_combine.lambdamin",
411  CPL_TYPE_DOUBLE,
412  "Cut off the data below this wavelength after loading the pixel table(s).",
413  "muse.muse_exp_combine",
414  (double)4000.);
415  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
416  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
417 
418  cpl_parameterlist_append(recipe->parameters, p);
419 
420  /* --lambdamax: Cut off the data above this wavelength after loading the pixel table(s). */
421  p = cpl_parameter_new_value("muse.muse_exp_combine.lambdamax",
422  CPL_TYPE_DOUBLE,
423  "Cut off the data above this wavelength after loading the pixel table(s).",
424  "muse.muse_exp_combine",
425  (double)10000.);
426  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
427  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
428 
429  cpl_parameterlist_append(recipe->parameters, p);
430 
431  return 0;
432 } /* muse_exp_combine_create() */
433 
434 /*----------------------------------------------------------------------------*/
445 /*----------------------------------------------------------------------------*/
446 static int
447 muse_exp_combine_params_fill(muse_exp_combine_params_t *aParams, cpl_parameterlist *aParameters)
448 {
449  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
450  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
451  cpl_parameter *p;
452 
453  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.save");
454  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
455  aParams->save = cpl_parameter_get_string(p);
456 
457  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.resample");
458  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
459  aParams->resample_s = cpl_parameter_get_string(p);
460  aParams->resample =
461  (!strcasecmp(aParams->resample_s, "nearest")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_NEAREST :
462  (!strcasecmp(aParams->resample_s, "linear")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_LINEAR :
463  (!strcasecmp(aParams->resample_s, "quadratic")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_QUADRATIC :
464  (!strcasecmp(aParams->resample_s, "renka")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_RENKA :
465  (!strcasecmp(aParams->resample_s, "drizzle")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_DRIZZLE :
466  (!strcasecmp(aParams->resample_s, "lanczos")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_LANCZOS :
467  MUSE_EXP_COMBINE_PARAM_RESAMPLE_INVALID_VALUE;
468  cpl_ensure_code(aParams->resample != MUSE_EXP_COMBINE_PARAM_RESAMPLE_INVALID_VALUE,
469  CPL_ERROR_ILLEGAL_INPUT);
470 
471  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dx");
472  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
473  aParams->dx = cpl_parameter_get_double(p);
474 
475  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dy");
476  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
477  aParams->dy = cpl_parameter_get_double(p);
478 
479  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dlambda");
480  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
481  aParams->dlambda = cpl_parameter_get_double(p);
482 
483  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.crtype");
484  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
485  aParams->crtype_s = cpl_parameter_get_string(p);
486  aParams->crtype =
487  (!strcasecmp(aParams->crtype_s, "iraf")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_IRAF :
488  (!strcasecmp(aParams->crtype_s, "mean")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_MEAN :
489  (!strcasecmp(aParams->crtype_s, "median")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_MEDIAN :
490  MUSE_EXP_COMBINE_PARAM_CRTYPE_INVALID_VALUE;
491  cpl_ensure_code(aParams->crtype != MUSE_EXP_COMBINE_PARAM_CRTYPE_INVALID_VALUE,
492  CPL_ERROR_ILLEGAL_INPUT);
493 
494  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.crsigma");
495  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
496  aParams->crsigma = cpl_parameter_get_double(p);
497 
498  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.rc");
499  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
500  aParams->rc = cpl_parameter_get_double(p);
501 
502  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.pixfrac");
503  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
504  aParams->pixfrac = cpl_parameter_get_string(p);
505 
506  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.ld");
507  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
508  aParams->ld = cpl_parameter_get_int(p);
509 
510  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.format");
511  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
512  aParams->format_s = cpl_parameter_get_string(p);
513  aParams->format =
514  (!strcasecmp(aParams->format_s, "Cube")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_CUBE :
515  (!strcasecmp(aParams->format_s, "Euro3D")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_EURO3D :
516  (!strcasecmp(aParams->format_s, "xCube")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_XCUBE :
517  (!strcasecmp(aParams->format_s, "xEuro3D")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_XEURO3D :
518  (!strcasecmp(aParams->format_s, "sdpCube")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_SDPCUBE :
519  MUSE_EXP_COMBINE_PARAM_FORMAT_INVALID_VALUE;
520  cpl_ensure_code(aParams->format != MUSE_EXP_COMBINE_PARAM_FORMAT_INVALID_VALUE,
521  CPL_ERROR_ILLEGAL_INPUT);
522 
523  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.weight");
524  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
525  aParams->weight_s = cpl_parameter_get_string(p);
526  aParams->weight =
527  (!strcasecmp(aParams->weight_s, "exptime")) ? MUSE_EXP_COMBINE_PARAM_WEIGHT_EXPTIME :
528  (!strcasecmp(aParams->weight_s, "fwhm")) ? MUSE_EXP_COMBINE_PARAM_WEIGHT_FWHM :
529  (!strcasecmp(aParams->weight_s, "none")) ? MUSE_EXP_COMBINE_PARAM_WEIGHT_NONE :
530  MUSE_EXP_COMBINE_PARAM_WEIGHT_INVALID_VALUE;
531  cpl_ensure_code(aParams->weight != MUSE_EXP_COMBINE_PARAM_WEIGHT_INVALID_VALUE,
532  CPL_ERROR_ILLEGAL_INPUT);
533 
534  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.filter");
535  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
536  aParams->filter = cpl_parameter_get_string(p);
537 
538  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.lambdamin");
539  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
540  aParams->lambdamin = cpl_parameter_get_double(p);
541 
542  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.lambdamax");
543  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
544  aParams->lambdamax = cpl_parameter_get_double(p);
545 
546  return 0;
547 } /* muse_exp_combine_params_fill() */
548 
549 /*----------------------------------------------------------------------------*/
556 /*----------------------------------------------------------------------------*/
557 static int
558 muse_exp_combine_exec(cpl_plugin *aPlugin)
559 {
560  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
561  return -1;
562  }
564  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
565  cpl_msg_set_threadid_on();
566 
567  cpl_frameset *usedframes = cpl_frameset_new(),
568  *outframes = cpl_frameset_new();
570  muse_exp_combine_params_fill(&params, recipe->parameters);
571 
572  cpl_errorstate prestate = cpl_errorstate_get();
573 
574  muse_processing *proc = muse_processing_new("muse_exp_combine",
575  recipe);
576  int rc = muse_exp_combine_compute(proc, &params);
577  cpl_frameset_join(usedframes, proc->usedframes);
578  cpl_frameset_join(outframes, proc->outframes);
580 
581  if (!cpl_errorstate_is_equal(prestate)) {
582  /* dump all errors from this recipe in chronological order */
583  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
584  /* reset message level to not get the same errors displayed again by esorex */
585  cpl_msg_set_level(CPL_MSG_INFO);
586  }
587  /* clean up duplicates in framesets of used and output frames */
590 
591  /* to get esorex to see our classification (frame groups etc.), *
592  * replace the original frameset with the list of used frames *
593  * before appending product output frames */
594  /* keep the same pointer, so just erase all frames, not delete the frameset */
595  muse_cplframeset_erase_all(recipe->frames);
596  cpl_frameset_join(recipe->frames, usedframes);
597  cpl_frameset_join(recipe->frames, outframes);
598  cpl_frameset_delete(usedframes);
599  cpl_frameset_delete(outframes);
600  return rc;
601 } /* muse_exp_combine_exec() */
602 
603 /*----------------------------------------------------------------------------*/
610 /*----------------------------------------------------------------------------*/
611 static int
612 muse_exp_combine_destroy(cpl_plugin *aPlugin)
613 {
614  /* Get the recipe from the plugin */
615  cpl_recipe *recipe;
616  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
617  recipe = (cpl_recipe *)aPlugin;
618  } else {
619  return -1;
620  }
621 
622  /* Clean up */
623  cpl_parameterlist_delete(recipe->parameters);
625  return 0;
626 } /* muse_exp_combine_destroy() */
627 
628 /*----------------------------------------------------------------------------*/
638 /*----------------------------------------------------------------------------*/
639 int
640 cpl_plugin_get_info(cpl_pluginlist *aList)
641 {
642  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
643  cpl_plugin *plugin = &recipe->interface;
644 
645  char *helptext;
647  helptext = cpl_sprintf("%s%s", muse_exp_combine_help,
648  muse_exp_combine_help_esorex);
649  } else {
650  helptext = cpl_sprintf("%s", muse_exp_combine_help);
651  }
652 
653  /* Initialize the CPL plugin stuff for this module */
654  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
655  CPL_PLUGIN_TYPE_RECIPE,
656  "muse_exp_combine",
657  "Combine several exposures into one datacube.",
658  helptext,
659  "Peter Weilbacher",
660  "usd-help@eso.org",
662  muse_exp_combine_create,
663  muse_exp_combine_exec,
664  muse_exp_combine_destroy);
665  cpl_pluginlist_append(aList, plugin);
666  cpl_free(helptext);
667 
668  return 0;
669 } /* cpl_plugin_get_info() */
670 
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
int ld
Number of adjacent pixels to take into account during resampling in all three directions (loop distan...
const char * crtype_s
Type of statistics used for detection of cosmic rays during final resampling. "iraf" uses the varianc...
const char * resample_s
The resampling technique to use for the final output cube. (as string)
const char * pixfrac
Pixel down-scaling factor for the "drizzle" resampling method. Up to three, comma-separated, floating-point values can be given. If only one value is given, it applies to all dimensions, two values are interpreted as spatial and spectral direction, respectively, while three are taken as horizontal, vertical, and spectral.
muse_cplframework_type muse_cplframework(void)
Return the CPL framework the recipe is run under.
double crsigma
Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative va...
const char * format_s
Type of output file format, "Cube" is a standard FITS cube with NAXIS=3 and multiple extensions (for ...
int format
Type of output file format, "Cube" is a standard FITS cube with NAXIS=3 and multiple extensions (for ...
cpl_frameset * usedframes
muse_processing * muse_processing_new(const char *aName, cpl_recipe *aRecipe)
Create a new processing structure.
double dy
Vertical step size for resampling (in arcsec or pixel). The following defaults are taken when this va...
const char * muse_get_license(void)
Get the pipeline copyright and license.
Definition: muse_utils.c:83
Structure to hold the parameters of the muse_exp_combine recipe.
muse_frame_mode
const char * weight_s
Type of weighting scheme to use when combining multiple exposures. "exptime" just uses the exposure t...
cpl_frameset * outframes
int crtype
Type of statistics used for detection of cosmic rays during final resampling. "iraf" uses the varianc...
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
int weight
Type of weighting scheme to use when combining multiple exposures. "exptime" just uses the exposure t...
const char * filter
The filter name(s) to be used for the output field-of-view image. Each name has to correspond to an E...
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.
int resample
The resampling technique to use for the final output cube.
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
const char * save
Select output product(s) to save. Can contain one or more of "cube" (output cube and associated image...
double dlambda
Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0...
double dx
Horizontal step size for resampling (in arcsec or pixel). The following defaults are taken when this ...
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.
double rc
Critical radius for the "renka" resampling method.
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.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.
cpl_error_code muse_processing_prepare_property(cpl_propertylist *, const char *, cpl_type, const char *)
Prepare and check the specified property.