MUSE Pipeline Reference Manual  2.1.1
muse_scipost_subtract_sky_simple_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_simple_z.h" /* in turn includes muse.h */
36 
37 /*----------------------------------------------------------------------------*/
43 /*----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------*
47  * Static variables *
48  *----------------------------------------------------------------------------*/
49 static const char *muse_scipost_subtract_sky_simple_help =
50  "Subtract the sky in a simple way, just using a sky spectrum created by muse_create_sky. This is a separated task of muse_scipost.";
51 
52 static const char *muse_scipost_subtract_sky_simple_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_SPECTRUM calib Y 1 Sky line list"
58  "\n\nProduct frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
59  "\n Frame tag Level Description"
60  "\n -------------------- -------- ------------"
61  "\n PIXTABLE_REDUCED final Output pixel table(s) after simple sky subtraction.";
62 
63 /*----------------------------------------------------------------------------*/
71 /*----------------------------------------------------------------------------*/
72 static cpl_recipeconfig *
73 muse_scipost_subtract_sky_simple_new_recipeconfig(void)
74 {
75  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
76 
77  cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_REDUCED", 1, -1);
78  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "SKY_SPECTRUM", 1, 1);
79  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_REDUCED", "PIXTABLE_REDUCED");
80 
81  return recipeconfig;
82 } /* muse_scipost_subtract_sky_simple_new_recipeconfig() */
83 
84 /*----------------------------------------------------------------------------*/
94 /*----------------------------------------------------------------------------*/
95 static cpl_error_code
96 muse_scipost_subtract_sky_simple_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
97 {
98  cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
99  cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
100  if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
101  } else {
102  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
103  return CPL_ERROR_ILLEGAL_INPUT;
104  }
105  return CPL_ERROR_NONE;
106 } /* muse_scipost_subtract_sky_simple_prepare_header() */
107 
108 /*----------------------------------------------------------------------------*/
117 /*----------------------------------------------------------------------------*/
118 static cpl_frame_level
119 muse_scipost_subtract_sky_simple_get_frame_level(const char *aFrametag)
120 {
121  if (!aFrametag) {
122  return CPL_FRAME_LEVEL_NONE;
123  }
124  if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
125  return CPL_FRAME_LEVEL_FINAL;
126  }
127  return CPL_FRAME_LEVEL_NONE;
128 } /* muse_scipost_subtract_sky_simple_get_frame_level() */
129 
130 /*----------------------------------------------------------------------------*/
139 /*----------------------------------------------------------------------------*/
140 static muse_frame_mode
141 muse_scipost_subtract_sky_simple_get_frame_mode(const char *aFrametag)
142 {
143  if (!aFrametag) {
144  return MUSE_FRAME_MODE_ALL;
145  }
146  if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
147  return MUSE_FRAME_MODE_ALL;
148  }
149  return MUSE_FRAME_MODE_ALL;
150 } /* muse_scipost_subtract_sky_simple_get_frame_mode() */
151 
152 /*----------------------------------------------------------------------------*/
162 /*----------------------------------------------------------------------------*/
163 static int
164 muse_scipost_subtract_sky_simple_create(cpl_plugin *aPlugin)
165 {
166  /* Check that the plugin is part of a valid recipe */
167  cpl_recipe *recipe;
168  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
169  recipe = (cpl_recipe *)aPlugin;
170  } else {
171  return -1;
172  }
173 
174  /* register the extended processing information (new FITS header creation, *
175  * getting of the frame level for a certain tag) */
177  muse_scipost_subtract_sky_simple_new_recipeconfig(),
178  muse_scipost_subtract_sky_simple_prepare_header,
179  muse_scipost_subtract_sky_simple_get_frame_level,
180  muse_scipost_subtract_sky_simple_get_frame_mode);
181 
182  /* XXX initialize timing in messages *
183  * since at least esorex is too stupid to turn it on, we have to do it */
185  cpl_msg_set_time_on();
186  }
187 
188  /* Create the parameter list in the cpl_recipe object */
189  recipe->parameters = cpl_parameterlist_new();
190  /* Fill the parameters list */
191  cpl_parameter *p;
192 
193  /* --lambdamin: Cut off the data below this wavelength after loading the pixel table(s). */
194  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky_simple.lambdamin",
195  CPL_TYPE_DOUBLE,
196  "Cut off the data below this wavelength after loading the pixel table(s).",
197  "muse.muse_scipost_subtract_sky_simple",
198  (double)4000.);
199  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
200  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
201 
202  cpl_parameterlist_append(recipe->parameters, p);
203 
204  /* --lambdamax: Cut off the data above this wavelength after loading the pixel table(s). */
205  p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky_simple.lambdamax",
206  CPL_TYPE_DOUBLE,
207  "Cut off the data above this wavelength after loading the pixel table(s).",
208  "muse.muse_scipost_subtract_sky_simple",
209  (double)10000.);
210  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
211  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
212 
213  cpl_parameterlist_append(recipe->parameters, p);
214 
215  return 0;
216 } /* muse_scipost_subtract_sky_simple_create() */
217 
218 /*----------------------------------------------------------------------------*/
229 /*----------------------------------------------------------------------------*/
230 static int
231 muse_scipost_subtract_sky_simple_params_fill(muse_scipost_subtract_sky_simple_params_t *aParams, cpl_parameterlist *aParameters)
232 {
233  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
234  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
235  cpl_parameter *p;
236 
237  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky_simple.lambdamin");
238  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
239  aParams->lambdamin = cpl_parameter_get_double(p);
240 
241  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky_simple.lambdamax");
242  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
243  aParams->lambdamax = cpl_parameter_get_double(p);
244 
245  return 0;
246 } /* muse_scipost_subtract_sky_simple_params_fill() */
247 
248 /*----------------------------------------------------------------------------*/
255 /*----------------------------------------------------------------------------*/
256 static int
257 muse_scipost_subtract_sky_simple_exec(cpl_plugin *aPlugin)
258 {
259  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
260  return -1;
261  }
263  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
264  cpl_msg_set_threadid_on();
265 
266  cpl_frameset *usedframes = cpl_frameset_new(),
267  *outframes = cpl_frameset_new();
269  muse_scipost_subtract_sky_simple_params_fill(&params, recipe->parameters);
270 
271  cpl_errorstate prestate = cpl_errorstate_get();
272 
273  muse_processing *proc = muse_processing_new("muse_scipost_subtract_sky_simple",
274  recipe);
275  int rc = muse_scipost_subtract_sky_simple_compute(proc, &params);
276  cpl_frameset_join(usedframes, proc->usedframes);
277  cpl_frameset_join(outframes, proc->outframes);
279 
280  if (!cpl_errorstate_is_equal(prestate)) {
281  /* dump all errors from this recipe in chronological order */
282  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
283  /* reset message level to not get the same errors displayed again by esorex */
284  cpl_msg_set_level(CPL_MSG_INFO);
285  }
286  /* clean up duplicates in framesets of used and output frames */
289 
290  /* to get esorex to see our classification (frame groups etc.), *
291  * replace the original frameset with the list of used frames *
292  * before appending product output frames */
293  /* keep the same pointer, so just erase all frames, not delete the frameset */
294  muse_cplframeset_erase_all(recipe->frames);
295  cpl_frameset_join(recipe->frames, usedframes);
296  cpl_frameset_join(recipe->frames, outframes);
297  cpl_frameset_delete(usedframes);
298  cpl_frameset_delete(outframes);
299  return rc;
300 } /* muse_scipost_subtract_sky_simple_exec() */
301 
302 /*----------------------------------------------------------------------------*/
309 /*----------------------------------------------------------------------------*/
310 static int
311 muse_scipost_subtract_sky_simple_destroy(cpl_plugin *aPlugin)
312 {
313  /* Get the recipe from the plugin */
314  cpl_recipe *recipe;
315  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
316  recipe = (cpl_recipe *)aPlugin;
317  } else {
318  return -1;
319  }
320 
321  /* Clean up */
322  cpl_parameterlist_delete(recipe->parameters);
324  return 0;
325 } /* muse_scipost_subtract_sky_simple_destroy() */
326 
327 /*----------------------------------------------------------------------------*/
337 /*----------------------------------------------------------------------------*/
338 int
339 cpl_plugin_get_info(cpl_pluginlist *aList)
340 {
341  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
342  cpl_plugin *plugin = &recipe->interface;
343 
344  char *helptext;
346  helptext = cpl_sprintf("%s%s", muse_scipost_subtract_sky_simple_help,
347  muse_scipost_subtract_sky_simple_help_esorex);
348  } else {
349  helptext = cpl_sprintf("%s", muse_scipost_subtract_sky_simple_help);
350  }
351 
352  /* Initialize the CPL plugin stuff for this module */
353  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
354  CPL_PLUGIN_TYPE_RECIPE,
355  "muse_scipost_subtract_sky_simple",
356  "Subtract night sky spectrum.",
357  helptext,
358  "Peter Weilbacher",
359  "usd-help@eso.org",
361  muse_scipost_subtract_sky_simple_create,
362  muse_scipost_subtract_sky_simple_exec,
363  muse_scipost_subtract_sky_simple_destroy);
364  cpl_pluginlist_append(aList, plugin);
365  cpl_free(helptext);
366 
367  return 0;
368 } /* cpl_plugin_get_info() */
369 
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
muse_cplframework_type muse_cplframework(void)
Return the CPL framework the recipe is run under.
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
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
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.
cpl_error_code muse_cplframeset_erase_duplicate(cpl_frameset *aFrames)
Erase all duplicate frames from a frameset.
Structure to hold the parameters of the muse_scipost_subtract_sky_simple recipe.
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.
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.