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 #include <string.h>
00033 #include <math.h>
00034 #include <cpl.h>
00035 #include <moses.h>
00036 #include <fors_dfs.h>
00037
00038 static int fors_config_create(cpl_plugin *);
00039 static int fors_config_exec(cpl_plugin *);
00040 static int fors_config_destroy(cpl_plugin *);
00041 static int fors_config(cpl_parameterlist *, cpl_frameset *);
00042
00043 static char fors_config_description[] =
00044 "This recipe is used to create the so-called GRISM_TABLE, containing all\n"
00045 "the FORS spectral pipeline configuration parameters related to a specific\n"
00046 "grism. This is a way to provide for each specific instrument mode a set of\n"
00047 "appropriate defaults for the recipe parameters.\n"
00048 "The values assigned to each input parameter of fors_config are simply\n"
00049 "copied to a FITS table consisting of one row, and as many columns as the\n"
00050 "input parameter: each column will have the same name and type of each\n"
00051 "parameter. Only the three parameters \"instrument\", \"grism\", and\n"
00052 "\"id\" are not written to the table columns, but to the descriptor header\n"
00053 "keywords INSTRUME, ESO INS GRIS1 NAME, and ESO INS GRIS1 ID, that will be\n"
00054 "used by the automatic pipeline for appropriate data association.\n\n"
00055 "Input files: none\n\n"
00056 " DO category: Type: Explanation: Required:\n"
00057 "Output files:\n\n"
00058 " DO category: Data type: Explanation:\n"
00059 " GRISM_TABLE FITS table Recipe configuration parameters\n\n";
00060
00061 #define fors_config_exit(message) \
00062 { \
00063 if (message) cpl_msg_error(recipe, message); \
00064 cpl_table_delete(table); \
00065 cpl_propertylist_delete(header); \
00066 cpl_free(filename); \
00067 return -1; \
00068 }
00069
00070
00082 int cpl_plugin_get_info(cpl_pluginlist *list)
00083 {
00084 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe );
00085 cpl_plugin *plugin = &recipe->interface;
00086
00087 cpl_plugin_init(plugin,
00088 CPL_PLUGIN_API,
00089 FORS_BINARY_VERSION,
00090 CPL_PLUGIN_TYPE_RECIPE,
00091 "fors_config",
00092 "Creation of FORS recipes configuration tables",
00093 fors_config_description,
00094 "Carlo Izzo",
00095 PACKAGE_BUGREPORT,
00096 "This file is currently part of the FORS Instrument Pipeline\n"
00097 "Copyright (C) 2002-2010 European Southern Observatory\n\n"
00098 "This program is free software; you can redistribute it and/or modify\n"
00099 "it under the terms of the GNU General Public License as published by\n"
00100 "the Free Software Foundation; either version 2 of the License, or\n"
00101 "(at your option) any later version.\n\n"
00102 "This program is distributed in the hope that it will be useful,\n"
00103 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00104 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00105 "GNU General Public License for more details.\n\n"
00106 "You should have received a copy of the GNU General Public License\n"
00107 "along with this program; if not, write to the Free Software Foundation,\n"
00108 "Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n",
00109 fors_config_create,
00110 fors_config_exec,
00111 fors_config_destroy);
00112
00113 cpl_pluginlist_append(list, plugin);
00114
00115 return 0;
00116 }
00117
00118
00129 static int fors_config_create(cpl_plugin *plugin)
00130 {
00131 cpl_recipe *recipe;
00132 cpl_parameter *p;
00133
00134
00135
00136
00137
00138
00139 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00140 recipe = (cpl_recipe *)plugin;
00141 else
00142 return -1;
00143
00144
00145
00146
00147
00148 recipe->parameters = cpl_parameterlist_new();
00149
00150
00151
00152
00153
00154
00155 p = cpl_parameter_new_value("fors.fors_config.dispersion",
00156 CPL_TYPE_DOUBLE,
00157 "Expected spectral dispersion (Angstrom/pixel)",
00158 "fors.fors_config",
00159 0.0);
00160 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dispersion");
00161 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00162 cpl_parameterlist_append(recipe->parameters, p);
00163
00164
00165
00166
00167
00168 p = cpl_parameter_new_value("fors.fors_config.peakdetection",
00169 CPL_TYPE_DOUBLE,
00170 "Peak detection threshold (ADU)",
00171 "fors.fors_config",
00172 250.0);
00173 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "peakdetection");
00174 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00175 cpl_parameterlist_append(recipe->parameters, p);
00176
00177
00178
00179
00180
00181 p = cpl_parameter_new_value("fors.fors_config.wdegree",
00182 CPL_TYPE_INT,
00183 "Degree of wavelength calibration polynomial",
00184 "fors.fors_config",
00185 4);
00186 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wdegree");
00187 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00188 cpl_parameterlist_append(recipe->parameters, p);
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 p = cpl_parameter_new_value("fors.fors_config.cdegree",
00245 CPL_TYPE_INT,
00246 "Degree of spectral curvature polynomial",
00247 "fors.fors_config",
00248 4);
00249 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "cdegree");
00250 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00251 cpl_parameterlist_append(recipe->parameters, p);
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 p = cpl_parameter_new_value("fors.fors_config.startwavelength",
00273 CPL_TYPE_DOUBLE,
00274 "Start wavelength in spectral extraction",
00275 "fors.fors_config",
00276 0.0);
00277 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "startwavelength");
00278 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00279 cpl_parameterlist_append(recipe->parameters, p);
00280
00281
00282
00283
00284
00285 p = cpl_parameter_new_value("fors.fors_config.endwavelength",
00286 CPL_TYPE_DOUBLE,
00287 "End wavelength in spectral extraction",
00288 "fors.fors_config",
00289 0.0);
00290 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "endwavelength");
00291 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00292 cpl_parameterlist_append(recipe->parameters, p);
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 p = cpl_parameter_new_value("fors.fors_config.instrument",
00399 CPL_TYPE_STRING,
00400 "Name of instrument",
00401 "fors.fors_config",
00402 "0");
00403 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "instrument");
00404 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00405 cpl_parameterlist_append(recipe->parameters, p);
00406
00407
00408
00409
00410
00411 p = cpl_parameter_new_value("fors.fors_config.grism",
00412 CPL_TYPE_STRING,
00413 "Name of grism",
00414 "fors.fors_config",
00415 "0");
00416 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "grism");
00417 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00418 cpl_parameterlist_append(recipe->parameters, p);
00419
00420
00421
00422
00423
00424 p = cpl_parameter_new_value("fors.fors_config.grism_id",
00425 CPL_TYPE_STRING,
00426 "Grism ID",
00427 "fors.fors_config",
00428 "0");
00429 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "grism_id");
00430 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00431 cpl_parameterlist_append(recipe->parameters, p);
00432
00433
00434
00435
00436
00437 p = cpl_parameter_new_value("fors.fors_config.filter",
00438 CPL_TYPE_STRING,
00439 "Name of filter",
00440 "fors.fors_config",
00441 "0");
00442 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "filter");
00443 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00444 cpl_parameterlist_append(recipe->parameters, p);
00445
00446
00447
00448
00449
00450 p = cpl_parameter_new_value("fors.fors_config.filter_id",
00451 CPL_TYPE_STRING,
00452 "Filter ID",
00453 "fors.fors_config",
00454 "0");
00455 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "filter_id");
00456 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00457 cpl_parameterlist_append(recipe->parameters, p);
00458
00459 return 0;
00460 }
00461
00462
00471 static int fors_config_exec(cpl_plugin *plugin)
00472 {
00473 cpl_recipe *recipe;
00474
00475 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00476 recipe = (cpl_recipe *)plugin;
00477 else
00478 return -1;
00479
00480 return fors_config(recipe->parameters, recipe->frames);
00481 }
00482
00483
00492 static int fors_config_destroy(cpl_plugin *plugin)
00493 {
00494 cpl_recipe *recipe;
00495
00496 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00497 recipe = (cpl_recipe *)plugin;
00498 else
00499 return -1;
00500
00501 cpl_parameterlist_delete(recipe->parameters);
00502
00503 return 0;
00504 }
00505
00506
00516 static int fors_config(cpl_parameterlist *parlist, cpl_frameset *frameset)
00517 {
00518
00519 const char *recipe = "fors_config";
00520
00521
00522
00523
00524
00525
00526 double dispersion;
00527 double peakdetection;
00528 int wdegree;
00529 int cdegree;
00530 double startwavelength;
00531 double endwavelength;
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 const char *instrument;
00546 const char *grism;
00547 const char *grism_id;
00548 const char *filter;
00549 const char *filter_id;
00550
00551 char *filename = NULL;
00552
00553
00554
00555
00556
00557 cpl_table *table = NULL;
00558 cpl_propertylist *header = NULL;
00559
00560
00561
00562
00563
00564 int len;
00565
00566
00567 if (frameset){}
00568
00569
00570
00571
00572
00573 cpl_msg_info(recipe, "Recipe %s configuration parameters:", recipe);
00574 cpl_msg_indent_more();
00575
00576 table = cpl_table_new(1);
00577
00578 dispersion = dfs_get_parameter_double(parlist,
00579 "fors.fors_config.dispersion", NULL);
00580
00581 if (dispersion <= 0.0)
00582 fors_config_exit("Invalid spectral dispersion value");
00583
00584 cpl_table_new_column(table, "dispersion", CPL_TYPE_DOUBLE);
00585 cpl_table_set_double(table, "dispersion", 0, dispersion);
00586
00587 peakdetection = dfs_get_parameter_double(parlist,
00588 "fors.fors_config.peakdetection", NULL);
00589 if (peakdetection <= 0.0)
00590 fors_config_exit("Invalid peak detection level");
00591
00592 cpl_table_new_column(table, "peakdetection", CPL_TYPE_DOUBLE);
00593 cpl_table_set_double(table, "peakdetection", 0, peakdetection);
00594
00595 wdegree = dfs_get_parameter_int(parlist, "fors.fors_config.wdegree", NULL);
00596
00597 if (wdegree < 1)
00598 fors_config_exit("Invalid polynomial degree");
00599
00600 if (wdegree > 5)
00601 fors_config_exit("Max allowed polynomial degree is 5");
00602
00603 cpl_table_new_column(table, "wdegree", CPL_TYPE_INT);
00604 cpl_table_set_int(table, "wdegree", 0, wdegree);
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634 cdegree = dfs_get_parameter_int(parlist, "fors.fors_config.cdegree", NULL);
00635
00636 if (cdegree < 1)
00637 fors_config_exit("Invalid polynomial degree");
00638
00639 if (cdegree > 5)
00640 fors_config_exit("Max allowed polynomial degree is 5");
00641
00642 cpl_table_new_column(table, "cdegree", CPL_TYPE_INT);
00643 cpl_table_set_int(table, "cdegree", 0, cdegree);
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653 startwavelength = dfs_get_parameter_double(parlist,
00654 "fors.fors_config.startwavelength", NULL);
00655 if (startwavelength > 1.0)
00656 if (startwavelength < 3000.0 || startwavelength > 13000.0)
00657 fors_config_exit("Invalid wavelength");
00658
00659 cpl_table_new_column(table, "startwavelength", CPL_TYPE_DOUBLE);
00660 cpl_table_set_double(table, "startwavelength", 0, startwavelength);
00661
00662 endwavelength = dfs_get_parameter_double(parlist,
00663 "fors.fors_config.endwavelength", NULL);
00664 if (endwavelength > 1.0)
00665 if (endwavelength < 3000.0 || endwavelength > 13000.0)
00666 fors_config_exit("Invalid wavelength");
00667
00668 if (startwavelength > 1.0 && endwavelength > 1.0)
00669 if (endwavelength - startwavelength <= 0.0)
00670 fors_config_exit("Invalid wavelength interval");
00671
00672 cpl_table_new_column(table, "endwavelength", CPL_TYPE_DOUBLE);
00673 cpl_table_set_double(table, "endwavelength", 0, endwavelength);
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714 header = cpl_propertylist_new();
00715
00716 instrument = dfs_get_parameter_string(parlist,
00717 "fors.fors_config.instrument", NULL);
00718 cpl_propertylist_update_string(header, "INSTRUME", instrument);
00719
00720 grism = dfs_get_parameter_string(parlist, "fors.fors_config.grism", NULL);
00721 cpl_propertylist_update_string(header, "ESO INS GRIS1 NAME", grism);
00722
00723 grism_id = dfs_get_parameter_string(parlist,
00724 "fors.fors_config.grism_id", NULL);
00725 cpl_propertylist_update_string(header, "ESO INS GRIS1 ID", grism_id);
00726
00727 filter = dfs_get_parameter_string(parlist, "fors.fors_config.filter", NULL);
00728 cpl_propertylist_update_string(header, "ESO INS FILT1 NAME", filter);
00729
00730 filter_id = dfs_get_parameter_string(parlist,
00731 "fors.fors_config.filter_id", NULL);
00732 cpl_propertylist_update_string(header, "ESO INS FILT1 ID", filter_id);
00733
00734 if (cpl_error_get_code())
00735 fors_config_exit("Failed to get the configuration parameters");
00736
00737 cpl_propertylist_update_string(header, "ESO PRO CATG", "GRISM_TABLE");
00738
00739 len = 14;
00740 len += strlen(instrument);
00741 len += strlen(grism + 5);
00742 len += strlen(grism_id);
00743 len += strlen(filter);
00744 len += strlen(filter_id);
00745
00746 filename = cpl_calloc(len, sizeof(char));
00747
00748 sprintf(filename, "%s_GRS_%s_%s_%s_%s.fits",
00749 instrument, grism + 5, grism_id+1, filter, filter_id+1);
00750
00751 cpl_table_save(table, header, NULL, filename, CPL_IO_DEFAULT);
00752 cpl_propertylist_delete(header); header = NULL;
00753 cpl_table_delete(table); table = NULL;
00754 cpl_free(filename); filename = NULL;
00755
00756 if (cpl_error_get_code()) {
00757 cpl_msg_error(cpl_error_get_where(), cpl_error_get_message());
00758 fors_config_exit(NULL);
00759 }
00760 else
00761 return 0;
00762 }