MUSE Pipeline Reference Manual  0.18.5
muse_scipost_combine_pixtables_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-2013 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_combine_pixtables_z.h" /* in turn includes muse.h */
36 
37 /*----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------*/
49 /*----------------------------------------------------------------------------*
50  * Static variables *
51  *----------------------------------------------------------------------------*/
52 static const char *muse_scipost_combine_pixtables_help =
53  "Sort pixel tables by exposure and combine them with applied weights into one big pixel table. This is a task separated from muse_scipost.";
54 
55 static const char *muse_scipost_combine_pixtables_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 Input pixel tables"
60  "\n\nProduct frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
61  "\n Frame tag Level Description"
62  "\n -------------------- -------- ------------"
63  "\n PIXTABLE_COMBINED intermed Combined pixel table";
64 
65 /*----------------------------------------------------------------------------*/
73 /*----------------------------------------------------------------------------*/
74 static cpl_recipeconfig *
75 muse_scipost_combine_pixtables_new_recipeconfig(void)
76 {
77  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
78  const char *tag;
79 
80  tag = "PIXTABLE_OBJECT";
81  cpl_recipeconfig_set_tag(recipeconfig, tag, 1, -1);
82  cpl_recipeconfig_set_output(recipeconfig, tag, "PIXTABLE_COMBINED");
83 
84  return recipeconfig;
85 } /* muse_scipost_combine_pixtables_new_recipeconfig() */
86 
87 /*----------------------------------------------------------------------------*/
97 /*----------------------------------------------------------------------------*/
98 static cpl_error_code
99 muse_scipost_combine_pixtables_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
100 {
101  cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
102  cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
103  if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
104  } else {
105  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
106  return CPL_ERROR_ILLEGAL_INPUT;
107  }
108  return CPL_ERROR_NONE;
109 } /* muse_scipost_combine_pixtables_prepare_header() */
110 
111 /*----------------------------------------------------------------------------*/
120 /*----------------------------------------------------------------------------*/
121 static cpl_frame_level
122 muse_scipost_combine_pixtables_get_frame_level(const char *aFrametag)
123 {
124  if (!aFrametag) {
125  return CPL_FRAME_LEVEL_NONE;
126  }
127  if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
128  return CPL_FRAME_LEVEL_INTERMEDIATE;
129  }
130  return CPL_FRAME_LEVEL_NONE;
131 } /* muse_scipost_combine_pixtables_get_frame_level() */
132 
133 /*----------------------------------------------------------------------------*/
142 /*----------------------------------------------------------------------------*/
143 static muse_frame_mode
144 muse_scipost_combine_pixtables_get_frame_mode(const char *aFrametag)
145 {
146  if (!aFrametag) {
147  return MUSE_FRAME_MODE_ALL;
148  }
149  if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
150  return MUSE_FRAME_MODE_MASTER;
151  }
152  return MUSE_FRAME_MODE_ALL;
153 } /* muse_scipost_combine_pixtables_get_frame_mode() */
154 
155 /*----------------------------------------------------------------------------*/
165 /*----------------------------------------------------------------------------*/
166 static int
167 muse_scipost_combine_pixtables_create(cpl_plugin *aPlugin)
168 {
169  /* Check that the plugin is part of a valid recipe */
170  cpl_recipe *recipe;
171  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
172  recipe = (cpl_recipe *)aPlugin;
173  } else {
174  return -1;
175  }
176 
177  /* register the extended processing information (new FITS header creation, *
178  * getting of the frame level for a certain tag) */
180  muse_scipost_combine_pixtables_new_recipeconfig(),
181  muse_scipost_combine_pixtables_prepare_header,
182  muse_scipost_combine_pixtables_get_frame_level,
183  muse_scipost_combine_pixtables_get_frame_mode);
184 
185  /* XXX initialize timing in messages *
186  * since at least esorex is too stupid to turn it on, we have to do it */
188  cpl_msg_set_time_on();
189  }
190 
191  /* Create the parameter list in the cpl_recipe object */
192  recipe->parameters = cpl_parameterlist_new();
193  /* Fill the parameters list */
194  cpl_parameter *p;
195 
196  /* --lambdamin: Cut off the data below this wavelength after loading the pixel table(s). */
197  p = cpl_parameter_new_value("muse.muse_scipost_combine_pixtables.lambdamin",
198  CPL_TYPE_DOUBLE,
199  "Cut off the data below this wavelength after loading the pixel table(s).",
200  "muse.muse_scipost_combine_pixtables",
201  (double)4000.);
202  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
203  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
204 
205  cpl_parameterlist_append(recipe->parameters, p);
206 
207  /* --lambdamax: Cut off the data above this wavelength after loading the pixel table(s). */
208  p = cpl_parameter_new_value("muse.muse_scipost_combine_pixtables.lambdamax",
209  CPL_TYPE_DOUBLE,
210  "Cut off the data above this wavelength after loading the pixel table(s).",
211  "muse.muse_scipost_combine_pixtables",
212  (double)10000.);
213  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
214  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
215 
216  cpl_parameterlist_append(recipe->parameters, p);
217 
218  /* --weight: Type of weighting scheme to use when combining multiple exposures. */
219  p = cpl_parameter_new_enum("muse.muse_scipost_combine_pixtables.weight",
220  CPL_TYPE_STRING,
221  "Type of weighting scheme to use when combining multiple exposures.",
222  "muse.muse_scipost_combine_pixtables",
223  (const char *)"exptime",
224  2,
225  (const char *)"exptime",
226  (const char *)"fwhm");
227  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "weight");
228  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "weight");
229 
230  cpl_parameterlist_append(recipe->parameters, p);
231 
232  return 0;
233 } /* muse_scipost_combine_pixtables_create() */
234 
235 /*----------------------------------------------------------------------------*/
246 /*----------------------------------------------------------------------------*/
247 static int
248 muse_scipost_combine_pixtables_params_fill(muse_scipost_combine_pixtables_params_t *aParams, cpl_parameterlist *aParameters)
249 {
250  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
251  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
252  cpl_parameter *p;
253 
254  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_combine_pixtables.lambdamin");
255  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
256  aParams->lambdamin = cpl_parameter_get_double(p);
257 
258  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_combine_pixtables.lambdamax");
259  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
260  aParams->lambdamax = cpl_parameter_get_double(p);
261 
262  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_combine_pixtables.weight");
263  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
264  aParams->weight_s = cpl_parameter_get_string(p);
265  aParams->weight =
266  (!strcasecmp(aParams->weight_s, "exptime")) ? MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_EXPTIME :
267  (!strcasecmp(aParams->weight_s, "fwhm")) ? MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_FWHM :
268  MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_INVALID_VALUE;
269  cpl_ensure_code(aParams->weight != MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_INVALID_VALUE,
270  CPL_ERROR_ILLEGAL_INPUT);
271 
272  return 0;
273 } /* muse_scipost_combine_pixtables_params_fill() */
274 
275 /*----------------------------------------------------------------------------*/
282 /*----------------------------------------------------------------------------*/
283 static int
284 muse_scipost_combine_pixtables_exec(cpl_plugin *aPlugin)
285 {
286  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
287  return -1;
288  }
289  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
290  cpl_msg_set_threadid_on();
291 
292  cpl_frameset *usedframes = cpl_frameset_new(),
293  *outframes = cpl_frameset_new();
295  muse_scipost_combine_pixtables_params_fill(&params, recipe->parameters);
296 
297  cpl_errorstate prestate = cpl_errorstate_get();
298 
299  muse_processing *proc = muse_processing_new("muse_scipost_combine_pixtables",
300  recipe);
301  int rc = muse_scipost_combine_pixtables_compute(proc, &params);
302  cpl_frameset_join(usedframes, proc->usedFrames);
303  cpl_frameset_join(outframes, proc->outputFrames);
305 
306  if (!cpl_errorstate_is_equal(prestate)) {
307  /* dump all errors from this recipe in chronological order */
308  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
309  /* reset message level to not get the same errors displayed again by esorex */
310  cpl_msg_set_level(CPL_MSG_INFO);
311  }
312  /* clean up duplicates in framesets of used and output frames */
315  /* to get esorex to see our classification (frame groups etc.), *
316  * replace the original frameset with the list of used frames *
317  * before appending product output frames */
318  /* keep the same pointer, so just erase all frames, not delete the frameset */
319  muse_cplframeset_erase_all(recipe->frames);
320  cpl_frameset_join(recipe->frames, usedframes);
321  cpl_frameset_join(recipe->frames, outframes);
322  cpl_frameset_delete(usedframes);
323  cpl_frameset_delete(outframes);
324  return rc;
325 } /* muse_scipost_combine_pixtables_exec() */
326 
327 /*----------------------------------------------------------------------------*/
334 /*----------------------------------------------------------------------------*/
335 static int
336 muse_scipost_combine_pixtables_destroy(cpl_plugin *aPlugin)
337 {
338  /* Get the recipe from the plugin */
339  cpl_recipe *recipe;
340  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
341  recipe = (cpl_recipe *)aPlugin;
342  } else {
343  return -1;
344  }
345 
346  /* Clean up */
347  cpl_parameterlist_delete(recipe->parameters);
349  return 0;
350 } /* muse_scipost_combine_pixtables_destroy() */
351 
352 /*----------------------------------------------------------------------------*/
362 /*----------------------------------------------------------------------------*/
363 int
364 cpl_plugin_get_info(cpl_pluginlist *aList)
365 {
366  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
367  cpl_plugin *plugin = &recipe->interface;
368 
369  char *helptext;
371  helptext = cpl_sprintf("%s%s", muse_scipost_combine_pixtables_help,
372  muse_scipost_combine_pixtables_help_esorex);
373  } else {
374  helptext = cpl_sprintf("%s", muse_scipost_combine_pixtables_help);
375  }
376 
377  /* Initialize the CPL plugin stuff for this module */
378  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
379  CPL_PLUGIN_TYPE_RECIPE,
380  "muse_scipost_combine_pixtables",
381  "Combine MUSE pixel tables, either from different IFUs, or from different exposures, or both.",
382  helptext,
383  "Ole Streicher",
384  "usd-help@eso.org",
386  muse_scipost_combine_pixtables_create,
387  muse_scipost_combine_pixtables_exec,
388  muse_scipost_combine_pixtables_destroy);
389  cpl_pluginlist_append(aList, plugin);
390  cpl_free(helptext);
391 
392  return 0;
393 } /* cpl_plugin_get_info() */
394 
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
Structure to hold the parameters of the muse_scipost_combine_pixtables recipe.
muse_cplframework_type muse_cplframework(void)
Return the CPL framework the recipe is run under.
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
const char * weight_s
Type of weighting scheme to use when combining multiple exposures. (as string)
const char * muse_get_license(void)
Get the pipeline copyright and license.
Definition: muse_utils.c:80
muse_processing * muse_processing_new(const char *aRecipeName, cpl_recipe *aRecipe)
Create a new processing structure.
muse_frame_mode
int weight
Type of weighting scheme to use when combining multiple exposures.
cpl_frameset * outputFrames
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 lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
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.
cpl_frameset * usedFrames