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_combine_pixtables_z.h"
00036
00037
00046
00049
00050
00051
00052 static const char *muse_scipost_combine_pixtables_help =
00053 "Sort pixel tables by exposure and combine them with applied weights into one big pixel table. This is a task separated from muse_scipost.";
00054
00055 static const char *muse_scipost_combine_pixtables_help_esorex =
00056 "\n\nInput frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
00057 "\n Frame tag Type Req #Fr Description"
00058 "\n -------------------- ---- --- --- ------------"
00059 "\n PIXTABLE_OBJECT raw Y Input pixel tables"
00060 "\n OFFSET_LIST calib . 1 List of coordinate offsets (and optional flux scale factors)"
00061 "\n\nProduct frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
00062 "\n Frame tag Level Description"
00063 "\n -------------------- -------- ------------"
00064 "\n PIXTABLE_COMBINED intermed Combined pixel table";
00065
00066
00074
00075 static cpl_recipeconfig *
00076 muse_scipost_combine_pixtables_new_recipeconfig(void)
00077 {
00078 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
00079
00080 cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_OBJECT", 1, -1);
00081 cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_OBJECT", "OFFSET_LIST", -1, 1);
00082 cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_OBJECT", "PIXTABLE_COMBINED");
00083
00084 return recipeconfig;
00085 }
00086
00087
00097
00098 static cpl_error_code
00099 muse_scipost_combine_pixtables_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
00100 {
00101 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
00102 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
00103 if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
00104 } else {
00105 cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
00106 return CPL_ERROR_ILLEGAL_INPUT;
00107 }
00108 return CPL_ERROR_NONE;
00109 }
00110
00111
00120
00121 static cpl_frame_level
00122 muse_scipost_combine_pixtables_get_frame_level(const char *aFrametag)
00123 {
00124 if (!aFrametag) {
00125 return CPL_FRAME_LEVEL_NONE;
00126 }
00127 if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
00128 return CPL_FRAME_LEVEL_INTERMEDIATE;
00129 }
00130 return CPL_FRAME_LEVEL_NONE;
00131 }
00132
00133
00142
00143 static muse_frame_mode
00144 muse_scipost_combine_pixtables_get_frame_mode(const char *aFrametag)
00145 {
00146 if (!aFrametag) {
00147 return MUSE_FRAME_MODE_ALL;
00148 }
00149 if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
00150 return MUSE_FRAME_MODE_MASTER;
00151 }
00152 return MUSE_FRAME_MODE_ALL;
00153 }
00154
00155
00165
00166 static int
00167 muse_scipost_combine_pixtables_create(cpl_plugin *aPlugin)
00168 {
00169
00170 cpl_recipe *recipe;
00171 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00172 recipe = (cpl_recipe *)aPlugin;
00173 } else {
00174 return -1;
00175 }
00176
00177
00178
00179 muse_processinginfo_register(recipe,
00180 muse_scipost_combine_pixtables_new_recipeconfig(),
00181 muse_scipost_combine_pixtables_prepare_header,
00182 muse_scipost_combine_pixtables_get_frame_level,
00183 muse_scipost_combine_pixtables_get_frame_mode);
00184
00185
00186
00187 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00188 cpl_msg_set_time_on();
00189 }
00190
00191
00192 recipe->parameters = cpl_parameterlist_new();
00193
00194 cpl_parameter *p;
00195
00196
00197 p = cpl_parameter_new_value("muse.muse_scipost_combine_pixtables.lambdamin",
00198 CPL_TYPE_DOUBLE,
00199 "Cut off the data below this wavelength after loading the pixel table(s).",
00200 "muse.muse_scipost_combine_pixtables",
00201 (double)4000.);
00202 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
00203 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
00204
00205 cpl_parameterlist_append(recipe->parameters, p);
00206
00207
00208 p = cpl_parameter_new_value("muse.muse_scipost_combine_pixtables.lambdamax",
00209 CPL_TYPE_DOUBLE,
00210 "Cut off the data above this wavelength after loading the pixel table(s).",
00211 "muse.muse_scipost_combine_pixtables",
00212 (double)10000.);
00213 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
00214 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
00215
00216 cpl_parameterlist_append(recipe->parameters, p);
00217
00218
00219 p = cpl_parameter_new_enum("muse.muse_scipost_combine_pixtables.weight",
00220 CPL_TYPE_STRING,
00221 "Type of weighting scheme to use when combining multiple exposures. \"exptime\" just uses the exposure time to weight the exposures, \"fwhm\" uses the DIMM information in the header as well, \"none\" preserves an existing weight column in the input pixel tables without changes.",
00222 "muse.muse_scipost_combine_pixtables",
00223 (const char *)"exptime",
00224 3,
00225 (const char *)"exptime",
00226 (const char *)"fwhm",
00227 (const char *)"none");
00228 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "weight");
00229 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "weight");
00230
00231 cpl_parameterlist_append(recipe->parameters, p);
00232
00233 return 0;
00234 }
00235
00236
00247
00248 static int
00249 muse_scipost_combine_pixtables_params_fill(muse_scipost_combine_pixtables_params_t *aParams, cpl_parameterlist *aParameters)
00250 {
00251 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
00252 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
00253 cpl_parameter *p;
00254
00255 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_combine_pixtables.lambdamin");
00256 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00257 aParams->lambdamin = cpl_parameter_get_double(p);
00258
00259 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_combine_pixtables.lambdamax");
00260 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00261 aParams->lambdamax = cpl_parameter_get_double(p);
00262
00263 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_combine_pixtables.weight");
00264 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00265 aParams->weight_s = cpl_parameter_get_string(p);
00266 aParams->weight =
00267 (!strcasecmp(aParams->weight_s, "exptime")) ? MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_EXPTIME :
00268 (!strcasecmp(aParams->weight_s, "fwhm")) ? MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_FWHM :
00269 (!strcasecmp(aParams->weight_s, "none")) ? MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_NONE :
00270 MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_INVALID_VALUE;
00271 cpl_ensure_code(aParams->weight != MUSE_SCIPOST_COMBINE_PIXTABLES_PARAM_WEIGHT_INVALID_VALUE,
00272 CPL_ERROR_ILLEGAL_INPUT);
00273
00274 return 0;
00275 }
00276
00277
00284
00285 static int
00286 muse_scipost_combine_pixtables_exec(cpl_plugin *aPlugin)
00287 {
00288 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
00289 return -1;
00290 }
00291 muse_processing_recipeinfo(aPlugin);
00292 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
00293 cpl_msg_set_threadid_on();
00294
00295 cpl_frameset *usedframes = cpl_frameset_new(),
00296 *outframes = cpl_frameset_new();
00297 muse_scipost_combine_pixtables_params_t params;
00298 muse_scipost_combine_pixtables_params_fill(¶ms, recipe->parameters);
00299
00300 cpl_errorstate prestate = cpl_errorstate_get();
00301
00302 muse_processing *proc = muse_processing_new("muse_scipost_combine_pixtables",
00303 recipe);
00304 int rc = muse_scipost_combine_pixtables_compute(proc, ¶ms);
00305 cpl_frameset_join(usedframes, proc->usedframes);
00306 cpl_frameset_join(outframes, proc->outframes);
00307 muse_processing_delete(proc);
00308
00309 if (!cpl_errorstate_is_equal(prestate)) {
00310
00311 cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
00312
00313 cpl_msg_set_level(CPL_MSG_INFO);
00314 }
00315
00316 muse_cplframeset_erase_duplicate(usedframes);
00317 muse_cplframeset_erase_duplicate(outframes);
00318
00319
00320
00321
00322
00323 muse_cplframeset_erase_all(recipe->frames);
00324 cpl_frameset_join(recipe->frames, usedframes);
00325 cpl_frameset_join(recipe->frames, outframes);
00326 cpl_frameset_delete(usedframes);
00327 cpl_frameset_delete(outframes);
00328 return rc;
00329 }
00330
00331
00338
00339 static int
00340 muse_scipost_combine_pixtables_destroy(cpl_plugin *aPlugin)
00341 {
00342
00343 cpl_recipe *recipe;
00344 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00345 recipe = (cpl_recipe *)aPlugin;
00346 } else {
00347 return -1;
00348 }
00349
00350
00351 cpl_parameterlist_delete(recipe->parameters);
00352 muse_processinginfo_delete(recipe);
00353 return 0;
00354 }
00355
00356
00366
00367 int
00368 cpl_plugin_get_info(cpl_pluginlist *aList)
00369 {
00370 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00371 cpl_plugin *plugin = &recipe->interface;
00372
00373 char *helptext;
00374 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00375 helptext = cpl_sprintf("%s%s", muse_scipost_combine_pixtables_help,
00376 muse_scipost_combine_pixtables_help_esorex);
00377 } else {
00378 helptext = cpl_sprintf("%s", muse_scipost_combine_pixtables_help);
00379 }
00380
00381
00382 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
00383 CPL_PLUGIN_TYPE_RECIPE,
00384 "muse_scipost_combine_pixtables",
00385 "Combine MUSE pixel tables, either from different IFUs, or from different exposures, or both.",
00386 helptext,
00387 "Ole Streicher",
00388 "usd-help@eso.org",
00389 muse_get_license(),
00390 muse_scipost_combine_pixtables_create,
00391 muse_scipost_combine_pixtables_exec,
00392 muse_scipost_combine_pixtables_destroy);
00393 cpl_pluginlist_append(aList, plugin);
00394 cpl_free(helptext);
00395
00396 return 0;
00397 }
00398