35 #include "muse_scipost_subtract_sky_z.h"
49 static const char *muse_scipost_subtract_sky_help =
50 "Subtract the sky as defined by the sky lines and continuum from a pixel table. This is a separated task of muse_scipost.";
52 static const char *muse_scipost_subtract_sky_help_esorex =
53 "\n\nInput frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
54 "\n Frame tag Type Req #Fr Description"
55 "\n -------------------- ---- --- --- ------------"
56 "\n PIXTABLE_REDUCED raw Y Flux calibrated input pixel table(s)."
57 "\n SKY_LINES calib Y 1 Sky line list"
58 "\n SKY_CONTINUUM calib Y 1 Sky continuum spectrum"
59 "\n LSF_PROFILE calib Y Slice specific LSF parameters"
60 "\n\nProduct frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
61 "\n Frame tag Level Description"
62 "\n -------------------- -------- ------------"
63 "\n PIXTABLE_REDUCED final Output pixel table(s) for sky subtraction.";
74 static cpl_recipeconfig *
75 muse_scipost_subtract_sky_new_recipeconfig(
void)
77 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
80 tag =
"PIXTABLE_REDUCED";
81 cpl_recipeconfig_set_tag(recipeconfig, tag, 1, -1);
82 cpl_recipeconfig_set_input(recipeconfig, tag,
"SKY_LINES", 1, 1);
83 cpl_recipeconfig_set_input(recipeconfig, tag,
"SKY_CONTINUUM", 1, 1);
84 cpl_recipeconfig_set_input(recipeconfig, tag,
"LSF_PROFILE", 1, -1);
85 cpl_recipeconfig_set_output(recipeconfig, tag,
"PIXTABLE_REDUCED");
101 static cpl_error_code
102 muse_scipost_subtract_sky_prepare_header(
const char *aFrametag, cpl_propertylist *aHeader)
104 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
105 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
106 if (!strcmp(aFrametag,
"PIXTABLE_REDUCED")) {
108 cpl_msg_warning(__func__,
"Frame tag %s is not defined", aFrametag);
109 return CPL_ERROR_ILLEGAL_INPUT;
111 return CPL_ERROR_NONE;
124 static cpl_frame_level
125 muse_scipost_subtract_sky_get_frame_level(
const char *aFrametag)
128 return CPL_FRAME_LEVEL_NONE;
130 if (!strcmp(aFrametag,
"PIXTABLE_REDUCED")) {
131 return CPL_FRAME_LEVEL_FINAL;
133 return CPL_FRAME_LEVEL_NONE;
147 muse_scipost_subtract_sky_get_frame_mode(
const char *aFrametag)
152 if (!strcmp(aFrametag,
"PIXTABLE_REDUCED")) {
170 muse_scipost_subtract_sky_create(cpl_plugin *aPlugin)
174 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
175 recipe = (cpl_recipe *)aPlugin;
183 muse_scipost_subtract_sky_new_recipeconfig(),
184 muse_scipost_subtract_sky_prepare_header,
185 muse_scipost_subtract_sky_get_frame_level,
186 muse_scipost_subtract_sky_get_frame_mode);
191 cpl_msg_set_time_on();
195 recipe->parameters = cpl_parameterlist_new();
200 p = cpl_parameter_new_value(
"muse.muse_scipost_subtract_sky.lambdamin",
202 "Cut off the data below this wavelength after loading the pixel table(s).",
203 "muse.muse_scipost_subtract_sky",
205 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"lambdamin");
206 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"lambdamin");
208 cpl_parameterlist_append(recipe->parameters, p);
211 p = cpl_parameter_new_value(
"muse.muse_scipost_subtract_sky.lambdamax",
213 "Cut off the data above this wavelength after loading the pixel table(s).",
214 "muse.muse_scipost_subtract_sky",
216 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"lambdamax");
217 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"lambdamax");
219 cpl_parameterlist_append(recipe->parameters, p);
223 p = cpl_parameter_new_value(
"muse.muse_scipost_subtract_sky.orig",
225 "If specified, write an additional column containing the original data to the pixel table.",
226 "muse.muse_scipost_subtract_sky",
228 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"orig");
229 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"orig");
231 cpl_parameterlist_append(recipe->parameters, p);
234 p = cpl_parameter_new_value(
"muse.muse_scipost_subtract_sky.flux_sky",
236 "Reference flat field flux, obtained by sky exposure. This parameter is needed to scale the data of each pixel table if more than one pixel table was used to determine the sky. By default, it is taken from the parameter ESO DRS MUSE FLAT FLUX SKY of the first pixel table.",
237 "muse.muse_scipost_subtract_sky",
239 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"flux_sky");
240 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"flux_sky");
242 cpl_parameterlist_append(recipe->parameters, p);
245 p = cpl_parameter_new_value(
"muse.muse_scipost_subtract_sky.flux_lamp",
247 "Reference flat field flux, obtained by lamp exposure. This parameter is needed to scale the data of each pixel table if more than one pixel table was used to determine the sky. By default, it is taken from the parameter ESO DRS MUSE FLAT FLUX LAMP of the first pixel table.",
248 "muse.muse_scipost_subtract_sky",
250 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"flux_lamp");
251 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"flux_lamp");
253 cpl_parameterlist_append(recipe->parameters, p);
273 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
274 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
277 p = cpl_parameterlist_find(aParameters,
"muse.muse_scipost_subtract_sky.lambdamin");
278 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
279 aParams->
lambdamin = cpl_parameter_get_double(p);
281 p = cpl_parameterlist_find(aParameters,
"muse.muse_scipost_subtract_sky.lambdamax");
282 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
283 aParams->
lambdamax = cpl_parameter_get_double(p);
285 p = cpl_parameterlist_find(aParameters,
"muse.muse_scipost_subtract_sky.orig");
286 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
287 aParams->
orig = cpl_parameter_get_string(p);
289 p = cpl_parameterlist_find(aParameters,
"muse.muse_scipost_subtract_sky.flux_sky");
290 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
291 aParams->
flux_sky = cpl_parameter_get_double(p);
293 p = cpl_parameterlist_find(aParameters,
"muse.muse_scipost_subtract_sky.flux_lamp");
294 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
295 aParams->
flux_lamp = cpl_parameter_get_double(p);
309 muse_scipost_subtract_sky_exec(cpl_plugin *aPlugin)
311 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
314 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
315 cpl_msg_set_threadid_on();
317 cpl_frameset *usedframes = cpl_frameset_new(),
318 *outframes = cpl_frameset_new();
320 muse_scipost_subtract_sky_params_fill(¶ms, recipe->parameters);
322 cpl_errorstate prestate = cpl_errorstate_get();
326 int rc = muse_scipost_subtract_sky_compute(proc, ¶ms);
327 cpl_frameset_join(usedframes, proc->
usedframes);
328 cpl_frameset_join(outframes, proc->
outframes);
331 if (!cpl_errorstate_is_equal(prestate)) {
335 cpl_msg_set_level(CPL_MSG_INFO);
346 cpl_frameset_join(recipe->frames, usedframes);
347 cpl_frameset_join(recipe->frames, outframes);
348 cpl_frameset_delete(usedframes);
349 cpl_frameset_delete(outframes);
362 muse_scipost_subtract_sky_destroy(cpl_plugin *aPlugin)
366 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
367 recipe = (cpl_recipe *)aPlugin;
373 cpl_parameterlist_delete(recipe->parameters);
390 cpl_plugin_get_info(cpl_pluginlist *aList)
392 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
393 cpl_plugin *plugin = &recipe->interface;
397 helptext = cpl_sprintf(
"%s%s", muse_scipost_subtract_sky_help,
398 muse_scipost_subtract_sky_help_esorex);
400 helptext = cpl_sprintf(
"%s", muse_scipost_subtract_sky_help);
404 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
405 CPL_PLUGIN_TYPE_RECIPE,
406 "muse_scipost_subtract_sky",
407 "Subtract night sky model.",
412 muse_scipost_subtract_sky_create,
413 muse_scipost_subtract_sky_exec,
414 muse_scipost_subtract_sky_destroy);
415 cpl_pluginlist_append(aList, plugin);
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
const char * orig
If specified, write an additional column containing the original data to the pixel table...
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.
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
double flux_lamp
Reference flat field flux, obtained by lamp exposure. This parameter is needed to scale the data of e...
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_subtract_sky recipe.
double flux_sky
Reference flat field flux, obtained by sky exposure. This parameter is needed to scale the data of ea...
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.