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_calibrate_flux_z.h"
00036
00037
00043
00046
00047
00048
00049 static const char *muse_scipost_calibrate_flux_help =
00050 "Replace the intensity in the MUSE pixel tables by the absolute flux. This is a task separated from muse_scipost.";
00051
00052 static const char *muse_scipost_calibrate_flux_help_esorex =
00053 "\n\nInput frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
00054 "\n Frame tag Type Req #Fr Description"
00055 "\n -------------------- ---- --- --- ------------"
00056 "\n PIXTABLE_OBJECT raw Y Pixel table without flux calibration"
00057 "\n EXTINCT_TABLE calib Y 1 Atmospheric extinction table"
00058 "\n STD_RESPONSE calib Y 1 Response curve as derived from standard star(s)"
00059 "\n STD_TELLURIC calib . 1 Telluric absorption correction as derived from standard star(s)"
00060 "\n\nProduct frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
00061 "\n Frame tag Level Description"
00062 "\n -------------------- -------- ------------"
00063 "\n PIXTABLE_OBJECT final Flux calibrated pixel table";
00064
00065
00073
00074 static cpl_recipeconfig *
00075 muse_scipost_calibrate_flux_new_recipeconfig(void)
00076 {
00077 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
00078
00079 cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_OBJECT", 1, -1);
00080 cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_OBJECT", "EXTINCT_TABLE", 1, 1);
00081 cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_OBJECT", "STD_RESPONSE", 1, 1);
00082 cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_OBJECT", "STD_TELLURIC", -1, 1);
00083 cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_OBJECT", "PIXTABLE_OBJECT");
00084
00085 return recipeconfig;
00086 }
00087
00088
00098
00099 static cpl_error_code
00100 muse_scipost_calibrate_flux_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_OBJECT")) {
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_calibrate_flux_get_frame_level(const char *aFrametag)
00124 {
00125 if (!aFrametag) {
00126 return CPL_FRAME_LEVEL_NONE;
00127 }
00128 if (!strcmp(aFrametag, "PIXTABLE_OBJECT")) {
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_calibrate_flux_get_frame_mode(const char *aFrametag)
00146 {
00147 if (!aFrametag) {
00148 return MUSE_FRAME_MODE_ALL;
00149 }
00150 if (!strcmp(aFrametag, "PIXTABLE_OBJECT")) {
00151 return MUSE_FRAME_MODE_ALL;
00152 }
00153 return MUSE_FRAME_MODE_ALL;
00154 }
00155
00156
00166
00167 static int
00168 muse_scipost_calibrate_flux_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_calibrate_flux_new_recipeconfig(),
00182 muse_scipost_calibrate_flux_prepare_header,
00183 muse_scipost_calibrate_flux_get_frame_level,
00184 muse_scipost_calibrate_flux_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_calibrate_flux.lambdamin",
00199 CPL_TYPE_DOUBLE,
00200 "Cut off the data below this wavelength after loading the pixel table(s).",
00201 "muse.muse_scipost_calibrate_flux",
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_calibrate_flux.lambdamax",
00210 CPL_TYPE_DOUBLE,
00211 "Cut off the data above this wavelength after loading the pixel table(s).",
00212 "muse.muse_scipost_calibrate_flux",
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 return 0;
00220 }
00221
00222
00233
00234 static int
00235 muse_scipost_calibrate_flux_params_fill(muse_scipost_calibrate_flux_params_t *aParams, cpl_parameterlist *aParameters)
00236 {
00237 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
00238 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
00239 cpl_parameter *p;
00240
00241 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_calibrate_flux.lambdamin");
00242 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00243 aParams->lambdamin = cpl_parameter_get_double(p);
00244
00245 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_calibrate_flux.lambdamax");
00246 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00247 aParams->lambdamax = cpl_parameter_get_double(p);
00248
00249 return 0;
00250 }
00251
00252
00259
00260 static int
00261 muse_scipost_calibrate_flux_exec(cpl_plugin *aPlugin)
00262 {
00263 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
00264 return -1;
00265 }
00266 muse_processing_recipeinfo(aPlugin);
00267 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
00268 cpl_msg_set_threadid_on();
00269
00270 cpl_frameset *usedframes = cpl_frameset_new(),
00271 *outframes = cpl_frameset_new();
00272 muse_scipost_calibrate_flux_params_t params;
00273 muse_scipost_calibrate_flux_params_fill(¶ms, recipe->parameters);
00274
00275 cpl_errorstate prestate = cpl_errorstate_get();
00276
00277 muse_processing *proc = muse_processing_new("muse_scipost_calibrate_flux",
00278 recipe);
00279 int rc = muse_scipost_calibrate_flux_compute(proc, ¶ms);
00280 cpl_frameset_join(usedframes, proc->usedframes);
00281 cpl_frameset_join(outframes, proc->outframes);
00282 muse_processing_delete(proc);
00283
00284 if (!cpl_errorstate_is_equal(prestate)) {
00285
00286 cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
00287
00288 cpl_msg_set_level(CPL_MSG_INFO);
00289 }
00290
00291 muse_cplframeset_erase_duplicate(usedframes);
00292 muse_cplframeset_erase_duplicate(outframes);
00293
00294
00295
00296
00297
00298 muse_cplframeset_erase_all(recipe->frames);
00299 cpl_frameset_join(recipe->frames, usedframes);
00300 cpl_frameset_join(recipe->frames, outframes);
00301 cpl_frameset_delete(usedframes);
00302 cpl_frameset_delete(outframes);
00303 return rc;
00304 }
00305
00306
00313
00314 static int
00315 muse_scipost_calibrate_flux_destroy(cpl_plugin *aPlugin)
00316 {
00317
00318 cpl_recipe *recipe;
00319 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00320 recipe = (cpl_recipe *)aPlugin;
00321 } else {
00322 return -1;
00323 }
00324
00325
00326 cpl_parameterlist_delete(recipe->parameters);
00327 muse_processinginfo_delete(recipe);
00328 return 0;
00329 }
00330
00331
00341
00342 int
00343 cpl_plugin_get_info(cpl_pluginlist *aList)
00344 {
00345 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00346 cpl_plugin *plugin = &recipe->interface;
00347
00348 char *helptext;
00349 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00350 helptext = cpl_sprintf("%s%s", muse_scipost_calibrate_flux_help,
00351 muse_scipost_calibrate_flux_help_esorex);
00352 } else {
00353 helptext = cpl_sprintf("%s", muse_scipost_calibrate_flux_help);
00354 }
00355
00356
00357 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
00358 CPL_PLUGIN_TYPE_RECIPE,
00359 "muse_scipost_calibrate_flux",
00360 "Calibrate flux for MUSE pixel tables.",
00361 helptext,
00362 "Ole Streicher",
00363 "usd-help@eso.org",
00364 muse_get_license(),
00365 muse_scipost_calibrate_flux_create,
00366 muse_scipost_calibrate_flux_exec,
00367 muse_scipost_calibrate_flux_destroy);
00368 cpl_pluginlist_append(aList, plugin);
00369 cpl_free(helptext);
00370
00371 return 0;
00372 }
00373