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