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_correct_rv_z.h"
00036
00037
00043
00046
00047
00048
00049 static const char *muse_scipost_correct_rv_help =
00050 "Correct the wavelengths in the pixel table by given radial-velocity correction. This is a task separated from muse_scipost.";
00051
00052 static const char *muse_scipost_correct_rv_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 RV correction"
00057 "\n\nProduct frames for raw frame tag \"PIXTABLE_OBJECT\":\n"
00058 "\n Frame tag Level Description"
00059 "\n -------------------- -------- ------------"
00060 "\n PIXTABLE_REDUCED final RV corrected pixel table";
00061
00062
00070
00071 static cpl_recipeconfig *
00072 muse_scipost_correct_rv_new_recipeconfig(void)
00073 {
00074 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
00075
00076 cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_OBJECT", 1, -1);
00077 cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_OBJECT", "PIXTABLE_REDUCED");
00078
00079 return recipeconfig;
00080 }
00081
00082
00092
00093 static cpl_error_code
00094 muse_scipost_correct_rv_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
00095 {
00096 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
00097 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
00098 if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00099 } else {
00100 cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
00101 return CPL_ERROR_ILLEGAL_INPUT;
00102 }
00103 return CPL_ERROR_NONE;
00104 }
00105
00106
00115
00116 static cpl_frame_level
00117 muse_scipost_correct_rv_get_frame_level(const char *aFrametag)
00118 {
00119 if (!aFrametag) {
00120 return CPL_FRAME_LEVEL_NONE;
00121 }
00122 if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00123 return CPL_FRAME_LEVEL_FINAL;
00124 }
00125 return CPL_FRAME_LEVEL_NONE;
00126 }
00127
00128
00137
00138 static muse_frame_mode
00139 muse_scipost_correct_rv_get_frame_mode(const char *aFrametag)
00140 {
00141 if (!aFrametag) {
00142 return MUSE_FRAME_MODE_ALL;
00143 }
00144 if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00145 return MUSE_FRAME_MODE_ALL;
00146 }
00147 return MUSE_FRAME_MODE_ALL;
00148 }
00149
00150
00160
00161 static int
00162 muse_scipost_correct_rv_create(cpl_plugin *aPlugin)
00163 {
00164
00165 cpl_recipe *recipe;
00166 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00167 recipe = (cpl_recipe *)aPlugin;
00168 } else {
00169 return -1;
00170 }
00171
00172
00173
00174 muse_processinginfo_register(recipe,
00175 muse_scipost_correct_rv_new_recipeconfig(),
00176 muse_scipost_correct_rv_prepare_header,
00177 muse_scipost_correct_rv_get_frame_level,
00178 muse_scipost_correct_rv_get_frame_mode);
00179
00180
00181
00182 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00183 cpl_msg_set_time_on();
00184 }
00185
00186
00187 recipe->parameters = cpl_parameterlist_new();
00188
00189 cpl_parameter *p;
00190
00191
00192 p = cpl_parameter_new_value("muse.muse_scipost_correct_rv.lambdamin",
00193 CPL_TYPE_DOUBLE,
00194 "Cut off the data below this wavelength after loading the pixel table(s).",
00195 "muse.muse_scipost_correct_rv",
00196 (double)4000.);
00197 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
00198 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
00199
00200 cpl_parameterlist_append(recipe->parameters, p);
00201
00202
00203 p = cpl_parameter_new_value("muse.muse_scipost_correct_rv.lambdamax",
00204 CPL_TYPE_DOUBLE,
00205 "Cut off the data above this wavelength after loading the pixel table(s).",
00206 "muse.muse_scipost_correct_rv",
00207 (double)10000.);
00208 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
00209 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
00210
00211 cpl_parameterlist_append(recipe->parameters, p);
00212
00213
00214 p = cpl_parameter_new_enum("muse.muse_scipost_correct_rv.rvcorr",
00215 CPL_TYPE_STRING,
00216 "Correct the radial velocity of the telescope with reference to either the barycenter of the Solar System (bary), the center of the Sun (helio), or to the center of the Earth (geo).",
00217 "muse.muse_scipost_correct_rv",
00218 (const char *)"bary",
00219 4,
00220 (const char *)"bary",
00221 (const char *)"helio",
00222 (const char *)"geo",
00223 (const char *)"none");
00224 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "rvcorr");
00225 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "rvcorr");
00226
00227 cpl_parameterlist_append(recipe->parameters, p);
00228
00229 return 0;
00230 }
00231
00232
00243
00244 static int
00245 muse_scipost_correct_rv_params_fill(muse_scipost_correct_rv_params_t *aParams, cpl_parameterlist *aParameters)
00246 {
00247 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
00248 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
00249 cpl_parameter *p;
00250
00251 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_correct_rv.lambdamin");
00252 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00253 aParams->lambdamin = cpl_parameter_get_double(p);
00254
00255 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_correct_rv.lambdamax");
00256 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00257 aParams->lambdamax = cpl_parameter_get_double(p);
00258
00259 p = cpl_parameterlist_find(aParameters, "muse.muse_scipost_correct_rv.rvcorr");
00260 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00261 aParams->rvcorr_s = cpl_parameter_get_string(p);
00262 aParams->rvcorr =
00263 (!strcasecmp(aParams->rvcorr_s, "bary")) ? MUSE_SCIPOST_CORRECT_RV_PARAM_RVCORR_BARY :
00264 (!strcasecmp(aParams->rvcorr_s, "helio")) ? MUSE_SCIPOST_CORRECT_RV_PARAM_RVCORR_HELIO :
00265 (!strcasecmp(aParams->rvcorr_s, "geo")) ? MUSE_SCIPOST_CORRECT_RV_PARAM_RVCORR_GEO :
00266 (!strcasecmp(aParams->rvcorr_s, "none")) ? MUSE_SCIPOST_CORRECT_RV_PARAM_RVCORR_NONE :
00267 MUSE_SCIPOST_CORRECT_RV_PARAM_RVCORR_INVALID_VALUE;
00268 cpl_ensure_code(aParams->rvcorr != MUSE_SCIPOST_CORRECT_RV_PARAM_RVCORR_INVALID_VALUE,
00269 CPL_ERROR_ILLEGAL_INPUT);
00270
00271 return 0;
00272 }
00273
00274
00281
00282 static int
00283 muse_scipost_correct_rv_exec(cpl_plugin *aPlugin)
00284 {
00285 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
00286 return -1;
00287 }
00288 muse_processing_recipeinfo(aPlugin);
00289 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
00290 cpl_msg_set_threadid_on();
00291
00292 cpl_frameset *usedframes = cpl_frameset_new(),
00293 *outframes = cpl_frameset_new();
00294 muse_scipost_correct_rv_params_t params;
00295 muse_scipost_correct_rv_params_fill(¶ms, recipe->parameters);
00296
00297 cpl_errorstate prestate = cpl_errorstate_get();
00298
00299 muse_processing *proc = muse_processing_new("muse_scipost_correct_rv",
00300 recipe);
00301 int rc = muse_scipost_correct_rv_compute(proc, ¶ms);
00302 cpl_frameset_join(usedframes, proc->usedframes);
00303 cpl_frameset_join(outframes, proc->outframes);
00304 muse_processing_delete(proc);
00305
00306 if (!cpl_errorstate_is_equal(prestate)) {
00307
00308 cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
00309
00310 cpl_msg_set_level(CPL_MSG_INFO);
00311 }
00312
00313 muse_cplframeset_erase_duplicate(usedframes);
00314 muse_cplframeset_erase_duplicate(outframes);
00315
00316
00317
00318
00319
00320 muse_cplframeset_erase_all(recipe->frames);
00321 cpl_frameset_join(recipe->frames, usedframes);
00322 cpl_frameset_join(recipe->frames, outframes);
00323 cpl_frameset_delete(usedframes);
00324 cpl_frameset_delete(outframes);
00325 return rc;
00326 }
00327
00328
00335
00336 static int
00337 muse_scipost_correct_rv_destroy(cpl_plugin *aPlugin)
00338 {
00339
00340 cpl_recipe *recipe;
00341 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00342 recipe = (cpl_recipe *)aPlugin;
00343 } else {
00344 return -1;
00345 }
00346
00347
00348 cpl_parameterlist_delete(recipe->parameters);
00349 muse_processinginfo_delete(recipe);
00350 return 0;
00351 }
00352
00353
00363
00364 int
00365 cpl_plugin_get_info(cpl_pluginlist *aList)
00366 {
00367 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00368 cpl_plugin *plugin = &recipe->interface;
00369
00370 char *helptext;
00371 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00372 helptext = cpl_sprintf("%s%s", muse_scipost_correct_rv_help,
00373 muse_scipost_correct_rv_help_esorex);
00374 } else {
00375 helptext = cpl_sprintf("%s", muse_scipost_correct_rv_help);
00376 }
00377
00378
00379 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
00380 CPL_PLUGIN_TYPE_RECIPE,
00381 "muse_scipost_correct_rv",
00382 "Apply RV correction for MUSE pixel tables.",
00383 helptext,
00384 "Peter Weilbacher",
00385 "usd-help@eso.org",
00386 muse_get_license(),
00387 muse_scipost_correct_rv_create,
00388 muse_scipost_correct_rv_exec,
00389 muse_scipost_correct_rv_destroy);
00390 cpl_pluginlist_append(aList, plugin);
00391 cpl_free(helptext);
00392
00393 return 0;
00394 }
00395