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
00052
00053
00054
00055
00056 #define NACO_XCORR_SX 10
00057 #define NACO_XCORR_SY 10
00058
00059
00060 #define NACO_PARAMETER_SET(MASK, VARNAME, TYPE, MAN, DEFAULT, SHORT) \
00061 if (bitmask & MASK) { \
00062 char * paramname = cpl_sprintf(PACKAGE ".%s.%s", recipe, VARNAME); \
00063 assert( paramname != NULL ); \
00064 \
00065 bitmask ^= MASK; \
00066 \
00067 p = cpl_parameter_new_value(paramname, TYPE, MAN, context, DEFAULT); \
00068 \
00069 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, SHORT); \
00070 \
00071 cpl_free(paramname); \
00072 \
00073 paramname = cpl_sprintf("%s_%s", recipe, VARNAME); \
00074 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, paramname); \
00075 cpl_free(paramname); \
00076 \
00077 cpl_parameterlist_append(self, p); \
00078 \
00079 }
00080
00081
00082 #define NACO_PARAMETER_GET_BOOL(MASK, VARNAME) \
00083 if (bitmask & MASK) { \
00084 value = irplib_parameterlist_get_bool(self, PACKAGE, recipe, VARNAME); \
00085 \
00086 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), CPL_FALSE); \
00087 \
00088 nbits++; \
00089 bitmask ^= MASK; \
00090 \
00091 }
00092
00093
00094 #define NACO_PARAMETER_GET_INT(MASK, VARNAME) \
00095 if (bitmask & MASK) { \
00096 value = irplib_parameterlist_get_int(self, PACKAGE, recipe, VARNAME); \
00097 \
00098 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), 0); \
00099 \
00100 nbits++; \
00101 bitmask ^= MASK; \
00102 \
00103 }
00104
00105
00106 #define NACO_PARAMETER_GET_DOUBLE(MASK, VARNAME) \
00107 if (bitmask & MASK) { \
00108 value = irplib_parameterlist_get_double(self, PACKAGE, recipe, VARNAME); \
00109 \
00110 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), 0.0); \
00111 \
00112 nbits++; \
00113 bitmask ^= MASK; \
00114 \
00115 }
00116
00117
00118 #define NACO_PARAMETER_GET_STRING(MASK, VARNAME) \
00119 if (bitmask & MASK) { \
00120 value = irplib_parameterlist_get_string(self, PACKAGE, recipe, VARNAME); \
00121 \
00122 cpl_ensure(value != NULL, cpl_error_get_code(), NULL); \
00123 \
00124 nbits++; \
00125 bitmask ^= MASK; \
00126 \
00127 }
00128
00129
00130
00136
00137
00141
00150
00151 cpl_error_code naco_parameter_set(cpl_parameterlist * self,
00152 const char * recipe,
00153 naco_parameter bitmask)
00154 {
00155
00156 cpl_parameter * p;
00157 char * context;
00158
00159
00160 cpl_ensure_code(self, CPL_ERROR_NULL_INPUT);
00161 cpl_ensure_code(recipe, CPL_ERROR_NULL_INPUT);
00162
00163
00164 context = cpl_sprintf(PACKAGE ".%s", recipe);
00165
00166
00167 NACO_PARAMETER_SET(NACO_PARAM_XTMAX, "extract_max", CPL_TYPE_INT,
00168 "Stop the spectrum extraction at this column", 1024,
00169 "xtmax");
00170
00171
00172 NACO_PARAMETER_SET(NACO_PARAM_XTMIN, "extract_min", CPL_TYPE_INT,
00173 "Start the spectrum extraction at this column", 1,
00174 "xtmin");
00175
00176
00177 NACO_PARAMETER_SET(NACO_PARAM_SAVE, "save", CPL_TYPE_INT,
00178 "A positive value causes additional, intermediate "
00179 "products to be saved", 0, "save");
00180
00181
00182 NACO_PARAMETER_SET(NACO_PARAM_PLOT, "plot", CPL_TYPE_INT,
00183 irplib_plot_manpage, 0, "plot");
00184
00185
00186 NACO_PARAMETER_SET(NACO_PARAM_STAR_R, "star_r", CPL_TYPE_DOUBLE,
00187 "The star radius [arcsecond]",
00188 STREHL_STAR_RADIUS, "star_r");
00189
00190
00191 NACO_PARAMETER_SET(NACO_PARAM_BG_RINT, "bg_r1", CPL_TYPE_DOUBLE,
00192 "The internal radius of the background [arcsecond]",
00193 STREHL_BACKGROUND_R1, "bg_r1");
00194
00195
00196 NACO_PARAMETER_SET(NACO_PARAM_BG_REXT, "bg_r2", CPL_TYPE_DOUBLE,
00197 "The external radius of the background [arcsecond]",
00198 STREHL_BACKGROUND_R2, "bg_r2");
00199
00200
00201 NACO_PARAMETER_SET(NACO_PARAM_REJBORD, "rej_bord", CPL_TYPE_STRING,
00202 "Rejected left right bottom and top border [pixel]",
00203 "200 200 200 200", "r");
00204
00205
00206 NACO_PARAMETER_SET(NACO_PARAM_HOT_LIM, "hot_threshold", CPL_TYPE_DOUBLE,
00207 "Hot pixel map threshold", 10.0, "hot_t");
00208
00209
00210 NACO_PARAMETER_SET(NACO_PARAM_COLD_LIM, "cold_threshold", CPL_TYPE_DOUBLE,
00211 "Cold pixel map threshold", 6.0, "cold_t");
00212
00213
00214 NACO_PARAMETER_SET(NACO_PARAM_DEV_LIM, "dev_threshold", CPL_TYPE_DOUBLE,
00215 "Deviant pixel map threshold", 5.0, "dev_t");
00216
00217
00218 NACO_PARAMETER_SET(NACO_PARAM_NSAMPLES, "nsamples", CPL_TYPE_INT,
00219 "Number of samples for RON computation", 100,
00220 "nsamples");
00221
00222
00223 NACO_PARAMETER_SET(NACO_PARAM_HALFSIZE, "hsize", CPL_TYPE_INT,
00224 "Half size of the window for RON computation", 2,
00225 "hsize");
00226
00227
00228 NACO_PARAMETER_SET(NACO_PARAM_FORCE, "force", CPL_TYPE_BOOL,
00229 "Force the computation", FALSE, "force");
00230
00231
00232 NACO_PARAMETER_SET(NACO_PARAM_SLIT_W, "slit_width", CPL_TYPE_INT,
00233 "Slit width", 20, "slit_w");
00234
00235
00236 NACO_PARAMETER_SET(NACO_PARAM_BPMTHRES, "thresholds", CPL_TYPE_STRING,
00237 "Low and high thresholds for the Bad Pixel Map",
00238 "0.5 2.0", "t");
00239
00240
00241 NACO_PARAMETER_SET(NACO_PARAM_PROPFIT, "proport", CPL_TYPE_BOOL,
00242 "Use the proportional fit", FALSE, "prop");
00243
00244
00245 NACO_PARAMETER_SET(NACO_PARAM_BPM, "bpm", CPL_TYPE_BOOL,
00246 "Create the bad pixel map", FALSE, "bpm");
00247
00248
00249 NACO_PARAMETER_SET(NACO_PARAM_ERRORMAP, "errmap", CPL_TYPE_BOOL,
00250 "Create the error map", FALSE, "errmap");
00251
00252
00253 NACO_PARAMETER_SET(NACO_PARAM_INTCEPT, "intercept", CPL_TYPE_BOOL,
00254 "Create the intercept image", FALSE, "intercept");
00255
00256
00257 NACO_PARAMETER_SET(NACO_PARAM_RA, "ra", CPL_TYPE_DOUBLE,
00258 "Right Ascension [Degrees]", 999.0, "ra");
00259
00260
00261 NACO_PARAMETER_SET(NACO_PARAM_DEC, "dec", CPL_TYPE_DOUBLE,
00262 "DEClination [Degrees]", 999.0, "dec");
00263
00264
00265 NACO_PARAMETER_SET(NACO_PARAM_PIXSCALE, "pscale", CPL_TYPE_DOUBLE,
00266 "Pixel scale", -1.0, "pscale");
00267
00268
00269 NACO_PARAMETER_SET(NACO_PARAM_MAGNITD, "mag", CPL_TYPE_DOUBLE,
00270 "Magnitude", IRPLIB_STDSTAR_NOMAG, "mag");
00271
00272
00273 NACO_PARAMETER_SET(NACO_PARAM_SX, "sx", CPL_TYPE_INT,
00274 "Size of the search window in X-direction [pixel]",
00275 NACO_XCORR_SX, "sx");
00276
00277
00278 NACO_PARAMETER_SET(NACO_PARAM_SY, "sy", CPL_TYPE_INT,
00279 "Size of the search window in Y-direction [pixel]",
00280 NACO_XCORR_SY, "sy");
00281
00282
00283 NACO_PARAMETER_SET(NACO_PARAM_CHK_IMG, "check_im", CPL_TYPE_BOOL,
00284 "Create the check image", FALSE, "check_im");
00285
00286
00287
00288 NACO_PARAMETER_SET(NACO_PARAM_OFFSETS, "offsets", CPL_TYPE_STRING,
00289 "offsets file", NULL, "off");
00290
00291
00292 NACO_PARAMETER_SET(NACO_PARAM_OBJECTS, "objects", CPL_TYPE_STRING,
00293 "objects file", NULL, "objs");
00294
00295
00296 NACO_PARAMETER_SET(NACO_PARAM_ODDEVEN, "oddeven", CPL_TYPE_BOOL,
00297 "Apply the odd-even correction. Warning: This flag "
00298 "currently has no effect", CPL_FALSE, "oddeven");
00299
00300
00301 NACO_PARAMETER_SET(NACO_PARAM_XCORR, "xcorr", CPL_TYPE_STRING,
00302 "Cross correlation search and measure sizes",
00303 "40 40 65 65", "xcorr");
00304
00305
00306 NACO_PARAMETER_SET(NACO_PARAM_UNION, "union", CPL_TYPE_BOOL,
00307 "Create the union of the frames", CPL_TRUE, "union");
00308
00309
00310 NACO_PARAMETER_SET(NACO_PARAM_REJ_HILO, "rej", CPL_TYPE_STRING,
00311 "Low and high number of rejected values", "2 2", "rej");
00312
00313 cpl_free(context);
00314
00315 cpl_ensure_code(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE);
00316
00317 return CPL_ERROR_NONE;
00318 }
00319
00320
00330
00331 cpl_boolean naco_parameterlist_get_bool(const cpl_parameterlist * self,
00332 const char * recipe,
00333 naco_parameter bitmask)
00334 {
00335
00336 int nbits = 0;
00337 cpl_boolean value = CPL_FALSE;
00338
00339
00340 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), CPL_FALSE);
00341 cpl_ensure(self, CPL_ERROR_NULL_INPUT, CPL_FALSE);
00342 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, CPL_FALSE);
00343
00344
00345 NACO_PARAMETER_GET_BOOL(NACO_PARAM_FORCE, "force");
00346
00347
00348 NACO_PARAMETER_GET_BOOL(NACO_PARAM_PROPFIT, "proport");
00349
00350
00351 NACO_PARAMETER_GET_BOOL(NACO_PARAM_BPM, "bpm");
00352
00353
00354 NACO_PARAMETER_GET_BOOL(NACO_PARAM_ERRORMAP, "errmap");
00355
00356
00357 NACO_PARAMETER_GET_BOOL(NACO_PARAM_INTCEPT, "intercept");
00358
00359
00360 NACO_PARAMETER_GET_BOOL(NACO_PARAM_CHK_IMG, "check_im");
00361
00362
00363 NACO_PARAMETER_GET_BOOL(NACO_PARAM_ODDEVEN, "oddeven");
00364
00365
00366 NACO_PARAMETER_GET_BOOL(NACO_PARAM_UNION, "union");
00367
00368 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, CPL_FALSE);
00369 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, CPL_FALSE);
00370
00371 return value;
00372
00373 }
00374
00375
00385
00386 int naco_parameterlist_get_int(const cpl_parameterlist * self,
00387 const char * recipe,
00388 naco_parameter bitmask)
00389 {
00390
00391 int nbits = 0;
00392 int value = 0;
00393
00394
00395 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), 0);
00396 cpl_ensure(self, CPL_ERROR_NULL_INPUT, 0);
00397 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, 0);
00398
00399
00400
00401
00402
00403 NACO_PARAMETER_GET_INT(NACO_PARAM_XTMAX, "extract_max");
00404
00405
00406 NACO_PARAMETER_GET_INT(NACO_PARAM_XTMIN, "extract_min");
00407
00408
00409 NACO_PARAMETER_GET_INT(NACO_PARAM_SAVE, "save");
00410
00411
00412 NACO_PARAMETER_GET_INT(NACO_PARAM_PLOT, "plot");
00413
00414
00415 NACO_PARAMETER_GET_INT(NACO_PARAM_NSAMPLES, "nsamples");
00416
00417
00418 NACO_PARAMETER_GET_INT(NACO_PARAM_HALFSIZE, "hsize");
00419
00420
00421 NACO_PARAMETER_GET_INT(NACO_PARAM_SX, "sx");
00422
00423
00424 NACO_PARAMETER_GET_INT(NACO_PARAM_SY, "sy");
00425
00426
00427 NACO_PARAMETER_GET_INT(NACO_PARAM_SLIT_W, "slit_width");
00428
00429 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, 0);
00430 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, 0);
00431
00432 return value;
00433
00434 }
00435
00436
00446
00447 double naco_parameterlist_get_double(const cpl_parameterlist * self,
00448 const char * recipe,
00449 naco_parameter bitmask)
00450 {
00451
00452 int nbits = 0;
00453 double value = DBL_MAX;
00454
00455
00456 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), 0.0);
00457 cpl_ensure(self, CPL_ERROR_NULL_INPUT, 0.0);
00458 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, 0.0);
00459
00460
00461
00462 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_STAR_R, "star_r");
00463
00464
00465 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_BG_RINT, "bg_r1");
00466
00467
00468 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_BG_REXT, "bg_r2");
00469
00470
00471
00472 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_HOT_LIM, "hot_threshold");
00473
00474
00475 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_COLD_LIM, "cold_threshold");
00476
00477
00478 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_DEV_LIM, "dev_threshold");
00479
00480
00481 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_RA, "ra");
00482
00483
00484 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_DEC, "dec");
00485
00486
00487 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_PIXSCALE, "pscale");
00488
00489
00490 NACO_PARAMETER_GET_DOUBLE(NACO_PARAM_MAGNITD, "mag");
00491
00492
00493 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, 0.0);
00494 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, 0.0);
00495
00496 return value;
00497
00498 }
00499
00500
00509
00510 const char * naco_parameterlist_get_string(const cpl_parameterlist * self,
00511 const char * recipe,
00512 naco_parameter bitmask)
00513 {
00514
00515 int nbits = 0;
00516 const char * value = NULL;
00517
00518
00519 cpl_ensure(self, CPL_ERROR_NULL_INPUT, NULL);
00520 cpl_ensure(recipe, CPL_ERROR_NULL_INPUT, NULL);
00521
00522
00523
00524 NACO_PARAMETER_GET_STRING(NACO_PARAM_REJBORD, "rej_bord");
00525
00526
00527 NACO_PARAMETER_GET_STRING(NACO_PARAM_BPMTHRES, "thresholds");
00528
00529
00530 NACO_PARAMETER_GET_STRING(NACO_PARAM_OFFSETS, "offsets");
00531
00532
00533 NACO_PARAMETER_GET_STRING(NACO_PARAM_OBJECTS, "objects");
00534
00535
00536 NACO_PARAMETER_GET_STRING(NACO_PARAM_XCORR, "xcorr");
00537
00538
00539 NACO_PARAMETER_GET_STRING(NACO_PARAM_REJ_HILO, "rej");
00540
00541 cpl_ensure(bitmask == 0, CPL_ERROR_UNSUPPORTED_MODE, NULL);
00542 cpl_ensure(nbits == 1, CPL_ERROR_ILLEGAL_INPUT, NULL);
00543
00544 assert(value != NULL);
00545
00546 return value;
00547
00548 }
00549