MUSE Pipeline Reference Manual  2.1.1
muse_scipost_subtract_sky_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_subtract_sky_z.h" /* in turn includes muse.h */
36 
37 /*----------------------------------------------------------------------------*/
43 /*----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------*
47  * Static variables *
48  *----------------------------------------------------------------------------*/
49 static const char *muse_scipost_subtract_sky_help =
50  "Subtract the sky as defined by the sky lines and continuum from a pixel table. This is a separated task of muse_scipost.";
51 
52 static const char *muse_scipost_subtract_sky_help_esorex =
53  "\n\nInput frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
54  "\n Frame tag Type Req #Fr Description"
55  "\n -------------------- ---- --- --- ------------"
56  "\n PIXTABLE_REDUCED raw Y Flux calibrated input pixel table(s)."
57  "\n SKY_LINES calib Y 1 Sky line list"
58  "\n SKY_CONTINUUM calib Y 1 Sky continuum spectrum"
59  "\n LSF_PROFILE calib Y LSF for each IFU."
60  "\n\nProduct frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
61  "\n Frame tag Level Description"
62  "\n -------------------- -------- ------------"
63  "\n PIXTABLE_REDUCED final Output pixel table(s) for sky subtraction.";
64 
65 /*----------------------------------------------------------------------------*/
73 /*----------------------------------------------------------------------------*/
74 static cpl_recipeconfig *
75 muse_scipost_subtract_sky_new_recipeconfig(void)
76 {
77  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
78 
79  cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_REDUCED", 1, -1);
80  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "SKY_LINES", 1, 1);
81  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "SKY_CONTINUUM", 1, 1);
82  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "LSF_PROFILE", 1, -1);
83  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_REDUCED", "PIXTABLE_REDUCED");
84 
85  return recipeconfig;
86 } /* muse_scipost_subtract_sky_new_recipeconfig() */
87 
88 /*----------------------------------------------------------------------------*/
98 /*----------------------------------------------------------------------------*/
99 static cpl_error_code
100 muse_scipost_subtract_sky_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
101 {
102  cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
103  cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
104  if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
105  } else {
106  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
107  return CPL_ERROR_ILLEGAL_INPUT;
108  }
109  return CPL_ERROR_NONE;
110 } /* muse_scipost_subtract_sky_prepare_header() */
111 
112 /*----------------------------------------------------------------------------*/
121 /*----------------------------------------------------------------------------*/
122 static cpl_frame_level
123 muse_scipost_subtract_sky_get_frame_level(const char *aFrametag)
124 {
125  if (!aFrametag) {
126  return CPL_FRAME_LEVEL_NONE;
127  }
128  if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
129  return CPL_FRAME_LEVEL_FINAL;
130  }
131  return CPL_FRAME_LEVEL_NONE;
132 } /* muse_scipost_subtract_sky_get_frame_level() */
133 
134 /*----------------------------------------------------------------------------*/
143 /*----------------------------------------------------------------------------*/
144 static muse_frame_mode
145 muse_scipost_subtract_sky_get_frame_mode(const char *aFrametag)
146 {
147  if (!aFrametag) {
148  return MUSE_FRAME_MODE_ALL;
149  }
150  if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
151  return MUSE_FRAME_MODE_ALL;
152  }
153  return MUSE_FRAME_MODE_ALL;
154 } /* muse_scipost_subtract_sky_get_frame_mode() */
155 
156 /*----------------------------------------------------------------------------*/
166 /*----------------------------------------------------------------------------*/
167 static int
168 muse_scipost_subtract_sky_create(cpl_plugin *aPlugin)
169 {
170  /* Check that the plugin is part of a valid recipe */
171  cpl_recipe *recipe;
172  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
173  recipe = (cpl_recipe *)aPlugin;
174  } else {
175  return -1;
176  }
177 
178  /* register the extended processing information (new FITS header creation, *
179  * getting of the frame level for a certain tag) */
181  muse_scipost_subtract_sky_new_recipeconfig(),
182  muse_scipost_subtract_sky_prepare_header,
183  muse_scipost_subtract_sky_get_frame_level,
184  muse_scipost_subtract_sky_get_frame_mode);
185 
186  /* XXX initialize timing in messages *
187  * since at least esorex is too stupid to turn it on, we have to do it */
189  cpl_msg_set_time_on();
190  }
191 
192  /* Create the parameter list in the cpl_recipe object */
193  recipe->parameters = cpl_parameterlist_new();
194  /* Fill the parameters list */
195  cpl_parameter *p;
196 
197  /* --lambdamin: Cut off the data below this wavelength after loading the pixel table(s). */
198  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.lambdamin",
199  CPL_TYPE_DOUBLE,
200  "Cut off the data below this wavelength after loading the pixel table(s).",
201  "muse.muse_scipost_subtract_sky",
202  (double)4000.);
203  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
204  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
205 
206  cpl_parameterlist_append(recipe->parameters, p);
207 
208  /* --lambdamax: Cut off the data above this wavelength after loading the pixel table(s). */
209  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.lambdamax",
210  CPL_TYPE_DOUBLE,
211  "Cut off the data above this wavelength after loading the pixel table(s).",
212  "muse.muse_scipost_subtract_sky",
213  (double)10000.);
214  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
215  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
216 
217  cpl_parameterlist_append(recipe->parameters, p);
218 
219  /* --orig: If specified, write an additional column containing the
220  original data to the pixel table. */
221  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.orig",
222  CPL_TYPE_STRING,
223  "If specified, write an additional column containing the original data to the pixel table.",
224  "muse.muse_scipost_subtract_sky",
225  (const char *)"");
226  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "orig");
227  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "orig");
228 
229  cpl_parameterlist_append(recipe->parameters, p);
230 
231  /* --flux_sky: Reference flat field flux, obtained by sky exposure. This parameter is needed to scale the data of each pixel table if more than one pixel table was used to determine the sky. By default, it is taken from the parameter ESO DRS MUSE FLAT FLUX SKY of the first pixel table. */
232  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.flux_sky",
233  CPL_TYPE_DOUBLE,
234  "Reference flat field flux, obtained by sky exposure. This parameter is needed to scale the data of each pixel table if more than one pixel table was used to determine the sky. By default, it is taken from the parameter ESO DRS MUSE FLAT FLUX SKY of the first pixel table.",
235  "muse.muse_scipost_subtract_sky",
236  (double)0.0);
237  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "flux_sky");
238  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "flux_sky");
239 
240  cpl_parameterlist_append(recipe->parameters, p);
241 
242  /* --flux_lamp: Reference flat field flux, obtained by lamp exposure. This parameter is needed to scale the data of each pixel table if more than one pixel table was used to determine the sky. By default, it is taken from the parameter ESO DRS MUSE FLAT FLUX LAMP of the first pixel table. */
243  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.flux_lamp",
244  CPL_TYPE_DOUBLE,
245  "Reference flat field flux, obtained by lamp exposure. This parameter is needed to scale the data of each pixel table if more than one pixel table was used to determine the sky. By default, it is taken from the parameter ESO DRS MUSE FLAT FLUX LAMP of the first pixel table.",
246  "muse.muse_scipost_subtract_sky",
247  (double)0.0);
248  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "flux_lamp");
249  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "flux_lamp");
250 
251  cpl_parameterlist_append(recipe->parameters, p);
252 
253  return 0;
254 } /* muse_scipost_subtract_sky_create() */
255 
256 /*----------------------------------------------------------------------------*/
267 /*----------------------------------------------------------------------------*/
268 static int
269 muse_scipost_subtract_sky_params_fill(muse_scipost_subtract_sky_params_t *aParams, cpl_parameterlist *aParameters)
270 {
271  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
272  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
273  cpl_parameter *p;
274 
275  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.lambdamin");
276  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
277  aParams->lambdamin = cpl_parameter_get_double(p);
278 
279  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.lambdamax");
280  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
281  aParams->lambdamax = cpl_parameter_get_double(p);
282 
283  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.orig");
284  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
285  aParams->orig = cpl_parameter_get_string(p);
286 
287  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.flux_sky");
288  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
289  aParams->flux_sky = cpl_parameter_get_double(p);
290 
291  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.flux_lamp");
292  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
293  aParams->flux_lamp = cpl_parameter_get_double(p);
294 
295  return 0;
296 } /* muse_scipost_subtract_sky_params_fill() */
297 
298 /*----------------------------------------------------------------------------*/
305 /*----------------------------------------------------------------------------*/
306 static int
307 muse_scipost_subtract_sky_exec(cpl_plugin *aPlugin)
308 {
309  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
310  return -1;
311  }
313  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
314  cpl_msg_set_threadid_on();
315 
316  cpl_frameset *usedframes = cpl_frameset_new(),
317  *outframes = cpl_frameset_new();
319  muse_scipost_subtract_sky_params_fill(&params, recipe->parameters);
320 
321  cpl_errorstate prestate = cpl_errorstate_get();
322 
323  muse_processing *proc = muse_processing_new("muse_scipost_subtract_sky",
324  recipe);
325  int rc = muse_scipost_subtract_sky_compute(proc, &params);
326  cpl_frameset_join(usedframes, proc->usedframes);
327  cpl_frameset_join(outframes, proc->outframes);
329 
330  if (!cpl_errorstate_is_equal(prestate)) {
331  /* dump all errors from this recipe in chronological order */
332  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
333  /* reset message level to not get the same errors displayed again by esorex */
334  cpl_msg_set_level(CPL_MSG_INFO);
335  }
336  /* clean up duplicates in framesets of used and output frames */
339 
340  /* to get esorex to see our classification (frame groups etc.), *
341  * replace the original frameset with the list of used frames *
342  * before appending product output frames */
343  /* keep the same pointer, so just erase all frames, not delete the frameset */
344  muse_cplframeset_erase_all(recipe->frames);
345  cpl_frameset_join(recipe->frames, usedframes);
346  cpl_frameset_join(recipe->frames, outframes);
347  cpl_frameset_delete(usedframes);
348  cpl_frameset_delete(outframes);
349  return rc;
350 } /* muse_scipost_subtract_sky_exec() */
351 
352 /*----------------------------------------------------------------------------*/
359 /*----------------------------------------------------------------------------*/
360 static int
361 muse_scipost_subtract_sky_destroy(cpl_plugin *aPlugin)
362 {
363  /* Get the recipe from the plugin */
364  cpl_recipe *recipe;
365  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
366  recipe = (cpl_recipe *)aPlugin;
367  } else {
368  return -1;
369  }
370 
371  /* Clean up */
372  cpl_parameterlist_delete(recipe->parameters);
374  return 0;
375 } /* muse_scipost_subtract_sky_destroy() */
376 
377 /*----------------------------------------------------------------------------*/
387 /*----------------------------------------------------------------------------*/
388 int
389 cpl_plugin_get_info(cpl_pluginlist *aList)
390 {
391  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
392  cpl_plugin *plugin = &recipe->interface;
393 
394  char *helptext;
396  helptext = cpl_sprintf("%s%s", muse_scipost_subtract_sky_help,
397  muse_scipost_subtract_sky_help_esorex);
398  } else {
399  helptext = cpl_sprintf("%s", muse_scipost_subtract_sky_help);
400  }
401 
402  /* Initialize the CPL plugin stuff for this module */
403  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
404  CPL_PLUGIN_TYPE_RECIPE,
405  "muse_scipost_subtract_sky",
406  "Subtract night sky model.",
407  helptext,
408  "Ole Streicher",
409  "usd-help@eso.org",
411  muse_scipost_subtract_sky_create,
412  muse_scipost_subtract_sky_exec,
413  muse_scipost_subtract_sky_destroy);
414  cpl_pluginlist_append(aList, plugin);
415  cpl_free(helptext);
416 
417  return 0;
418 } /* cpl_plugin_get_info() */
419 
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
const char * orig
If specified, write an additional column containing the original data to the pixel table...
muse_cplframework_type muse_cplframework(void)
Return the CPL framework the recipe is run under.
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
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
muse_frame_mode
cpl_frameset * outframes
double flux_lamp
Reference flat field flux, obtained by lamp exposure. This parameter is needed to scale the data of e...
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
void muse_processinginfo_delete(cpl_recipe *)
Clear all information from the processing info and from the recipe config.
Structure to hold the parameters of the muse_scipost_subtract_sky recipe.
double flux_sky
Reference flat field flux, obtained by sky exposure. This parameter is needed to scale the data of ea...
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.
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.