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_scibasic_z.h"
00036
00037
00082
00085
00086
00087
00088 static const char *muse_scibasic_help =
00089 "Processing handles each raw input image separately: it trims the raw data and records the overscan statistics, subtracts the bias (taking account of the overscan, if --overscan is not &none&), optionally detects cosmic rays (note that by default cosmic ray rejection is handled in the post processing recipes while the data is reformatted into a datacube, so that the default setting is cr=&none& here), converts the images from adu to count, subtracts the dark, divides by the flat-field, and (optionally) propagates the integrated flux value from the twilight-sky cube. [For special cases, users can choose to combine all input files at the image level, so that the pixel table is only created once, for the combined data. This is not recommended for science data, where the combination should take place after correcting for atmospheric effects, before the creation of the final cube.] The reduced image is then saved (if --saveimage=true). The input calibrations geometry table, trace table, and wavelength calibration table are used to assign 3D coordinates to each CCD-based pixel, thereby creating a pixel table for each exposure. If --skylines contains one or more wavelengths for (bright and isolated) sky emission lines, these lines are used to correct the wavelength calibration using an offset. The data is then cut to a useful wavelength range (if --crop=true). If an ILLUM exposure was given as input, it is then used to correct the relative illumination between all slices of one IFU. For this, the data of each slice is multiplied by the normalized median flux of that slice in the ILLUM exposure. As last step, the data is divided by the normalized twilight cube (if given), using the 3D coordinate of each pixel in the pixel table to interpolate the twilight correction onto the data. This pre-reduced pixel table for each exposure is then saved to disk.";
00090
00091 static const char *muse_scibasic_help_esorex =
00092 "\n\nInput frames for raw frame tag \"OBJECT\":\n"
00093 "\n Frame tag Type Req #Fr Description"
00094 "\n -------------------- ---- --- --- ------------"
00095 "\n OBJECT raw . Raw exposure of a science target"
00096 "\n STD raw . Raw exposure of a standard star field"
00097 "\n SKY raw . Raw exposure of an (almost) empty sky field"
00098 "\n ASTROMETRY raw . Raw exposure of an astrometric field"
00099 "\n ILLUM raw . 1 Single optional raw (attached/illumination) flat-field exposure"
00100 "\n MASTER_BIAS calib Y 1 Master bias"
00101 "\n MASTER_DARK calib . 1 Master dark"
00102 "\n MASTER_FLAT calib Y 1 Master flat"
00103 "\n TRACE_TABLE calib Y 1 Trace table"
00104 "\n WAVECAL_TABLE calib Y 1 Wavelength calibration table"
00105 "\n GEOMETRY_TABLE calib Y 1 Relative positions of the slices in the field of view"
00106 "\n TWILIGHT_CUBE calib . Smoothed cube of twilight sky"
00107 "\n BADPIX_TABLE calib . 1 Known bad pixels"
00108 "\n\nProduct frames for raw frame tag \"OBJECT\":\n"
00109 "\n Frame tag Level Description"
00110 "\n -------------------- -------- ------------"
00111 "\n OBJECT_RED intermed Pre-processed CCD-based images for OBJECT input (if --saveimage=true)"
00112 "\n OBJECT_RESAMPLED intermed Resampled 2D image for OBJECT input (if --resample=true)"
00113 "\n PIXTABLE_OBJECT intermed Output pixel table for OBJECT input"
00114 "\n STD_RED intermed Pre-processed CCD-based images for STD input (if --saveimage=true)"
00115 "\n STD_RESAMPLED intermed Resampled 2D image for STD input (if --resample=true)"
00116 "\n PIXTABLE_STD intermed Output pixel table for STD input"
00117 "\n SKY_RED intermed Pre-processed CCD-based images for SKY input (if --saveimage=true)"
00118 "\n SKY_RESAMPLED intermed Resampled 2D image for SKY input (if --resample=true)"
00119 "\n PIXTABLE_SKY intermed Output pixel table for SKY input"
00120 "\n ASTROMETRY_RED intermed Pre-processed CCD-based images for ASTROMETRY input (if --saveimage=true)"
00121 "\n ASTROMETRY_RESAMPLED intermed Resampled 2D image for ASTROMETRY input (if --resample=true)"
00122 "\n PIXTABLE_ASTROMETRY intermed Output pixel table for ASTROMETRY input" "\n\nInput frames for raw frame tag \"REDUCED\":\n"
00123 "\n Frame tag Type Req #Fr Description"
00124 "\n -------------------- ---- --- --- ------------"
00125 "\n REDUCED raw Y Reduced CCD image"
00126 "\n TRACE_TABLE calib Y 1 Trace table"
00127 "\n WAVECAL_TABLE calib Y 1 Wavelength calibration table"
00128 "\n GEOMETRY_TABLE calib Y 1 Relative positions of the slices in the field of view"
00129 "\n\nProduct frames for raw frame tag \"REDUCED\":\n"
00130 "\n Frame tag Level Description"
00131 "\n -------------------- -------- ------------"
00132 "\n REDUCED_RESAMPLED intermed Resampled 2D image (if --resample=true)"
00133 "\n PIXTABLE_REDUCED intermed Output pixel table";
00134
00135
00143
00144 static cpl_recipeconfig *
00145 muse_scibasic_new_recipeconfig(void)
00146 {
00147 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
00148
00149 cpl_recipeconfig_set_tag(recipeconfig, "OBJECT", -1, -1);
00150 cpl_recipeconfig_set_input(recipeconfig, "OBJECT", "MASTER_BIAS", 1, 1);
00151 cpl_recipeconfig_set_input(recipeconfig, "OBJECT", "MASTER_DARK", -1, 1);
00152 cpl_recipeconfig_set_input(recipeconfig, "OBJECT", "MASTER_FLAT", 1, 1);
00153 cpl_recipeconfig_set_input(recipeconfig, "OBJECT", "TRACE_TABLE", 1, 1);
00154 cpl_recipeconfig_set_input(recipeconfig, "OBJECT", "WAVECAL_TABLE", 1, 1);
00155 cpl_recipeconfig_set_input(recipeconfig, "OBJECT", "GEOMETRY_TABLE", 1, 1);
00156 cpl_recipeconfig_set_input(recipeconfig, "OBJECT", "TWILIGHT_CUBE", -1, -1);
00157 cpl_recipeconfig_set_input(recipeconfig, "OBJECT", "BADPIX_TABLE", -1, 1);
00158 cpl_recipeconfig_set_output(recipeconfig, "OBJECT", "OBJECT_RED");
00159 cpl_recipeconfig_set_output(recipeconfig, "OBJECT", "OBJECT_RESAMPLED");
00160 cpl_recipeconfig_set_output(recipeconfig, "OBJECT", "PIXTABLE_OBJECT");
00161 cpl_recipeconfig_set_tag(recipeconfig, "STD", -1, -1);
00162 cpl_recipeconfig_set_input(recipeconfig, "STD", "MASTER_BIAS", 1, 1);
00163 cpl_recipeconfig_set_input(recipeconfig, "STD", "MASTER_DARK", -1, 1);
00164 cpl_recipeconfig_set_input(recipeconfig, "STD", "MASTER_FLAT", 1, 1);
00165 cpl_recipeconfig_set_input(recipeconfig, "STD", "TRACE_TABLE", 1, 1);
00166 cpl_recipeconfig_set_input(recipeconfig, "STD", "WAVECAL_TABLE", 1, 1);
00167 cpl_recipeconfig_set_input(recipeconfig, "STD", "GEOMETRY_TABLE", 1, 1);
00168 cpl_recipeconfig_set_input(recipeconfig, "STD", "TWILIGHT_CUBE", -1, -1);
00169 cpl_recipeconfig_set_input(recipeconfig, "STD", "BADPIX_TABLE", -1, 1);
00170 cpl_recipeconfig_set_output(recipeconfig, "STD", "STD_RED");
00171 cpl_recipeconfig_set_output(recipeconfig, "STD", "STD_RESAMPLED");
00172 cpl_recipeconfig_set_output(recipeconfig, "STD", "PIXTABLE_STD");
00173 cpl_recipeconfig_set_tag(recipeconfig, "SKY", -1, -1);
00174 cpl_recipeconfig_set_input(recipeconfig, "SKY", "MASTER_BIAS", 1, 1);
00175 cpl_recipeconfig_set_input(recipeconfig, "SKY", "MASTER_DARK", -1, 1);
00176 cpl_recipeconfig_set_input(recipeconfig, "SKY", "MASTER_FLAT", 1, 1);
00177 cpl_recipeconfig_set_input(recipeconfig, "SKY", "TRACE_TABLE", 1, 1);
00178 cpl_recipeconfig_set_input(recipeconfig, "SKY", "WAVECAL_TABLE", 1, 1);
00179 cpl_recipeconfig_set_input(recipeconfig, "SKY", "GEOMETRY_TABLE", 1, 1);
00180 cpl_recipeconfig_set_input(recipeconfig, "SKY", "TWILIGHT_CUBE", -1, -1);
00181 cpl_recipeconfig_set_input(recipeconfig, "SKY", "BADPIX_TABLE", -1, 1);
00182 cpl_recipeconfig_set_output(recipeconfig, "SKY", "SKY_RED");
00183 cpl_recipeconfig_set_output(recipeconfig, "SKY", "SKY_RESAMPLED");
00184 cpl_recipeconfig_set_output(recipeconfig, "SKY", "PIXTABLE_SKY");
00185 cpl_recipeconfig_set_tag(recipeconfig, "ASTROMETRY", -1, -1);
00186 cpl_recipeconfig_set_input(recipeconfig, "ASTROMETRY", "MASTER_BIAS", 1, 1);
00187 cpl_recipeconfig_set_input(recipeconfig, "ASTROMETRY", "MASTER_DARK", -1, 1);
00188 cpl_recipeconfig_set_input(recipeconfig, "ASTROMETRY", "MASTER_FLAT", 1, 1);
00189 cpl_recipeconfig_set_input(recipeconfig, "ASTROMETRY", "TRACE_TABLE", 1, 1);
00190 cpl_recipeconfig_set_input(recipeconfig, "ASTROMETRY", "WAVECAL_TABLE", 1, 1);
00191 cpl_recipeconfig_set_input(recipeconfig, "ASTROMETRY", "GEOMETRY_TABLE", 1, 1);
00192 cpl_recipeconfig_set_input(recipeconfig, "ASTROMETRY", "TWILIGHT_CUBE", -1, -1);
00193 cpl_recipeconfig_set_input(recipeconfig, "ASTROMETRY", "BADPIX_TABLE", -1, 1);
00194 cpl_recipeconfig_set_output(recipeconfig, "ASTROMETRY", "ASTROMETRY_RED");
00195 cpl_recipeconfig_set_output(recipeconfig, "ASTROMETRY", "ASTROMETRY_RESAMPLED");
00196 cpl_recipeconfig_set_output(recipeconfig, "ASTROMETRY", "PIXTABLE_ASTROMETRY");
00197 cpl_recipeconfig_set_tag(recipeconfig, "ILLUM", -1, 1);
00198 cpl_recipeconfig_set_input(recipeconfig, "ILLUM", "MASTER_BIAS", 1, 1);
00199 cpl_recipeconfig_set_input(recipeconfig, "ILLUM", "MASTER_DARK", -1, 1);
00200 cpl_recipeconfig_set_input(recipeconfig, "ILLUM", "MASTER_FLAT", 1, 1);
00201 cpl_recipeconfig_set_input(recipeconfig, "ILLUM", "TRACE_TABLE", 1, 1);
00202 cpl_recipeconfig_set_input(recipeconfig, "ILLUM", "WAVECAL_TABLE", 1, 1);
00203 cpl_recipeconfig_set_input(recipeconfig, "ILLUM", "GEOMETRY_TABLE", 1, 1);
00204 cpl_recipeconfig_set_input(recipeconfig, "ILLUM", "TWILIGHT_CUBE", -1, -1);
00205 cpl_recipeconfig_set_input(recipeconfig, "ILLUM", "BADPIX_TABLE", -1, 1);
00206
00207 cpl_recipeconfig_set_tag(recipeconfig, "REDUCED", 1, -1);
00208 cpl_recipeconfig_set_input(recipeconfig, "REDUCED", "TRACE_TABLE", 1, 1);
00209 cpl_recipeconfig_set_input(recipeconfig, "REDUCED", "WAVECAL_TABLE", 1, 1);
00210 cpl_recipeconfig_set_input(recipeconfig, "REDUCED", "GEOMETRY_TABLE", 1, 1);
00211 cpl_recipeconfig_set_output(recipeconfig, "REDUCED", "REDUCED_RESAMPLED");
00212 cpl_recipeconfig_set_output(recipeconfig, "REDUCED", "PIXTABLE_REDUCED");
00213
00214 return recipeconfig;
00215 }
00216
00217
00227
00228 static cpl_error_code
00229 muse_scibasic_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
00230 {
00231 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
00232 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
00233 if (!strcmp(aFrametag, "OBJECT_RED")) {
00234 muse_processing_prepare_property(aHeader, "ESO QC SCIBASIC NSATURATED",
00235 CPL_TYPE_INT,
00236 "Number of saturated pixels in output data");
00237 } else if (!strcmp(aFrametag, "OBJECT_RESAMPLED")) {
00238 } else if (!strcmp(aFrametag, "PIXTABLE_OBJECT")) {
00239 muse_processing_prepare_property(aHeader, "ESO QC SCIBASIC NSATURATED",
00240 CPL_TYPE_INT,
00241 "Number of saturated pixels in output data");
00242 muse_processing_prepare_property(aHeader, "ESO QC SCIBASIC LAMBDA SHIFT",
00243 CPL_TYPE_FLOAT,
00244 "[Angstrom] Shift in wavelength applied to the data using sky emission line(s)");
00245 } else if (!strcmp(aFrametag, "STD_RED")) {
00246 muse_processing_prepare_property(aHeader, "ESO QC SCIBASIC NSATURATED",
00247 CPL_TYPE_INT,
00248 "Number of saturated pixels in output data");
00249 } else if (!strcmp(aFrametag, "STD_RESAMPLED")) {
00250 } else if (!strcmp(aFrametag, "PIXTABLE_STD")) {
00251 muse_processing_prepare_property(aHeader, "ESO QC SCIBASIC NSATURATED",
00252 CPL_TYPE_INT,
00253 "Number of saturated pixels in output data");
00254 } else if (!strcmp(aFrametag, "SKY_RED")) {
00255 muse_processing_prepare_property(aHeader, "ESO QC SCIBASIC NSATURATED",
00256 CPL_TYPE_INT,
00257 "Number of saturated pixels in output data");
00258 } else if (!strcmp(aFrametag, "SKY_RESAMPLED")) {
00259 } else if (!strcmp(aFrametag, "PIXTABLE_SKY")) {
00260 muse_processing_prepare_property(aHeader, "ESO QC SCIBASIC NSATURATED",
00261 CPL_TYPE_INT,
00262 "Number of saturated pixels in output data");
00263 } else if (!strcmp(aFrametag, "ASTROMETRY_RED")) {
00264 muse_processing_prepare_property(aHeader, "ESO QC SCIBASIC NSATURATED",
00265 CPL_TYPE_INT,
00266 "Number of saturated pixels in output data");
00267 } else if (!strcmp(aFrametag, "ASTROMETRY_RESAMPLED")) {
00268 } else if (!strcmp(aFrametag, "PIXTABLE_ASTROMETRY")) {
00269 muse_processing_prepare_property(aHeader, "ESO QC SCIBASIC NSATURATED",
00270 CPL_TYPE_INT,
00271 "Number of saturated pixels in output data");
00272 } else if (!strcmp(aFrametag, "REDUCED_RESAMPLED")) {
00273 } else if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00274 } else {
00275 cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
00276 return CPL_ERROR_ILLEGAL_INPUT;
00277 }
00278 return CPL_ERROR_NONE;
00279 }
00280
00281
00290
00291 static cpl_frame_level
00292 muse_scibasic_get_frame_level(const char *aFrametag)
00293 {
00294 if (!aFrametag) {
00295 return CPL_FRAME_LEVEL_NONE;
00296 }
00297 if (!strcmp(aFrametag, "OBJECT_RED")) {
00298 return CPL_FRAME_LEVEL_INTERMEDIATE;
00299 }
00300 if (!strcmp(aFrametag, "OBJECT_RESAMPLED")) {
00301 return CPL_FRAME_LEVEL_INTERMEDIATE;
00302 }
00303 if (!strcmp(aFrametag, "PIXTABLE_OBJECT")) {
00304 return CPL_FRAME_LEVEL_INTERMEDIATE;
00305 }
00306 if (!strcmp(aFrametag, "STD_RED")) {
00307 return CPL_FRAME_LEVEL_INTERMEDIATE;
00308 }
00309 if (!strcmp(aFrametag, "STD_RESAMPLED")) {
00310 return CPL_FRAME_LEVEL_INTERMEDIATE;
00311 }
00312 if (!strcmp(aFrametag, "PIXTABLE_STD")) {
00313 return CPL_FRAME_LEVEL_INTERMEDIATE;
00314 }
00315 if (!strcmp(aFrametag, "SKY_RED")) {
00316 return CPL_FRAME_LEVEL_INTERMEDIATE;
00317 }
00318 if (!strcmp(aFrametag, "SKY_RESAMPLED")) {
00319 return CPL_FRAME_LEVEL_INTERMEDIATE;
00320 }
00321 if (!strcmp(aFrametag, "PIXTABLE_SKY")) {
00322 return CPL_FRAME_LEVEL_INTERMEDIATE;
00323 }
00324 if (!strcmp(aFrametag, "ASTROMETRY_RED")) {
00325 return CPL_FRAME_LEVEL_INTERMEDIATE;
00326 }
00327 if (!strcmp(aFrametag, "ASTROMETRY_RESAMPLED")) {
00328 return CPL_FRAME_LEVEL_INTERMEDIATE;
00329 }
00330 if (!strcmp(aFrametag, "PIXTABLE_ASTROMETRY")) {
00331 return CPL_FRAME_LEVEL_INTERMEDIATE;
00332 }
00333 if (!strcmp(aFrametag, "REDUCED_RESAMPLED")) {
00334 return CPL_FRAME_LEVEL_INTERMEDIATE;
00335 }
00336 if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00337 return CPL_FRAME_LEVEL_INTERMEDIATE;
00338 }
00339 return CPL_FRAME_LEVEL_NONE;
00340 }
00341
00342
00351
00352 static muse_frame_mode
00353 muse_scibasic_get_frame_mode(const char *aFrametag)
00354 {
00355 if (!aFrametag) {
00356 return MUSE_FRAME_MODE_ALL;
00357 }
00358 if (!strcmp(aFrametag, "OBJECT_RED")) {
00359 return MUSE_FRAME_MODE_DATEOBS;
00360 }
00361 if (!strcmp(aFrametag, "OBJECT_RESAMPLED")) {
00362 return MUSE_FRAME_MODE_DATEOBS;
00363 }
00364 if (!strcmp(aFrametag, "PIXTABLE_OBJECT")) {
00365 return MUSE_FRAME_MODE_DATEOBS;
00366 }
00367 if (!strcmp(aFrametag, "STD_RED")) {
00368 return MUSE_FRAME_MODE_DATEOBS;
00369 }
00370 if (!strcmp(aFrametag, "STD_RESAMPLED")) {
00371 return MUSE_FRAME_MODE_DATEOBS;
00372 }
00373 if (!strcmp(aFrametag, "PIXTABLE_STD")) {
00374 return MUSE_FRAME_MODE_DATEOBS;
00375 }
00376 if (!strcmp(aFrametag, "SKY_RED")) {
00377 return MUSE_FRAME_MODE_DATEOBS;
00378 }
00379 if (!strcmp(aFrametag, "SKY_RESAMPLED")) {
00380 return MUSE_FRAME_MODE_DATEOBS;
00381 }
00382 if (!strcmp(aFrametag, "PIXTABLE_SKY")) {
00383 return MUSE_FRAME_MODE_DATEOBS;
00384 }
00385 if (!strcmp(aFrametag, "ASTROMETRY_RED")) {
00386 return MUSE_FRAME_MODE_DATEOBS;
00387 }
00388 if (!strcmp(aFrametag, "ASTROMETRY_RESAMPLED")) {
00389 return MUSE_FRAME_MODE_DATEOBS;
00390 }
00391 if (!strcmp(aFrametag, "PIXTABLE_ASTROMETRY")) {
00392 return MUSE_FRAME_MODE_DATEOBS;
00393 }
00394 if (!strcmp(aFrametag, "REDUCED_RESAMPLED")) {
00395 return MUSE_FRAME_MODE_DATEOBS;
00396 }
00397 if (!strcmp(aFrametag, "PIXTABLE_REDUCED")) {
00398 return MUSE_FRAME_MODE_DATEOBS;
00399 }
00400 return MUSE_FRAME_MODE_ALL;
00401 }
00402
00403
00413
00414 static int
00415 muse_scibasic_create(cpl_plugin *aPlugin)
00416 {
00417
00418 cpl_recipe *recipe;
00419 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
00420 recipe = (cpl_recipe *)aPlugin;
00421 } else {
00422 return -1;
00423 }
00424
00425
00426
00427 muse_processinginfo_register(recipe,
00428 muse_scibasic_new_recipeconfig(),
00429 muse_scibasic_prepare_header,
00430 muse_scibasic_get_frame_level,
00431 muse_scibasic_get_frame_mode);
00432
00433
00434
00435 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
00436 cpl_msg_set_time_on();
00437 }
00438
00439
00440 recipe->parameters = cpl_parameterlist_new();
00441
00442 cpl_parameter *p;
00443
00444
00445 p = cpl_parameter_new_range("muse.muse_scibasic.nifu",
00446 CPL_TYPE_INT,
00447 "IFU to handle. If set to 0, all IFUs are processed serially. If set to -1, all IFUs are processed in parallel.",
00448 "muse.muse_scibasic",
00449 (int)0,
00450 (int)-1,
00451 (int)24);
00452 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "nifu");
00453 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "nifu");
00454
00455 cpl_parameterlist_append(recipe->parameters, p);
00456
00457
00458 p = cpl_parameter_new_value("muse.muse_scibasic.overscan",
00459 CPL_TYPE_STRING,
00460 "If this is \"none\", stop when detecting discrepant overscan levels (see ovscsigma), for \"offset\" it assumes that the mean overscan level represents the real offset in the bias levels of the exposures involved, and adjusts the data accordingly; for \"vpoly\", a polynomial is fit to the vertical overscan and subtracted from the whole quadrant.",
00461 "muse.muse_scibasic",
00462 (const char *)"vpoly");
00463 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "overscan");
00464 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "overscan");
00465
00466 cpl_parameterlist_append(recipe->parameters, p);
00467
00468
00469 p = cpl_parameter_new_value("muse.muse_scibasic.ovscreject",
00470 CPL_TYPE_STRING,
00471 "This influences how values are rejected when computing overscan statistics. Either no rejection at all (\"none\"), rejection using the DCR algorithm (\"dcr\"), or rejection using an iterative constant fit (\"fit\").",
00472 "muse.muse_scibasic",
00473 (const char *)"dcr");
00474 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "ovscreject");
00475 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ovscreject");
00476
00477 cpl_parameterlist_append(recipe->parameters, p);
00478
00479
00480 p = cpl_parameter_new_value("muse.muse_scibasic.ovscsigma",
00481 CPL_TYPE_DOUBLE,
00482 "If the deviation of mean overscan levels between a raw input image and the reference image is higher than |ovscsigma x stdev|, stop the processing. If overscan=\"vpoly\", this is used as sigma rejection level for the iterative polynomial fit (the level comparison is then done afterwards with |100 x stdev| to guard against incompatible settings). Has no effect for overscan=\"offset\".",
00483 "muse.muse_scibasic",
00484 (double)30.);
00485 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "ovscsigma");
00486 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ovscsigma");
00487
00488 cpl_parameterlist_append(recipe->parameters, p);
00489
00490
00491 p = cpl_parameter_new_value("muse.muse_scibasic.ovscignore",
00492 CPL_TYPE_INT,
00493 "The number of pixels of the overscan adjacent to the data region of the CCD that are ignored when computing statistics or fits.",
00494 "muse.muse_scibasic",
00495 (int)3);
00496 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "ovscignore");
00497 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ovscignore");
00498
00499 cpl_parameterlist_append(recipe->parameters, p);
00500
00501
00502 p = cpl_parameter_new_value("muse.muse_scibasic.crop",
00503 CPL_TYPE_BOOL,
00504 "Automatically crop the output pixel tables in wavelength depending on the expected useful wavelength range of the observation mode used (4750-9350 Angstrom for nominal mode, 4600-9350 Angstrom for extended mode).",
00505 "muse.muse_scibasic",
00506 (int)TRUE);
00507 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "crop");
00508 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "crop");
00509
00510 cpl_parameterlist_append(recipe->parameters, p);
00511
00512
00513 p = cpl_parameter_new_enum("muse.muse_scibasic.cr",
00514 CPL_TYPE_STRING,
00515 "Type of cosmic ray cleaning to use (for quick-look data processing).",
00516 "muse.muse_scibasic",
00517 (const char *)"none",
00518 2,
00519 (const char *)"none",
00520 (const char *)"dcr");
00521 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "cr");
00522 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "cr");
00523
00524 cpl_parameterlist_append(recipe->parameters, p);
00525
00526
00527 p = cpl_parameter_new_value("muse.muse_scibasic.xbox",
00528 CPL_TYPE_INT,
00529 "Search box size in x. Only used if cr=dcr.",
00530 "muse.muse_scibasic",
00531 (int)15);
00532 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "xbox");
00533 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "xbox");
00534
00535 cpl_parameterlist_append(recipe->parameters, p);
00536
00537
00538 p = cpl_parameter_new_value("muse.muse_scibasic.ybox",
00539 CPL_TYPE_INT,
00540 "Search box size in y. Only used if cr=dcr.",
00541 "muse.muse_scibasic",
00542 (int)40);
00543 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "ybox");
00544 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ybox");
00545
00546 cpl_parameterlist_append(recipe->parameters, p);
00547
00548
00549 p = cpl_parameter_new_value("muse.muse_scibasic.passes",
00550 CPL_TYPE_INT,
00551 "Maximum number of cleaning passes. Only used if cr=dcr.",
00552 "muse.muse_scibasic",
00553 (int)2);
00554 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "passes");
00555 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "passes");
00556
00557 cpl_parameterlist_append(recipe->parameters, p);
00558
00559
00560 p = cpl_parameter_new_value("muse.muse_scibasic.thres",
00561 CPL_TYPE_DOUBLE,
00562 "Threshold for detection gap in factors of standard deviation. Only used if cr=dcr.",
00563 "muse.muse_scibasic",
00564 (double)5.8);
00565 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "thres");
00566 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "thres");
00567
00568 cpl_parameterlist_append(recipe->parameters, p);
00569
00570
00571 p = cpl_parameter_new_enum("muse.muse_scibasic.combine",
00572 CPL_TYPE_STRING,
00573 "Type of combination to use. Note that in most cases, science exposures cannot easily be combined on the CCD level, so this should usually be kept as \"none\"! This does not pay attention about the type of input data, and will combine all raw inputs!",
00574 "muse.muse_scibasic",
00575 (const char *)"none",
00576 5,
00577 (const char *)"none",
00578 (const char *)"average",
00579 (const char *)"median",
00580 (const char *)"minmax",
00581 (const char *)"sigclip");
00582 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "combine");
00583 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "combine");
00584
00585 cpl_parameterlist_append(recipe->parameters, p);
00586
00587
00588 p = cpl_parameter_new_value("muse.muse_scibasic.nlow",
00589 CPL_TYPE_INT,
00590 "Number of minimum pixels to reject with minmax",
00591 "muse.muse_scibasic",
00592 (int)1);
00593 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "nlow");
00594 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "nlow");
00595
00596 cpl_parameterlist_append(recipe->parameters, p);
00597
00598
00599 p = cpl_parameter_new_value("muse.muse_scibasic.nhigh",
00600 CPL_TYPE_INT,
00601 "Number of maximum pixels to reject with minmax",
00602 "muse.muse_scibasic",
00603 (int)1);
00604 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "nhigh");
00605 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "nhigh");
00606
00607 cpl_parameterlist_append(recipe->parameters, p);
00608
00609
00610 p = cpl_parameter_new_value("muse.muse_scibasic.nkeep",
00611 CPL_TYPE_INT,
00612 "Number of pixels to keep with minmax",
00613 "muse.muse_scibasic",
00614 (int)1);
00615 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "nkeep");
00616 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "nkeep");
00617
00618 cpl_parameterlist_append(recipe->parameters, p);
00619
00620
00621 p = cpl_parameter_new_value("muse.muse_scibasic.lsigma",
00622 CPL_TYPE_DOUBLE,
00623 "Low sigma for pixel rejection with sigclip",
00624 "muse.muse_scibasic",
00625 (double)3);
00626 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "lsigma");
00627 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lsigma");
00628
00629 cpl_parameterlist_append(recipe->parameters, p);
00630
00631
00632 p = cpl_parameter_new_value("muse.muse_scibasic.hsigma",
00633 CPL_TYPE_DOUBLE,
00634 "High sigma for pixel rejection with sigclip",
00635 "muse.muse_scibasic",
00636 (double)3);
00637 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "hsigma");
00638 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "hsigma");
00639
00640 cpl_parameterlist_append(recipe->parameters, p);
00641
00642
00643 p = cpl_parameter_new_value("muse.muse_scibasic.scale",
00644 CPL_TYPE_BOOL,
00645 "Scale the individual images to a common exposure time before combining them.",
00646 "muse.muse_scibasic",
00647 (int)TRUE);
00648 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "scale");
00649 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "scale");
00650
00651 cpl_parameterlist_append(recipe->parameters, p);
00652
00653
00654 p = cpl_parameter_new_value("muse.muse_scibasic.saveimage",
00655 CPL_TYPE_BOOL,
00656 "Save the pre-processed CCD-based image of each input exposure before it is transformed into a pixel table.",
00657 "muse.muse_scibasic",
00658 (int)TRUE);
00659 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "saveimage");
00660 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "saveimage");
00661
00662 cpl_parameterlist_append(recipe->parameters, p);
00663
00664
00665 p = cpl_parameter_new_value("muse.muse_scibasic.skylines",
00666 CPL_TYPE_STRING,
00667 "List of wavelengths of sky emission lines (in Angstrom) to use as reference for wavelength offset correction using a Gaussian fit. It can contain multiple (isolated) lines, as comma-separated list, individual shifts are then combined into one weighted average offset. Set to \"none\" to deactivate.",
00668 "muse.muse_scibasic",
00669 (const char *)"5577.339,6300.304");
00670 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "skylines");
00671 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skylines");
00672
00673 cpl_parameterlist_append(recipe->parameters, p);
00674
00675
00676 p = cpl_parameter_new_value("muse.muse_scibasic.skyhalfwidth",
00677 CPL_TYPE_DOUBLE,
00678 "Half-width of the extraction box (in Angstrom) around each sky emission line.",
00679 "muse.muse_scibasic",
00680 (double)5.);
00681 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "skyhalfwidth");
00682 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skyhalfwidth");
00683
00684 cpl_parameterlist_append(recipe->parameters, p);
00685
00686
00687 p = cpl_parameter_new_value("muse.muse_scibasic.skybinsize",
00688 CPL_TYPE_DOUBLE,
00689 "Size of the bins (in Angstrom per pixel) for the intermediate spectrum to do the Gaussian fit to each sky emission line.",
00690 "muse.muse_scibasic",
00691 (double)0.1);
00692 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "skybinsize");
00693 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skybinsize");
00694
00695 cpl_parameterlist_append(recipe->parameters, p);
00696
00697
00698 p = cpl_parameter_new_value("muse.muse_scibasic.skyreject",
00699 CPL_TYPE_STRING,
00700 "Sigma clipping parameters for the intermediate spectrum to do the Gaussian fit to each sky emission line. Up to three comma-separated numbers can be given, which are interpreted as high sigma-clipping limit (float), low limit (float), and number of iterations (integer), respectively.",
00701 "muse.muse_scibasic",
00702 (const char *)"15.,15.,1");
00703 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "skyreject");
00704 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "skyreject");
00705
00706 cpl_parameterlist_append(recipe->parameters, p);
00707
00708
00709 p = cpl_parameter_new_value("muse.muse_scibasic.resample",
00710 CPL_TYPE_BOOL,
00711 "Resample the input science data into 2D spectral images using tracing and wavelength calibration solutions for a visual check. Note that the image produced will show small wiggles even when the input calibrations are good and were applied successfully!",
00712 "muse.muse_scibasic",
00713 (int)FALSE);
00714 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "resample");
00715 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "resample");
00716
00717 cpl_parameterlist_append(recipe->parameters, p);
00718
00719
00720 p = cpl_parameter_new_value("muse.muse_scibasic.dlambda",
00721 CPL_TYPE_DOUBLE,
00722 "Wavelength step (in Angstrom per pixel) to use for resampling.",
00723 "muse.muse_scibasic",
00724 (double)1.25);
00725 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "dlambda");
00726 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dlambda");
00727
00728 cpl_parameterlist_append(recipe->parameters, p);
00729
00730
00731 p = cpl_parameter_new_value("muse.muse_scibasic.merge",
00732 CPL_TYPE_BOOL,
00733 "Merge output products from different IFUs into a common file.",
00734 "muse.muse_scibasic",
00735 (int)FALSE);
00736 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG, "merge");
00737 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "merge");
00738
00739 cpl_parameterlist_append(recipe->parameters, p);
00740
00741 return 0;
00742 }
00743
00744
00755
00756 static int
00757 muse_scibasic_params_fill(muse_scibasic_params_t *aParams, cpl_parameterlist *aParameters)
00758 {
00759 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
00760 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
00761 cpl_parameter *p;
00762
00763 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.nifu");
00764 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00765 aParams->nifu = cpl_parameter_get_int(p);
00766
00767 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.overscan");
00768 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00769 aParams->overscan = cpl_parameter_get_string(p);
00770
00771 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.ovscreject");
00772 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00773 aParams->ovscreject = cpl_parameter_get_string(p);
00774
00775 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.ovscsigma");
00776 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00777 aParams->ovscsigma = cpl_parameter_get_double(p);
00778
00779 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.ovscignore");
00780 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00781 aParams->ovscignore = cpl_parameter_get_int(p);
00782
00783 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.crop");
00784 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00785 aParams->crop = cpl_parameter_get_bool(p);
00786
00787 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.cr");
00788 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00789 aParams->cr_s = cpl_parameter_get_string(p);
00790 aParams->cr =
00791 (!strcasecmp(aParams->cr_s, "none")) ? MUSE_SCIBASIC_PARAM_CR_NONE :
00792 (!strcasecmp(aParams->cr_s, "dcr")) ? MUSE_SCIBASIC_PARAM_CR_DCR :
00793 MUSE_SCIBASIC_PARAM_CR_INVALID_VALUE;
00794 cpl_ensure_code(aParams->cr != MUSE_SCIBASIC_PARAM_CR_INVALID_VALUE,
00795 CPL_ERROR_ILLEGAL_INPUT);
00796
00797 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.xbox");
00798 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00799 aParams->xbox = cpl_parameter_get_int(p);
00800
00801 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.ybox");
00802 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00803 aParams->ybox = cpl_parameter_get_int(p);
00804
00805 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.passes");
00806 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00807 aParams->passes = cpl_parameter_get_int(p);
00808
00809 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.thres");
00810 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00811 aParams->thres = cpl_parameter_get_double(p);
00812
00813 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.combine");
00814 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00815 aParams->combine_s = cpl_parameter_get_string(p);
00816 aParams->combine =
00817 (!strcasecmp(aParams->combine_s, "none")) ? MUSE_SCIBASIC_PARAM_COMBINE_NONE :
00818 (!strcasecmp(aParams->combine_s, "average")) ? MUSE_SCIBASIC_PARAM_COMBINE_AVERAGE :
00819 (!strcasecmp(aParams->combine_s, "median")) ? MUSE_SCIBASIC_PARAM_COMBINE_MEDIAN :
00820 (!strcasecmp(aParams->combine_s, "minmax")) ? MUSE_SCIBASIC_PARAM_COMBINE_MINMAX :
00821 (!strcasecmp(aParams->combine_s, "sigclip")) ? MUSE_SCIBASIC_PARAM_COMBINE_SIGCLIP :
00822 MUSE_SCIBASIC_PARAM_COMBINE_INVALID_VALUE;
00823 cpl_ensure_code(aParams->combine != MUSE_SCIBASIC_PARAM_COMBINE_INVALID_VALUE,
00824 CPL_ERROR_ILLEGAL_INPUT);
00825
00826 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.nlow");
00827 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00828 aParams->nlow = cpl_parameter_get_int(p);
00829
00830 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.nhigh");
00831 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00832 aParams->nhigh = cpl_parameter_get_int(p);
00833
00834 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.nkeep");
00835 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00836 aParams->nkeep = cpl_parameter_get_int(p);
00837
00838 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.lsigma");
00839 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00840 aParams->lsigma = cpl_parameter_get_double(p);
00841
00842 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.hsigma");
00843 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00844 aParams->hsigma = cpl_parameter_get_double(p);
00845
00846 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.scale");
00847 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00848 aParams->scale = cpl_parameter_get_bool(p);
00849
00850 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.saveimage");
00851 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00852 aParams->saveimage = cpl_parameter_get_bool(p);
00853
00854 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.skylines");
00855 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00856 aParams->skylines = cpl_parameter_get_string(p);
00857
00858 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.skyhalfwidth");
00859 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00860 aParams->skyhalfwidth = cpl_parameter_get_double(p);
00861
00862 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.skybinsize");
00863 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00864 aParams->skybinsize = cpl_parameter_get_double(p);
00865
00866 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.skyreject");
00867 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00868 aParams->skyreject = cpl_parameter_get_string(p);
00869
00870 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.resample");
00871 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00872 aParams->resample = cpl_parameter_get_bool(p);
00873
00874 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.dlambda");
00875 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00876 aParams->dlambda = cpl_parameter_get_double(p);
00877
00878 p = cpl_parameterlist_find(aParameters, "muse.muse_scibasic.merge");
00879 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
00880 aParams->merge = cpl_parameter_get_bool(p);
00881
00882 return 0;
00883 }
00884
00885
00892
00893 static int
00894 muse_scibasic_exec(cpl_plugin *aPlugin)
00895 {
00896 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
00897 return -1;
00898 }
00899 muse_processing_recipeinfo(aPlugin);
00900 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
00901 cpl_msg_set_threadid_on();
00902
00903 cpl_frameset *usedframes = cpl_frameset_new(),
00904 *outframes = cpl_frameset_new();
00905 muse_scibasic_params_t params;
00906 muse_scibasic_params_fill(¶ms, recipe->parameters);
00907
00908 cpl_errorstate prestate = cpl_errorstate_get();
00909
00910 if (params.nifu < -1 || params.nifu > kMuseNumIFUs) {
00911 cpl_msg_error(__func__, "Please specify a valid IFU number (between 1 and "
00912 "%d), 0 (to process all IFUs consecutively), or -1 (to "
00913 "process all IFUs in parallel) using --nifu.", kMuseNumIFUs);
00914 return -1;
00915 }
00916
00917 cpl_boolean donotmerge = CPL_FALSE;
00918 int rc = 0;
00919 if (params.nifu > 0) {
00920 muse_processing *proc = muse_processing_new("muse_scibasic",
00921 recipe);
00922 rc = muse_scibasic_compute(proc, ¶ms);
00923 cpl_frameset_join(usedframes, proc->usedframes);
00924 cpl_frameset_join(outframes, proc->outframes);
00925 muse_processing_delete(proc);
00926 donotmerge = CPL_TRUE;
00927 } else if (params.nifu < 0) {
00928 int *rcs = cpl_calloc(kMuseNumIFUs, sizeof(int));
00929 int nifu;
00930 #pragma omp parallel for default(none) \
00931 shared(outframes, params, rcs, recipe, usedframes)
00932 for (nifu = 1; nifu <= kMuseNumIFUs; nifu++) {
00933 muse_processing *proc = muse_processing_new("muse_scibasic",
00934 recipe);
00935 muse_scibasic_params_t *pars = cpl_malloc(sizeof(muse_scibasic_params_t));
00936 memcpy(pars, ¶ms, sizeof(muse_scibasic_params_t));
00937 pars->nifu = nifu;
00938 int *rci = rcs + (nifu - 1);
00939 *rci = muse_scibasic_compute(proc, pars);
00940 if (rci && (int)cpl_error_get_code() == MUSE_ERROR_CHIP_NOT_LIVE) {
00941 *rci = 0;
00942 }
00943 cpl_free(pars);
00944 #pragma omp critical(muse_processing_used_frames)
00945 cpl_frameset_join(usedframes, proc->usedframes);
00946 #pragma omp critical(muse_processing_output_frames)
00947 cpl_frameset_join(outframes, proc->outframes);
00948 muse_processing_delete(proc);
00949 }
00950
00951
00952 for (nifu = 1; nifu <= kMuseNumIFUs; nifu++) {
00953 if (rcs[nifu-1] != 0) {
00954 rc = rcs[nifu-1];
00955 }
00956 }
00957 cpl_free(rcs);
00958 } else {
00959 for (params.nifu = 1; params.nifu <= kMuseNumIFUs && !rc; params.nifu++) {
00960 muse_processing *proc = muse_processing_new("muse_scibasic",
00961 recipe);
00962 rc = muse_scibasic_compute(proc, ¶ms);
00963 if (rc && (int)cpl_error_get_code() == MUSE_ERROR_CHIP_NOT_LIVE) {
00964 rc = 0;
00965 }
00966 cpl_frameset_join(usedframes, proc->usedframes);
00967 cpl_frameset_join(outframes, proc->outframes);
00968 muse_processing_delete(proc);
00969 }
00970 }
00971 UNUSED_ARGUMENT(donotmerge);
00972
00973 if (!cpl_errorstate_is_equal(prestate)) {
00974
00975 cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
00976
00977 cpl_msg_set_level(CPL_MSG_INFO);
00978 }
00979
00980 muse_cplframeset_erase_duplicate(usedframes);
00981 muse_cplframeset_erase_duplicate(outframes);
00982
00983
00984 if (params.merge && !donotmerge) {
00985 muse_utils_frameset_merge_frames(outframes, CPL_TRUE);
00986 }
00987
00988
00989
00990
00991
00992 muse_cplframeset_erase_all(recipe->frames);
00993 cpl_frameset_join(recipe->frames, usedframes);
00994 cpl_frameset_join(recipe->frames, outframes);
00995 cpl_frameset_delete(usedframes);
00996 cpl_frameset_delete(outframes);
00997 return rc;
00998 }
00999
01000
01007
01008 static int
01009 muse_scibasic_destroy(cpl_plugin *aPlugin)
01010 {
01011
01012 cpl_recipe *recipe;
01013 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
01014 recipe = (cpl_recipe *)aPlugin;
01015 } else {
01016 return -1;
01017 }
01018
01019
01020 cpl_parameterlist_delete(recipe->parameters);
01021 muse_processinginfo_delete(recipe);
01022 return 0;
01023 }
01024
01025
01035
01036 int
01037 cpl_plugin_get_info(cpl_pluginlist *aList)
01038 {
01039 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
01040 cpl_plugin *plugin = &recipe->interface;
01041
01042 char *helptext;
01043 if (muse_cplframework() == MUSE_CPLFRAMEWORK_ESOREX) {
01044 helptext = cpl_sprintf("%s%s", muse_scibasic_help,
01045 muse_scibasic_help_esorex);
01046 } else {
01047 helptext = cpl_sprintf("%s", muse_scibasic_help);
01048 }
01049
01050
01051 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
01052 CPL_PLUGIN_TYPE_RECIPE,
01053 "muse_scibasic",
01054 "Remove the instrumental signature from the data of each CCD and convert them from an image into a pixel table.",
01055 helptext,
01056 "Peter Weilbacher",
01057 "usd-help@eso.org",
01058 muse_get_license(),
01059 muse_scibasic_create,
01060 muse_scibasic_exec,
01061 muse_scibasic_destroy);
01062 cpl_pluginlist_append(aList, plugin);
01063 cpl_free(helptext);
01064
01065 return 0;
01066 }
01067