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_simple_z.h"
00036
00037
00043
00046
00047
00048
00049 static const char *muse_scipost_subtract_sky_simple_help =
00050 "Subtract the sky in a simple way, just using a sky spectrum created by muse_create_sky. This is a separated task of muse_scipost.";
00051
00052 static const char *muse_scipost_subtract_sky_simple_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_SPECTRUM calib Y 1 Sky line list"
00058 "\n\nProduct frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
00059 "\n Frame tag Level Description"
00060 "\n -------------------- -------- ------------"
00061 "\n PIXTABLE_REDUCED final Output pixel table(s) after simple sky subtraction.";
00062
00063
00071
00072 static cpl_recipeconfig *
00073 muse_scipost_subtract_sky_simple_new_recipeconfig(void)
00074 {
00075 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
00076
00077 cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_REDUCED", 1, -1);
00078 cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "SKY_SPECTRUM", 1, 1);
00079 cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_REDUCED", "PIXTABLE_REDUCED");
00080
00081 return recipeconfig;
00082 }
00083
00084
00094
00095 static cpl_error_code
00096 muse_scipost_subtract_sky_simple_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
00097 {
00098 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
00099 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
00100 if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00101 } else {
00102 cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
00103 return CPL_ERROR_ILLEGAL_INPUT;
00104 }
00105 return CPL_ERROR_NONE;
00106 }
00107
00108
00117
00118 static cpl_frame_level
00119 muse_scipost_subtract_sky_simple_get_frame_level(const char *aFrametag)
00120 {
00121 if (!aFrametag) {
00122 return CPL_FRAME_LEVEL_NONE;
00123 }
00124 if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00125 return CPL_FRAME_LEVEL_FINAL;
00126 }
00127 return CPL_FRAME_LEVEL_NONE;
00128 }
00129
00130
00139
00140 static muse_frame_mode
00141 muse_scipost_subtract_sky_simple_get_frame_mode(const char *aFrametag)
00142 {
00143 if (!aFrametag) {
00144 return MUSE_FRAME_MODE_ALL;
00145 }
00146 if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00147 return MUSE_FRAME_MODE_ALL;
00148 }
00149 return MUSE_FRAME_MODE_ALL;
00150 }
00151
00152
00162
00163 static int
00164 muse_scipost_subtract_sky_simple_create(cpl_plugin *aPlugin)
00165 {
00166
00167 cpl_recipe *recipe;
00168 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00169 recipe = (cpl_recipe *)aPlugin;
00170 } else {
00171 return -1;
00172 }
00173
00174
00175
00176 muse_processinginfo_register(recipe,
00177 muse_scipost_subtract_sky_simple_new_recipeconfig(),
00178 muse_scipost_subtract_sky_simple_prepare_header,
00179 muse_scipost_subtract_sky_simple_get_frame_level,
00180 muse_scipost_subtract_sky_simple_get_frame_mode);
00181
00182
00183
00184 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00185 cpl_msg_set_time_on();
00186 }
00187
00188
00189 recipe->parameters = cpl_parameterlist_new();
00190
00191 cpl_parameter *p;
00192
00193
00194 p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky_simple.lambdamin",
00195 CPL_TYPE_DOUBLE,
00196 "Cut off the data below this wavelength after loading the pixel table(s).",
00197 "muse.muse_scipost_subtract_sky_simple",
00198 (double)4000.);
00199 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
00200 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
00201
00202 cpl_parameterlist_append(recipe->parameters, p);
00203
00204
00205 p = cpl_parameter_new_value("muse.muse_scipost_subtract_sky_simple.lambdamax",
00206 CPL_TYPE_DOUBLE,
00207 "Cut off the data above this wavelength after loading the pixel table(s).",
00208 "muse.muse_scipost_subtract_sky_simple",
00209 (double)10000.);
00210 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
00211 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
00212
00213 cpl_parameterlist_append(recipe->parameters, p);
00214
00215 return 0;
00216 }
00217
00218
00229
00230 static int
00231 muse_scipost_subtract_sky_simple_params_fill(muse_scipost_subtract_sky_simple_params_t *aParams, cpl_parameterlist *aParameters)
00232 {
00233 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
00234 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
00235 cpl_parameter *p;
00236
00237 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky_simple.lambdamin");
00238 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00239 aParams->lambdamin = cpl_parameter_get_double(p);
00240
00241 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_subtract_sky_simple.lambdamax");
00242 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00243 aParams->lambdamax = cpl_parameter_get_double(p);
00244
00245 return 0;
00246 }
00247
00248
00255
00256 static int
00257 muse_scipost_subtract_sky_simple_exec(cpl_plugin *aPlugin)
00258 {
00259 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
00260 return -1;
00261 }
00262 muse_processing_recipeinfo(aPlugin);
00263 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
00264 cpl_msg_set_threadid_on();
00265
00266 cpl_frameset *usedframes = cpl_frameset_new(),
00267 *outframes = cpl_frameset_new();
00268 muse_scipost_subtract_sky_simple_params_t params;
00269 muse_scipost_subtract_sky_simple_params_fill(¶ms, recipe->parameters);
00270
00271 cpl_errorstate prestate = cpl_errorstate_get();
00272
00273 muse_processing *proc = muse_processing_new("muse_scipost_subtract_sky_simple",
00274 recipe);
00275 int rc = muse_scipost_subtract_sky_simple_compute(proc, ¶ms);
00276 cpl_frameset_join(usedframes, proc->usedframes);
00277 cpl_frameset_join(outframes, proc->outframes);
00278 muse_processing_delete(proc);
00279
00280 if (!cpl_errorstate_is_equal(prestate)) {
00281
00282 cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
00283
00284 cpl_msg_set_level(CPL_MSG_INFO);
00285 }
00286
00287 muse_cplframeset_erase_duplicate(usedframes);
00288 muse_cplframeset_erase_duplicate(outframes);
00289
00290
00291
00292
00293
00294 muse_cplframeset_erase_all(recipe->frames);
00295 cpl_frameset_join(recipe->frames, usedframes);
00296 cpl_frameset_join(recipe->frames, outframes);
00297 cpl_frameset_delete(usedframes);
00298 cpl_frameset_delete(outframes);
00299 return rc;
00300 }
00301
00302
00309
00310 static int
00311 muse_scipost_subtract_sky_simple_destroy(cpl_plugin *aPlugin)
00312 {
00313
00314 cpl_recipe *recipe;
00315 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00316 recipe = (cpl_recipe *)aPlugin;
00317 } else {
00318 return -1;
00319 }
00320
00321
00322 cpl_parameterlist_delete(recipe->parameters);
00323 muse_processinginfo_delete(recipe);
00324 return 0;
00325 }
00326
00327
00337
00338 int
00339 cpl_plugin_get_info(cpl_pluginlist *aList)
00340 {
00341 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00342 cpl_plugin *plugin = &recipe->interface;
00343
00344 char *helptext;
00345 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00346 helptext = cpl_sprintf("%s%s", muse_scipost_subtract_sky_simple_help,
00347 muse_scipost_subtract_sky_simple_help_esorex);
00348 } else {
00349 helptext = cpl_sprintf("%s", muse_scipost_subtract_sky_simple_help);
00350 }
00351
00352
00353 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
00354 CPL_PLUGIN_TYPE_RECIPE,
00355 "muse_scipost_subtract_sky_simple",
00356 "Subtract night sky spectrum.",
00357 helptext,
00358 "Peter Weilbacher",
00359 "usd-help@eso.org",
00360 muse_get_license(),
00361 muse_scipost_subtract_sky_simple_create,
00362 muse_scipost_subtract_sky_simple_exec,
00363 muse_scipost_subtract_sky_simple_destroy);
00364 cpl_pluginlist_append(aList, plugin);
00365 cpl_free(helptext);
00366
00367 return 0;
00368 }
00369