00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027
00028
00029
00030
00031 #include <string.h>
00032 #include <strings.h>
00033 #include <cpl.h>
00034
00035 #include "muse_scipost_subtract_sky_z.h"
00036
00037
00043
00046
00047
00048
00049 static const char *muse_scipost_subtract_sky_help =
00050 "Subtract the sky as defined by the sky lines and continuum from a pixel table. This is a separated task of muse_scipost.";
00051
00052 static const char *muse_scipost_subtract_sky_help_esorex =
00053 "\n\nInput frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
00054 "\n Frame tag Type Req #Fr Description"
00055 "\n -------------------- ---- --- --- ------------"
00056 "\n PIXTABLE_REDUCED raw Y Flux calibrated input pixel table(s)."
00057 "\n SKY_LINES calib Y 1 Sky line list"
00058 "\n SKY_CONTINUUM calib Y 1 Sky continuum spectrum"
00059 "\n LSF_PROFILE calib Y LSF for each IFU."
00060 "\n\nProduct frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
00061 "\n Frame tag Level Description"
00062 "\n -------------------- -------- ------------"
00063 "\n PIXTABLE_REDUCED final Output pixel table(s) for sky subtraction.";
00064
00065
00073
00074 static cpl_recipeconfig *
00075 muse_scipost_subtract_sky_new_recipeconfig(void)
00076 {
00077 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
00078
00079 cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_REDUCED", 1, -1);
00080 cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "SKY_LINES", 1, 1);
00081 cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "SKY_CONTINUUM", 1, 1);
00082 cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "LSF_PROFILE", 1, -1);
00083 cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_REDUCED", "PIXTABLE_REDUCED");
00084
00085 return recipeconfig;
00086 }
00087
00088
00098
00099 static cpl_error_code
00100 muse_scipost_subtract_sky_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
00101 {
00102 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
00103 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
00104 if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00105 } else {
00106 cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
00107 return CPL_ERROR_ILLEGAL_INPUT;
00108 }
00109 return CPL_ERROR_NONE;
00110 }
00111
00112
00121
00122 static cpl_frame_level
00123 muse_scipost_subtract_sky_get_frame_level(const char *aFrametag)
00124 {
00125 if (!aFrametag) {
00126 return CPL_FRAME_LEVEL_NONE;
00127 }
00128 if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00129 return CPL_FRAME_LEVEL_FINAL;
00130 }
00131 return CPL_FRAME_LEVEL_NONE;
00132 }
00133
00134
00143
00144 static muse_frame_mode
00145 muse_scipost_subtract_sky_get_frame_mode(const char *aFrametag)
00146 {
00147 if (!aFrametag) {
00148 return MUSE_FRAME_MODE_ALL;
00149 }
00150 if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00151 return MUSE_FRAME_MODE_ALL;
00152 }
00153 return MUSE_FRAME_MODE_ALL;
00154 }
00155
00156
00166
00167 static int
00168 muse_scipost_subtract_sky_create(cpl_plugin *aPlugin)
00169 {
00170
00171 cpl_recipe *recipe;
00172 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00173 recipe = (cpl_recipe *)aPlugin;
00174 } else {
00175 return -1;
00176 }
00177
00178
00179
00180 muse_processinginfo_register(recipe,
00181 muse_scipost_subtract_sky_new_recipeconfig(),
00182 muse_scipost_subtract_sky_prepare_header,
00183 muse_scipost_subtract_sky_get_frame_level,
00184 muse_scipost_subtract_sky_get_frame_mode);
00185
00186
00187
00188 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00189 cpl_msg_set_time_on();
00190 }
00191
00192
00193 recipe->parameters = cpl_parameterlist_new();
00194
00195 cpl_parameter *p;
00196
00197
00198 p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.lambdamin",
00199 CPL_TYPE_DOUBLE,
00200 "Cut off the data below this wavelength after loading the pixel table(s).",
00201 "muse.muse_scipost_subtract_sky",
00202 (double)4000.);
00203 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
00204 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
00205
00206 cpl_parameterlist_append(recipe->parameters, p);
00207
00208
00209 p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.lambdamax",
00210 CPL_TYPE_DOUBLE,
00211 "Cut off the data above this wavelength after loading the pixel table(s).",
00212 "muse.muse_scipost_subtract_sky",
00213 (double)10000.);
00214 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
00215 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
00216
00217 cpl_parameterlist_append(recipe->parameters, p);
00218
00219
00220
00221 p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.orig",
00222 CPL_TYPE_STRING,
00223 "If specified, write an additional column containing the original data to the pixel table.",
00224 "muse.muse_scipost_subtract_sky",
00225 (const char *)"");
00226 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "orig");
00227 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "orig");
00228
00229 cpl_parameterlist_append(recipe->parameters, p);
00230
00231
00232 p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.flux_sky",
00233 CPL_TYPE_DOUBLE,
00234 "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.",
00235 "muse.muse_scipost_subtract_sky",
00236 (double)0.0);
00237 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "flux_sky");
00238 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "flux_sky");
00239
00240 cpl_parameterlist_append(recipe->parameters, p);
00241
00242
00243 p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky.flux_lamp",
00244 CPL_TYPE_DOUBLE,
00245 "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.",
00246 "muse.muse_scipost_subtract_sky",
00247 (double)0.0);
00248 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "flux_lamp");
00249 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "flux_lamp");
00250
00251 cpl_parameterlist_append(recipe->parameters, p);
00252
00253 return 0;
00254 }
00255
00256
00267
00268 static int
00269 muse_scipost_subtract_sky_params_fill(muse_scipost_subtract_sky_params_t *aParams, cpl_parameterlist *aParameters)
00270 {
00271 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
00272 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
00273 cpl_parameter *p;
00274
00275 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.lambdamin");
00276 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00277 aParams->lambdamin = cpl_parameter_get_double(p);
00278
00279 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.lambdamax");
00280 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00281 aParams->lambdamax = cpl_parameter_get_double(p);
00282
00283 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.orig");
00284 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00285 aParams->orig = cpl_parameter_get_string(p);
00286
00287 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.flux_sky");
00288 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00289 aParams->flux_sky = cpl_parameter_get_double(p);
00290
00291 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky.flux_lamp");
00292 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00293 aParams->flux_lamp = cpl_parameter_get_double(p);
00294
00295 return 0;
00296 }
00297
00298
00305
00306 static int
00307 muse_scipost_subtract_sky_exec(cpl_plugin *aPlugin)
00308 {
00309 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
00310 return -1;
00311 }
00312 muse_processing_recipeinfo(aPlugin);
00313 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
00314 cpl_msg_set_threadid_on();
00315
00316 cpl_frameset *usedframes = cpl_frameset_new(),
00317 *outframes = cpl_frameset_new();
00318 muse_scipost_subtract_sky_params_t params;
00319 muse_scipost_subtract_sky_params_fill(¶ms, recipe->parameters);
00320
00321 cpl_errorstate prestate = cpl_errorstate_get();
00322
00323 muse_processing *proc = muse_processing_new("muse_scipost_subtract_sky",
00324 recipe);
00325 int rc = muse_scipost_subtract_sky_compute(proc, ¶ms);
00326 cpl_frameset_join(usedframes, proc->usedframes);
00327 cpl_frameset_join(outframes, proc->outframes);
00328 muse_processing_delete(proc);
00329
00330 if (!cpl_errorstate_is_equal(prestate)) {
00331
00332 cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
00333
00334 cpl_msg_set_level(CPL_MSG_INFO);
00335 }
00336
00337 muse_cplframeset_erase_duplicate(usedframes);
00338 muse_cplframeset_erase_duplicate(outframes);
00339
00340
00341
00342
00343
00344 muse_cplframeset_erase_all(recipe->frames);
00345 cpl_frameset_join(recipe->frames, usedframes);
00346 cpl_frameset_join(recipe->frames, outframes);
00347 cpl_frameset_delete(usedframes);
00348 cpl_frameset_delete(outframes);
00349 return rc;
00350 }
00351
00352
00359
00360 static int
00361 muse_scipost_subtract_sky_destroy(cpl_plugin *aPlugin)
00362 {
00363
00364 cpl_recipe *recipe;
00365 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00366 recipe = (cpl_recipe *)aPlugin;
00367 } else {
00368 return -1;
00369 }
00370
00371
00372 cpl_parameterlist_delete(recipe->parameters);
00373 muse_processinginfo_delete(recipe);
00374 return 0;
00375 }
00376
00377
00387
00388 int
00389 cpl_plugin_get_info(cpl_pluginlist *aList)
00390 {
00391 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00392 cpl_plugin *plugin = &recipe->interface;
00393
00394 char *helptext;
00395 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00396 helptext = cpl_sprintf("%s%s", muse_scipost_subtract_sky_help,
00397 muse_scipost_subtract_sky_help_esorex);
00398 } else {
00399 helptext = cpl_sprintf("%s", muse_scipost_subtract_sky_help);
00400 }
00401
00402
00403 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
00404 CPL_PLUGIN_TYPE_RECIPE,
00405 "muse_scipost_subtract_sky",
00406 "Subtract night sky model.",
00407 helptext,
00408 "Ole Streicher",
00409 "usd-help@eso.org",
00410 muse_get_license(),
00411 muse_scipost_subtract_sky_create,
00412 muse_scipost_subtract_sky_exec,
00413 muse_scipost_subtract_sky_destroy);
00414 cpl_pluginlist_append(aList, plugin);
00415 cpl_free(helptext);
00416
00417 return 0;
00418 }
00419