MUSE Pipeline Reference Manual  1.0.2
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-2014 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 FILTER_LIST calib . 1 File to be used to create field-of-view images."
61  "\n OUTPUT_WCS calib . 1 WCS to override output cube location / dimensions"
62  "\n\nProduct frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
63  "\n Frame tag Level Description"
64  "\n -------------------- -------- ------------"
65  "\n DATACUBE_FINAL final Output datacube (if --save contains \"cube\")"
66  "\n IMAGE_FOV final Field-of-view images corresponding to the \"filter\" parameter (if --save contains \"cube\")."
67  "\n PIXTABLE_COMBINED intermed Combined pixel table (if --save contains \"combined\")";
68 
69 /*----------------------------------------------------------------------------*/
77 /*----------------------------------------------------------------------------*/
78 static cpl_recipeconfig *
79 muse_exp_combine_new_recipeconfig(void)
80 {
81  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
82  const char *tag;
83 
84  tag = "PIXTABLE_REDUCED";
85  cpl_recipeconfig_set_tag(recipeconfig, tag, 2, -1);
86  cpl_recipeconfig_set_input(recipeconfig, tag, "FILTER_LIST", -1, 1);
87  cpl_recipeconfig_set_input(recipeconfig, tag, "OUTPUT_WCS", -1, 1);
88  cpl_recipeconfig_set_output(recipeconfig, tag, "DATACUBE_FINAL");
89  cpl_recipeconfig_set_output(recipeconfig, tag, "IMAGE_FOV");
90  cpl_recipeconfig_set_output(recipeconfig, tag, "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 POS[0-9]+ X",
113  CPL_TYPE_FLOAT,
114  "[pix] Position of source k in x-direction in combined frame");
115  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB POS[0-9]+ Y",
116  CPL_TYPE_FLOAT,
117  "[pix] Position of source k in y-direction in combined frame");
118  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM[0-9]+ X",
119  CPL_TYPE_FLOAT,
120  "[arcsec] FWHM of source k in x-direction in combined frame");
121  muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM[0-9]+ Y",
122  CPL_TYPE_FLOAT,
123  "[arcsec] FWHM of source k in y-direction in combined frame");
124  } else if (!strcmp(aFrametag, "IMAGE_FOV")) {
125  } else if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
126  } else {
127  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
128  return CPL_ERROR_ILLEGAL_INPUT;
129  }
130  return CPL_ERROR_NONE;
131 } /* muse_exp_combine_prepare_header() */
132 
133 /*----------------------------------------------------------------------------*/
142 /*----------------------------------------------------------------------------*/
143 static cpl_frame_level
144 muse_exp_combine_get_frame_level(const char *aFrametag)
145 {
146  if (!aFrametag) {
147  return CPL_FRAME_LEVEL_NONE;
148  }
149  if (!strcmp(aFrametag, "DATACUBE_FINAL")) {
150  return CPL_FRAME_LEVEL_FINAL;
151  }
152  if (!strcmp(aFrametag, "IMAGE_FOV")) {
153  return CPL_FRAME_LEVEL_FINAL;
154  }
155  if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
156  return CPL_FRAME_LEVEL_INTERMEDIATE;
157  }
158  return CPL_FRAME_LEVEL_NONE;
159 } /* muse_exp_combine_get_frame_level() */
160 
161 /*----------------------------------------------------------------------------*/
170 /*----------------------------------------------------------------------------*/
171 static muse_frame_mode
172 muse_exp_combine_get_frame_mode(const char *aFrametag)
173 {
174  if (!aFrametag) {
175  return MUSE_FRAME_MODE_ALL;
176  }
177  if (!strcmp(aFrametag, "DATACUBE_FINAL")) {
178  return MUSE_FRAME_MODE_MASTER;
179  }
180  if (!strcmp(aFrametag, "IMAGE_FOV")) {
182  }
183  if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
184  return MUSE_FRAME_MODE_MASTER;
185  }
186  return MUSE_FRAME_MODE_ALL;
187 } /* muse_exp_combine_get_frame_mode() */
188 
189 /*----------------------------------------------------------------------------*/
199 /*----------------------------------------------------------------------------*/
200 static int
201 muse_exp_combine_create(cpl_plugin *aPlugin)
202 {
203  /* Check that the plugin is part of a valid recipe */
204  cpl_recipe *recipe;
205  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
206  recipe = (cpl_recipe *)aPlugin;
207  } else {
208  return -1;
209  }
210 
211  /* register the extended processing information (new FITS header creation, *
212  * getting of the frame level for a certain tag) */
214  muse_exp_combine_new_recipeconfig(),
215  muse_exp_combine_prepare_header,
216  muse_exp_combine_get_frame_level,
217  muse_exp_combine_get_frame_mode);
218 
219  /* XXX initialize timing in messages *
220  * since at least esorex is too stupid to turn it on, we have to do it */
222  cpl_msg_set_time_on();
223  }
224 
225  /* Create the parameter list in the cpl_recipe object */
226  recipe->parameters = cpl_parameterlist_new();
227  /* Fill the parameters list */
228  cpl_parameter *p;
229 
230  /* --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. */
231  p = cpl_parameter_new_value("muse.muse_exp_combine.save",
232  CPL_TYPE_STRING,
233  "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.",
234  "muse.muse_exp_combine",
235  (const char *)"cube");
236  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "save");
237  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "save");
238 
239  cpl_parameterlist_append(recipe->parameters, p);
240 
241  /* --resample: The resampling technique to use for the final output cube. */
242  p = cpl_parameter_new_enum("muse.muse_exp_combine.resample",
243  CPL_TYPE_STRING,
244  "The resampling technique to use for the final output cube.",
245  "muse.muse_exp_combine",
246  (const char *)"drizzle",
247  6,
248  (const char *)"nearest",
249  (const char *)"linear",
250  (const char *)"quadratic",
251  (const char *)"renka",
252  (const char *)"drizzle",
253  (const char *)"lanczos");
254  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "resample");
255  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "resample");
256 
257  cpl_parameterlist_append(recipe->parameters, p);
258 
259  /* --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. */
260  p = cpl_parameter_new_value("muse.muse_exp_combine.dx",
261  CPL_TYPE_DOUBLE,
262  "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.",
263  "muse.muse_exp_combine",
264  (double)0.0);
265  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dx");
266  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dx");
267 
268  cpl_parameterlist_append(recipe->parameters, p);
269 
270  /* --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. */
271  p = cpl_parameter_new_value("muse.muse_exp_combine.dy",
272  CPL_TYPE_DOUBLE,
273  "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.",
274  "muse.muse_exp_combine",
275  (double)0.0);
276  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dy");
277  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dy");
278 
279  cpl_parameterlist_append(recipe->parameters, p);
280 
281  /* --dlambda: Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0.0 */
282  p = cpl_parameter_new_value("muse.muse_exp_combine.dlambda",
283  CPL_TYPE_DOUBLE,
284  "Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0.0",
285  "muse.muse_exp_combine",
286  (double)0.0);
287  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dlambda");
288  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dlambda");
289 
290  cpl_parameterlist_append(recipe->parameters, p);
291 
292  /* --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. */
293  p = cpl_parameter_new_enum("muse.muse_exp_combine.crtype",
294  CPL_TYPE_STRING,
295  "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.",
296  "muse.muse_exp_combine",
297  (const char *)"median",
298  3,
299  (const char *)"iraf",
300  (const char *)"mean",
301  (const char *)"median");
302  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crtype");
303  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crtype");
304 
305  cpl_parameterlist_append(recipe->parameters, p);
306 
307  /* --crsigma: Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative value switches cosmic ray rejection off. */
308  p = cpl_parameter_new_value("muse.muse_exp_combine.crsigma",
309  CPL_TYPE_DOUBLE,
310  "Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative value switches cosmic ray rejection off.",
311  "muse.muse_exp_combine",
312  (double)10.);
313  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crsigma");
314  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crsigma");
315 
316  cpl_parameterlist_append(recipe->parameters, p);
317 
318  /* --rc: Critical radius for the "renka" resampling method. */
319  p = cpl_parameter_new_value("muse.muse_exp_combine.rc",
320  CPL_TYPE_DOUBLE,
321  "Critical radius for the \"renka\" resampling method.",
322  "muse.muse_exp_combine",
323  (double)1.25);
324  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "rc");
325  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "rc");
326 
327  cpl_parameterlist_append(recipe->parameters, p);
328 
329  /* --pixfrac: Pixel down-scaling factor for the "drizzle" resampling method. */
330  p = cpl_parameter_new_value("muse.muse_exp_combine.pixfrac",
331  CPL_TYPE_DOUBLE,
332  "Pixel down-scaling factor for the \"drizzle\" resampling method.",
333  "muse.muse_exp_combine",
334  (double)0.6);
335  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "pixfrac");
336  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "pixfrac");
337 
338  cpl_parameterlist_append(recipe->parameters, p);
339 
340  /* --ld: Number of adjacent pixels to take into account during resampling in all three directions (loop distance); this affects all resampling methods except "nearest". */
341  p = cpl_parameter_new_value("muse.muse_exp_combine.ld",
342  CPL_TYPE_INT,
343  "Number of adjacent pixels to take into account during resampling in all three directions (loop distance); this affects all resampling methods except \"nearest\".",
344  "muse.muse_exp_combine",
345  (int)1);
346  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "ld");
347  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ld");
348 
349  cpl_parameterlist_append(recipe->parameters, p);
350 
351  /* --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. */
352  p = cpl_parameter_new_enum("muse.muse_exp_combine.format",
353  CPL_TYPE_STRING,
354  "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.",
355  "muse.muse_exp_combine",
356  (const char *)"Cube",
357  4,
358  (const char *)"Cube",
359  (const char *)"Euro3D",
360  (const char *)"xCube",
361  (const char *)"xEuro3D");
362  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "format");
363  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "format");
364 
365  cpl_parameterlist_append(recipe->parameters, p);
366 
367  /* --weight: Type of weighting scheme to use when combining multiple exposures. "exptime" just uses the exposure time to weight the exposures, "fwhm" uses the DIMM information in the header as well, "none" preserves an existing weight column in the input pixel tables without changes. */
368  p = cpl_parameter_new_enum("muse.muse_exp_combine.weight",
369  CPL_TYPE_STRING,
370  "Type of weighting scheme to use when combining multiple exposures. \"exptime\" just uses the exposure time to weight the exposures, \"fwhm\" uses the DIMM information in the header as well, \"none\" preserves an existing weight column in the input pixel tables without changes.",
371  "muse.muse_exp_combine",
372  (const char *)"exptime",
373  3,
374  (const char *)"exptime",
375  (const char *)"fwhm",
376  (const char *)"none");
377  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "weight");
378  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "weight");
379 
380  cpl_parameterlist_append(recipe->parameters, p);
381 
382  /* --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. */
383  p = cpl_parameter_new_value("muse.muse_exp_combine.filter",
384  CPL_TYPE_STRING,
385  "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.",
386  "muse.muse_exp_combine",
387  (const char *)"white");
388  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "filter");
389  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "filter");
390 
391  cpl_parameterlist_append(recipe->parameters, p);
392 
393  /* --lambdamin: Cut off the data below this wavelength after loading the pixel table(s). */
394  p = cpl_parameter_new_value("muse.muse_exp_combine.lambdamin",
395  CPL_TYPE_DOUBLE,
396  "Cut off the data below this wavelength after loading the pixel table(s).",
397  "muse.muse_exp_combine",
398  (double)4000.);
399  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
400  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
401 
402  cpl_parameterlist_append(recipe->parameters, p);
403 
404  /* --lambdamax: Cut off the data above this wavelength after loading the pixel table(s). */
405  p = cpl_parameter_new_value("muse.muse_exp_combine.lambdamax",
406  CPL_TYPE_DOUBLE,
407  "Cut off the data above this wavelength after loading the pixel table(s).",
408  "muse.muse_exp_combine",
409  (double)10000.);
410  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
411  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
412 
413  cpl_parameterlist_append(recipe->parameters, p);
414 
415  return 0;
416 } /* muse_exp_combine_create() */
417 
418 /*----------------------------------------------------------------------------*/
429 /*----------------------------------------------------------------------------*/
430 static int
431 muse_exp_combine_params_fill(muse_exp_combine_params_t *aParams, cpl_parameterlist *aParameters)
432 {
433  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
434  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
435  cpl_parameter *p;
436 
437  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.save");
438  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
439  aParams->save = cpl_parameter_get_string(p);
440 
441  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.resample");
442  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
443  aParams->resample_s = cpl_parameter_get_string(p);
444  aParams->resample =
445  (!strcasecmp(aParams->resample_s, "nearest")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_NEAREST :
446  (!strcasecmp(aParams->resample_s, "linear")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_LINEAR :
447  (!strcasecmp(aParams->resample_s, "quadratic")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_QUADRATIC :
448  (!strcasecmp(aParams->resample_s, "renka")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_RENKA :
449  (!strcasecmp(aParams->resample_s, "drizzle")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_DRIZZLE :
450  (!strcasecmp(aParams->resample_s, "lanczos")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_LANCZOS :
451  MUSE_EXP_COMBINE_PARAM_RESAMPLE_INVALID_VALUE;
452  cpl_ensure_code(aParams->resample != MUSE_EXP_COMBINE_PARAM_RESAMPLE_INVALID_VALUE,
453  CPL_ERROR_ILLEGAL_INPUT);
454 
455  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dx");
456  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
457  aParams->dx = cpl_parameter_get_double(p);
458 
459  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dy");
460  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
461  aParams->dy = cpl_parameter_get_double(p);
462 
463  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dlambda");
464  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
465  aParams->dlambda = cpl_parameter_get_double(p);
466 
467  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.crtype");
468  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
469  aParams->crtype_s = cpl_parameter_get_string(p);
470  aParams->crtype =
471  (!strcasecmp(aParams->crtype_s, "iraf")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_IRAF :
472  (!strcasecmp(aParams->crtype_s, "mean")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_MEAN :
473  (!strcasecmp(aParams->crtype_s, "median")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_MEDIAN :
474  MUSE_EXP_COMBINE_PARAM_CRTYPE_INVALID_VALUE;
475  cpl_ensure_code(aParams->crtype != MUSE_EXP_COMBINE_PARAM_CRTYPE_INVALID_VALUE,
476  CPL_ERROR_ILLEGAL_INPUT);
477 
478  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.crsigma");
479  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
480  aParams->crsigma = cpl_parameter_get_double(p);
481 
482  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.rc");
483  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
484  aParams->rc = cpl_parameter_get_double(p);
485 
486  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.pixfrac");
487  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
488  aParams->pixfrac = cpl_parameter_get_double(p);
489 
490  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.ld");
491  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
492  aParams->ld = cpl_parameter_get_int(p);
493 
494  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.format");
495  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
496  aParams->format_s = cpl_parameter_get_string(p);
497  aParams->format =
498  (!strcasecmp(aParams->format_s, "Cube")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_CUBE :
499  (!strcasecmp(aParams->format_s, "Euro3D")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_EURO3D :
500  (!strcasecmp(aParams->format_s, "xCube")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_XCUBE :
501  (!strcasecmp(aParams->format_s, "xEuro3D")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_XEURO3D :
502  MUSE_EXP_COMBINE_PARAM_FORMAT_INVALID_VALUE;
503  cpl_ensure_code(aParams->format != MUSE_EXP_COMBINE_PARAM_FORMAT_INVALID_VALUE,
504  CPL_ERROR_ILLEGAL_INPUT);
505 
506  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.weight");
507  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
508  aParams->weight_s = cpl_parameter_get_string(p);
509  aParams->weight =
510  (!strcasecmp(aParams->weight_s, "exptime")) ? MUSE_EXP_COMBINE_PARAM_WEIGHT_EXPTIME :
511  (!strcasecmp(aParams->weight_s, "fwhm")) ? MUSE_EXP_COMBINE_PARAM_WEIGHT_FWHM :
512  (!strcasecmp(aParams->weight_s, "none")) ? MUSE_EXP_COMBINE_PARAM_WEIGHT_NONE :
513  MUSE_EXP_COMBINE_PARAM_WEIGHT_INVALID_VALUE;
514  cpl_ensure_code(aParams->weight != MUSE_EXP_COMBINE_PARAM_WEIGHT_INVALID_VALUE,
515  CPL_ERROR_ILLEGAL_INPUT);
516 
517  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.filter");
518  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
519  aParams->filter = cpl_parameter_get_string(p);
520 
521  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.lambdamin");
522  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
523  aParams->lambdamin = cpl_parameter_get_double(p);
524 
525  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.lambdamax");
526  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
527  aParams->lambdamax = cpl_parameter_get_double(p);
528 
529  return 0;
530 } /* muse_exp_combine_params_fill() */
531 
532 /*----------------------------------------------------------------------------*/
539 /*----------------------------------------------------------------------------*/
540 static int
541 muse_exp_combine_exec(cpl_plugin *aPlugin)
542 {
543  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
544  return -1;
545  }
546  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
547  cpl_msg_set_threadid_on();
548 
549  cpl_frameset *usedframes = cpl_frameset_new(),
550  *outframes = cpl_frameset_new();
552  muse_exp_combine_params_fill(&params, recipe->parameters);
553 
554  cpl_errorstate prestate = cpl_errorstate_get();
555 
556  muse_processing *proc = muse_processing_new("muse_exp_combine",
557  recipe);
558  int rc = muse_exp_combine_compute(proc, &params);
559  cpl_frameset_join(usedframes, proc->usedframes);
560  cpl_frameset_join(outframes, proc->outframes);
562 
563  if (!cpl_errorstate_is_equal(prestate)) {
564  /* dump all errors from this recipe in chronological order */
565  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
566  /* reset message level to not get the same errors displayed again by esorex */
567  cpl_msg_set_level(CPL_MSG_INFO);
568  }
569  /* clean up duplicates in framesets of used and output frames */
572 
573  /* to get esorex to see our classification (frame groups etc.), *
574  * replace the original frameset with the list of used frames *
575  * before appending product output frames */
576  /* keep the same pointer, so just erase all frames, not delete the frameset */
577  muse_cplframeset_erase_all(recipe->frames);
578  cpl_frameset_join(recipe->frames, usedframes);
579  cpl_frameset_join(recipe->frames, outframes);
580  cpl_frameset_delete(usedframes);
581  cpl_frameset_delete(outframes);
582  return rc;
583 } /* muse_exp_combine_exec() */
584 
585 /*----------------------------------------------------------------------------*/
592 /*----------------------------------------------------------------------------*/
593 static int
594 muse_exp_combine_destroy(cpl_plugin *aPlugin)
595 {
596  /* Get the recipe from the plugin */
597  cpl_recipe *recipe;
598  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
599  recipe = (cpl_recipe *)aPlugin;
600  } else {
601  return -1;
602  }
603 
604  /* Clean up */
605  cpl_parameterlist_delete(recipe->parameters);
607  return 0;
608 } /* muse_exp_combine_destroy() */
609 
610 /*----------------------------------------------------------------------------*/
620 /*----------------------------------------------------------------------------*/
621 int
622 cpl_plugin_get_info(cpl_pluginlist *aList)
623 {
624  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
625  cpl_plugin *plugin = &recipe->interface;
626 
627  char *helptext;
629  helptext = cpl_sprintf("%s%s", muse_exp_combine_help,
630  muse_exp_combine_help_esorex);
631  } else {
632  helptext = cpl_sprintf("%s", muse_exp_combine_help);
633  }
634 
635  /* Initialize the CPL plugin stuff for this module */
636  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
637  CPL_PLUGIN_TYPE_RECIPE,
638  "muse_exp_combine",
639  "Combine several exposures into one datacube.",
640  helptext,
641  "Peter Weilbacher",
642  "usd-help@eso.org",
644  muse_exp_combine_create,
645  muse_exp_combine_exec,
646  muse_exp_combine_destroy);
647  cpl_pluginlist_append(aList, plugin);
648  cpl_free(helptext);
649 
650  return 0;
651 } /* cpl_plugin_get_info() */
652 
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)
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...
double pixfrac
Pixel down-scaling factor for the "drizzle" resampling method.
const char * muse_get_license(void)
Get the pipeline copyright and license.
Definition: muse_utils.c:84
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.
cpl_error_code muse_processing_prepare_property(cpl_propertylist *, const char *, cpl_type, const char *)
Prepare and check the specified property.