MUSE Pipeline Reference Manual  2.1.1
muse_scipost_make_cube_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_scipost_make_cube_z.h" /* in turn includes muse.h */
36 
37 /*----------------------------------------------------------------------------*/
43 /*----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------*
47  * Static variables *
48  *----------------------------------------------------------------------------*/
49 static const char *muse_scipost_make_cube_help =
50  "This recipe takes a pixel table and resamples it to either a FITS cube or a Euro3D table and optionally to a stacked spectrum. This is a part of the muse_scipost recipe.";
51 
52 static const char *muse_scipost_make_cube_help_esorex =
53  "\n\nInput frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
54  "\n Frame tag Type Req #Fr Description"
55  "\n -------------------- ---- --- --- ------------"
56  "\n PIXTABLE_OBJECT raw Y Input pixel table"
57  "\n FILTER_LIST calib . 1 File to be used to create field-of-view images."
58  "\n OUTPUT_WCS calib . 1 WCS to override output cube location / dimensions"
59  "\n\nProduct frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
60  "\n Frame tag Level Description"
61  "\n -------------------- -------- ------------"
62  "\n DATACUBE_FINAL final Output datacube"
63  "\n IMAGE_FOV final Field-of-view images corresponding to the \"filter\" parameter."
64  "\n OBJECT_RESAMPLED final Stacked image (if --stacked=true)";
65 
66 /*----------------------------------------------------------------------------*/
74 /*----------------------------------------------------------------------------*/
75 static cpl_recipeconfig *
76 muse_scipost_make_cube_new_recipeconfig(void)
77 {
78  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
79 
80  cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_OBJECT", 1, -1);
81  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_OBJECT", "FILTER_LIST", -1, 1);
82  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_OBJECT", "OUTPUT_WCS", -1, 1);
83  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_OBJECT", "DATACUBE_FINAL");
84  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_OBJECT", "IMAGE_FOV");
85  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_OBJECT", "OBJECT_RESAMPLED");
86 
87  return recipeconfig;
88 } /* muse_scipost_make_cube_new_recipeconfig() */
89 
90 /*----------------------------------------------------------------------------*/
100 /*----------------------------------------------------------------------------*/
101 static cpl_error_code
102 muse_scipost_make_cube_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
103 {
104  cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
105  cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
106  if (!strcmp(aFrametag, "DATACUBE_FINAL")) {
107  } else if (!strcmp(aFrametag, "IMAGE_FOV")) {
108  } else if (!strcmp(aFrametag, "OBJECT_RESAMPLED")) {
109  } else {
110  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
111  return CPL_ERROR_ILLEGAL_INPUT;
112  }
113  return CPL_ERROR_NONE;
114 } /* muse_scipost_make_cube_prepare_header() */
115 
116 /*----------------------------------------------------------------------------*/
125 /*----------------------------------------------------------------------------*/
126 static cpl_frame_level
127 muse_scipost_make_cube_get_frame_level(const char *aFrametag)
128 {
129  if (!aFrametag) {
130  return CPL_FRAME_LEVEL_NONE;
131  }
132  if (!strcmp(aFrametag, "DATACUBE_FINAL")) {
133  return CPL_FRAME_LEVEL_FINAL;
134  }
135  if (!strcmp(aFrametag, "IMAGE_FOV")) {
136  return CPL_FRAME_LEVEL_FINAL;
137  }
138  if (!strcmp(aFrametag, "OBJECT_RESAMPLED")) {
139  return CPL_FRAME_LEVEL_FINAL;
140  }
141  return CPL_FRAME_LEVEL_NONE;
142 } /* muse_scipost_make_cube_get_frame_level() */
143 
144 /*----------------------------------------------------------------------------*/
153 /*----------------------------------------------------------------------------*/
154 static muse_frame_mode
155 muse_scipost_make_cube_get_frame_mode(const char *aFrametag)
156 {
157  if (!aFrametag) {
158  return MUSE_FRAME_MODE_ALL;
159  }
160  if (!strcmp(aFrametag, "DATACUBE_FINAL")) {
161  return MUSE_FRAME_MODE_MASTER;
162  }
163  if (!strcmp(aFrametag, "IMAGE_FOV")) {
165  }
166  if (!strcmp(aFrametag, "OBJECT_RESAMPLED")) {
167  return MUSE_FRAME_MODE_MASTER;
168  }
169  return MUSE_FRAME_MODE_ALL;
170 } /* muse_scipost_make_cube_get_frame_mode() */
171 
172 /*----------------------------------------------------------------------------*/
182 /*----------------------------------------------------------------------------*/
183 static int
184 muse_scipost_make_cube_create(cpl_plugin *aPlugin)
185 {
186  /* Check that the plugin is part of a valid recipe */
187  cpl_recipe *recipe;
188  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
189  recipe = (cpl_recipe *)aPlugin;
190  } else {
191  return -1;
192  }
193 
194  /* register the extended processing information (new FITS header creation, *
195  * getting of the frame level for a certain tag) */
197  muse_scipost_make_cube_new_recipeconfig(),
198  muse_scipost_make_cube_prepare_header,
199  muse_scipost_make_cube_get_frame_level,
200  muse_scipost_make_cube_get_frame_mode);
201 
202  /* XXX initialize timing in messages *
203  * since at least esorex is too stupid to turn it on, we have to do it */
205  cpl_msg_set_time_on();
206  }
207 
208  /* Create the parameter list in the cpl_recipe object */
209  recipe->parameters = cpl_parameterlist_new();
210  /* Fill the parameters list */
211  cpl_parameter *p;
212 
213  /* --lambdamin: Cut off the data below this wavelength after loading the pixel table(s). */
214  p = cpl_parameter_new_value("muse.muse_scipost_make_cube.lambdamin",
215  CPL_TYPE_DOUBLE,
216  "Cut off the data below this wavelength after loading the pixel table(s).",
217  "muse.muse_scipost_make_cube",
218  (double)4000.);
219  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
220  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
221 
222  cpl_parameterlist_append(recipe->parameters, p);
223 
224  /* --lambdamax: Cut off the data above this wavelength after loading the pixel table(s). */
225  p = cpl_parameter_new_value("muse.muse_scipost_make_cube.lambdamax",
226  CPL_TYPE_DOUBLE,
227  "Cut off the data above this wavelength after loading the pixel table(s).",
228  "muse.muse_scipost_make_cube",
229  (double)10000.);
230  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
231  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
232 
233  cpl_parameterlist_append(recipe->parameters, p);
234 
235  /* --resample: The resampling technique to use for the final output cube. */
236  p = cpl_parameter_new_enum("muse.muse_scipost_make_cube.resample",
237  CPL_TYPE_STRING,
238  "The resampling technique to use for the final output cube.",
239  "muse.muse_scipost_make_cube",
240  (const char *)"drizzle",
241  6,
242  (const char *)"nearest",
243  (const char *)"linear",
244  (const char *)"quadratic",
245  (const char *)"renka",
246  (const char *)"drizzle",
247  (const char *)"lanczos");
248  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "resample");
249  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "resample");
250 
251  cpl_parameterlist_append(recipe->parameters, p);
252 
253  /* --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. */
254  p = cpl_parameter_new_value("muse.muse_scipost_make_cube.dx",
255  CPL_TYPE_DOUBLE,
256  "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.",
257  "muse.muse_scipost_make_cube",
258  (double)0.0);
259  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dx");
260  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dx");
261 
262  cpl_parameterlist_append(recipe->parameters, p);
263 
264  /* --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. */
265  p = cpl_parameter_new_value("muse.muse_scipost_make_cube.dy",
266  CPL_TYPE_DOUBLE,
267  "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.",
268  "muse.muse_scipost_make_cube",
269  (double)0.0);
270  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dy");
271  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dy");
272 
273  cpl_parameterlist_append(recipe->parameters, p);
274 
275  /* --dlambda: Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0.0 */
276  p = cpl_parameter_new_value("muse.muse_scipost_make_cube.dlambda",
277  CPL_TYPE_DOUBLE,
278  "Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0.0",
279  "muse.muse_scipost_make_cube",
280  (double)0.0);
281  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dlambda");
282  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dlambda");
283 
284  cpl_parameterlist_append(recipe->parameters, p);
285 
286  /* --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. */
287  p = cpl_parameter_new_enum("muse.muse_scipost_make_cube.crtype",
288  CPL_TYPE_STRING,
289  "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.",
290  "muse.muse_scipost_make_cube",
291  (const char *)"median",
292  3,
293  (const char *)"iraf",
294  (const char *)"mean",
295  (const char *)"median");
296  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crtype");
297  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crtype");
298 
299  cpl_parameterlist_append(recipe->parameters, p);
300 
301  /* --crsigma: Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative value switches cosmic ray rejection off. */
302  p = cpl_parameter_new_value("muse.muse_scipost_make_cube.crsigma",
303  CPL_TYPE_DOUBLE,
304  "Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative value switches cosmic ray rejection off.",
305  "muse.muse_scipost_make_cube",
306  (double)15.);
307  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crsigma");
308  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crsigma");
309 
310  cpl_parameterlist_append(recipe->parameters, p);
311 
312  /* --rc: Critical radius for the "renka" resampling method. */
313  p = cpl_parameter_new_value("muse.muse_scipost_make_cube.rc",
314  CPL_TYPE_DOUBLE,
315  "Critical radius for the \"renka\" resampling method.",
316  "muse.muse_scipost_make_cube",
317  (double)1.25);
318  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "rc");
319  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "rc");
320 
321  cpl_parameterlist_append(recipe->parameters, p);
322 
323  /* --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. */
324  p = cpl_parameter_new_value("muse.muse_scipost_make_cube.pixfrac",
325  CPL_TYPE_STRING,
326  "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.",
327  "muse.muse_scipost_make_cube",
328  (const char *)"0.8,0.8");
329  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "pixfrac");
330  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "pixfrac");
331 
332  cpl_parameterlist_append(recipe->parameters, p);
333 
334  /* --ld: Number of adjacent pixels to take into account during resampling in all three directions (loop distance); this affects all resampling methods except "nearest". */
335  p = cpl_parameter_new_value("muse.muse_scipost_make_cube.ld",
336  CPL_TYPE_INT,
337  "Number of adjacent pixels to take into account during resampling in all three directions (loop distance); this affects all resampling methods except \"nearest\".",
338  "muse.muse_scipost_make_cube",
339  (int)1);
340  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "ld");
341  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ld");
342 
343  cpl_parameterlist_append(recipe->parameters, p);
344 
345  /* --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. */
346  p = cpl_parameter_new_enum("muse.muse_scipost_make_cube.format",
347  CPL_TYPE_STRING,
348  "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.",
349  "muse.muse_scipost_make_cube",
350  (const char *)"Cube",
351  4,
352  (const char *)"Cube",
353  (const char *)"Euro3D",
354  (const char *)"xCube",
355  (const char *)"xEuro3D");
356  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "format");
357  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "format");
358 
359  cpl_parameterlist_append(recipe->parameters, p);
360 
361  /* --stacked: If true, write an additional output file in form of a 2D stacked image (x direction is pseudo-spatial, y direction is wavelength). */
362  p = cpl_parameter_new_value("muse.muse_scipost_make_cube.stacked",
363  CPL_TYPE_BOOL,
364  "If true, write an additional output file in form of a 2D stacked image (x direction is pseudo-spatial, y direction is wavelength).",
365  "muse.muse_scipost_make_cube",
366  (int)FALSE);
367  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "stacked");
368  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stacked");
369 
370  cpl_parameterlist_append(recipe->parameters, p);
371 
372  /* --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. */
373  p = cpl_parameter_new_value("muse.muse_scipost_make_cube.filter",
374  CPL_TYPE_STRING,
375  "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.",
376  "muse.muse_scipost_make_cube",
377  (const char *)"white");
378  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "filter");
379  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "filter");
380 
381  cpl_parameterlist_append(recipe->parameters, p);
382 
383  return 0;
384 } /* muse_scipost_make_cube_create() */
385 
386 /*----------------------------------------------------------------------------*/
397 /*----------------------------------------------------------------------------*/
398 static int
399 muse_scipost_make_cube_params_fill(muse_scipost_make_cube_params_t *aParams, cpl_parameterlist *aParameters)
400 {
401  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
402  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
403  cpl_parameter *p;
404 
405  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.lambdamin");
406  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
407  aParams->lambdamin = cpl_parameter_get_double(p);
408 
409  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.lambdamax");
410  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
411  aParams->lambdamax = cpl_parameter_get_double(p);
412 
413  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.resample");
414  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
415  aParams->resample_s = cpl_parameter_get_string(p);
416  aParams->resample =
417  (!strcasecmp(aParams->resample_s, "nearest")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_RESAMPLE_NEAREST :
418  (!strcasecmp(aParams->resample_s, "linear")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_RESAMPLE_LINEAR :
419  (!strcasecmp(aParams->resample_s, "quadratic")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_RESAMPLE_QUADRATIC :
420  (!strcasecmp(aParams->resample_s, "renka")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_RESAMPLE_RENKA :
421  (!strcasecmp(aParams->resample_s, "drizzle")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_RESAMPLE_DRIZZLE :
422  (!strcasecmp(aParams->resample_s, "lanczos")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_RESAMPLE_LANCZOS :
423  MUSE_SCIPOST_MAKE_CUBE_PARAM_RESAMPLE_INVALID_VALUE;
424  cpl_ensure_code(aParams->resample != MUSE_SCIPOST_MAKE_CUBE_PARAM_RESAMPLE_INVALID_VALUE,
425  CPL_ERROR_ILLEGAL_INPUT);
426 
427  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.dx");
428  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
429  aParams->dx = cpl_parameter_get_double(p);
430 
431  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.dy");
432  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
433  aParams->dy = cpl_parameter_get_double(p);
434 
435  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.dlambda");
436  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
437  aParams->dlambda = cpl_parameter_get_double(p);
438 
439  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.crtype");
440  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
441  aParams->crtype_s = cpl_parameter_get_string(p);
442  aParams->crtype =
443  (!strcasecmp(aParams->crtype_s, "iraf")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_CRTYPE_IRAF :
444  (!strcasecmp(aParams->crtype_s, "mean")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_CRTYPE_MEAN :
445  (!strcasecmp(aParams->crtype_s, "median")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_CRTYPE_MEDIAN :
446  MUSE_SCIPOST_MAKE_CUBE_PARAM_CRTYPE_INVALID_VALUE;
447  cpl_ensure_code(aParams->crtype != MUSE_SCIPOST_MAKE_CUBE_PARAM_CRTYPE_INVALID_VALUE,
448  CPL_ERROR_ILLEGAL_INPUT);
449 
450  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.crsigma");
451  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
452  aParams->crsigma = cpl_parameter_get_double(p);
453 
454  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.rc");
455  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
456  aParams->rc = cpl_parameter_get_double(p);
457 
458  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.pixfrac");
459  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
460  aParams->pixfrac = cpl_parameter_get_string(p);
461 
462  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.ld");
463  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
464  aParams->ld = cpl_parameter_get_int(p);
465 
466  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.format");
467  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
468  aParams->format_s = cpl_parameter_get_string(p);
469  aParams->format =
470  (!strcasecmp(aParams->format_s, "Cube")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_FORMAT_CUBE :
471  (!strcasecmp(aParams->format_s, "Euro3D")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_FORMAT_EURO3D :
472  (!strcasecmp(aParams->format_s, "xCube")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_FORMAT_XCUBE :
473  (!strcasecmp(aParams->format_s, "xEuro3D")) ? MUSE_SCIPOST_MAKE_CUBE_PARAM_FORMAT_XEURO3D :
474  MUSE_SCIPOST_MAKE_CUBE_PARAM_FORMAT_INVALID_VALUE;
475  cpl_ensure_code(aParams->format != MUSE_SCIPOST_MAKE_CUBE_PARAM_FORMAT_INVALID_VALUE,
476  CPL_ERROR_ILLEGAL_INPUT);
477 
478  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.stacked");
479  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
480  aParams->stacked = cpl_parameter_get_bool(p);
481 
482  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_make_cube.filter");
483  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
484  aParams->filter = cpl_parameter_get_string(p);
485 
486  return 0;
487 } /* muse_scipost_make_cube_params_fill() */
488 
489 /*----------------------------------------------------------------------------*/
496 /*----------------------------------------------------------------------------*/
497 static int
498 muse_scipost_make_cube_exec(cpl_plugin *aPlugin)
499 {
500  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
501  return -1;
502  }
504  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
505  cpl_msg_set_threadid_on();
506 
507  cpl_frameset *usedframes = cpl_frameset_new(),
508  *outframes = cpl_frameset_new();
510  muse_scipost_make_cube_params_fill(&params, recipe->parameters);
511 
512  cpl_errorstate prestate = cpl_errorstate_get();
513 
514  muse_processing *proc = muse_processing_new("muse_scipost_make_cube",
515  recipe);
516  int rc = muse_scipost_make_cube_compute(proc, &params);
517  cpl_frameset_join(usedframes, proc->usedframes);
518  cpl_frameset_join(outframes, proc->outframes);
520 
521  if (!cpl_errorstate_is_equal(prestate)) {
522  /* dump all errors from this recipe in chronological order */
523  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
524  /* reset message level to not get the same errors displayed again by esorex */
525  cpl_msg_set_level(CPL_MSG_INFO);
526  }
527  /* clean up duplicates in framesets of used and output frames */
530 
531  /* to get esorex to see our classification (frame groups etc.), *
532  * replace the original frameset with the list of used frames *
533  * before appending product output frames */
534  /* keep the same pointer, so just erase all frames, not delete the frameset */
535  muse_cplframeset_erase_all(recipe->frames);
536  cpl_frameset_join(recipe->frames, usedframes);
537  cpl_frameset_join(recipe->frames, outframes);
538  cpl_frameset_delete(usedframes);
539  cpl_frameset_delete(outframes);
540  return rc;
541 } /* muse_scipost_make_cube_exec() */
542 
543 /*----------------------------------------------------------------------------*/
550 /*----------------------------------------------------------------------------*/
551 static int
552 muse_scipost_make_cube_destroy(cpl_plugin *aPlugin)
553 {
554  /* Get the recipe from the plugin */
555  cpl_recipe *recipe;
556  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
557  recipe = (cpl_recipe *)aPlugin;
558  } else {
559  return -1;
560  }
561 
562  /* Clean up */
563  cpl_parameterlist_delete(recipe->parameters);
565  return 0;
566 } /* muse_scipost_make_cube_destroy() */
567 
568 /*----------------------------------------------------------------------------*/
578 /*----------------------------------------------------------------------------*/
579 int
580 cpl_plugin_get_info(cpl_pluginlist *aList)
581 {
582  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
583  cpl_plugin *plugin = &recipe->interface;
584 
585  char *helptext;
587  helptext = cpl_sprintf("%s%s", muse_scipost_make_cube_help,
588  muse_scipost_make_cube_help_esorex);
589  } else {
590  helptext = cpl_sprintf("%s", muse_scipost_make_cube_help);
591  }
592 
593  /* Initialize the CPL plugin stuff for this module */
594  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
595  CPL_PLUGIN_TYPE_RECIPE,
596  "muse_scipost_make_cube",
597  "Make a MUSE cube from a MUSE pixel table.",
598  helptext,
599  "Ole Streicher",
600  "usd-help@eso.org",
602  muse_scipost_make_cube_create,
603  muse_scipost_make_cube_exec,
604  muse_scipost_make_cube_destroy);
605  cpl_pluginlist_append(aList, plugin);
606  cpl_free(helptext);
607 
608  return 0;
609 } /* cpl_plugin_get_info() */
610 
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
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...
muse_cplframework_type muse_cplframework(void)
Return the CPL framework the recipe is run under.
const char * resample_s
The resampling technique to use for the final output cube. (as string)
double crsigma
Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative va...
int ld
Number of adjacent pixels to take into account during resampling in all three directions (loop distan...
cpl_frameset * usedframes
muse_processing * muse_processing_new(const char *aName, cpl_recipe *aRecipe)
Create a new processing structure.
const char * muse_get_license(void)
Get the pipeline copyright and license.
Definition: muse_utils.c:83
int format
Type of output file format, "Cube" is a standard FITS cube with NAXIS=3 and multiple extensions (for ...
muse_frame_mode
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
int stacked
If true, write an additional output file in form of a 2D stacked image (x direction is pseudo-spatial...
cpl_frameset * outframes
int resample
The resampling technique to use for the final output cube.
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
void muse_processinginfo_delete(cpl_recipe *)
Clear all information from the processing info and from the recipe config.
double dx
Horizontal step size for resampling (in arcsec or pixel). The following defaults are taken when this ...
double rc
Critical radius for the "renka" resampling method.
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.
Structure to hold the parameters of the muse_scipost_make_cube recipe.
const char * crtype_s
Type of statistics used for detection of cosmic rays during final resampling. "iraf" uses the varianc...
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
double dy
Vertical step size for resampling (in arcsec or pixel). The following defaults are taken when this va...
int crtype
Type of statistics used for detection of cosmic rays during final resampling. "iraf" uses the varianc...
void muse_processinginfo_register(cpl_recipe *, cpl_recipeconfig *, muse_processing_prepare_header_func *, muse_processing_get_frame_level_func *, muse_processing_get_frame_mode_func *)
Register extended functionalities for MUSE recipes.
const char * 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.
double dlambda
Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0...
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.
const char * format_s
Type of output file format, "Cube" is a standard FITS cube with NAXIS=3 and multiple extensions (for ...