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
00029
00030
00031 #include <strings.h>
00032 #include <string.h>
00033 #include <stdio.h>
00034
00035 #ifdef HAVE_CONFIG_H
00036 #include <config.h>
00037 #endif
00038 #include <cxmacros.h>
00039 #include <cxtypes.h>
00040 #include <cxmessages.h>
00041 #include <cpl_memory.h>
00042
00043 #include <cpl_parameterlist.h>
00044 #include <cpl_msg.h>
00045 #include <cpl_error.h>
00046 #include <cpl_image.h>
00047
00048 #include <cpl_recipe.h>
00049 #include <cpl_plugin.h>
00050 #include <cpl_pluginlist.h>
00051 #include <cpl_frameset.h>
00052 #include <sinfoni_pro_types.h>
00053 #include <sinfoni_raw_types.h>
00054 #include <sinfoni_globals.h>
00055 #include <sinfoni_key_names.h>
00056 #include <sinfoni_general_config.h>
00057 #include <sinfoni_bp_config.h>
00058 #include <sinfoni_bp_lin_config.h>
00059 #include <sinfoni_bp_noise_config.h>
00060 #include <sinfoni_dark_config.h>
00061 #include <sinfoni_lamp_flats_config.h>
00062 #include <sinfoni_bp_norm_config.h>
00063 #include <sinfoni_bp_dist_config.h>
00064 #include <sinfoni_prepare_stacked_frames_config.h>
00065 #include <sinfoni_find_distortions_config.h>
00066 #include <sinfoni_north_south_test_config.h>
00067 #include <sinfoni_wavecal_config.h>
00068 #include <sinfoni_memory.h>
00069
00070 #include <bp_lin.h>
00071 #include <bp_noise.h>
00072 #include <bp_norm.h>
00073 #include <dark.h>
00074 #include <lamp_flats.h>
00075 #include <add_bp_map.h>
00076 #include <prepare_stacked_frames.h>
00077 #include <find_distortions.h>
00078 #include <nst.h>
00079 #include <wave_cal_slit.h>
00080 #include <sinfoni_hidden.h>
00081
00082 #include <xmemory.h>
00083
00084
00085
00086 static cxint si_cdb_popul(cpl_parameterlist *, cpl_frameset *);
00087 const char * sinfoni_get_licence(void)
00088 {
00089 return "bla bla";
00090
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100 cxint
00101 si_cdb_popul_create(cpl_plugin *plugin)
00102 {
00103
00104
00105
00106
00107
00108
00109 cpl_recipe *recipe = (cpl_recipe *)plugin;
00110 recipe->parameters = cpl_parameterlist_new();
00111 if(recipe->parameters == NULL) {
00112 return 1;
00113 }
00114
00115
00116
00117
00118 sinfoni_general_config_add(recipe->parameters);
00119 sinfoni_bp_config_add(recipe->parameters);
00120
00121 sinfoni_bp_lin_config_add(recipe->parameters);
00122
00123 sinfoni_bp_noise_config_add(recipe->parameters);
00124 sinfoni_dark_config_add(recipe->parameters);
00125
00126 sinfoni_lamp_flats_config_add(recipe->parameters);
00127 sinfoni_bp_norm_config_add(recipe->parameters);
00128 sinfoni_bp_dist_config_add(recipe->parameters);
00129 sinfoni_prepare_stacked_frames_config_add(recipe->parameters);
00130 sinfoni_find_distortions_config_add(recipe->parameters);
00131 sinfoni_north_south_test_config_add(recipe->parameters);
00132
00133 sinfoni_wavecal_config_add(recipe->parameters);
00134
00135
00136 return 0;
00137
00138 }
00139
00140 cxint
00141 si_cdb_popul_exec(cpl_plugin *plugin)
00142 {
00143
00144 cpl_recipe *recipe = (cpl_recipe *) plugin;
00145 if(recipe->parameters == NULL) {
00146 return 1;
00147 }
00148 if(recipe->frames == NULL) {
00149 return 1;
00150 }
00151
00152 cpl_error_reset();
00153 return si_cdb_popul(recipe->parameters, recipe->frames);
00154
00155 }
00156
00157 cxint
00158 si_cdb_popul_destroy(cpl_plugin *plugin)
00159 {
00160
00161 cpl_recipe *recipe = (cpl_recipe *) plugin;
00162
00163
00164
00165
00166
00167
00168 cpl_parameterlist_delete(recipe->parameters);
00169
00170 return 0;
00171
00172 }
00173
00174
00175
00176 int
00177 cpl_plugin_get_info(cpl_pluginlist *list)
00178 {
00179
00180 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00181 cpl_plugin *plugin = &recipe->interface;
00182
00183
00184 cpl_plugin_init(plugin,
00185 CPL_PLUGIN_API,
00186 SINFONI_BINARY_VERSION,
00187 CPL_PLUGIN_TYPE_RECIPE,
00188 "si_cdb_popul",
00189 "CDB creation",
00190 "TBD",
00191 "A. Modigliani",
00192 "amodigli@eso.org",
00193 "No license",
00194 si_cdb_popul_create,
00195 si_cdb_popul_exec,
00196 si_cdb_popul_destroy);
00197
00198 cpl_pluginlist_append(list, plugin);
00199
00200 return 0;
00201
00202 }
00203
00204
00205
00206
00207
00208 static cxint
00209 si_cdb_popul(cpl_parameterlist *config, cpl_frameset *set)
00210 {
00211
00212 const cxchar *_id = "si_cdb_popul";
00213 int ind =0;
00214
00215 cpl_parameter *p;
00216 cpl_frame* frame=NULL;
00217 char* file_name=NULL;
00218 cpl_propertylist* plist=NULL;
00219 cpl_image* ima=NULL;
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 p = cpl_parameterlist_find(config,"sinfoni.bp.method");
00237 cpl_parameter_set_string(p,"Linear");
00238 {
00239
00240 if ( -1 == (ind = badSearchLin( config, set ) ) )
00241 {
00242 cpl_msg_error(_id,"badSearchLin(), no: %d\n", ind) ;
00243 xsinfoni_memory_status() ;
00244 return -1 ;
00245 }
00246 cpl_msg_info(_id,"success");
00247 }
00248
00249
00250
00251
00252
00253
00254
00255 p = cpl_parameterlist_find(config,"sinfoni.bp.method");
00256 cpl_parameter_set_string(p,"Noise");
00257
00258 {
00259 cpl_msg_info(_id,"Running");
00260 if ( -1 == (ind = badSearchNoise(config, set ) ) )
00261 {
00262 cpl_msg_error(_id,"badSearchNoise(), no: %d\n", ind) ;
00263 xsinfoni_memory_status() ;
00264 return -1 ;
00265 }
00266 cpl_msg_info(_id,"success");
00267 }
00268
00269
00270
00271
00272
00273
00274
00275 {
00276 cpl_msg_info(_id,"Running RECIPE dark...") ;
00277 if ( -1 == (ind = dark(config, set ) ) )
00278 {
00279 cpl_msg_error(_id,"dark(), no: %d\n", ind) ;
00280 return -1 ;
00281 }
00282 cpl_msg_info(_id,"RECIPE dark successfull") ;
00283 }
00284
00285
00286
00287
00288
00289
00290
00291 {
00292 cpl_msg_info (_id,"Running") ;
00293 if ( -1 == (ind = lamp_flats(config, set ) ) )
00294 {
00295 cpl_msg_error(_id,"no: %d\n", ind) ;
00296 return -1 ;
00297 }
00298
00299 cpl_msg_info (_id,"success") ;
00300 }
00301
00302
00303
00304
00305
00306
00307
00308 p = cpl_parameterlist_find(config,"sinfoni.bp.method");
00309 cpl_parameter_set_string(p,"Normal");
00310
00311
00312 {
00313 cpl_msg_info(_id,"Running");
00314 if ( -1 == (ind = badSearchNormal(config, set, PRO_BP_MAP_NO ) ) )
00315 {
00316 cpl_msg_error(_id,"badSearchNormal(), no: %d\n", ind) ;
00317 xsinfoni_memory_status() ;
00318 return -1 ;
00319 }
00320 cpl_msg_info(_id,"success");
00321 }
00322
00323
00324
00325
00326
00327
00328
00329
00330 {
00331 cpl_msg_info(_id,"Running");
00332 if ( -1 == (ind = add_bp_map(config, set) ) )
00333 {
00334 cpl_msg_error(_id,"add_bp_map(), no: %d\n", ind) ;
00335 xsinfoni_memory_status() ;
00336 return -1 ;
00337 }
00338 cpl_msg_info(_id,"success");
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 {
00356 cpl_msg_info (_id,"REDUCE LAMPFLAT\n") ;
00357 if ( -1 == (ind = lamp_flats(config, set ) ) )
00358 {
00359 cpl_msg_error(_id,"no: %d\n", ind) ;
00360 xsinfoni_memory_status() ;
00361 return -1 ;
00362 }
00363 cpl_msg_info (_id,"SUCCES: REDUCED LAMPFLAT\n") ;
00364
00365 }
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375 {
00376 cpl_msg_info(_id,"Running");
00377 if ( -1 == (ind = badSearchNormal(config, set, PRO_BP_MAP_DI ) ) )
00378 {
00379 cpl_msg_error(_id,"badSearchNormal(), no: %d\n", ind) ;
00380 xsinfoni_memory_status() ;
00381 return -1 ;
00382 }
00383 cpl_msg_info(_id,"success");
00384 }
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 {
00398
00399
00400 cpl_msg_info (_id,"STACK FIBRE,NS TO GET FAKE OFF\n") ;
00401
00402 strcpy(fk->pro_class,RAW_FIBRE_NS);
00403 fk->frm_switch=1;
00404 fk->mask_index=0;
00405 fk->ind_index=0;
00406 fk->flat_index=0;
00407 fk->wfix_index=0;
00408 fk->low_rej=0.0;
00409 fk->hig_rej=0.2;
00410
00411
00412 if ( -1 == (ind = prepare_stacked_frames(config, set,PRO_FIBRE_NS_STACKED_OFF,0,fk)))
00413 {
00414 cpl_msg_error(_id," no: %d\n", ind) ;
00415 fake_delete(fk);
00416 return -1 ;
00417 }
00418
00419 if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_OFF)) {
00420 frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_OFF);
00421 strcpy(file_name,cpl_frame_get_filename(frame));
00422 } else {
00423 cpl_msg_error(_id,"Frame %s not found!", PRO_FIBRE_NS_STACKED_OFF);
00424 fake_delete(fk);
00425 return -1;
00426 }
00427 ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
00428
00429
00430 if ((cpl_error_code)((plist = cpl_propertylist_load(file_name, 0)) == NULL)) {
00431 cpl_msg_error(_id, "getting header from reference ima frame %s",file_name);
00432 cpl_propertylist_delete(plist) ;
00433 fake_delete(fk);
00434 return -1 ;
00435 }
00436
00437 if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_HALO)) {
00438 cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_OFF);
00439 } else {
00440 cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_OFF) ;
00441 }
00442
00443
00444
00445
00446
00447
00448
00449
00450 cpl_propertylist_delete(plist);
00451 cpl_msg_info (_id,"SUCCESS DETERMINATION %s",PRO_FIBRE_NS_STACKED_OFF) ;
00452
00453 }
00454 cpl_image_delete(ima);
00455 sinfoni_memory_status();
00456
00457
00458
00459
00460
00461
00462
00463 {
00464
00465 cpl_msg_info (_id,"STACK FIBRE,NS TO GET FAKE ON\n") ;
00466
00467 strcpy(fk->pro_class,RAW_FIBRE_NS);
00468 fk->frm_switch=1;
00469 fk->mask_index=0;
00470 fk->ind_index=0;
00471 fk->flat_index=0;
00472 fk->wfix_index=0;
00473 fk->low_rej=0.0;
00474 fk->hig_rej=0.0;
00475
00476
00477 if ( -1 == (ind = prepare_stacked_frames(config, set, PRO_FIBRE_NS_STACKED_ON,0,fk)))
00478 {
00479 cpl_msg_error(_id," no: %d\n", ind) ;
00480 fake_delete(fk);
00481 return -1 ;
00482 }
00483 cpl_msg_info (_id,"SUCCESS DETERMINATION %s",PRO_FIBRE_NS_STACKED_ON) ;
00484 }
00485 sinfoni_memory_status();
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495 {
00496
00497 cpl_msg_info (_id,"COMBINES FAKE ON AND OFF\n") ;
00498
00499
00500 strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED);
00501 fk->frm_switch=1;
00502 fk->mask_index=0;
00503 fk->ind_index=0;
00504 fk->flat_index=1;
00505 fk->wfix_index=0;
00506 fk->low_rej=0.0;
00507 fk->hig_rej=0.0;
00508
00509
00510 if ( -1 == (ind = prepare_stacked_frames(config, set, PRO_FIBRE_NS_STACKED,0,fk)))
00511 {
00512 cpl_msg_error(_id," no: %d\n", ind) ;
00513 fake_delete(fk);
00514 return -1 ;
00515 }
00516 cpl_msg_info (_id,"SUCCESS DETERMINATION %s",PRO_FIBRE_NS_STACKED) ;
00517
00518 }
00519 sinfoni_memory_status();
00520
00521
00522
00523
00524
00525
00526
00527
00528 {
00529
00530 cpl_msg_info (_id,"STACK on WAVE frame\n") ;
00531
00532 strcpy(fk->pro_class,RAW_WAVE_NS);
00533 fk->frm_switch=1;
00534 fk->mask_index=0;
00535 fk->ind_index=0;
00536 fk->flat_index=1;
00537 fk->wfix_index=0;
00538 fk->low_rej=0.1;
00539 fk->hig_rej=0.1;
00540
00541 cpl_msg_info (_id,"STACK on WAVE frame\n") ;
00542 if ( -1 == (ind = prepare_stacked_frames(config, set, PRO_WAVE_LAMP_STACKED,0,fk)))
00543 {
00544 cpl_msg_error(_id," no: %d\n", ind) ;
00545 fake_delete(fk);
00546 return -1 ;
00547 }
00548 cpl_msg_info (_id,"SUCCESS DETERMINATION %s",PRO_WAVE_LAMP_STACKED) ;
00549 }
00550 sinfoni_memory_status();
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562 {
00563
00564 cpl_msg_info(_id,"COMPUTE DISTORTIONS\n") ;
00565 if ( -1 == (ind = find_distortions(config, set ) ) )
00566 {
00567 cpl_msg_error(_id,"step_distortion(), no: %d\n", ind) ;
00568 fake_delete(fk);
00569 return -1 ;
00570 }
00571
00572 if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED)) {
00573 frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED);
00574 strcpy(file_name,cpl_frame_get_filename(frame));
00575 } else {
00576 cpl_msg_error(_id,"Frame %s not found!", PRO_FIBRE_NS_STACKED);
00577 fake_delete(fk);
00578 return -1;
00579 }
00580 ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
00581
00582 if ((cpl_error_code)((plist = cpl_propertylist_load(file_name, 0)) == NULL)) {
00583 cpl_msg_error(_id, "getting header from reference ima frame %s",file_name);
00584 cpl_propertylist_delete(plist) ;
00585 fake_delete(fk);
00586 return -1 ;
00587 }
00588
00589 if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_HALO)) {
00590 cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
00591 } else {
00592 cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
00593 }
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606 cpl_propertylist_delete(plist);
00607 cpl_msg_info(_id,"SUCCESS: COMPUTED DISTORTIONS\n") ;
00608 }
00609 cpl_image_delete(ima);
00610 sinfoni_memory_status();
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620 {
00621 cpl_msg_info (_id,"DISTORT FAKE FRAME\n") ;
00622
00623 strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED_DIST);
00624 fk->frm_switch=1;
00625 fk->mask_index=1;
00626 fk->ind_index=1;
00627 fk->flat_index=0;
00628 fk->wfix_index=1;
00629 fk->low_rej=0.0;
00630 fk->hig_rej=0.0;
00631
00632
00633 if ( -1 == (ind = prepare_stacked_frames(config, set, PRO_FIBRE_NS_STACKED_DIST,0,fk)))
00634 {
00635 cpl_msg_error(_id," no: %d\n", ind) ;
00636 fake_delete(fk);
00637 return -1 ;
00638 }
00639 cpl_msg_info (_id,"SUCCESS: DISTORTED FAKE FRAME\n") ;
00640
00641
00642 if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST)) {
00643 frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST);
00644 strcpy(file_name,cpl_frame_get_filename(frame));
00645 } else {
00646 cpl_msg_error(_id,"Frame %s not found!", PRO_FIBRE_NS_STACKED_DIST);
00647 fake_delete(fk);
00648 return -1;
00649 }
00650 ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
00651
00652
00653
00654 if ((cpl_error_code)((plist = cpl_propertylist_load(file_name, 0)) == NULL)) {
00655 cpl_msg_error(_id, "getting header from reference ima frame %s",file_name);
00656 cpl_propertylist_delete(plist) ;
00657 fake_delete(fk);
00658 return -1 ;
00659 }
00660
00661 if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_HALO)) {
00662 cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
00663 } else {
00664 cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
00665 }
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677 cpl_propertylist_delete(plist);
00678 cpl_image_delete(ima);
00679
00680 cpl_msg_info(_id,"SUCCESS: COMPUTED DISTORTIONS\n") ;
00681 }
00682 sinfoni_memory_status();
00683
00684
00685
00686
00687
00688
00689
00690
00691 {
00692 cpl_msg_info (_id,"RUN NORD SUD TEST\n") ;
00693 if ( -1 == (ind = nst(config, set ) ) )
00694 {
00695 cpl_msg_error(_id,"no: %d\n", ind) ;
00696 fake_delete(fk);
00697 return -1 ;
00698 }
00699
00700 cpl_msg_info (_id,"SUCCESS: RUNNED NORD SUD TEST\n") ;
00701
00702 }
00703 cpl_msg_info (_id,"SUCCESS: RECIPE\n") ;
00704
00705
00706
00707
00708
00709
00710
00711
00712 {
00713 cpl_msg_info (_id,"running") ;
00714 if ( -1 == (ind = prepare_stacked_frames(config, set, PRO_WAVE_LAMP_STACKED,
00715 STACKED_OUT_FILENAME ) ) )
00716 {
00717 cpl_msg_error(_id," no: %d\n", ind) ;
00718 return -1 ;
00719 }
00720 cpl_msg_info (_id,"success") ;
00721 }
00722
00723
00724
00725
00726
00727 {
00728
00729 if ( -1 == (ind = wave_cal_slit(config, set ) ) )
00730 {
00731 cpl_msg_error(_id,"no: %d\n", ind) ;
00732 return -1 ;
00733 }
00734 cpl_msg_info(_id,"success");
00735 }
00736
00737
00738
00739 xsinfoni_memory_status() ;
00740 return 0 ;
00741
00742 }
00743
00744
00745