MUSE Pipeline Reference Manual  2.1.1
muse_qi_mask_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_qi_mask_z.h" /* in turn includes muse.h */
36 
37 /*----------------------------------------------------------------------------*/
57 /*----------------------------------------------------------------------------*/
60 /*----------------------------------------------------------------------------*
61  * Static variables *
62  *----------------------------------------------------------------------------*/
63 static const char *muse_qi_mask_help =
64  "Trace and wavelength calibration tables (24 of them each, one per IFU) are used to build wavelength maps. If the input data is binned, the wavelength maps are binned in the same way (averaging of pixels). The wavelength maps are then thresholded to create masks of the desired wavelength range. Finally, the mask is \"untrimmed\", i.e. empty regions for the pre- and overscans are added (in a simple way, assuming quadrants of equal size, and padding of 32 pixels on all quadrant edges). Note: this recipe is not part of the main MUSE pipeline but to be used in the integration phase to create image masks until the system is fully qualified. It therefore does only minimal error checking.";
65 
66 static const char *muse_qi_mask_help_esorex =
67  "\n\nInput frames for raw frame tag \"BIAS\":\n"
68  "\n Frame tag Type Req #Fr Description"
69  "\n -------------------- ---- --- --- ------------"
70  "\n BIAS raw . 1 Raw bias, should be given, used to determine detector setup for the output mask"
71  "\n TRACE_TABLE calib Y 1 Trace table"
72  "\n WAVECAL_TABLE calib Y 1 Wavelength calibration table"
73  "\n\nProduct frames for raw frame tag \"BIAS\":\n"
74  "\n Frame tag Level Description"
75  "\n -------------------- -------- ------------"
76  "\n MASK_IMAGE final Image masks for quick image reconstruction";
77 
78 /*----------------------------------------------------------------------------*/
86 /*----------------------------------------------------------------------------*/
87 static cpl_recipeconfig *
88 muse_qi_mask_new_recipeconfig(void)
89 {
90  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
91 
92  cpl_recipeconfig_set_tag(recipeconfig, "BIAS", -1, 1);
93  cpl_recipeconfig_set_input(recipeconfig, "BIAS", "TRACE_TABLE", 1, 1);
94  cpl_recipeconfig_set_input(recipeconfig, "BIAS", "WAVECAL_TABLE", 1, 1);
95  cpl_recipeconfig_set_output(recipeconfig, "BIAS", "MASK_IMAGE");
96 
97  return recipeconfig;
98 } /* muse_qi_mask_new_recipeconfig() */
99 
100 /*----------------------------------------------------------------------------*/
110 /*----------------------------------------------------------------------------*/
111 static cpl_error_code
112 muse_qi_mask_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
113 {
114  cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
115  cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
116  if (!strcmp(aFrametag, "MASK_IMAGE")) {
117  } else {
118  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
119  return CPL_ERROR_ILLEGAL_INPUT;
120  }
121  return CPL_ERROR_NONE;
122 } /* muse_qi_mask_prepare_header() */
123 
124 /*----------------------------------------------------------------------------*/
133 /*----------------------------------------------------------------------------*/
134 static cpl_frame_level
135 muse_qi_mask_get_frame_level(const char *aFrametag)
136 {
137  if (!aFrametag) {
138  return CPL_FRAME_LEVEL_NONE;
139  }
140  if (!strcmp(aFrametag, "MASK_IMAGE")) {
141  return CPL_FRAME_LEVEL_FINAL;
142  }
143  return CPL_FRAME_LEVEL_NONE;
144 } /* muse_qi_mask_get_frame_level() */
145 
146 /*----------------------------------------------------------------------------*/
155 /*----------------------------------------------------------------------------*/
156 static muse_frame_mode
157 muse_qi_mask_get_frame_mode(const char *aFrametag)
158 {
159  if (!aFrametag) {
160  return MUSE_FRAME_MODE_ALL;
161  }
162  if (!strcmp(aFrametag, "MASK_IMAGE")) {
163  return MUSE_FRAME_MODE_ALL;
164  }
165  return MUSE_FRAME_MODE_ALL;
166 } /* muse_qi_mask_get_frame_mode() */
167 
168 /*----------------------------------------------------------------------------*/
178 /*----------------------------------------------------------------------------*/
179 static int
180 muse_qi_mask_create(cpl_plugin *aPlugin)
181 {
182  /* Check that the plugin is part of a valid recipe */
183  cpl_recipe *recipe;
184  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
185  recipe = (cpl_recipe *)aPlugin;
186  } else {
187  return -1;
188  }
189 
190  /* register the extended processing information (new FITS header creation, *
191  * getting of the frame level for a certain tag) */
193  muse_qi_mask_new_recipeconfig(),
194  muse_qi_mask_prepare_header,
195  muse_qi_mask_get_frame_level,
196  muse_qi_mask_get_frame_mode);
197 
198  /* XXX initialize timing in messages *
199  * since at least esorex is too stupid to turn it on, we have to do it */
201  cpl_msg_set_time_on();
202  }
203 
204  /* Create the parameter list in the cpl_recipe object */
205  recipe->parameters = cpl_parameterlist_new();
206  /* Fill the parameters list */
207  cpl_parameter *p;
208 
209  /* --nifu: IFU to handle. If set to 0, all IFUs are processed serially, which is the recommendation for this recipe, since only then all extensions end up in the same output file. */
210  p = cpl_parameter_new_range("muse.muse_qi_mask.nifu",
211  CPL_TYPE_INT,
212  "IFU to handle. If set to 0, all IFUs are processed serially, which is the recommendation for this recipe, since only then all extensions end up in the same output file.",
213  "muse.muse_qi_mask",
214  (int)0,
215  (int)0,
216  (int)24);
217  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "nifu");
218  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "nifu");
219 
220  cpl_parameterlist_append(recipe->parameters, p);
221 
222  return 0;
223 } /* muse_qi_mask_create() */
224 
225 /*----------------------------------------------------------------------------*/
236 /*----------------------------------------------------------------------------*/
237 static int
238 muse_qi_mask_params_fill(muse_qi_mask_params_t *aParams, cpl_parameterlist *aParameters)
239 {
240  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
241  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
242  cpl_parameter *p;
243 
244  p = cpl_parameterlist_find(aParameters, "muse.muse_qi_mask.nifu");
245  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
246  aParams->nifu = cpl_parameter_get_int(p);
247 
248  return 0;
249 } /* muse_qi_mask_params_fill() */
250 
251 /*----------------------------------------------------------------------------*/
258 /*----------------------------------------------------------------------------*/
259 static int
260 muse_qi_mask_exec(cpl_plugin *aPlugin)
261 {
262  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
263  return -1;
264  }
266  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
267  cpl_msg_set_threadid_on();
268 
269  cpl_frameset *usedframes = cpl_frameset_new(),
270  *outframes = cpl_frameset_new();
271  muse_qi_mask_params_t params;
272  muse_qi_mask_params_fill(&params, recipe->parameters);
273 
274  cpl_errorstate prestate = cpl_errorstate_get();
275 
276  muse_processing *proc = muse_processing_new("muse_qi_mask",
277  recipe);
278  int rc = muse_qi_mask_compute(proc, &params);
279  cpl_frameset_join(usedframes, proc->usedframes);
280  cpl_frameset_join(outframes, proc->outframes);
282 
283  if (!cpl_errorstate_is_equal(prestate)) {
284  /* dump all errors from this recipe in chronological order */
285  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
286  /* reset message level to not get the same errors displayed again by esorex */
287  cpl_msg_set_level(CPL_MSG_INFO);
288  }
289  /* clean up duplicates in framesets of used and output frames */
292 
293  /* to get esorex to see our classification (frame groups etc.), *
294  * replace the original frameset with the list of used frames *
295  * before appending product output frames */
296  /* keep the same pointer, so just erase all frames, not delete the frameset */
297  muse_cplframeset_erase_all(recipe->frames);
298  cpl_frameset_join(recipe->frames, usedframes);
299  cpl_frameset_join(recipe->frames, outframes);
300  cpl_frameset_delete(usedframes);
301  cpl_frameset_delete(outframes);
302  return rc;
303 } /* muse_qi_mask_exec() */
304 
305 /*----------------------------------------------------------------------------*/
312 /*----------------------------------------------------------------------------*/
313 static int
314 muse_qi_mask_destroy(cpl_plugin *aPlugin)
315 {
316  /* Get the recipe from the plugin */
317  cpl_recipe *recipe;
318  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
319  recipe = (cpl_recipe *)aPlugin;
320  } else {
321  return -1;
322  }
323 
324  /* Clean up */
325  cpl_parameterlist_delete(recipe->parameters);
327  return 0;
328 } /* muse_qi_mask_destroy() */
329 
330 /*----------------------------------------------------------------------------*/
340 /*----------------------------------------------------------------------------*/
341 int
342 cpl_plugin_get_info(cpl_pluginlist *aList)
343 {
344  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
345  cpl_plugin *plugin = &recipe->interface;
346 
347  char *helptext;
349  helptext = cpl_sprintf("%s%s", muse_qi_mask_help,
350  muse_qi_mask_help_esorex);
351  } else {
352  helptext = cpl_sprintf("%s", muse_qi_mask_help);
353  }
354 
355  /* Initialize the CPL plugin stuff for this module */
356  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
357  CPL_PLUGIN_TYPE_RECIPE,
358  "muse_qi_mask",
359  "Create image masks for use with the quick image reconstruction.",
360  helptext,
361  "Peter Weilbacher",
362  "usd-help@eso.org",
364  muse_qi_mask_create,
365  muse_qi_mask_exec,
366  muse_qi_mask_destroy);
367  cpl_pluginlist_append(aList, plugin);
368  cpl_free(helptext);
369 
370  return 0;
371 } /* cpl_plugin_get_info() */
372 
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.
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.
Structure to hold the parameters of the muse_qi_mask recipe.
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.
int nifu
IFU to handle. If set to 0, all IFUs are processed serially, which is the recommendation for this rec...