MUSE Pipeline Reference Manual  1.0.2
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-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_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 Slice specific LSF parameters"
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  const char *tag;
79 
80  tag = "PIXTABLE_REDUCED";
81  cpl_recipeconfig_set_tag(recipeconfig, tag, 1, -1);
82  cpl_recipeconfig_set_input(recipeconfig, tag, "SKY_LINES", 1, 1);
83  cpl_recipeconfig_set_input(recipeconfig, tag, "SKY_CONTINUUM", 1, 1);
84  cpl_recipeconfig_set_input(recipeconfig, tag, "LSF_PROFILE", 1, -1);
85  cpl_recipeconfig_set_output(recipeconfig, tag, "PIXTABLE_REDUCED");
86 
87  return recipeconfig;
88 } /* muse_scipost_subtract_sky_new_recipeconfig() */
89 
90 /*----------------------------------------------------------------------------*/
100 /*----------------------------------------------------------------------------*/
101 static cpl_error_code
102 muse_scipost_subtract_sky_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, "PIXTABLE_REDUCED")) {
107  } else {
108  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
109  return CPL_ERROR_ILLEGAL_INPUT;
110  }
111  return CPL_ERROR_NONE;
112 } /* muse_scipost_subtract_sky_prepare_header() */
113 
114 /*----------------------------------------------------------------------------*/
123 /*----------------------------------------------------------------------------*/
124 static cpl_frame_level
125 muse_scipost_subtract_sky_get_frame_level(const char *aFrametag)
126 {
127  if (!aFrametag) {
128  return CPL_FRAME_LEVEL_NONE;
129  }
130  if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
131  return CPL_FRAME_LEVEL_FINAL;
132  }
133  return CPL_FRAME_LEVEL_NONE;
134 } /* muse_scipost_subtract_sky_get_frame_level() */
135 
136 /*----------------------------------------------------------------------------*/
145 /*----------------------------------------------------------------------------*/
146 static muse_frame_mode
147 muse_scipost_subtract_sky_get_frame_mode(const char *aFrametag)
148 {
149  if (!aFrametag) {
150  return MUSE_FRAME_MODE_ALL;
151  }
152  if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
153  return MUSE_FRAME_MODE_ALL;
154  }
155  return MUSE_FRAME_MODE_ALL;
156 } /* muse_scipost_subtract_sky_get_frame_mode() */
157 
158 /*----------------------------------------------------------------------------*/
168 /*----------------------------------------------------------------------------*/
169 static int
170 muse_scipost_subtract_sky_create(cpl_plugin *aPlugin)
171 {
172  /* Check that the plugin is part of a valid recipe */
173  cpl_recipe *recipe;
174  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
175  recipe = (cpl_recipe *)aPlugin;
176  } else {
177  return -1;
178  }
179 
180  /* register the extended processing information (new FITS header creation, *
181  * getting of the frame level for a certain tag) */
183  muse_scipost_subtract_sky_new_recipeconfig(),
184  muse_scipost_subtract_sky_prepare_header,
185  muse_scipost_subtract_sky_get_frame_level,
186  muse_scipost_subtract_sky_get_frame_mode);
187 
188  /* XXX initialize timing in messages *
189  * since at least esorex is too stupid to turn it on, we have to do it */
191  cpl_msg_set_time_on();
192  }
193 
194  /* Create the parameter list in the cpl_recipe object */
195  recipe->parameters = cpl_parameterlist_new();
196  /* Fill the parameters list */
197  cpl_parameter *p;
198 
199  /* --lambdamin: Cut off the data below this wavelength after loading the pixel table(s). */
200  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.lambdamin",
201  CPL_TYPE_DOUBLE,
202  "Cut off the data below this wavelength after loading the pixel table(s).",
203  "muse.muse_scipost_subtract_sky",
204  (double)4000.);
205  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
206  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
207 
208  cpl_parameterlist_append(recipe->parameters, p);
209 
210  /* --lambdamax: Cut off the data above this wavelength after loading the pixel table(s). */
211  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.lambdamax",
212  CPL_TYPE_DOUBLE,
213  "Cut off the data above this wavelength after loading the pixel table(s).",
214  "muse.muse_scipost_subtract_sky",
215  (double)10000.);
216  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
217  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
218 
219  cpl_parameterlist_append(recipe->parameters, p);
220 
221  /* --orig: If specified, write an additional column containing the
222  original data to the pixel table. */
223  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.orig",
224  CPL_TYPE_STRING,
225  "If specified, write an additional column containing the original data to the pixel table.",
226  "muse.muse_scipost_subtract_sky",
227  (const char *)"");
228  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "orig");
229  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "orig");
230 
231  cpl_parameterlist_append(recipe->parameters, p);
232 
233  /* --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. */
234  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.flux_sky",
235  CPL_TYPE_DOUBLE,
236  "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.",
237  "muse.muse_scipost_subtract_sky",
238  (double)0.0);
239  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "flux_sky");
240  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "flux_sky");
241 
242  cpl_parameterlist_append(recipe->parameters, p);
243 
244  /* --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. */
245  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.flux_lamp",
246  CPL_TYPE_DOUBLE,
247  "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.",
248  "muse.muse_scipost_subtract_sky",
249  (double)0.0);
250  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "flux_lamp");
251  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "flux_lamp");
252 
253  cpl_parameterlist_append(recipe->parameters, p);
254 
255  return 0;
256 } /* muse_scipost_subtract_sky_create() */
257 
258 /*----------------------------------------------------------------------------*/
269 /*----------------------------------------------------------------------------*/
270 static int
271 muse_scipost_subtract_sky_params_fill(muse_scipost_subtract_sky_params_t *aParams, cpl_parameterlist *aParameters)
272 {
273  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
274  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
275  cpl_parameter *p;
276 
277  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.lambdamin");
278  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
279  aParams->lambdamin = cpl_parameter_get_double(p);
280 
281  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.lambdamax");
282  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
283  aParams->lambdamax = cpl_parameter_get_double(p);
284 
285  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.orig");
286  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
287  aParams->orig = cpl_parameter_get_string(p);
288 
289  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.flux_sky");
290  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
291  aParams->flux_sky = cpl_parameter_get_double(p);
292 
293  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.flux_lamp");
294  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
295  aParams->flux_lamp = cpl_parameter_get_double(p);
296 
297  return 0;
298 } /* muse_scipost_subtract_sky_params_fill() */
299 
300 /*----------------------------------------------------------------------------*/
307 /*----------------------------------------------------------------------------*/
308 static int
309 muse_scipost_subtract_sky_exec(cpl_plugin *aPlugin)
310 {
311  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
312  return -1;
313  }
314  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
315  cpl_msg_set_threadid_on();
316 
317  cpl_frameset *usedframes = cpl_frameset_new(),
318  *outframes = cpl_frameset_new();
320  muse_scipost_subtract_sky_params_fill(&params, recipe->parameters);
321 
322  cpl_errorstate prestate = cpl_errorstate_get();
323 
324  muse_processing *proc = muse_processing_new("muse_scipost_subtract_sky",
325  recipe);
326  int rc = muse_scipost_subtract_sky_compute(proc, &params);
327  cpl_frameset_join(usedframes, proc->usedframes);
328  cpl_frameset_join(outframes, proc->outframes);
330 
331  if (!cpl_errorstate_is_equal(prestate)) {
332  /* dump all errors from this recipe in chronological order */
333  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
334  /* reset message level to not get the same errors displayed again by esorex */
335  cpl_msg_set_level(CPL_MSG_INFO);
336  }
337  /* clean up duplicates in framesets of used and output frames */
340 
341  /* to get esorex to see our classification (frame groups etc.), *
342  * replace the original frameset with the list of used frames *
343  * before appending product output frames */
344  /* keep the same pointer, so just erase all frames, not delete the frameset */
345  muse_cplframeset_erase_all(recipe->frames);
346  cpl_frameset_join(recipe->frames, usedframes);
347  cpl_frameset_join(recipe->frames, outframes);
348  cpl_frameset_delete(usedframes);
349  cpl_frameset_delete(outframes);
350  return rc;
351 } /* muse_scipost_subtract_sky_exec() */
352 
353 /*----------------------------------------------------------------------------*/
360 /*----------------------------------------------------------------------------*/
361 static int
362 muse_scipost_subtract_sky_destroy(cpl_plugin *aPlugin)
363 {
364  /* Get the recipe from the plugin */
365  cpl_recipe *recipe;
366  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
367  recipe = (cpl_recipe *)aPlugin;
368  } else {
369  return -1;
370  }
371 
372  /* Clean up */
373  cpl_parameterlist_delete(recipe->parameters);
375  return 0;
376 } /* muse_scipost_subtract_sky_destroy() */
377 
378 /*----------------------------------------------------------------------------*/
388 /*----------------------------------------------------------------------------*/
389 int
390 cpl_plugin_get_info(cpl_pluginlist *aList)
391 {
392  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
393  cpl_plugin *plugin = &recipe->interface;
394 
395  char *helptext;
397  helptext = cpl_sprintf("%s%s", muse_scipost_subtract_sky_help,
398  muse_scipost_subtract_sky_help_esorex);
399  } else {
400  helptext = cpl_sprintf("%s", muse_scipost_subtract_sky_help);
401  }
402 
403  /* Initialize the CPL plugin stuff for this module */
404  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
405  CPL_PLUGIN_TYPE_RECIPE,
406  "muse_scipost_subtract_sky",
407  "Subtract night sky model.",
408  helptext,
409  "Ole Streicher",
410  "usd-help@eso.org",
412  muse_scipost_subtract_sky_create,
413  muse_scipost_subtract_sky_exec,
414  muse_scipost_subtract_sky_destroy);
415  cpl_pluginlist_append(aList, plugin);
416  cpl_free(helptext);
417 
418  return 0;
419 } /* cpl_plugin_get_info() */
420 
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:84
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.