MUSE Pipeline Reference Manual  2.1.1
muse_scipost_correct_dar_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_correct_dar_z.h" /* in turn includes muse.h */
36 
37 /*----------------------------------------------------------------------------*/
43 /*----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------*
47  * Static variables *
48  *----------------------------------------------------------------------------*/
49 static const char *muse_scipost_correct_dar_help =
50  "Correct the coordinates in the pixel table by differential atmospheric refraction. This is a task separated from muse_scipost.";
51 
52 static const char *muse_scipost_correct_dar_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 DAR correction"
57  "\n\nProduct frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
58  "\n Frame tag Level Description"
59  "\n -------------------- -------- ------------"
60  "\n PIXTABLE_OBJECT final DAR corrected pixel table";
61 
62 /*----------------------------------------------------------------------------*/
70 /*----------------------------------------------------------------------------*/
71 static cpl_recipeconfig *
72 muse_scipost_correct_dar_new_recipeconfig(void)
73 {
74  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
75 
76  cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_OBJECT", 1, -1);
77  cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_OBJECT", "PIXTABLE_OBJECT");
78 
79  return recipeconfig;
80 } /* muse_scipost_correct_dar_new_recipeconfig() */
81 
82 /*----------------------------------------------------------------------------*/
92 /*----------------------------------------------------------------------------*/
93 static cpl_error_code
94 muse_scipost_correct_dar_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
95 {
96  cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
97  cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
98  if (!strcmp(aFrametag, "PIXTABLE_OBJECT")) {
99  } else {
100  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
101  return CPL_ERROR_ILLEGAL_INPUT;
102  }
103  return CPL_ERROR_NONE;
104 } /* muse_scipost_correct_dar_prepare_header() */
105 
106 /*----------------------------------------------------------------------------*/
115 /*----------------------------------------------------------------------------*/
116 static cpl_frame_level
117 muse_scipost_correct_dar_get_frame_level(const char *aFrametag)
118 {
119  if (!aFrametag) {
120  return CPL_FRAME_LEVEL_NONE;
121  }
122  if (!strcmp(aFrametag, "PIXTABLE_OBJECT")) {
123  return CPL_FRAME_LEVEL_FINAL;
124  }
125  return CPL_FRAME_LEVEL_NONE;
126 } /* muse_scipost_correct_dar_get_frame_level() */
127 
128 /*----------------------------------------------------------------------------*/
137 /*----------------------------------------------------------------------------*/
138 static muse_frame_mode
139 muse_scipost_correct_dar_get_frame_mode(const char *aFrametag)
140 {
141  if (!aFrametag) {
142  return MUSE_FRAME_MODE_ALL;
143  }
144  if (!strcmp(aFrametag, "PIXTABLE_OBJECT")) {
145  return MUSE_FRAME_MODE_ALL;
146  }
147  return MUSE_FRAME_MODE_ALL;
148 } /* muse_scipost_correct_dar_get_frame_mode() */
149 
150 /*----------------------------------------------------------------------------*/
160 /*----------------------------------------------------------------------------*/
161 static int
162 muse_scipost_correct_dar_create(cpl_plugin *aPlugin)
163 {
164  /* Check that the plugin is part of a valid recipe */
165  cpl_recipe *recipe;
166  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
167  recipe = (cpl_recipe *)aPlugin;
168  } else {
169  return -1;
170  }
171 
172  /* register the extended processing information (new FITS header creation, *
173  * getting of the frame level for a certain tag) */
175  muse_scipost_correct_dar_new_recipeconfig(),
176  muse_scipost_correct_dar_prepare_header,
177  muse_scipost_correct_dar_get_frame_level,
178  muse_scipost_correct_dar_get_frame_mode);
179 
180  /* XXX initialize timing in messages *
181  * since at least esorex is too stupid to turn it on, we have to do it */
183  cpl_msg_set_time_on();
184  }
185 
186  /* Create the parameter list in the cpl_recipe object */
187  recipe->parameters = cpl_parameterlist_new();
188  /* Fill the parameters list */
189  cpl_parameter *p;
190 
191  /* --lambdamin: Cut off the data below this wavelength after loading the pixel table(s). */
192  p = cpl_parameter_new_value("muse.muse_scipost_correct_dar.lambdamin",
193  CPL_TYPE_DOUBLE,
194  "Cut off the data below this wavelength after loading the pixel table(s).",
195  "muse.muse_scipost_correct_dar",
196  (double)4000.);
197  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
198  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
199 
200  cpl_parameterlist_append(recipe->parameters, p);
201 
202  /* --lambdamax: Cut off the data above this wavelength after loading the pixel table(s). */
203  p = cpl_parameter_new_value("muse.muse_scipost_correct_dar.lambdamax",
204  CPL_TYPE_DOUBLE,
205  "Cut off the data above this wavelength after loading the pixel table(s).",
206  "muse.muse_scipost_correct_dar",
207  (double)10000.);
208  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
209  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
210 
211  cpl_parameterlist_append(recipe->parameters, p);
212 
213  /* --lambdaref: Reference wavelength used for correction of differential atmospheric refraction. The R-band (peak wavelength ~7000 Angstrom) that is usually used for guiding, is close to the central wavelength of MUSE, so a value of 7000.0 Angstrom should be used if nothing else is known. A value less than zero switches DAR correction off. */
214  p = cpl_parameter_new_value("muse.muse_scipost_correct_dar.lambdaref",
215  CPL_TYPE_DOUBLE,
216  "Reference wavelength used for correction of differential atmospheric refraction. The R-band (peak wavelength ~7000 Angstrom) that is usually used for guiding, is close to the central wavelength of MUSE, so a value of 7000.0 Angstrom should be used if nothing else is known. A value less than zero switches DAR correction off.",
217  "muse.muse_scipost_correct_dar",
218  (double)7000.);
219  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdaref");
220  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdaref");
221 
222  cpl_parameterlist_append(recipe->parameters, p);
223 
224  /* --darcheck: Carry out a check of the theoretical DAR correction using source centroiding. If "correct" it will also apply an empirical correction. */
225  p = cpl_parameter_new_enum("muse.muse_scipost_correct_dar.darcheck",
226  CPL_TYPE_STRING,
227  "Carry out a check of the theoretical DAR correction using source centroiding. If \"correct\" it will also apply an empirical correction.",
228  "muse.muse_scipost_correct_dar",
229  (const char *)"none",
230  3,
231  (const char *)"none",
232  (const char *)"check",
233  (const char *)"correct");
234  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "darcheck");
235  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "darcheck");
236 
237  cpl_parameterlist_append(recipe->parameters, p);
238 
239  return 0;
240 } /* muse_scipost_correct_dar_create() */
241 
242 /*----------------------------------------------------------------------------*/
253 /*----------------------------------------------------------------------------*/
254 static int
255 muse_scipost_correct_dar_params_fill(muse_scipost_correct_dar_params_t *aParams, cpl_parameterlist *aParameters)
256 {
257  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
258  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
259  cpl_parameter *p;
260 
261  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_correct_dar.lambdamin");
262  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
263  aParams->lambdamin = cpl_parameter_get_double(p);
264 
265  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_correct_dar.lambdamax");
266  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
267  aParams->lambdamax = cpl_parameter_get_double(p);
268 
269  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_correct_dar.lambdaref");
270  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
271  aParams->lambdaref = cpl_parameter_get_double(p);
272 
273  p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_correct_dar.darcheck");
274  cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
275  aParams->darcheck_s = cpl_parameter_get_string(p);
276  aParams->darcheck =
277  (!strcasecmp(aParams->darcheck_s, "none")) ? MUSE_SCIPOST_CORRECT_DAR_PARAM_DARCHECK_NONE :
278  (!strcasecmp(aParams->darcheck_s, "check")) ? MUSE_SCIPOST_CORRECT_DAR_PARAM_DARCHECK_CHECK :
279  (!strcasecmp(aParams->darcheck_s, "correct")) ? MUSE_SCIPOST_CORRECT_DAR_PARAM_DARCHECK_CORRECT :
280  MUSE_SCIPOST_CORRECT_DAR_PARAM_DARCHECK_INVALID_VALUE;
281  cpl_ensure_code(aParams->darcheck != MUSE_SCIPOST_CORRECT_DAR_PARAM_DARCHECK_INVALID_VALUE,
282  CPL_ERROR_ILLEGAL_INPUT);
283 
284  return 0;
285 } /* muse_scipost_correct_dar_params_fill() */
286 
287 /*----------------------------------------------------------------------------*/
294 /*----------------------------------------------------------------------------*/
295 static int
296 muse_scipost_correct_dar_exec(cpl_plugin *aPlugin)
297 {
298  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
299  return -1;
300  }
302  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
303  cpl_msg_set_threadid_on();
304 
305  cpl_frameset *usedframes = cpl_frameset_new(),
306  *outframes = cpl_frameset_new();
308  muse_scipost_correct_dar_params_fill(&params, recipe->parameters);
309 
310  cpl_errorstate prestate = cpl_errorstate_get();
311 
312  muse_processing *proc = muse_processing_new("muse_scipost_correct_dar",
313  recipe);
314  int rc = muse_scipost_correct_dar_compute(proc, &params);
315  cpl_frameset_join(usedframes, proc->usedframes);
316  cpl_frameset_join(outframes, proc->outframes);
318 
319  if (!cpl_errorstate_is_equal(prestate)) {
320  /* dump all errors from this recipe in chronological order */
321  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
322  /* reset message level to not get the same errors displayed again by esorex */
323  cpl_msg_set_level(CPL_MSG_INFO);
324  }
325  /* clean up duplicates in framesets of used and output frames */
328 
329  /* to get esorex to see our classification (frame groups etc.), *
330  * replace the original frameset with the list of used frames *
331  * before appending product output frames */
332  /* keep the same pointer, so just erase all frames, not delete the frameset */
333  muse_cplframeset_erase_all(recipe->frames);
334  cpl_frameset_join(recipe->frames, usedframes);
335  cpl_frameset_join(recipe->frames, outframes);
336  cpl_frameset_delete(usedframes);
337  cpl_frameset_delete(outframes);
338  return rc;
339 } /* muse_scipost_correct_dar_exec() */
340 
341 /*----------------------------------------------------------------------------*/
348 /*----------------------------------------------------------------------------*/
349 static int
350 muse_scipost_correct_dar_destroy(cpl_plugin *aPlugin)
351 {
352  /* Get the recipe from the plugin */
353  cpl_recipe *recipe;
354  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
355  recipe = (cpl_recipe *)aPlugin;
356  } else {
357  return -1;
358  }
359 
360  /* Clean up */
361  cpl_parameterlist_delete(recipe->parameters);
363  return 0;
364 } /* muse_scipost_correct_dar_destroy() */
365 
366 /*----------------------------------------------------------------------------*/
376 /*----------------------------------------------------------------------------*/
377 int
378 cpl_plugin_get_info(cpl_pluginlist *aList)
379 {
380  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
381  cpl_plugin *plugin = &recipe->interface;
382 
383  char *helptext;
385  helptext = cpl_sprintf("%s%s", muse_scipost_correct_dar_help,
386  muse_scipost_correct_dar_help_esorex);
387  } else {
388  helptext = cpl_sprintf("%s", muse_scipost_correct_dar_help);
389  }
390 
391  /* Initialize the CPL plugin stuff for this module */
392  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
393  CPL_PLUGIN_TYPE_RECIPE,
394  "muse_scipost_correct_dar",
395  "Apply DAR correction for MUSE pixel tables.",
396  helptext,
397  "Ole Streicher",
398  "usd-help@eso.org",
400  muse_scipost_correct_dar_create,
401  muse_scipost_correct_dar_exec,
402  muse_scipost_correct_dar_destroy);
403  cpl_pluginlist_append(aList, plugin);
404  cpl_free(helptext);
405 
406  return 0;
407 } /* cpl_plugin_get_info() */
408 
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
double lambdaref
Reference wavelength used for correction of differential atmospheric refraction. The R-band (peak wav...
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_scipost_correct_dar 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.
int darcheck
Carry out a check of the theoretical DAR correction using source centroiding. If "correct" it will al...
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
const char * darcheck_s
Carry out a check of the theoretical DAR correction using source centroiding. If "correct" it will al...
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 lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.