MUSE Pipeline Reference Manual  0.18.5
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-2013 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"
66  "\n IMAGE_FOV final Field-of-view images corresponding to the \"filter\" parameter."
67  "\n PIXTABLE_COMBINED intermed Combined pixel table";
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  /* --resample: The resampling technique to use for the final output cube. */
231  p = cpl_parameter_new_enum("muse.muse_exp_combine.resample",
232  CPL_TYPE_STRING,
233  "The resampling technique to use for the final output cube.",
234  "muse.muse_exp_combine",
235  (const char *)"drizzle",
236  6,
237  (const char *)"nearest",
238  (const char *)"linear",
239  (const char *)"quadratic",
240  (const char *)"renka",
241  (const char *)"drizzle",
242  (const char *)"lanczos");
243  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "resample");
244  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "resample");
245 
246  cpl_parameterlist_append(recipe->parameters, p);
247 
248  /* --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. */
249  p = cpl_parameter_new_value("muse.muse_exp_combine.dx",
250  CPL_TYPE_DOUBLE,
251  "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.",
252  "muse.muse_exp_combine",
253  (double)0.0);
254  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dx");
255  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dx");
256 
257  cpl_parameterlist_append(recipe->parameters, p);
258 
259  /* --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. */
260  p = cpl_parameter_new_value("muse.muse_exp_combine.dy",
261  CPL_TYPE_DOUBLE,
262  "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.",
263  "muse.muse_exp_combine",
264  (double)0.0);
265  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dy");
266  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dy");
267 
268  cpl_parameterlist_append(recipe->parameters, p);
269 
270  /* --dlambda: Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0.0 */
271  p = cpl_parameter_new_value("muse.muse_exp_combine.dlambda",
272  CPL_TYPE_DOUBLE,
273  "Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0.0",
274  "muse.muse_exp_combine",
275  (double)0.0);
276  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dlambda");
277  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dlambda");
278 
279  cpl_parameterlist_append(recipe->parameters, p);
280 
281  /* --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 median deviation statistics. */
282  p = cpl_parameter_new_enum("muse.muse_exp_combine.crtype",
283  CPL_TYPE_STRING,
284  "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 median deviation statistics.",
285  "muse.muse_exp_combine",
286  (const char *)"median",
287  3,
288  (const char *)"iraf",
289  (const char *)"mean",
290  (const char *)"median");
291  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crtype");
292  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crtype");
293 
294  cpl_parameterlist_append(recipe->parameters, p);
295 
296  /* --crsigma: Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative value switches cosmic ray rejection off. */
297  p = cpl_parameter_new_value("muse.muse_exp_combine.crsigma",
298  CPL_TYPE_DOUBLE,
299  "Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative value switches cosmic ray rejection off.",
300  "muse.muse_exp_combine",
301  (double)8.);
302  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crsigma");
303  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crsigma");
304 
305  cpl_parameterlist_append(recipe->parameters, p);
306 
307  /* --rc: Critical radius for the "renka" resampling method. */
308  p = cpl_parameter_new_value("muse.muse_exp_combine.rc",
309  CPL_TYPE_DOUBLE,
310  "Critical radius for the \"renka\" resampling method.",
311  "muse.muse_exp_combine",
312  (double)1.25);
313  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "rc");
314  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "rc");
315 
316  cpl_parameterlist_append(recipe->parameters, p);
317 
318  /* --pixfrac: Pixel down-scaling factor for the "drizzle" resampling method. */
319  p = cpl_parameter_new_value("muse.muse_exp_combine.pixfrac",
320  CPL_TYPE_DOUBLE,
321  "Pixel down-scaling factor for the \"drizzle\" resampling method.",
322  "muse.muse_exp_combine",
323  (double)0.6);
324  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "pixfrac");
325  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "pixfrac");
326 
327  cpl_parameterlist_append(recipe->parameters, p);
328 
329  /* --ld: Number of adjacent pixels to take into account during resampling in all three directions (loop distance); this affects all resampling methods except "nearest". */
330  p = cpl_parameter_new_value("muse.muse_exp_combine.ld",
331  CPL_TYPE_INT,
332  "Number of adjacent pixels to take into account during resampling in all three directions (loop distance); this affects all resampling methods except \"nearest\".",
333  "muse.muse_exp_combine",
334  (int)1);
335  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "ld");
336  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ld");
337 
338  cpl_parameterlist_append(recipe->parameters, p);
339 
340  /* --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. */
341  p = cpl_parameter_new_enum("muse.muse_exp_combine.format",
342  CPL_TYPE_STRING,
343  "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.",
344  "muse.muse_exp_combine",
345  (const char *)"Cube",
346  4,
347  (const char *)"Cube",
348  (const char *)"Euro3D",
349  (const char *)"xCube",
350  (const char *)"xEuro3D");
351  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "format");
352  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "format");
353 
354  cpl_parameterlist_append(recipe->parameters, p);
355 
356  /* --weight: Type of weighting scheme to use when combining multiple exposures. */
357  p = cpl_parameter_new_enum("muse.muse_exp_combine.weight",
358  CPL_TYPE_STRING,
359  "Type of weighting scheme to use when combining multiple exposures.",
360  "muse.muse_exp_combine",
361  (const char *)"exptime",
362  2,
363  (const char *)"exptime",
364  (const char *)"fwhm");
365  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "weight");
366  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "weight");
367 
368  cpl_parameterlist_append(recipe->parameters, p);
369 
370  /* --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. */
371  p = cpl_parameter_new_value("muse.muse_exp_combine.filter",
372  CPL_TYPE_STRING,
373  "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.",
374  "muse.muse_exp_combine",
375  (const char *)"white");
376  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "filter");
377  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "filter");
378 
379  cpl_parameterlist_append(recipe->parameters, p);
380 
381  /* --lambdamin: Cut off the data below this wavelength after loading the pixel table(s). */
382  p = cpl_parameter_new_value("muse.muse_exp_combine.lambdamin",
383  CPL_TYPE_DOUBLE,
384  "Cut off the data below this wavelength after loading the pixel table(s).",
385  "muse.muse_exp_combine",
386  (double)4000.);
387  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
388  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
389 
390  cpl_parameterlist_append(recipe->parameters, p);
391 
392  /* --lambdamax: Cut off the data above this wavelength after loading the pixel table(s). */
393  p = cpl_parameter_new_value("muse.muse_exp_combine.lambdamax",
394  CPL_TYPE_DOUBLE,
395  "Cut off the data above this wavelength after loading the pixel table(s).",
396  "muse.muse_exp_combine",
397  (double)10000.);
398  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
399  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
400 
401  cpl_parameterlist_append(recipe->parameters, p);
402 
403  /* --save_combined: If true, save the fully reduced and combined pixel table for the full set of exposures. */
404  p = cpl_parameter_new_value("muse.muse_exp_combine.save_combined",
405  CPL_TYPE_BOOL,
406  "If true, save the fully reduced and combined pixel table for the full set of exposures.",
407  "muse.muse_exp_combine",
408  (int)FALSE);
409  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "save_combined");
410  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "save_combined");
411 
412  cpl_parameterlist_append(recipe->parameters, p);
413 
414  return 0;
415 } /* muse_exp_combine_create() */
416 
417 /*----------------------------------------------------------------------------*/
428 /*----------------------------------------------------------------------------*/
429 static int
430 muse_exp_combine_params_fill(muse_exp_combine_params_t *aParams, cpl_parameterlist *aParameters)
431 {
432  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
433  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
434  cpl_parameter *p;
435 
436  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.resample");
437  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
438  aParams->resample_s = cpl_parameter_get_string(p);
439  aParams->resample =
440  (!strcasecmp(aParams->resample_s, "nearest")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_NEAREST :
441  (!strcasecmp(aParams->resample_s, "linear")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_LINEAR :
442  (!strcasecmp(aParams->resample_s, "quadratic")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_QUADRATIC :
443  (!strcasecmp(aParams->resample_s, "renka")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_RENKA :
444  (!strcasecmp(aParams->resample_s, "drizzle")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_DRIZZLE :
445  (!strcasecmp(aParams->resample_s, "lanczos")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_LANCZOS :
446  MUSE_EXP_COMBINE_PARAM_RESAMPLE_INVALID_VALUE;
447  cpl_ensure_code(aParams->resample != MUSE_EXP_COMBINE_PARAM_RESAMPLE_INVALID_VALUE,
448  CPL_ERROR_ILLEGAL_INPUT);
449 
450  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dx");
451  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
452  aParams->dx = cpl_parameter_get_double(p);
453 
454  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dy");
455  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
456  aParams->dy = cpl_parameter_get_double(p);
457 
458  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dlambda");
459  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
460  aParams->dlambda = cpl_parameter_get_double(p);
461 
462  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.crtype");
463  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
464  aParams->crtype_s = cpl_parameter_get_string(p);
465  aParams->crtype =
466  (!strcasecmp(aParams->crtype_s, "iraf")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_IRAF :
467  (!strcasecmp(aParams->crtype_s, "mean")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_MEAN :
468  (!strcasecmp(aParams->crtype_s, "median")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_MEDIAN :
469  MUSE_EXP_COMBINE_PARAM_CRTYPE_INVALID_VALUE;
470  cpl_ensure_code(aParams->crtype != MUSE_EXP_COMBINE_PARAM_CRTYPE_INVALID_VALUE,
471  CPL_ERROR_ILLEGAL_INPUT);
472 
473  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.crsigma");
474  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
475  aParams->crsigma = cpl_parameter_get_double(p);
476 
477  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.rc");
478  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
479  aParams->rc = cpl_parameter_get_double(p);
480 
481  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.pixfrac");
482  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
483  aParams->pixfrac = cpl_parameter_get_double(p);
484 
485  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.ld");
486  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
487  aParams->ld = cpl_parameter_get_int(p);
488 
489  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.format");
490  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
491  aParams->format_s = cpl_parameter_get_string(p);
492  aParams->format =
493  (!strcasecmp(aParams->format_s, "Cube")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_CUBE :
494  (!strcasecmp(aParams->format_s, "Euro3D")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_EURO3D :
495  (!strcasecmp(aParams->format_s, "xCube")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_XCUBE :
496  (!strcasecmp(aParams->format_s, "xEuro3D")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_XEURO3D :
497  MUSE_EXP_COMBINE_PARAM_FORMAT_INVALID_VALUE;
498  cpl_ensure_code(aParams->format != MUSE_EXP_COMBINE_PARAM_FORMAT_INVALID_VALUE,
499  CPL_ERROR_ILLEGAL_INPUT);
500 
501  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.weight");
502  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
503  aParams->weight_s = cpl_parameter_get_string(p);
504  aParams->weight =
505  (!strcasecmp(aParams->weight_s, "exptime")) ? MUSE_EXP_COMBINE_PARAM_WEIGHT_EXPTIME :
506  (!strcasecmp(aParams->weight_s, "fwhm")) ? MUSE_EXP_COMBINE_PARAM_WEIGHT_FWHM :
507  MUSE_EXP_COMBINE_PARAM_WEIGHT_INVALID_VALUE;
508  cpl_ensure_code(aParams->weight != MUSE_EXP_COMBINE_PARAM_WEIGHT_INVALID_VALUE,
509  CPL_ERROR_ILLEGAL_INPUT);
510 
511  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.filter");
512  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
513  aParams->filter = cpl_parameter_get_string(p);
514 
515  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.lambdamin");
516  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
517  aParams->lambdamin = cpl_parameter_get_double(p);
518 
519  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.lambdamax");
520  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
521  aParams->lambdamax = cpl_parameter_get_double(p);
522 
523  p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.save_combined");
524  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
525  aParams->save_combined = cpl_parameter_get_bool(p);
526 
527  return 0;
528 } /* muse_exp_combine_params_fill() */
529 
530 /*----------------------------------------------------------------------------*/
537 /*----------------------------------------------------------------------------*/
538 static int
539 muse_exp_combine_exec(cpl_plugin *aPlugin)
540 {
541  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
542  return -1;
543  }
544  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
545  cpl_msg_set_threadid_on();
546 
547  cpl_frameset *usedframes = cpl_frameset_new(),
548  *outframes = cpl_frameset_new();
550  muse_exp_combine_params_fill(&params, recipe->parameters);
551 
552  cpl_errorstate prestate = cpl_errorstate_get();
553 
554  muse_processing *proc = muse_processing_new("muse_exp_combine",
555  recipe);
556  int rc = muse_exp_combine_compute(proc, &params);
557  cpl_frameset_join(usedframes, proc->usedFrames);
558  cpl_frameset_join(outframes, proc->outputFrames);
560 
561  if (!cpl_errorstate_is_equal(prestate)) {
562  /* dump all errors from this recipe in chronological order */
563  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
564  /* reset message level to not get the same errors displayed again by esorex */
565  cpl_msg_set_level(CPL_MSG_INFO);
566  }
567  /* clean up duplicates in framesets of used and output frames */
570  /* to get esorex to see our classification (frame groups etc.), *
571  * replace the original frameset with the list of used frames *
572  * before appending product output frames */
573  /* keep the same pointer, so just erase all frames, not delete the frameset */
574  muse_cplframeset_erase_all(recipe->frames);
575  cpl_frameset_join(recipe->frames, usedframes);
576  cpl_frameset_join(recipe->frames, outframes);
577  cpl_frameset_delete(usedframes);
578  cpl_frameset_delete(outframes);
579  return rc;
580 } /* muse_exp_combine_exec() */
581 
582 /*----------------------------------------------------------------------------*/
589 /*----------------------------------------------------------------------------*/
590 static int
591 muse_exp_combine_destroy(cpl_plugin *aPlugin)
592 {
593  /* Get the recipe from the plugin */
594  cpl_recipe *recipe;
595  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
596  recipe = (cpl_recipe *)aPlugin;
597  } else {
598  return -1;
599  }
600 
601  /* Clean up */
602  cpl_parameterlist_delete(recipe->parameters);
604  return 0;
605 } /* muse_exp_combine_destroy() */
606 
607 /*----------------------------------------------------------------------------*/
617 /*----------------------------------------------------------------------------*/
618 int
619 cpl_plugin_get_info(cpl_pluginlist *aList)
620 {
621  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
622  cpl_plugin *plugin = &recipe->interface;
623 
624  char *helptext;
626  helptext = cpl_sprintf("%s%s", muse_exp_combine_help,
627  muse_exp_combine_help_esorex);
628  } else {
629  helptext = cpl_sprintf("%s", muse_exp_combine_help);
630  }
631 
632  /* Initialize the CPL plugin stuff for this module */
633  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
634  CPL_PLUGIN_TYPE_RECIPE,
635  "muse_exp_combine",
636  "Combine several exposures into one datacube.",
637  helptext,
638  "Peter Weilbacher",
639  "usd-help@eso.org",
641  muse_exp_combine_create,
642  muse_exp_combine_exec,
643  muse_exp_combine_destroy);
644  cpl_pluginlist_append(aList, plugin);
645  cpl_free(helptext);
646 
647  return 0;
648 } /* cpl_plugin_get_info() */
649 
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.
int save_combined
If true, save the fully reduced and combined pixel table for the full set of exposures.
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 ...
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:80
Structure to hold the parameters of the muse_exp_combine recipe.
muse_processing * muse_processing_new(const char *aRecipeName, cpl_recipe *aRecipe)
Create a new processing structure.
muse_frame_mode
const char * weight_s
Type of weighting scheme to use when combining multiple exposures. (as string)
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.
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...
cpl_frameset * outputFrames
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).
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_frameset * usedFrames
cpl_error_code muse_processing_prepare_property(cpl_propertylist *, const char *, cpl_type, const char *)
Prepare and check the specified property.