MUSE Pipeline Reference Manual  2.5.2
muse_scipost_raman_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_raman_z.h" /* in turn includes muse.h */
36 
37 /*----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------*/
49 /*----------------------------------------------------------------------------*
50  * Static variables *
51  *----------------------------------------------------------------------------*/
52 static const char *muse_scipost_raman_help =
53  "This recipe removes the Raman scattered light of the 4GLSF system from the exposure. It must be before the normal sky subtraction.";
54 
55 static const char *muse_scipost_raman_help_esorex =
56  "\n\nInput frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
57  "\n Frame tag Type Req #Fr Description"
58  "\n -------------------- ---- --- --- ------------"
59  "\n PIXTABLE_OBJECT raw Y 1 Input pixel table"
60  "\n RAMAN_LINES calib Y 1 List of Raman emission lines"
61  "\n LSF_PROFILE calib Y Slice specific LSF parameters cubes"
62  "\n SKY_MASK calib Y 1 Sky mask to use"
63  "\n\nProduct frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
64  "\n Frame tag Level Description"
65  "\n -------------------- -------- ------------"
66  "\n RAMAN_IMAGES intermed Images for Raman correction diagnostics (if an input RAMAN_LINES was given, the instrument used AO and --save contains \"raman\"). Extensions are: DATA: model of the Raman light distribution in the field of view (arbitrary units), RAMAN_IMAGE_O2: reconstructed image in the O2 band, SKY_MASK_O2: sky mask used for the O2 band, RAMAN_IMAGE_N2: reconstructed image in the N2 band, SKY_MASK_N2: sky mask used for the N2 band, RAMAN_FIT_O2: model of Raman flux distribution in the O2 band, RAMAN_FIT_N2: model of Raman flux distribution in the N2 band."
67  "\n PIXTABLE_REDUCED final Output pixel table for raman subtraction.";
68 
69 /*----------------------------------------------------------------------------*/
77 /*----------------------------------------------------------------------------*/
78 static cpl_recipeconfig *
79 muse_scipost_raman_new_recipeconfig(void)
80 {
81  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
82 
83  cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_OBJECT", 1, 1);
84  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_OBJECT", "RAMAN_LINES", 1, 1);
85  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_OBJECT", "LSF_PROFILE", 1, -1);
86  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_OBJECT", "SKY_MASK", 1, 1);
87  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_OBJECT", "RAMAN_IMAGES");
88  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_OBJECT", "PIXTABLE_REDUCED");
89 
90  return recipeconfig;
91 } /* muse_scipost_raman_new_recipeconfig() */
92 
93 /*----------------------------------------------------------------------------*/
103 /*----------------------------------------------------------------------------*/
104 static cpl_error_code
105 muse_scipost_raman_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
106 {
107  cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
108  cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
109  if (!strcmp(aFrametag, "RAMAN_IMAGES")) {
110  muse_processing_prepare_property(aHeader, "ESO QC SCIPOST RAMAN SPATIAL XX",
111  CPL_TYPE_DOUBLE,
112  "2D Polynomial x^2 coefficient");
113  muse_processing_prepare_property(aHeader, "ESO QC SCIPOST RAMAN SPATIAL XY",
114  CPL_TYPE_DOUBLE,
115  "2D Polynomial xy coefficient");
116  muse_processing_prepare_property(aHeader, "ESO QC SCIPOST RAMAN SPATIAL YY",
117  CPL_TYPE_DOUBLE,
118  "2D Polynomial y^2 coefficient");
119  muse_processing_prepare_property(aHeader, "ESO QC SCIPOST RAMAN SPATIAL X",
120  CPL_TYPE_DOUBLE,
121  "2D Polynomial x coefficient");
122  muse_processing_prepare_property(aHeader, "ESO QC SCIPOST RAMAN SPATIAL Y",
123  CPL_TYPE_DOUBLE,
124  "2D Polynomial y coefficient");
125  muse_processing_prepare_property(aHeader, "ESO QC SCIPOST RAMAN FLUX O2",
126  CPL_TYPE_FLOAT,
127  "[erg/(s cm2 arcsec2)] Computed average Raman scattered flux in the O2 band (around 6484 Angstrom)");
128  muse_processing_prepare_property(aHeader, "ESO QC SCIPOST RAMAN FLUX N2",
129  CPL_TYPE_FLOAT,
130  "[erg/(s cm2 arcsec2)] Computed average Raman scattered flux in the N2 band (around 6827 Angstrom)");
131  } else if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
132  } else {
133  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
134  return CPL_ERROR_ILLEGAL_INPUT;
135  }
136  return CPL_ERROR_NONE;
137 } /* muse_scipost_raman_prepare_header() */
138 
139 /*----------------------------------------------------------------------------*/
148 /*----------------------------------------------------------------------------*/
149 static cpl_frame_level
150 muse_scipost_raman_get_frame_level(const char *aFrametag)
151 {
152  if (!aFrametag) {
153  return CPL_FRAME_LEVEL_NONE;
154  }
155  if (!strcmp(aFrametag, "RAMAN_IMAGES")) {
156  return CPL_FRAME_LEVEL_INTERMEDIATE;
157  }
158  if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
159  return CPL_FRAME_LEVEL_FINAL;
160  }
161  return CPL_FRAME_LEVEL_NONE;
162 } /* muse_scipost_raman_get_frame_level() */
163 
164 /*----------------------------------------------------------------------------*/
173 /*----------------------------------------------------------------------------*/
174 static muse_frame_mode
175 muse_scipost_raman_get_frame_mode(const char *aFrametag)
176 {
177  if (!aFrametag) {
178  return MUSE_FRAME_MODE_ALL;
179  }
180  if (!strcmp(aFrametag, "RAMAN_IMAGES")) {
182  }
183  if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
184  return MUSE_FRAME_MODE_MASTER;
185  }
186  return MUSE_FRAME_MODE_ALL;
187 } /* muse_scipost_raman_get_frame_mode() */
188 
189 /*----------------------------------------------------------------------------*/
199 /*----------------------------------------------------------------------------*/
200 static int
201 muse_scipost_raman_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_scipost_raman_new_recipeconfig(),
215  muse_scipost_raman_prepare_header,
216  muse_scipost_raman_get_frame_level,
217  muse_scipost_raman_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  /* --lambdamin: Cut off the data below this wavelength after loading the pixel table(s). */
231  p = cpl_parameter_new_value("muse.muse_scipost_raman.lambdamin",
232  CPL_TYPE_DOUBLE,
233  "Cut off the data below this wavelength after loading the pixel table(s).",
234  "muse.muse_scipost_raman",
235  (double)4000.);
236  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
237  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
238 
239  cpl_parameterlist_append(recipe->parameters, p);
240 
241  /* --lambdamax: Cut off the data above this wavelength after loading the pixel table(s). */
242  p = cpl_parameter_new_value("muse.muse_scipost_raman.lambdamax",
243  CPL_TYPE_DOUBLE,
244  "Cut off the data above this wavelength after loading the pixel table(s).",
245  "muse.muse_scipost_raman",
246  (double)10000.);
247  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
248  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
249 
250  cpl_parameterlist_append(recipe->parameters, p);
251 
252  /* --lambdaref: Reference wavelength used for correction of differential atmospheric refraction. The R-band (peak wavelength ~7000 Angstrom) that is usually used for guiding, is close to the central wavelength of MUSE, so a value of 7000.0 Angstrom should be used if nothing else is known. A value less than zero switches DAR correction off. */
253  p = cpl_parameter_new_value("muse.muse_scipost_raman.lambdaref",
254  CPL_TYPE_DOUBLE,
255  "Reference wavelength used for correction of differential atmospheric refraction. The R-band (peak wavelength ~7000 Angstrom) that is usually used for guiding, is close to the central wavelength of MUSE, so a value of 7000.0 Angstrom should be used if nothing else is known. A value less than zero switches DAR correction off.",
256  "muse.muse_scipost_raman",
257  (double)7000.);
258  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdaref");
259  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdaref");
260 
261  cpl_parameterlist_append(recipe->parameters, p);
262 
263  /* --width: Wavelength range around Raman lines [Angstrom]. */
264  p = cpl_parameter_new_value("muse.muse_scipost_raman.width",
265  CPL_TYPE_DOUBLE,
266  "Wavelength range around Raman lines [Angstrom].",
267  "muse.muse_scipost_raman",
268  (double)20.);
269  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "width");
270  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "width");
271  if (!getenv("MUSE_EXPERT_USER")) {
272  cpl_parameter_disable(p, CPL_PARAMETER_MODE_CLI);
273  }
274 
275  cpl_parameterlist_append(recipe->parameters, p);
276 
277  /* --crsigma: Sigma level clipping for cube-based CR rejection (using "median", see muse_scipost). It can be switched off, by passing zero or a negative value. */
278  p = cpl_parameter_new_value("muse.muse_scipost_raman.crsigma",
279  CPL_TYPE_DOUBLE,
280  "Sigma level clipping for cube-based CR rejection (using \"median\", see muse_scipost). It can be switched off, by passing zero or a negative value.",
281  "muse.muse_scipost_raman",
282  (double)15.);
283  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crsigma");
284  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crsigma");
285  if (!getenv("MUSE_EXPERT_USER")) {
286  cpl_parameter_disable(p, CPL_PARAMETER_MODE_CLI);
287  }
288 
289  cpl_parameterlist_append(recipe->parameters, p);
290 
291  /* --fraction: Fraction of the image (without the ignored part) to be considered as sky. If an input sky mask is provided, the fraction is applied to the regions within the mask. If the whole sky mask should be used, set this parameter to 1. */
292  p = cpl_parameter_new_value("muse.muse_scipost_raman.fraction",
293  CPL_TYPE_DOUBLE,
294  "Fraction of the image (without the ignored part) to be considered as sky. If an input sky mask is provided, the fraction is applied to the regions within the mask. If the whole sky mask should be used, set this parameter to 1.",
295  "muse.muse_scipost_raman",
296  (double)0.75);
297  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "fraction");
298  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fraction");
299 
300  cpl_parameterlist_append(recipe->parameters, p);
301 
302  /* --ignore: Lowest fraction of the image to be ignored. If an input sky mask is provided, the fraction is applied to the regions within the mask. If the whole sky mask should be used, set this parameter to 0. */
303  p = cpl_parameter_new_value("muse.muse_scipost_raman.ignore",
304  CPL_TYPE_DOUBLE,
305  "Lowest fraction of the image to be ignored. If an input sky mask is provided, the fraction is applied to the regions within the mask. If the whole sky mask should be used, set this parameter to 0.",
306  "muse.muse_scipost_raman",
307  (double)0.05);
308  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "ignore");
309  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ignore");
310 
311  cpl_parameterlist_append(recipe->parameters, p);
312 
313  return 0;
314 } /* muse_scipost_raman_create() */
315 
316 /*----------------------------------------------------------------------------*/
327 /*----------------------------------------------------------------------------*/
328 static int
329 muse_scipost_raman_params_fill(muse_scipost_raman_params_t *aParams, cpl_parameterlist *aParameters)
330 {
331  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
332  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
333  cpl_parameter *p;
334 
335  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_raman.lambdamin");
336  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
337  aParams->lambdamin = cpl_parameter_get_double(p);
338 
339  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_raman.lambdamax");
340  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
341  aParams->lambdamax = cpl_parameter_get_double(p);
342 
343  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_raman.lambdaref");
344  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
345  aParams->lambdaref = cpl_parameter_get_double(p);
346 
347  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_raman.width");
348  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
349  aParams->width = cpl_parameter_get_double(p);
350 
351  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_raman.crsigma");
352  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
353  aParams->crsigma = cpl_parameter_get_double(p);
354 
355  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_raman.fraction");
356  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
357  aParams->fraction = cpl_parameter_get_double(p);
358 
359  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_raman.ignore");
360  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
361  aParams->ignore = cpl_parameter_get_double(p);
362 
363  return 0;
364 } /* muse_scipost_raman_params_fill() */
365 
366 /*----------------------------------------------------------------------------*/
373 /*----------------------------------------------------------------------------*/
374 static int
375 muse_scipost_raman_exec(cpl_plugin *aPlugin)
376 {
377  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
378  return -1;
379  }
381  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
382  cpl_msg_set_threadid_on();
383 
384  cpl_frameset *usedframes = cpl_frameset_new(),
385  *outframes = cpl_frameset_new();
387  muse_scipost_raman_params_fill(&params, recipe->parameters);
388 
389  cpl_errorstate prestate = cpl_errorstate_get();
390 
391  muse_processing *proc = muse_processing_new("muse_scipost_raman",
392  recipe);
393  int rc = muse_scipost_raman_compute(proc, &params);
394  cpl_frameset_join(usedframes, proc->usedframes);
395  cpl_frameset_join(outframes, proc->outframes);
397 
398  if (!cpl_errorstate_is_equal(prestate)) {
399  /* dump all errors from this recipe in chronological order */
400  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
401  /* reset message level to not get the same errors displayed again by esorex */
402  cpl_msg_set_level(CPL_MSG_INFO);
403  }
404  /* clean up duplicates in framesets of used and output frames */
407 
408  /* to get esorex to see our classification (frame groups etc.), *
409  * replace the original frameset with the list of used frames *
410  * before appending product output frames */
411  /* keep the same pointer, so just erase all frames, not delete the frameset */
412  muse_cplframeset_erase_all(recipe->frames);
413  cpl_frameset_join(recipe->frames, usedframes);
414  cpl_frameset_join(recipe->frames, outframes);
415  cpl_frameset_delete(usedframes);
416  cpl_frameset_delete(outframes);
417  return rc;
418 } /* muse_scipost_raman_exec() */
419 
420 /*----------------------------------------------------------------------------*/
427 /*----------------------------------------------------------------------------*/
428 static int
429 muse_scipost_raman_destroy(cpl_plugin *aPlugin)
430 {
431  /* Get the recipe from the plugin */
432  cpl_recipe *recipe;
433  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
434  recipe = (cpl_recipe *)aPlugin;
435  } else {
436  return -1;
437  }
438 
439  /* Clean up */
440  cpl_parameterlist_delete(recipe->parameters);
442  return 0;
443 } /* muse_scipost_raman_destroy() */
444 
445 /*----------------------------------------------------------------------------*/
455 /*----------------------------------------------------------------------------*/
456 int
457 cpl_plugin_get_info(cpl_pluginlist *aList)
458 {
459  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
460  cpl_plugin *plugin = &recipe->interface;
461 
462  char *helptext;
464  helptext = cpl_sprintf("%s%s", muse_scipost_raman_help,
465  muse_scipost_raman_help_esorex);
466  } else {
467  helptext = cpl_sprintf("%s", muse_scipost_raman_help);
468  }
469 
470  /* Initialize the CPL plugin stuff for this module */
471  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
472  CPL_PLUGIN_TYPE_RECIPE,
473  "muse_scipost_raman",
474  "Remove of 4GLSF Raman emission.",
475  helptext,
476  "Ole Streicher",
477  "usd-help@eso.org",
479  muse_scipost_raman_create,
480  muse_scipost_raman_exec,
481  muse_scipost_raman_destroy);
482  cpl_pluginlist_append(aList, plugin);
483  cpl_free(helptext);
484 
485  return 0;
486 } /* cpl_plugin_get_info() */
487 
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
double width
Wavelength range around Raman lines [Angstrom].
double lambdaref
Reference wavelength used for correction of differential atmospheric refraction. The R-band (peak wav...
muse_cplframework_type muse_cplframework(void)
Return the CPL framework the recipe is run under.
double crsigma
Sigma level clipping for cube-based CR rejection (using "median", see muse_scipost). It can be switched off, by passing zero or a negative value.
double fraction
Fraction of the image (without the ignored part) to be considered as sky. If an input sky mask is pro...
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
muse_frame_mode
cpl_frameset * outframes
double ignore
Lowest fraction of the image to be ignored. If an input sky mask is provided, the fraction is applied...
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 lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
Structure to hold the parameters of the muse_scipost_raman recipe.
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 lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
void muse_processinginfo_register(cpl_recipe *, cpl_recipeconfig *, muse_processing_prepare_header_func *, muse_processing_get_frame_level_func *, muse_processing_get_frame_mode_func *)
Register extended functionalities for MUSE recipes.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.
cpl_error_code muse_processing_prepare_property(cpl_propertylist *, const char *, cpl_type, const char *)
Prepare and check the specified property.