MUSE Pipeline Reference Manual  1.0.2
muse_scipost_apply_astrometry_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_apply_astrometry_z.h" /* in turn includes muse.h */
36 
37 /*----------------------------------------------------------------------------*/
43 /*----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------*
47  * Static variables *
48  *----------------------------------------------------------------------------*/
49 static const char *muse_scipost_apply_astrometry_help =
50  "Apply an astrometric calibration to the pixel table spatial coordinates. This is a task separated from muse_scipost.";
51 
52 static const char *muse_scipost_apply_astrometry_help_esorex =
53  "\n\nInput frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
54  "\n Frame tag Type Req #Fr Description"
55  "\n -------------------- ---- --- --- ------------"
56  "\n PIXTABLE_OBJECT raw Y Pixel table without astrometric calibration"
57  "\n ASTROMETRY_WCS calib . 1 Astrometric solution derived from astrometric science frame"
58  "\n\nProduct frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
59  "\n Frame tag Level Description"
60  "\n -------------------- -------- ------------"
61  "\n PIXTABLE_OBJECT final Pixel table with astrometric calibration";
62 
63 /*----------------------------------------------------------------------------*/
71 /*----------------------------------------------------------------------------*/
72 static cpl_recipeconfig *
73 muse_scipost_apply_astrometry_new_recipeconfig(void)
74 {
75  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
76  const char *tag;
77 
78  tag = "PIXTABLE_OBJECT";
79  cpl_recipeconfig_set_tag(recipeconfig, tag, 1, -1);
80  cpl_recipeconfig_set_input(recipeconfig, tag, "ASTROMETRY_WCS", -1, 1);
81  cpl_recipeconfig_set_output(recipeconfig, tag, "PIXTABLE_OBJECT");
82 
83  return recipeconfig;
84 } /* muse_scipost_apply_astrometry_new_recipeconfig() */
85 
86 /*----------------------------------------------------------------------------*/
96 /*----------------------------------------------------------------------------*/
97 static cpl_error_code
98 muse_scipost_apply_astrometry_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
99 {
100  cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
101  cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
102  if (!strcmp(aFrametag, "PIXTABLE_OBJECT")) {
103  } else {
104  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
105  return CPL_ERROR_ILLEGAL_INPUT;
106  }
107  return CPL_ERROR_NONE;
108 } /* muse_scipost_apply_astrometry_prepare_header() */
109 
110 /*----------------------------------------------------------------------------*/
119 /*----------------------------------------------------------------------------*/
120 static cpl_frame_level
121 muse_scipost_apply_astrometry_get_frame_level(const char *aFrametag)
122 {
123  if (!aFrametag) {
124  return CPL_FRAME_LEVEL_NONE;
125  }
126  if (!strcmp(aFrametag, "PIXTABLE_OBJECT")) {
127  return CPL_FRAME_LEVEL_FINAL;
128  }
129  return CPL_FRAME_LEVEL_NONE;
130 } /* muse_scipost_apply_astrometry_get_frame_level() */
131 
132 /*----------------------------------------------------------------------------*/
141 /*----------------------------------------------------------------------------*/
142 static muse_frame_mode
143 muse_scipost_apply_astrometry_get_frame_mode(const char *aFrametag)
144 {
145  if (!aFrametag) {
146  return MUSE_FRAME_MODE_ALL;
147  }
148  if (!strcmp(aFrametag, "PIXTABLE_OBJECT")) {
149  return MUSE_FRAME_MODE_ALL;
150  }
151  return MUSE_FRAME_MODE_ALL;
152 } /* muse_scipost_apply_astrometry_get_frame_mode() */
153 
154 /*----------------------------------------------------------------------------*/
164 /*----------------------------------------------------------------------------*/
165 static int
166 muse_scipost_apply_astrometry_create(cpl_plugin *aPlugin)
167 {
168  /* Check that the plugin is part of a valid recipe */
169  cpl_recipe *recipe;
170  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
171  recipe = (cpl_recipe *)aPlugin;
172  } else {
173  return -1;
174  }
175 
176  /* register the extended processing information (new FITS header creation, *
177  * getting of the frame level for a certain tag) */
179  muse_scipost_apply_astrometry_new_recipeconfig(),
180  muse_scipost_apply_astrometry_prepare_header,
181  muse_scipost_apply_astrometry_get_frame_level,
182  muse_scipost_apply_astrometry_get_frame_mode);
183 
184  /* XXX initialize timing in messages *
185  * since at least esorex is too stupid to turn it on, we have to do it */
187  cpl_msg_set_time_on();
188  }
189 
190  /* Create the parameter list in the cpl_recipe object */
191  recipe->parameters = cpl_parameterlist_new();
192  /* Fill the parameters list */
193  cpl_parameter *p;
194 
195  /* --lambdamin: Cut off the data below this wavelength after loading the pixel table(s). */
196  p = cpl_parameter_new_value("muse.muse_scipost_apply_astrometry.lambdamin",
197  CPL_TYPE_DOUBLE,
198  "Cut off the data below this wavelength after loading the pixel table(s).",
199  "muse.muse_scipost_apply_astrometry",
200  (double)4000.);
201  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
202  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
203 
204  cpl_parameterlist_append(recipe->parameters, p);
205 
206  /* --lambdamax: Cut off the data above this wavelength after loading the pixel table(s). */
207  p = cpl_parameter_new_value("muse.muse_scipost_apply_astrometry.lambdamax",
208  CPL_TYPE_DOUBLE,
209  "Cut off the data above this wavelength after loading the pixel table(s).",
210  "muse.muse_scipost_apply_astrometry",
211  (double)10000.);
212  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
213  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
214 
215  cpl_parameterlist_append(recipe->parameters, p);
216 
217  return 0;
218 } /* muse_scipost_apply_astrometry_create() */
219 
220 /*----------------------------------------------------------------------------*/
231 /*----------------------------------------------------------------------------*/
232 static int
233 muse_scipost_apply_astrometry_params_fill(muse_scipost_apply_astrometry_params_t *aParams, cpl_parameterlist *aParameters)
234 {
235  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
236  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
237  cpl_parameter *p;
238 
239  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_apply_astrometry.lambdamin");
240  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
241  aParams->lambdamin = cpl_parameter_get_double(p);
242 
243  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_apply_astrometry.lambdamax");
244  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
245  aParams->lambdamax = cpl_parameter_get_double(p);
246 
247  return 0;
248 } /* muse_scipost_apply_astrometry_params_fill() */
249 
250 /*----------------------------------------------------------------------------*/
257 /*----------------------------------------------------------------------------*/
258 static int
259 muse_scipost_apply_astrometry_exec(cpl_plugin *aPlugin)
260 {
261  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
262  return -1;
263  }
264  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
265  cpl_msg_set_threadid_on();
266 
267  cpl_frameset *usedframes = cpl_frameset_new(),
268  *outframes = cpl_frameset_new();
270  muse_scipost_apply_astrometry_params_fill(&params, recipe->parameters);
271 
272  cpl_errorstate prestate = cpl_errorstate_get();
273 
274  muse_processing *proc = muse_processing_new("muse_scipost_apply_astrometry",
275  recipe);
276  int rc = muse_scipost_apply_astrometry_compute(proc, &params);
277  cpl_frameset_join(usedframes, proc->usedframes);
278  cpl_frameset_join(outframes, proc->outframes);
280 
281  if (!cpl_errorstate_is_equal(prestate)) {
282  /* dump all errors from this recipe in chronological order */
283  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
284  /* reset message level to not get the same errors displayed again by esorex */
285  cpl_msg_set_level(CPL_MSG_INFO);
286  }
287  /* clean up duplicates in framesets of used and output frames */
290 
291  /* to get esorex to see our classification (frame groups etc.), *
292  * replace the original frameset with the list of used frames *
293  * before appending product output frames */
294  /* keep the same pointer, so just erase all frames, not delete the frameset */
295  muse_cplframeset_erase_all(recipe->frames);
296  cpl_frameset_join(recipe->frames, usedframes);
297  cpl_frameset_join(recipe->frames, outframes);
298  cpl_frameset_delete(usedframes);
299  cpl_frameset_delete(outframes);
300  return rc;
301 } /* muse_scipost_apply_astrometry_exec() */
302 
303 /*----------------------------------------------------------------------------*/
310 /*----------------------------------------------------------------------------*/
311 static int
312 muse_scipost_apply_astrometry_destroy(cpl_plugin *aPlugin)
313 {
314  /* Get the recipe from the plugin */
315  cpl_recipe *recipe;
316  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
317  recipe = (cpl_recipe *)aPlugin;
318  } else {
319  return -1;
320  }
321 
322  /* Clean up */
323  cpl_parameterlist_delete(recipe->parameters);
325  return 0;
326 } /* muse_scipost_apply_astrometry_destroy() */
327 
328 /*----------------------------------------------------------------------------*/
338 /*----------------------------------------------------------------------------*/
339 int
340 cpl_plugin_get_info(cpl_pluginlist *aList)
341 {
342  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
343  cpl_plugin *plugin = &recipe->interface;
344 
345  char *helptext;
347  helptext = cpl_sprintf("%s%s", muse_scipost_apply_astrometry_help,
348  muse_scipost_apply_astrometry_help_esorex);
349  } else {
350  helptext = cpl_sprintf("%s", muse_scipost_apply_astrometry_help);
351  }
352 
353  /* Initialize the CPL plugin stuff for this module */
354  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
355  CPL_PLUGIN_TYPE_RECIPE,
356  "muse_scipost_apply_astrometry",
357  "Calibrate astrometry for MUSE pixel tables.",
358  helptext,
359  "Ole Streicher",
360  "usd-help@eso.org",
362  muse_scipost_apply_astrometry_create,
363  muse_scipost_apply_astrometry_exec,
364  muse_scipost_apply_astrometry_destroy);
365  cpl_pluginlist_append(aList, plugin);
366  cpl_free(helptext);
367 
368  return 0;
369 } /* cpl_plugin_get_info() */
370 
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
Structure to hold the parameters of the muse_scipost_apply_astrometry recipe.
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
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
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.
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.