00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include <string.h>
00037 #include <math.h>
00038 #include <float.h>
00039 #include <assert.h>
00040 #include <cpl.h>
00041
00042 #include <irplib_stdstar.h>
00043
00044 #include "irplib_tools.h"
00045 #include "irplib_utils.h"
00046
00047 #include "irplib_plot.h"
00048
00049 #include "naco_parameter.h"
00050 #include "naco_dfs.h"
00051 #include "naco_pfits.h"
00052
00053
00054
00055
00056
00057 #define NACO_XCORR_SX 10
00058 #define NACO_XCORR_SY 10
00059
00060
00061 #define NACO_PARAMETER_SET(MASK, VARNAME, TYPE, MAN, DEFAULT, SHORT) \
00062 if (bitmask & MASK) { \
00063 char * paramname = cpl_sprintf(PACKAGE ".%s." VARNAME, recipe); \
00064 \
00065 p = cpl_parameter_new_value(paramname, TYPE, MAN, context, DEFAULT); \
00066 cpl_free(paramname); \
00067 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, SHORT); \
00068 cpl_parameterlist_append(self, p); \
00069 \
00070 if (cpl_error_get_code()) \
00071 (void)cpl_error_set_where(cpl_func); \
00072 \
00073 bitmask ^= MASK; \
00074 \
00075 \
00076 if (chkmask & MASK) \
00077 (void)cpl_error_set(cpl_func, CPL_ERROR_UNSPECIFIED); \
00078 chkmask |= MASK; \
00079 \
00080 }
00081
00082
00083 #define NACO_PARAMETER_GET_BOOL(MASK, VARNAME) \
00084 if (bitmask & MASK) { \
00085 value = irplib_parameterlist_get_bool(self, PACKAGE, recipe, VARNAME); \
00086 \
00087 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), CPL_FALSE); \
00088 \
00089 nbits++; \
00090 bitmask ^= MASK; \
00091 \
00092 }
00093
00094
00095 #define NACO_PARAMETER_GET_INT(MASK, VARNAME) \
00096 if (bitmask & MASK) { \
00097 value = irplib_parameterlist_get_int(self, PACKAGE, recipe, VARNAME); \
00098 \
00099 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), 0); \
00100 \
00101 nbits++; \
00102 bitmask ^= MASK; \
00103 \
00104 }
00105
00106
00107 #define NACO_PARAMETER_GET_DOUBLE(MASK, VARNAME) \
00108 if (bitmask & MASK) { \
00109 value = irplib_parameterlist_get_double(self, PACKAGE, recipe, VARNAME); \
00110 \
00111 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), 0.0); \
00112 \
00113 nbits++; \
00114 bitmask ^= MASK; \
00115 \
00116 }
00117
00118
00119 #define NACO_PARAMETER_GET_STRING(MASK, VARNAME) \
00120 if (bitmask & MASK) { \
00121 value = irplib_parameterlist_get_string(self, PACKAGE, recipe, VARNAME); \
00122 \
00123 cpl_ensure(value != NULL, cpl_error_get_code(), NULL); \
00124 \
00125 nbits++; \
00126 bitmask ^= MASK; \
00127 \
00128 }
00129
00130
00131
00137
00138
00142
00151
00152 cpl_error_code naco_parameter_set(cpl_parameterlist * self,
00153 const char * recipe,
00154 naco_parameter bitmask)
00155 {
00156
00157 cpl_parameter * p;
00158 char * context;
00159 naco_parameter chkmask = 0;
00160
00161
00162 cpl_ensure_code(self, CPL_ERROR_NULL_INPUT);
00163 cpl_ensure_code(recipe, CPL_ERROR_NULL_INPUT);
00164
00165
00166 context = cpl_sprintf(PACKAGE ".%s", recipe);
00167
00168
00169 NACO_PARAMETER_SET(NACO_PARAM_XTMAX, "extract_max", CPL_TYPE_INT,
00170 "Stop the spectrum extraction at this column", 1024,
00171 "xtmax");
00172
00173
00174 NACO_PARAMETER_SET(NACO_PARAM_XTMIN, "extract_min", CPL_TYPE_INT,
00175 "Start the spectrum extraction at this column", 1,
00176 "xtmin");
00177
00178
00179 NACO_PARAMETER_SET(NACO_PARAM_SAVE, "save", CPL_TYPE_INT,
00180 "A positive value causes additional, intermediate "
00181 "products to be saved", 0, "save");
00182
00183
00184 NACO_PARAMETER_SET(NACO_PARAM_PLOT, "plot", CPL_TYPE_INT,
00185 irplib_plot_manpage, 0, "plot");
00186
00187
00188 NACO_PARAMETER_SET(NACO_PARAM_STAR_R, "star_r", CPL_TYPE_DOUBLE,
00189 "The star radius [arcsecond]",
00190 STREHL_STAR_RADIUS, "star_r");
00191
00192
00193 NACO_PARAMETER_SET(NACO_PARAM_BG_RINT, "bg_r1", CPL_TYPE_DOUBLE,
00194 "The internal radius of the background [arcsecond]",
00195 STREHL_BACKGROUND_R1, "bg_r1");
00196
00197
00198 NACO_PARAMETER_SET(NACO_PARAM_BG_REXT, "bg_r2", CPL_TYPE_DOUBLE,
00199 "The external radius of the background [arcsecond]",
00200 STREHL_BACKGROUND_R2, "bg_r2");
00201
00202
00203 NACO_PARAMETER_SET(NACO_PARAM_REJBORD, "rej_bord", CPL_TYPE_STRING,
00204 "Rejected left right bottom and top border [pixel]",
00205 "200 200 200 200", "r");
00206
00207
00208 NACO_PARAMETER_SET(NACO_PARAM_HOT_LIM, "hot_threshold", CPL_TYPE_DOUBLE,
00209 "Hot pixel map threshold", 10.0, "hot_t");
00210
00211
00212 NACO_PARAMETER_SET(NACO_PARAM_COLD_LIM, "cold_threshold", CPL_TYPE_DOUBLE,
00213 "Cold pixel map threshold", 6.0, "cold_t");
00214
00215
00216 NACO_PARAMETER_SET(NACO_PARAM_DEV_LIM, "dev_threshold", CPL_TYPE_DOUBLE,
00217 "Deviant pixel map threshold", 5.0, "dev_t");
00218
00219
00220 NACO_PARAMETER_SET(NACO_PARAM_NSAMPLES, "nsamples", CPL_TYPE_INT,
00221 "Number of samples for RON computation", 100,
00222 "nsamples");
00223
00224
00225 NACO_PARAMETER_SET(NACO_PARAM_HALFSIZE, "hsize", CPL_TYPE_INT,
00226 "Half size of the window for RON computation", 2,
00227 "hsize");
00228
00229
00230 NACO_PARAMETER_SET(NACO_PARAM_FORCE, "force", CPL_TYPE_BOOL,
00231 "Force the computation", FALSE, "force");
00232
00233
00234 NACO_PARAMETER_SET(NACO_PARAM_SLIT_W, "slit_width", CPL_TYPE_INT,
00235 "Slit width", 20, "slit_w");
00236
00237
00238 NACO_PARAMETER_SET(NACO_PARAM_BPMTHRES, "thresholds", CPL_TYPE_STRING,
00239 "Low and high thresholds for the Bad Pixel Map",
00240 "0.5 2.0", "t");
00241
00242
00243 NACO_PARAMETER_SET(NACO_PARAM_PROPFIT, "proport", CPL_TYPE_BOOL,
00244 "Use the proportional fit", FALSE, "prop");
00245
00246
00247 NACO_PARAMETER_SET(NACO_PARAM_BPM, "bpm", CPL_TYPE_BOOL,
00248 "Create the bad pixel map", FALSE, "bpm");
00249
00250
00251 NACO_PARAMETER_SET(NACO_PARAM_ERRORMAP, "errmap", CPL_TYPE_BOOL,
00252 "Create the error map", FALSE, "errmap");
00253
00254
00255 NACO_PARAMETER_SET(NACO_PARAM_INTCEPT, "intercept", CPL_TYPE_BOOL,
00256 "Create the intercept image", FALSE, "intercept");
00257
00258
00259 NACO_PARAMETER_SET(NACO_PARAM_RA, "ra", CPL_TYPE_DOUBLE,
00260 "Right Ascension [Degrees]", 999.0, "ra");
00261
00262
00263 NACO_PARAMETER_SET(NACO_PARAM_DEC, "dec", CPL_TYPE_DOUBLE,
00264 "DEClination [Degrees]", 999.0, "dec");
00265
00266
00267 NACO_PARAMETER_SET(NACO_PARAM_PIXSCALE, "pscale", CPL_TYPE_DOUBLE,
00268 "Pixel scale", -1.0, "pscale");
00269
00270
00271 NACO_PARAMETER_SET(NACO_PARAM_MAGNITD, "mag", CPL_TYPE_DOUBLE,
00272 "Magnitude", IRPLIB_STDSTAR_NOMAG, "mag");
00273
00274
00275 NACO_PARAMETER_SET(NACO_PARAM_SX, "sx", CPL_TYPE_INT,
00276 "Size of the search window in X-direction [pixel]",
00277 NACO_XCORR_SX, "sx");
00278
00279
00280 NACO_PARAMETER_SET(NACO_PARAM_SY, "sy", CPL_TYPE_INT,
00281 "Size of the search window in Y-direction [pixel]",
00282 NACO_XCORR_SY, "sy");
00283
00284
00285 NACO_PARAMETER_SET(NACO_PARAM_CHK_IMG, "check_im", CPL_TYPE_BOOL,
00286 "Create the check image", FALSE, "check_im");
00287
00288
00289
00290 NACO_PARAMETER_SET(NACO_PARAM_OFFSETS, "offsets", CPL_TYPE_STRING,
00291 "An optional ASCII specification of the offsets "
00292 "in case those in FITS-headers are missing or wrong. "
00293 "The file must consist of one line per object FITS-"
00294 "file and each line must consist of two "
00295 "numbers which represent the shift in pixels of that "
00296 "image relative to the first image. The first line "
00297 "should thus comprise two zeros. Correct FITS-header "
00298 "offsets mean that the i'th X offset can be gotten "
00299 "from Xoffset_0 - Xoffset_i, where Xoffset_i is the "
00300 "value of " NACO_PFITS_DOUBLE_CUMOFFSETX " and "
00301 "likewise for Y.", NULL, "off");
00302
00303
00304 NACO_PARAMETER_SET(NACO_PARAM_OBJECTS, "objects", CPL_TYPE_STRING,
00305 "objects file", NULL, "objs");
00306
00307
00308 NACO_PARAMETER_SET(NACO_PARAM_ODDEVEN, "oddeven", CPL_TYPE_BOOL,
00309 "Apply the odd-even correction. Warning: This flag "
00310 "currently has no effect", CPL_FALSE, "oddeven");
00311
00312
00313 NACO_PARAMETER_SET(NACO_PARAM_XCORR, "xcorr", CPL_TYPE_STRING,
00314 "Cross correlation search and measure sizes",
00315 "40 40 65 65", "xcorr");
00316
00317
00318 NACO_PARAMETER_SET(NACO_PARAM_UNION, "union", CPL_TYPE_BOOL,
00319 "Combine images using their union, as opposed to their "
00320 "intersection (deprecated and ignored, "
00321 "see --combine_method)", TRUE, "union");
00322
00323
00324 NACO_PARAMETER_SET(NACO_PARAM_REJ_HILO, "rej", CPL_TYPE_STRING,
00325 "Low and high number of rejected values", "2 2", "rej");
00326
00327
00328
00329
00330 NACO_PARAMETER_SET(NACO_PARAM_COMBINE, "comb_meth", CPL_TYPE_STRING,
00331 "Combine images using one of: 1) Onto the first image "
00332 "(first); 2) Their union (union); 3) Their intersection"
00333 " (inter). NB: Only the 'first'-method produces an "
00334 "image product with WCS coordinates. A successful "
00335 "'first'-method always produces a combined image with "
00336 "dimensions equal to those of the input images. "
00337 "For the 'union'-method the result image is at least "
00338 "as large as the input images while for the 'inter'-"
00339 "method the result image is at most as large as the "
00340 "input images", "union", "combine_method");
00341
00342
00343 NACO_PARAMETER_SET(NACO_PARAM_SKYPLANE, "sky_planes", CPL_TYPE_INT,
00344 "Estimate the sky using the median of the last n planes "
00345 "in the previous cube and the first n planes in the "
00346 "following cube. If the cube has less than n planes "
00347 "then use all planes. Zero means all. (Ignored for non-"
00348 "cube data)", 25, "sky_planes");
00349
00350
00351 NACO_PARAMETER_SET(NACO_PARAM_CUBEMODE, "cube_mode", CPL_TYPE_STRING,
00352 "Collapse cube data using one of: 1) No recentering "
00353 "(add); 2) Shift-and-Add (saa). (Ignored for non-"
00354 "cube data)", "saa", "cube_mode");
00355
00356
00357 NACO_PARAMETER_SET(NACO_PARAM_LUCK_STR, "lucky_strehl", CPL_TYPE_DOUBLE,
00358 "In cube mode use only the frames with a strehl ratio "
00359 "in the given top fraction. (Ignored for non-"
00360 "cube data)", 1.0, "lucky");
00361
00362 cpl_free(context);
00363
00364 cpl_ensure_code(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE);
00365
00366
00367 return cpl_error_set_where(cpl_func);
00368 }
00369
00370
00380
00381 cpl_boolean naco_parameterlist_get_bool(const cpl_parameterlist * self,
00382 const char * recipe,
00383 naco_parameter bitmask)
00384 {
00385
00386 int nbits = 0;
00387 cpl_boolean value = CPL_FALSE;
00388
00389
00390 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), CPL_FALSE);
00391 cpl_ensure(self, CPL_ERROR_NULL_INPUT, CPL_FALSE);
00392 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, CPL_FALSE);
00393
00394
00395 NACO_PARAMETER_GET_BOOL(NACO_PARAM_FORCE, "force");
00396
00397
00398 NACO_PARAMETER_GET_BOOL(NACO_PARAM_PROPFIT, "proport");
00399
00400
00401 NACO_PARAMETER_GET_BOOL(NACO_PARAM_BPM, "bpm");
00402
00403
00404 NACO_PARAMETER_GET_BOOL(NACO_PARAM_ERRORMAP, "errmap");
00405
00406
00407 NACO_PARAMETER_GET_BOOL(NACO_PARAM_INTCEPT, "intercept");
00408
00409
00410 NACO_PARAMETER_GET_BOOL(NACO_PARAM_CHK_IMG, "check_im");
00411
00412
00413 NACO_PARAMETER_GET_BOOL(NACO_PARAM_ODDEVEN, "oddeven");
00414
00415 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, CPL_FALSE);
00416 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, CPL_FALSE);
00417
00418 return value;
00419
00420 }
00421
00422
00432
00433 int naco_parameterlist_get_int(const cpl_parameterlist * self,
00434 const char * recipe,
00435 naco_parameter bitmask)
00436 {
00437
00438 int nbits = 0;
00439 int value = 0;
00440
00441
00442 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), 0);
00443 cpl_ensure(self, CPL_ERROR_NULL_INPUT, 0);
00444 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, 0);
00445
00446
00447
00448
00449
00450 NACO_PARAMETER_GET_INT(NACO_PARAM_XTMAX, "extract_max");
00451
00452
00453 NACO_PARAMETER_GET_INT(NACO_PARAM_XTMIN, "extract_min");
00454
00455
00456 NACO_PARAMETER_GET_INT(NACO_PARAM_SAVE, "save");
00457
00458
00459 NACO_PARAMETER_GET_INT(NACO_PARAM_PLOT, "plot");
00460
00461
00462 NACO_PARAMETER_GET_INT(NACO_PARAM_NSAMPLES, "nsamples");
00463
00464
00465 NACO_PARAMETER_GET_INT(NACO_PARAM_HALFSIZE, "hsize");
00466
00467
00468 NACO_PARAMETER_GET_INT(NACO_PARAM_SX, "sx");
00469
00470
00471 NACO_PARAMETER_GET_INT(NACO_PARAM_SY, "sy");
00472
00473
00474 NACO_PARAMETER_GET_INT(NACO_PARAM_SLIT_W, "slit_width");
00475
00476
00477 NACO_PARAMETER_GET_INT(NACO_PARAM_SKYPLANE, "sky_planes");
00478
00479 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, 0);
00480 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, 0);
00481
00482 return value;
00483
00484 }
00485
00486
00496
00497 double naco_parameterlist_get_double(const cpl_parameterlist * self,
00498 const char * recipe,
00499 naco_parameter bitmask)
00500 {
00501
00502 int nbits = 0;
00503 double value = DBL_MAX;
00504
00505
00506 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), 0.0);
00507 cpl_ensure(self, CPL_ERROR_NULL_INPUT, 0.0);
00508 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, 0.0);
00509
00510
00511
00512 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_STAR_R, "star_r");
00513
00514
00515 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_BG_RINT, "bg_r1");
00516
00517
00518 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_BG_REXT, "bg_r2");
00519
00520
00521
00522 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_HOT_LIM, "hot_threshold");
00523
00524
00525 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_COLD_LIM, "cold_threshold");
00526
00527
00528 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_DEV_LIM, "dev_threshold");
00529
00530
00531 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_RA, "ra");
00532
00533
00534 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_DEC, "dec");
00535
00536
00537 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_PIXSCALE, "pscale");
00538
00539
00540 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_MAGNITD, "mag");
00541
00542
00543 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_LUCK_STR, "lucky_strehl");
00544
00545
00546 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, 0.0);
00547 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, 0.0);
00548
00549 return value;
00550
00551 }
00552
00553
00562
00563 const char * naco_parameterlist_get_string(const cpl_parameterlist * self,
00564 const char * recipe,
00565 naco_parameter bitmask)
00566 {
00567
00568 int nbits = 0;
00569 const char * value = NULL;
00570 const cpl_boolean is_combine
00571 = bitmask & NACO_PARAM_COMBINE ? CPL_TRUE : CPL_FALSE;
00572
00573 cpl_ensure(self, CPL_ERROR_NULL_INPUT, NULL);
00574 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, NULL);
00575
00576
00577
00578 NACO_PARAMETER_GET_STRING(NACO_PARAM_REJBORD, "rej_bord");
00579
00580
00581 NACO_PARAMETER_GET_STRING(NACO_PARAM_BPMTHRES, "thresholds");
00582
00583
00584 NACO_PARAMETER_GET_STRING(NACO_PARAM_OFFSETS, "offsets");
00585
00586
00587 NACO_PARAMETER_GET_STRING(NACO_PARAM_OBJECTS, "objects");
00588
00589
00590 NACO_PARAMETER_GET_STRING(NACO_PARAM_XCORR, "xcorr");
00591
00592
00593 NACO_PARAMETER_GET_STRING(NACO_PARAM_REJ_HILO, "rej");
00594
00595
00596 NACO_PARAMETER_GET_STRING(NACO_PARAM_COMBINE, "comb_meth");
00597
00598
00599 NACO_PARAMETER_GET_STRING(NACO_PARAM_CUBEMODE, "cube_mode");
00600
00601
00602 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, NULL);
00603 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, NULL);
00604
00605 assert(value != NULL);
00606
00607
00608 if (is_combine)
00609 cpl_ensure(strcmp(value, "first") == 0 || strcmp(value, "union") == 0 ||
00610 strcmp(value, "intersect") == 0, CPL_ERROR_UNSUPPORTED_MODE,
00611 NULL);
00612
00613 return value;
00614 }
00615