MUSE Pipeline Reference Manual  2.1.1
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-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_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 OFFSET_LIST calib . 1 List of coordinate offsets (and optional flux scale factors)"
61  "\n\nProduct frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
62  "\n Frame tag Level Description"
63  "\n -------------------- -------- ------------"
64  "\n PIXTABLE_COMBINED intermed Combined pixel table";
65 
66 /*----------------------------------------------------------------------------*/
74 /*----------------------------------------------------------------------------*/
75 static cpl_recipeconfig *
76 muse_scipost_combine_pixtables_new_recipeconfig(void)
77 {
78  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
79 
80  cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_OBJECT", 1, -1);
81  cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_OBJECT", "OFFSET_LIST", -1, 1);
82  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_OBJECT", "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. "exptime" just uses the exposure time to weight the exposures, "fwhm" uses the DIMM information in the header as well, "none" preserves an existing weight column in the input pixel tables without changes. */
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. \"exptime\" just uses the exposure time to weight the exposures, \"fwhm\" uses the DIMM information in the header as well, \"none\" preserves an existing weight column in the input pixel tables without changes.",
222  "muse.muse_scipost_combine_pixtables",
223  (const char *)"exptime",
224  3,
225  (const char *)"exptime",
226  (const char *)"fwhm",
227  (const char *)"none");
228  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "weight");
229  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "weight");
230 
231  cpl_parameterlist_append(recipe->parameters, p);
232 
233  return 0;
234 } /* muse_scipost_combine_pixtables_create() */
235 
236 /*----------------------------------------------------------------------------*/
247 /*----------------------------------------------------------------------------*/
248 static int
249 muse_scipost_combine_pixtables_params_fill(muse_scipost_combine_pixtables_params_t *aParams, cpl_parameterlist *aParameters)
250 {
251  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
252  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
253  cpl_parameter *p;
254 
255  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_combine_pixtables.lambdamin");
256  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
257  aParams->lambdamin = cpl_parameter_get_double(p);
258 
259  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_combine_pixtables.lambdamax");
260  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
261  aParams->lambdamax = cpl_parameter_get_double(p);
262 
263  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_combine_pixtables.weight");
264  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
265  aParams->weight_s = cpl_parameter_get_string(p);
266  aParams->weight =
267  (!strcasecmp(aParams->weight_s, "exptime")) ? MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_EXPTIME :
268  (!strcasecmp(aParams->weight_s, "fwhm")) ? MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_FWHM :
269  (!strcasecmp(aParams->weight_s, "none")) ? MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_NONE :
270  MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_INVALID_VALUE;
271  cpl_ensure_code(aParams->weight != MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_INVALID_VALUE,
272  CPL_ERROR_ILLEGAL_INPUT);
273 
274  return 0;
275 } /* muse_scipost_combine_pixtables_params_fill() */
276 
277 /*----------------------------------------------------------------------------*/
284 /*----------------------------------------------------------------------------*/
285 static int
286 muse_scipost_combine_pixtables_exec(cpl_plugin *aPlugin)
287 {
288  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
289  return -1;
290  }
292  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
293  cpl_msg_set_threadid_on();
294 
295  cpl_frameset *usedframes = cpl_frameset_new(),
296  *outframes = cpl_frameset_new();
298  muse_scipost_combine_pixtables_params_fill(&params, recipe->parameters);
299 
300  cpl_errorstate prestate = cpl_errorstate_get();
301 
302  muse_processing *proc = muse_processing_new("muse_scipost_combine_pixtables",
303  recipe);
304  int rc = muse_scipost_combine_pixtables_compute(proc, &params);
305  cpl_frameset_join(usedframes, proc->usedframes);
306  cpl_frameset_join(outframes, proc->outframes);
308 
309  if (!cpl_errorstate_is_equal(prestate)) {
310  /* dump all errors from this recipe in chronological order */
311  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
312  /* reset message level to not get the same errors displayed again by esorex */
313  cpl_msg_set_level(CPL_MSG_INFO);
314  }
315  /* clean up duplicates in framesets of used and output frames */
318 
319  /* to get esorex to see our classification (frame groups etc.), *
320  * replace the original frameset with the list of used frames *
321  * before appending product output frames */
322  /* keep the same pointer, so just erase all frames, not delete the frameset */
323  muse_cplframeset_erase_all(recipe->frames);
324  cpl_frameset_join(recipe->frames, usedframes);
325  cpl_frameset_join(recipe->frames, outframes);
326  cpl_frameset_delete(usedframes);
327  cpl_frameset_delete(outframes);
328  return rc;
329 } /* muse_scipost_combine_pixtables_exec() */
330 
331 /*----------------------------------------------------------------------------*/
338 /*----------------------------------------------------------------------------*/
339 static int
340 muse_scipost_combine_pixtables_destroy(cpl_plugin *aPlugin)
341 {
342  /* Get the recipe from the plugin */
343  cpl_recipe *recipe;
344  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
345  recipe = (cpl_recipe *)aPlugin;
346  } else {
347  return -1;
348  }
349 
350  /* Clean up */
351  cpl_parameterlist_delete(recipe->parameters);
353  return 0;
354 } /* muse_scipost_combine_pixtables_destroy() */
355 
356 /*----------------------------------------------------------------------------*/
366 /*----------------------------------------------------------------------------*/
367 int
368 cpl_plugin_get_info(cpl_pluginlist *aList)
369 {
370  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
371  cpl_plugin *plugin = &recipe->interface;
372 
373  char *helptext;
375  helptext = cpl_sprintf("%s%s", muse_scipost_combine_pixtables_help,
376  muse_scipost_combine_pixtables_help_esorex);
377  } else {
378  helptext = cpl_sprintf("%s", muse_scipost_combine_pixtables_help);
379  }
380 
381  /* Initialize the CPL plugin stuff for this module */
382  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
383  CPL_PLUGIN_TYPE_RECIPE,
384  "muse_scipost_combine_pixtables",
385  "Combine MUSE pixel tables, either from different IFUs, or from different exposures, or both.",
386  helptext,
387  "Ole Streicher",
388  "usd-help@eso.org",
390  muse_scipost_combine_pixtables_create,
391  muse_scipost_combine_pixtables_exec,
392  muse_scipost_combine_pixtables_destroy);
393  cpl_pluginlist_append(aList, plugin);
394  cpl_free(helptext);
395 
396  return 0;
397 } /* cpl_plugin_get_info() */
398 
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).
cpl_frameset * usedframes
muse_processing * muse_processing_new(const char *aName, cpl_recipe *aRecipe)
Create a new processing structure.
const char * weight_s
Type of weighting scheme to use when combining multiple exposures. "exptime" just uses the exposure t...
const char * muse_get_license(void)
Get the pipeline copyright and license.
Definition: muse_utils.c:83
muse_frame_mode
cpl_frameset * outframes
int weight
Type of weighting scheme to use when combining multiple exposures. "exptime" just uses the exposure t...
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.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.