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_exp_combine_z.h"
00036
00037
00046
00049
00050
00051
00052 static const char *muse_exp_combine_help =
00053 "Sort reduced pixel tables, one per exposure, by exposure and combine them with applied weights into one final datacube.";
00054
00055 static const char *muse_exp_combine_help_esorex =
00056 "\n\nInput frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
00057 "\n Frame tag Type Req #Fr Description"
00058 "\n -------------------- ---- --- --- ------------"
00059 "\n PIXTABLE_REDUCED raw Y >=2 Input pixel tables"
00060 "\n OFFSET_LIST calib . 1 List of coordinate offsets (and optional flux scale factors)"
00061 "\n FILTER_LIST calib . 1 File to be used to create field-of-view images."
00062 "\n OUTPUT_WCS calib . 1 WCS to override output cube location / dimensions"
00063 "\n\nProduct frames for raw frame tag \"PIXTABLE_REDUCED\":\n"
00064 "\n Frame tag Level Description"
00065 "\n -------------------- -------- ------------"
00066 "\n DATACUBE_FINAL final Output datacube (if --save contains \"cube\")"
00067 "\n IMAGE_FOV final Field-of-view images corresponding to the \"filter\" parameter (if --save contains \"cube\")."
00068 "\n PIXTABLE_COMBINED intermed Combined pixel table (if --save contains \"combined\")";
00069
00070
00078
00079 static cpl_recipeconfig *
00080 muse_exp_combine_new_recipeconfig(void)
00081 {
00082 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
00083
00084 cpl_recipeconfig_set_tag(recipeconfig, "PIXTABLE_REDUCED", 2, -1);
00085 cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "OFFSET_LIST", -1, 1);
00086 cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "FILTER_LIST", -1, 1);
00087 cpl_recipeconfig_set_input(recipeconfig, "PIXTABLE_REDUCED", "OUTPUT_WCS", -1, 1);
00088 cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_REDUCED", "DATACUBE_FINAL");
00089 cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_REDUCED", "IMAGE_FOV");
00090 cpl_recipeconfig_set_output(recipeconfig, "PIXTABLE_REDUCED", "PIXTABLE_COMBINED");
00091
00092 return recipeconfig;
00093 }
00094
00095
00105
00106 static cpl_error_code
00107 muse_exp_combine_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
00108 {
00109 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
00110 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
00111 if (!strcmp(aFrametag, "DATACUBE_FINAL")) {
00112 muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB NDET",
00113 CPL_TYPE_INT,
00114 "Number of detected sources in combined cube.");
00115 muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB LAMBDA",
00116 CPL_TYPE_FLOAT,
00117 "[Angstrom] Wavelength of plane in combined cube that was used for object detection.");
00118 muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB POS[0-9]+ X",
00119 CPL_TYPE_FLOAT,
00120 "[pix] Position of source k in x-direction in combined cube. If the FWHM measurement fails, this value will be -1.");
00121 muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB POS[0-9]+ Y",
00122 CPL_TYPE_FLOAT,
00123 "[pix] Position of source k in y-direction in combined cube. If the FWHM measurement fails, this value will be -1.");
00124 muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM[0-9]+ X",
00125 CPL_TYPE_FLOAT,
00126 "[arcsec] FWHM of source k in x-direction in combined cube. If the FWHM measurement fails, this value will be -1.");
00127 muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM[0-9]+ Y",
00128 CPL_TYPE_FLOAT,
00129 "[arcsec] FWHM of source k in y-direction in combined cube. If the FWHM measurement fails, this value will be -1.");
00130 muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM NVALID",
00131 CPL_TYPE_INT,
00132 "Number of detected sources with valid FWHM in combined cube.");
00133 muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM MEDIAN",
00134 CPL_TYPE_FLOAT,
00135 "[arcsec] Median FWHM of all sources with valid FWHM measurement (in x- and y-direction) in combined cube. If less than three sources with valid FWHM are detected, this value is zero.");
00136 muse_processing_prepare_property(aHeader, "ESO QC EXPCOMB FWHM MAD",
00137 CPL_TYPE_FLOAT,
00138 "[arcsec] Median absolute deviation of the FWHM of all sources with valid FWHM measurement (in x- and y-direction) in combined cube. If less than three sources with valid FWHM are detected, this value is zero.");
00139 } else if (!strcmp(aFrametag, "IMAGE_FOV")) {
00140 } else if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
00141 } else {
00142 cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
00143 return CPL_ERROR_ILLEGAL_INPUT;
00144 }
00145 return CPL_ERROR_NONE;
00146 }
00147
00148
00157
00158 static cpl_frame_level
00159 muse_exp_combine_get_frame_level(const char *aFrametag)
00160 {
00161 if (!aFrametag) {
00162 return CPL_FRAME_LEVEL_NONE;
00163 }
00164 if (!strcmp(aFrametag, "DATACUBE_FINAL")) {
00165 return CPL_FRAME_LEVEL_FINAL;
00166 }
00167 if (!strcmp(aFrametag, "IMAGE_FOV")) {
00168 return CPL_FRAME_LEVEL_FINAL;
00169 }
00170 if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
00171 return CPL_FRAME_LEVEL_INTERMEDIATE;
00172 }
00173 return CPL_FRAME_LEVEL_NONE;
00174 }
00175
00176
00185
00186 static muse_frame_mode
00187 muse_exp_combine_get_frame_mode(const char *aFrametag)
00188 {
00189 if (!aFrametag) {
00190 return MUSE_FRAME_MODE_ALL;
00191 }
00192 if (!strcmp(aFrametag, "DATACUBE_FINAL")) {
00193 return MUSE_FRAME_MODE_MASTER;
00194 }
00195 if (!strcmp(aFrametag, "IMAGE_FOV")) {
00196 return MUSE_FRAME_MODE_SEQUENCE;
00197 }
00198 if (!strcmp(aFrametag, "PIXTABLE_COMBINED")) {
00199 return MUSE_FRAME_MODE_MASTER;
00200 }
00201 return MUSE_FRAME_MODE_ALL;
00202 }
00203
00204
00214
00215 static int
00216 muse_exp_combine_create(cpl_plugin *aPlugin)
00217 {
00218
00219 cpl_recipe *recipe;
00220 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00221 recipe = (cpl_recipe *)aPlugin;
00222 } else {
00223 return -1;
00224 }
00225
00226
00227
00228 muse_processinginfo_register(recipe,
00229 muse_exp_combine_new_recipeconfig(),
00230 muse_exp_combine_prepare_header,
00231 muse_exp_combine_get_frame_level,
00232 muse_exp_combine_get_frame_mode);
00233
00234
00235
00236 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00237 cpl_msg_set_time_on();
00238 }
00239
00240
00241 recipe->parameters = cpl_parameterlist_new();
00242
00243 cpl_parameter *p;
00244
00245
00246 p = cpl_parameter_new_value("muse.muse_exp_combine.save",
00247 CPL_TYPE_STRING,
00248 "Select output product(s) to save. Can contain one or more of \"cube\" (output cube and associated images; if this is not given, no resampling is done at all) or \"combined\" (fully reduced and combined pixel table for the full set of exposures; this is useful, if the final resampling step is to be done again separately). If several options are given, they have to be comma-separated.",
00249 "muse.muse_exp_combine",
00250 (const char *)"cube");
00251 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "save");
00252 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "save");
00253
00254 cpl_parameterlist_append(recipe->parameters, p);
00255
00256
00257 p = cpl_parameter_new_enum("muse.muse_exp_combine.resample",
00258 CPL_TYPE_STRING,
00259 "The resampling technique to use for the final output cube.",
00260 "muse.muse_exp_combine",
00261 (const char *)"drizzle",
00262 6,
00263 (const char *)"nearest",
00264 (const char *)"linear",
00265 (const char *)"quadratic",
00266 (const char *)"renka",
00267 (const char *)"drizzle",
00268 (const char *)"lanczos");
00269 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "resample");
00270 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "resample");
00271
00272 cpl_parameterlist_append(recipe->parameters, p);
00273
00274
00275 p = cpl_parameter_new_value("muse.muse_exp_combine.dx",
00276 CPL_TYPE_DOUBLE,
00277 "Horizontal step size for resampling (in arcsec or pixel). The following defaults are taken when this value is set to 0.0: 0.2'' for WFM, 0.075'' for NFM, 1.0 if data is in pixel units.",
00278 "muse.muse_exp_combine",
00279 (double)0.0);
00280 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dx");
00281 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dx");
00282
00283 cpl_parameterlist_append(recipe->parameters, p);
00284
00285
00286 p = cpl_parameter_new_value("muse.muse_exp_combine.dy",
00287 CPL_TYPE_DOUBLE,
00288 "Vertical step size for resampling (in arcsec or pixel). The following defaults are taken when this value is set to 0.0: 0.2'' for WFM, 0.075'' for NFM, 1.0 if data is in pixel units.",
00289 "muse.muse_exp_combine",
00290 (double)0.0);
00291 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dy");
00292 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dy");
00293
00294 cpl_parameterlist_append(recipe->parameters, p);
00295
00296
00297 p = cpl_parameter_new_value("muse.muse_exp_combine.dlambda",
00298 CPL_TYPE_DOUBLE,
00299 "Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0.0",
00300 "muse.muse_exp_combine",
00301 (double)0.0);
00302 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dlambda");
00303 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dlambda");
00304
00305 cpl_parameterlist_append(recipe->parameters, p);
00306
00307
00308 p = cpl_parameter_new_enum("muse.muse_exp_combine.crtype",
00309 CPL_TYPE_STRING,
00310 "Type of statistics used for detection of cosmic rays during final resampling. \"iraf\" uses the variance information, \"mean\" uses standard (mean/stdev) statistics, \"median\" uses median and the median median of the absolute median deviation.",
00311 "muse.muse_exp_combine",
00312 (const char *)"median",
00313 3,
00314 (const char *)"iraf",
00315 (const char *)"mean",
00316 (const char *)"median");
00317 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crtype");
00318 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crtype");
00319
00320 cpl_parameterlist_append(recipe->parameters, p);
00321
00322
00323 p = cpl_parameter_new_value("muse.muse_exp_combine.crsigma",
00324 CPL_TYPE_DOUBLE,
00325 "Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative value switches cosmic ray rejection off.",
00326 "muse.muse_exp_combine",
00327 (double)10.);
00328 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crsigma");
00329 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crsigma");
00330
00331 cpl_parameterlist_append(recipe->parameters, p);
00332
00333
00334 p = cpl_parameter_new_value("muse.muse_exp_combine.rc",
00335 CPL_TYPE_DOUBLE,
00336 "Critical radius for the \"renka\" resampling method.",
00337 "muse.muse_exp_combine",
00338 (double)1.25);
00339 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "rc");
00340 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "rc");
00341
00342 cpl_parameterlist_append(recipe->parameters, p);
00343
00344
00345 p = cpl_parameter_new_value("muse.muse_exp_combine.pixfrac",
00346 CPL_TYPE_DOUBLE,
00347 "Pixel down-scaling factor for the \"drizzle\" resampling method.",
00348 "muse.muse_exp_combine",
00349 (double)0.6);
00350 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "pixfrac");
00351 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "pixfrac");
00352
00353 cpl_parameterlist_append(recipe->parameters, p);
00354
00355
00356 p = cpl_parameter_new_value("muse.muse_exp_combine.ld",
00357 CPL_TYPE_INT,
00358 "Number of adjacent pixels to take into account during resampling in all three directions (loop distance); this affects all resampling methods except \"nearest\".",
00359 "muse.muse_exp_combine",
00360 (int)1);
00361 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "ld");
00362 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ld");
00363
00364 cpl_parameterlist_append(recipe->parameters, p);
00365
00366
00367 p = cpl_parameter_new_enum("muse.muse_exp_combine.format",
00368 CPL_TYPE_STRING,
00369 "Type of output file format, \"Cube\" is a standard FITS cube with NAXIS=3 and multiple extensions (for data and variance). The extended \"x\" formats include the reconstructed image(s) in FITS image extensions within the same file.",
00370 "muse.muse_exp_combine",
00371 (const char *)"Cube",
00372 5,
00373 (const char *)"Cube",
00374 (const char *)"Euro3D",
00375 (const char *)"xCube",
00376 (const char *)"xEuro3D",
00377 (const char *)"sdpCube");
00378 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "format");
00379 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "format");
00380
00381 cpl_parameterlist_append(recipe->parameters, p);
00382
00383
00384 p = cpl_parameter_new_enum("muse.muse_exp_combine.weight",
00385 CPL_TYPE_STRING,
00386 "Type of weighting scheme to use when combining multiple exposures. \"exptime\" just uses the exposure time to weight the exposures, \"fwhm\" uses the best available seeing information from the headers as well, \"none\" preserves an existing weight column in the input pixel tables without changes.",
00387 "muse.muse_exp_combine",
00388 (const char *)"exptime",
00389 3,
00390 (const char *)"exptime",
00391 (const char *)"fwhm",
00392 (const char *)"none");
00393 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "weight");
00394 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "weight");
00395
00396 cpl_parameterlist_append(recipe->parameters, p);
00397
00398
00399 p = cpl_parameter_new_value("muse.muse_exp_combine.filter",
00400 CPL_TYPE_STRING,
00401 "The filter name(s) to be used for the output field-of-view image. Each name has to correspond to an EXTNAME in an extension of the FILTER_LIST file. If an unsupported filter name is given, creation of the respective image is omitted. If multiple filter names are given, they have to be comma separated.",
00402 "muse.muse_exp_combine",
00403 (const char *)"white");
00404 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "filter");
00405 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "filter");
00406
00407 cpl_parameterlist_append(recipe->parameters, p);
00408
00409
00410 p = cpl_parameter_new_value("muse.muse_exp_combine.lambdamin",
00411 CPL_TYPE_DOUBLE,
00412 "Cut off the data below this wavelength after loading the pixel table(s).",
00413 "muse.muse_exp_combine",
00414 (double)4000.);
00415 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamin");
00416 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamin");
00417
00418 cpl_parameterlist_append(recipe->parameters, p);
00419
00420
00421 p = cpl_parameter_new_value("muse.muse_exp_combine.lambdamax",
00422 CPL_TYPE_DOUBLE,
00423 "Cut off the data above this wavelength after loading the pixel table(s).",
00424 "muse.muse_exp_combine",
00425 (double)10000.);
00426 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lambdamax");
00427 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lambdamax");
00428
00429 cpl_parameterlist_append(recipe->parameters, p);
00430
00431 return 0;
00432 }
00433
00434
00445
00446 static int
00447 muse_exp_combine_params_fill(muse_exp_combine_params_t *aParams, cpl_parameterlist *aParameters)
00448 {
00449 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
00450 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
00451 cpl_parameter *p;
00452
00453 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.save");
00454 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00455 aParams->save = cpl_parameter_get_string(p);
00456
00457 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.resample");
00458 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00459 aParams->resample_s = cpl_parameter_get_string(p);
00460 aParams->resample =
00461 (!strcasecmp(aParams->resample_s, "nearest")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_NEAREST :
00462 (!strcasecmp(aParams->resample_s, "linear")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_LINEAR :
00463 (!strcasecmp(aParams->resample_s, "quadratic")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_QUADRATIC :
00464 (!strcasecmp(aParams->resample_s, "renka")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_RENKA :
00465 (!strcasecmp(aParams->resample_s, "drizzle")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_DRIZZLE :
00466 (!strcasecmp(aParams->resample_s, "lanczos")) ? MUSE_EXP_COMBINE_PARAM_RESAMPLE_LANCZOS :
00467 MUSE_EXP_COMBINE_PARAM_RESAMPLE_INVALID_VALUE;
00468 cpl_ensure_code(aParams->resample != MUSE_EXP_COMBINE_PARAM_RESAMPLE_INVALID_VALUE,
00469 CPL_ERROR_ILLEGAL_INPUT);
00470
00471 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dx");
00472 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00473 aParams->dx = cpl_parameter_get_double(p);
00474
00475 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dy");
00476 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00477 aParams->dy = cpl_parameter_get_double(p);
00478
00479 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.dlambda");
00480 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00481 aParams->dlambda = cpl_parameter_get_double(p);
00482
00483 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.crtype");
00484 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00485 aParams->crtype_s = cpl_parameter_get_string(p);
00486 aParams->crtype =
00487 (!strcasecmp(aParams->crtype_s, "iraf")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_IRAF :
00488 (!strcasecmp(aParams->crtype_s, "mean")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_MEAN :
00489 (!strcasecmp(aParams->crtype_s, "median")) ? MUSE_EXP_COMBINE_PARAM_CRTYPE_MEDIAN :
00490 MUSE_EXP_COMBINE_PARAM_CRTYPE_INVALID_VALUE;
00491 cpl_ensure_code(aParams->crtype != MUSE_EXP_COMBINE_PARAM_CRTYPE_INVALID_VALUE,
00492 CPL_ERROR_ILLEGAL_INPUT);
00493
00494 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.crsigma");
00495 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00496 aParams->crsigma = cpl_parameter_get_double(p);
00497
00498 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.rc");
00499 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00500 aParams->rc = cpl_parameter_get_double(p);
00501
00502 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.pixfrac");
00503 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00504 aParams->pixfrac = cpl_parameter_get_double(p);
00505
00506 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.ld");
00507 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00508 aParams->ld = cpl_parameter_get_int(p);
00509
00510 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.format");
00511 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00512 aParams->format_s = cpl_parameter_get_string(p);
00513 aParams->format =
00514 (!strcasecmp(aParams->format_s, "Cube")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_CUBE :
00515 (!strcasecmp(aParams->format_s, "Euro3D")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_EURO3D :
00516 (!strcasecmp(aParams->format_s, "xCube")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_XCUBE :
00517 (!strcasecmp(aParams->format_s, "xEuro3D")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_XEURO3D :
00518 (!strcasecmp(aParams->format_s, "sdpCube")) ? MUSE_EXP_COMBINE_PARAM_FORMAT_SDPCUBE :
00519 MUSE_EXP_COMBINE_PARAM_FORMAT_INVALID_VALUE;
00520 cpl_ensure_code(aParams->format != MUSE_EXP_COMBINE_PARAM_FORMAT_INVALID_VALUE,
00521 CPL_ERROR_ILLEGAL_INPUT);
00522
00523 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.weight");
00524 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00525 aParams->weight_s = cpl_parameter_get_string(p);
00526 aParams->weight =
00527 (!strcasecmp(aParams->weight_s, "exptime")) ? MUSE_EXP_COMBINE_PARAM_WEIGHT_EXPTIME :
00528 (!strcasecmp(aParams->weight_s, "fwhm")) ? MUSE_EXP_COMBINE_PARAM_WEIGHT_FWHM :
00529 (!strcasecmp(aParams->weight_s, "none")) ? MUSE_EXP_COMBINE_PARAM_WEIGHT_NONE :
00530 MUSE_EXP_COMBINE_PARAM_WEIGHT_INVALID_VALUE;
00531 cpl_ensure_code(aParams->weight != MUSE_EXP_COMBINE_PARAM_WEIGHT_INVALID_VALUE,
00532 CPL_ERROR_ILLEGAL_INPUT);
00533
00534 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.filter");
00535 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00536 aParams->filter = cpl_parameter_get_string(p);
00537
00538 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.lambdamin");
00539 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00540 aParams->lambdamin = cpl_parameter_get_double(p);
00541
00542 p = cpl_parameterlist_find(aParameters, "muse.muse_exp_combine.lambdamax");
00543 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00544 aParams->lambdamax = cpl_parameter_get_double(p);
00545
00546 return 0;
00547 }
00548
00549
00556
00557 static int
00558 muse_exp_combine_exec(cpl_plugin *aPlugin)
00559 {
00560 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
00561 return -1;
00562 }
00563 muse_processing_recipeinfo(aPlugin);
00564 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
00565 cpl_msg_set_threadid_on();
00566
00567 cpl_frameset *usedframes = cpl_frameset_new(),
00568 *outframes = cpl_frameset_new();
00569 muse_exp_combine_params_t params;
00570 muse_exp_combine_params_fill(¶ms, recipe->parameters);
00571
00572 cpl_errorstate prestate = cpl_errorstate_get();
00573
00574 muse_processing *proc = muse_processing_new("muse_exp_combine",
00575 recipe);
00576 int rc = muse_exp_combine_compute(proc, ¶ms);
00577 cpl_frameset_join(usedframes, proc->usedframes);
00578 cpl_frameset_join(outframes, proc->outframes);
00579 muse_processing_delete(proc);
00580
00581 if (!cpl_errorstate_is_equal(prestate)) {
00582
00583 cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
00584
00585 cpl_msg_set_level(CPL_MSG_INFO);
00586 }
00587
00588 muse_cplframeset_erase_duplicate(usedframes);
00589 muse_cplframeset_erase_duplicate(outframes);
00590
00591
00592
00593
00594
00595 muse_cplframeset_erase_all(recipe->frames);
00596 cpl_frameset_join(recipe->frames, usedframes);
00597 cpl_frameset_join(recipe->frames, outframes);
00598 cpl_frameset_delete(usedframes);
00599 cpl_frameset_delete(outframes);
00600 return rc;
00601 }
00602
00603
00610
00611 static int
00612 muse_exp_combine_destroy(cpl_plugin *aPlugin)
00613 {
00614
00615 cpl_recipe *recipe;
00616 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00617 recipe = (cpl_recipe *)aPlugin;
00618 } else {
00619 return -1;
00620 }
00621
00622
00623 cpl_parameterlist_delete(recipe->parameters);
00624 muse_processinginfo_delete(recipe);
00625 return 0;
00626 }
00627
00628
00638
00639 int
00640 cpl_plugin_get_info(cpl_pluginlist *aList)
00641 {
00642 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00643 cpl_plugin *plugin = &recipe->interface;
00644
00645 char *helptext;
00646 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00647 helptext = cpl_sprintf("%s%s", muse_exp_combine_help,
00648 muse_exp_combine_help_esorex);
00649 } else {
00650 helptext = cpl_sprintf("%s", muse_exp_combine_help);
00651 }
00652
00653
00654 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
00655 CPL_PLUGIN_TYPE_RECIPE,
00656 "muse_exp_combine",
00657 "Combine several exposures into one datacube.",
00658 helptext,
00659 "Peter Weilbacher",
00660 "usd-help@eso.org",
00661 muse_get_license(),
00662 muse_exp_combine_create,
00663 muse_exp_combine_exec,
00664 muse_exp_combine_destroy);
00665 cpl_pluginlist_append(aList, plugin);
00666 cpl_free(helptext);
00667
00668 return 0;
00669 }
00670