00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023
00024
00025
00026
00027
00028
00029 #include <irplib_detmon_lg.h>
00030
00031
00032 #include <math.h>
00033
00034
00035
00036
00037
00038
00039 #define PI 3.141592653
00040
00041
00042
00043
00044 #ifndef IMAGESIZE
00045 #define IMAGESIZE 64
00046 #endif
00047
00048 #define IMAGELISTSIZE 10
00049
00050 #define NBADPIXS 10
00051
00052 #define ON_LEVEL 300.0
00053 #define OFF_LEVEL 100.0
00054
00055 #define NOISE_MIN 10.0
00056 #define NOISE_MAX 40.0
00057
00058 #define ON TRUE
00059 #define OFF FALSE
00060
00061
00062
00063
00064
00065
00066 static void irplib_detmon_lg_tests(void);
00067
00068 cpl_frameset * irplib_detmon_tests_fill_frameset(const char * tag_on,
00069 const char * tag_off,
00070 int non,
00071 cpl_boolean opt_nir,
00072 cpl_boolean with_exts,
00073 int nexts,
00074 int nsettings);
00075
00076 cpl_frameset * irplib_detmon_tests_fill_frameset_oct(const char * tag_on,
00077 const char * tag_off,
00078 int non,
00079 cpl_boolean opt_nir,
00080 cpl_boolean with_exts,
00081 int nexts);
00082
00083 int compare_settings(const cpl_frame * frame1, const cpl_frame * frame2);
00084
00085 cpl_imagelist * irplib_detmon_tests_imlist(int ndits, cpl_boolean onoff);
00086
00087
00088
00089
00090
00091
00092
00093 int main(void)
00094 {
00095
00096 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00097
00098 irplib_detmon_lg_tests();
00099
00100 return cpl_test_end(0);
00101 }
00102
00103 static void irplib_detmon_lg_tests(void)
00104 {
00105
00106
00107 int px, py;
00108 cpl_image * image1;
00109 #ifdef HAVE_FFTW
00110 cpl_image * image2;
00111 #endif
00112 cpl_image * result;
00113
00114 cpl_parameterlist * parlist;
00115 cpl_frameset * frameset;
00116 cpl_frameset * set;
00117
00118
00119
00120 const char * tag_on;
00121 const char * tag_off;
00122
00123
00124 cpl_table * gain_table;
00125 cpl_imagelist * imlist_on;
00126 cpl_imagelist * imlist_off;
00127 cpl_imagelist * diff;
00128 cpl_imagelist * corr;
00129 cpl_vector * exptimes;
00130 cpl_propertylist * qclist;
00131 int i;
00132 double gain;
00133 if(0) {
00134 #ifdef HAVE_FFTW
00135
00136
00137
00138 result = irplib_detmon_image_correlate(NULL, NULL, 0, 0);
00139 cpl_test_error(CPL_ERROR_NULL_INPUT);
00140 cpl_error_reset();
00141 cpl_test_null(result);
00142 cpl_image_delete(result);
00143
00144
00145 image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00146 cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2, (IMAGESIZE + 1)/2, 25, 40, 40);
00147
00148 image2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00149 cpl_image_fill_gaussian(image2, (IMAGESIZE + 1)/2, (IMAGESIZE + 1)/2, 25, 40, 40);
00150
00151 px = -1;
00152 py = -1;
00153
00154 result = irplib_detmon_image_correlate(image1, image2, 13, 13);
00155
00156 cpl_image_get_maxpos(result, &px, &py);
00157 cpl_test(px == 13+1 && py == 13+1);
00158
00159 cpl_image_delete(image1);
00160 cpl_image_delete(image2);
00161 cpl_image_delete(result);
00162
00163
00164 image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00165 cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2+30, (IMAGESIZE + 1)/2+30, 25, 40, 40);
00166
00167 image2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00168 cpl_image_fill_gaussian(image2, (IMAGESIZE + 1)/2+30, (IMAGESIZE + 1)/2+30, 25, 40, 40);
00169
00170 px = -1;
00171 py = -1;
00172
00173 result = irplib_detmon_image_correlate(image1, image2, 13, 13);
00174
00175 cpl_image_get_maxpos(result, &px, &py);
00176 cpl_test(px == 13+1 && py == 13+1);
00177
00178 cpl_image_delete(image1);
00179 cpl_image_delete(image2);
00180 cpl_image_delete(result);
00181
00182
00183 image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00184 cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2+30, (IMAGESIZE + 1)/2+30, 25, 40, 40);
00185
00186 image2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00187 cpl_image_fill_gaussian(image2, (IMAGESIZE + 1)/2+40, (IMAGESIZE + 1)/2+40, 25, 40, 40);
00188
00189 px = -1;
00190 py = -1;
00191
00192 result = irplib_detmon_image_correlate(image1, image2, 13, 13);
00193
00194 cpl_image_get_maxpos(result, &px, &py);
00195
00196
00197
00198 cpl_image_delete(image1);
00199 cpl_image_delete(image2);
00200 cpl_image_delete(result);
00201 #else
00202
00203
00204
00205 result = irplib_detmon_autocorrelate(NULL, 0, 0);
00206 cpl_test_error(CPL_ERROR_NULL_INPUT);
00207 cpl_error_reset();
00208 cpl_test_null(result);
00209 cpl_image_delete(result);
00210
00211
00212 image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00213 cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2, (IMAGESIZE + 1)/2, 25, 40, 40);
00214
00215 px = -1;
00216 py = -1;
00217
00218 result = irplib_detmon_autocorrelate(image1, 13, 13);
00219
00220
00221 cpl_image_get_maxpos(result, &px, &py);
00222 cpl_test(px == 13+1 && py == 13+1);
00223
00224 cpl_image_delete(image1);
00225 cpl_image_delete(result);
00226
00227 #endif
00228
00229
00230
00231 tag_on = "FRAME_ON";
00232 tag_off = "FRAME_OFF";
00233
00234 set = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00235 20, TRUE, FALSE, 0, 1);
00236
00237
00238
00239 irplib_detmon_lg(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
00240 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE);
00241 cpl_test_error(CPL_ERROR_NULL_INPUT);
00242 cpl_error_reset();
00243
00244
00245
00246 parlist = cpl_parameterlist_new();
00247 irplib_detmon_lg_fill_parlist_nir_default(parlist,
00248 "detmon_ir_lg", "detmon");
00249
00250 frameset = cpl_frameset_duplicate(set);
00251
00252 irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00253 "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00254 "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00255 NULL, NULL, TRUE);
00256 cpl_test_error(CPL_ERROR_NONE);
00257 cpl_error_reset();
00258
00259 cpl_frameset_delete(frameset);
00260 cpl_parameterlist_delete(parlist);
00261
00262
00263
00264 parlist = cpl_parameterlist_new();
00265 irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00266 "MED",
00267 3,
00268 3,
00269 25,
00270 -1,
00271 -1,
00272 -1,
00273 -1,
00274 10000,
00275 "CPL_FALSE",
00276 "CPL_FALSE",
00277 "CPL_FALSE",
00278 "CPL_TRUE",
00279 "CPL_TRUE",
00280 "CPL_FALSE",
00281 -1,
00282 26,
00283 26,
00284 1e-3,
00285 "detmon_ir_lg",
00286 -1,
00287 -1,
00288 -1,
00289 -1,
00290 -1,
00291 -1,
00292 -1,
00293 -1,
00294 -1,
00295 -1,
00296 -1,
00297 -1,
00298 -1,
00299 -1,
00300 -1,
00301 -1,
00302 -1,
00303 -1,
00304 -1,
00305 -1,
00306 0,
00307 NIR);
00308
00309 frameset = cpl_frameset_duplicate(set);
00310
00311 irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00312 "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00313 "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00314 NULL, NULL, TRUE);
00315 cpl_test_error(CPL_ERROR_NONE);
00316 cpl_error_reset();
00317
00318 cpl_frameset_delete(frameset);
00319 cpl_parameterlist_delete(parlist);
00320
00321
00322
00323
00324
00325 parlist = cpl_parameterlist_new();
00326 irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00327 "PTC",
00328 3,
00329 3,
00330 25,
00331 -1,
00332 -1,
00333 -1,
00334 -1,
00335 10000,
00336 "CPL_TRUE",
00337 "CPL_FALSE",
00338 "CPL_FALSE",
00339 "CPL_TRUE",
00340 "CPL_TRUE",
00341 "CPL_FALSE",
00342 -1,
00343 26,
00344 26,
00345 1e-3,
00346 "detmon_ir_lg",
00347 -1,
00348 -1,
00349 -1,
00350 -1,
00351 -1,
00352 -1,
00353 -1,
00354 -1,
00355 -1,
00356 -1,
00357 -1,
00358 -1,
00359 -1,
00360 -1,
00361 -1,
00362 -1,
00363 -1,
00364 -1,
00365 -1,
00366 -1,
00367 0,
00368 NIR);
00369
00370 frameset = cpl_frameset_duplicate(set);
00371
00372 irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00373 "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00374 "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00375 NULL, NULL, TRUE);
00376 cpl_test_error(CPL_ERROR_NONE);
00377 cpl_error_reset();
00378
00379 cpl_frameset_delete(frameset);
00380 cpl_parameterlist_delete(parlist);
00381
00382
00383
00384
00385 parlist = cpl_parameterlist_new();
00386 irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00387 "PTC",
00388 3,
00389 3,
00390 25,
00391 -1,
00392 -1,
00393 -1,
00394 -1,
00395 10000,
00396 "CPL_FALSE",
00397 "CPL_FALSE",
00398 "CPL_FALSE",
00399 "CPL_FALSE",
00400 "CPL_TRUE",
00401 "CPL_FALSE",
00402 -1,
00403 26,
00404 26,
00405 1e-3,
00406 "detmon_ir_lg",
00407 -1,
00408 -1,
00409 -1,
00410 -1,
00411 -1,
00412 -1,
00413 -1,
00414 -1,
00415 -1,
00416 -1,
00417 -1,
00418 -1,
00419 -1,
00420 -1,
00421 -1,
00422 -1,
00423 -1,
00424 -1,
00425 -1,
00426 -1,
00427 0,
00428 NIR);
00429
00430 frameset = cpl_frameset_duplicate(set);
00431
00432 irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00433 "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00434 "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00435 NULL, NULL, TRUE);
00436 cpl_test_error(CPL_ERROR_NONE);
00437 cpl_error_reset();
00438
00439 cpl_frameset_delete(frameset);
00440 cpl_parameterlist_delete(parlist);
00441
00442
00443 parlist = cpl_parameterlist_new();
00444 irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00445 "PTC",
00446 3,
00447 3,
00448 25,
00449 -1,
00450 -1,
00451 -1,
00452 -1,
00453 10000,
00454 "CPL_FALSE",
00455 "CPL_FALSE",
00456 "CPL_FALSE",
00457 "CPL_TRUE",
00458 "CPL_TRUE",
00459 "CPL_TRUE",
00460 -1,
00461 26,
00462 26,
00463 1e-3,
00464 "detmon_ir_lg",
00465 -1,
00466 -1,
00467 -1,
00468 -1,
00469 -1,
00470 -1,
00471 -1,
00472 -1,
00473 -1,
00474 -1,
00475 -1,
00476 -1,
00477 -1,
00478 -1,
00479 -1,
00480 -1,
00481 -1,
00482 -1,
00483 -1,
00484 -1,
00485 0,
00486 NIR);
00487
00488 frameset = cpl_frameset_duplicate(set);
00489
00490 irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00491 "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00492 "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00493 NULL, NULL, TRUE);
00494 cpl_test_error(CPL_ERROR_NONE);
00495 cpl_error_reset();
00496
00497 {
00498
00499 cpl_image * bpm = cpl_image_load("detmon_ir_lg_bpm.fits",
00500 CPL_TYPE_INT, 0, 0);
00501
00502 cpl_mask * mask = cpl_mask_threshold_image_create(bpm, 0.5, 1.5);
00503
00504 int nbpixs = cpl_mask_count(mask);
00505
00506 int flux = (int)cpl_image_get_flux(bpm);
00507
00508 cpl_test_eq(flux, nbpixs);
00509
00510 cpl_image_delete(bpm);
00511 cpl_mask_delete(mask);
00512 }
00513
00514 cpl_frameset_delete(frameset);
00515 cpl_parameterlist_delete(parlist);
00516
00517
00518
00519
00520
00521
00522 parlist = cpl_parameterlist_new();
00523 irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00524 "PTC",
00525 3,
00526 3,
00527 25,
00528 -1,
00529 -1,
00530 -1,
00531 -1,
00532 10000,
00533 "CPL_FALSE",
00534 "CPL_FALSE",
00535 "CPL_FALSE",
00536 "CPL_TRUE",
00537 "CPL_FALSE",
00538 "CPL_FALSE",
00539 -1,
00540 26,
00541 26,
00542 1e-3,
00543 "detmon_ir_lg",
00544 -1,
00545 -1,
00546 -1,
00547 -1,
00548 -1,
00549 -1,
00550 -1,
00551 -1,
00552 -1,
00553 -1,
00554 -1,
00555 -1,
00556 -1,
00557 -1,
00558 -1,
00559 -1,
00560 -1,
00561 -1,
00562 -1,
00563 -1,
00564 0,
00565 NIR);
00566
00567 frameset = cpl_frameset_duplicate(set);
00568
00569
00570
00571
00572
00573
00574
00575
00576 cpl_frameset_delete(frameset);
00577 cpl_parameterlist_delete(parlist);
00578
00579
00580
00581
00582 parlist = cpl_parameterlist_new();
00583 irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00584 "PTC",
00585 3,
00586 3,
00587 25,
00588 -1,
00589 -1,
00590 -1,
00591 -1,
00592 10000,
00593 "CPL_FALSE",
00594 "CPL_FALSE",
00595 "CPL_FALSE",
00596 "CPL_TRUE",
00597 "CPL_TRUE",
00598 "CPL_FALSE",
00599 4000,
00600 26,
00601 26,
00602 1e-3,
00603 "detmon_ir_lg",
00604 -1,
00605 -1,
00606 -1,
00607 -1,
00608 -1,
00609 -1,
00610 -1,
00611 -1,
00612 -1,
00613 -1,
00614 -1,
00615 -1,
00616 -1,
00617 -1,
00618 -1,
00619 -1,
00620 -1,
00621 -1,
00622 -1,
00623 -1,
00624 0,
00625 NIR);
00626
00627 frameset = cpl_frameset_duplicate(set);
00628
00629 irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00630 "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00631 "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00632 NULL, NULL, TRUE);
00633 cpl_test_error(CPL_ERROR_NONE);
00634 cpl_error_reset();
00635
00636 cpl_frameset_delete(frameset);
00637 cpl_parameterlist_delete(parlist);
00638
00639
00640
00641 cpl_frameset_delete(set);
00642
00643
00644
00645
00646
00647
00648
00649 parlist = cpl_parameterlist_new();
00650 irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00651 "PTC",
00652 3,
00653 3,
00654 25,
00655 -1,
00656 -1,
00657 -1,
00658 -1,
00659 10000,
00660 "CPL_FALSE",
00661 "CPL_FALSE",
00662 "CPL_FALSE",
00663 "CPL_TRUE",
00664 "CPL_TRUE",
00665 "CPL_FALSE",
00666 -1,
00667 26,
00668 26,
00669 1e-3,
00670 "detmon_ir_lg",
00671 -1,
00672 -1,
00673 -1,
00674 -1,
00675 -1,
00676 -1,
00677 -1,
00678 -1,
00679 -1,
00680 -1,
00681 -1,
00682 -1,
00683 -1,
00684 -1,
00685 -1,
00686 -1,
00687 -1,
00688 -1,
00689 -1,
00690 -1,
00691 0,
00692 NIR);
00693
00694 frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00695 6, TRUE, FALSE, 0, 1);
00696
00697
00698
00699
00700
00701
00702
00703
00704 cpl_frameset_delete(frameset);
00705 cpl_parameterlist_delete(parlist);
00706
00707
00708
00709 parlist = cpl_parameterlist_new();
00710 irplib_detmon_lg_fill_parlist_opt_default(parlist,
00711 "detmon_opt_lg", "detmon");
00712
00713 frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00714 20, FALSE, FALSE, 0, 1);
00715
00716
00717
00718
00719
00720
00721
00722
00723 cpl_frameset_delete(frameset);
00724 cpl_parameterlist_delete(parlist);
00725
00726 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 1, 0)
00727
00728 parlist = cpl_parameterlist_new();
00729 irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00730 "PTC",
00731 3,
00732 3,
00733 25,
00734 -1,
00735 -1,
00736 -1,
00737 -1,
00738 10000,
00739 "CPL_FALSE",
00740 "CPL_FALSE",
00741 "CPL_FALSE",
00742 "CPL_TRUE",
00743 "CPL_TRUE",
00744 "CPL_FALSE",
00745 -1,
00746 26,
00747 26,
00748 1e-3,
00749 "detmon_ir_lg",
00750 -1,
00751 -1,
00752 -1,
00753 -1,
00754 -1,
00755 -1,
00756 -1,
00757 -1,
00758 -1,
00759 -1,
00760 -1,
00761 -1,
00762 -1,
00763 -1,
00764 -1,
00765 -1,
00766 -1,
00767 -1,
00768 -1,
00769 -1,
00770 -1,
00771 NIR);
00772
00773
00774
00775
00776
00777
00778
00779
00780 frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00781 20, TRUE, TRUE, 8, 1);
00782
00783 irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon", REGEXP,
00784 "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0", NULL, NULL, TRUE);
00785 cpl_test(cpl_error_get_code() == CPL_ERROR_NONE ||
00786 cpl_error_get_code() == CPL_ERROR_UNSUPPORTED_MODE);
00787
00788 cpl_error_reset();
00789
00790 cpl_parameterlist_delete(parlist);
00791 cpl_frameset_delete(frameset);
00792 #endif
00793
00794
00795
00796 parlist = cpl_parameterlist_new();
00797 irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00798 "PTC",
00799 3,
00800 3,
00801 25,
00802 -1,
00803 -1,
00804 -1,
00805 -1,
00806 10000,
00807 "CPL_FALSE",
00808 "CPL_FALSE",
00809 "CPL_FALSE",
00810 "CPL_TRUE",
00811 "CPL_TRUE",
00812 "CPL_FALSE",
00813 -1,
00814 26,
00815 26,
00816 1e-3,
00817 "detmon_ir_lg",
00818 -1,
00819 -1,
00820 -1,
00821 -1,
00822 -1,
00823 -1,
00824 -1,
00825 -1,
00826 -1,
00827 -1,
00828 -1,
00829 -1,
00830 -1,
00831 -1,
00832 -1,
00833 -1,
00834 -1,
00835 -1,
00836 -1,
00837 -1,
00838 2,
00839 NIR);
00840
00841
00842
00843
00844
00845
00846
00847
00848 frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00849 20, TRUE, TRUE, 8, 1);
00850
00851 irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon", REGEXP,
00852 "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0", NULL, NULL, TRUE);
00853 cpl_test(cpl_error_get_code() == CPL_ERROR_NONE ||
00854 cpl_error_get_code() == CPL_ERROR_UNSUPPORTED_MODE);
00855
00856 cpl_error_reset();
00857
00858 cpl_parameterlist_delete(parlist);
00859 cpl_frameset_delete(frameset);
00860
00861
00862
00863 parlist = cpl_parameterlist_new();
00864 irplib_detmon_lg_fill_parlist_nir_default(parlist, "detmon_ir_lg", "detmon");
00865
00866 frameset = irplib_detmon_tests_fill_frameset_oct(tag_on, tag_off, 20, TRUE, FALSE, 0);
00867
00868
00869
00870
00871
00872
00873
00874 cpl_parameterlist_delete(parlist);
00875 cpl_frameset_delete(frameset);
00876
00877
00878 parlist = cpl_parameterlist_new();
00879 irplib_detmon_lg_fill_parlist_nir_default(parlist, "detmon_ir_lg", "detmon");
00880
00881 frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00882 20, TRUE, FALSE, 0, 3);
00883
00884 irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon", REGEXP,
00885 "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0", compare_settings, NULL, TRUE);
00886
00887 cpl_test_error(CPL_ERROR_NONE);
00888
00889 cpl_parameterlist_delete(parlist);
00890 cpl_frameset_delete(frameset);
00891
00892 cpl_test_zero(system("rm *.paf *.fits"));
00893
00894 }
00895
00896
00897
00898 gain_table = irplib_detmon_gain(NULL, NULL, NULL, 0, 0, 0, 0, 0.0,
00899 0, 0, 0, NULL, 0, NULL, NULL);
00900 cpl_test_null(gain_table);
00901 cpl_test_error(CPL_ERROR_NULL_INPUT);
00902
00903 imlist_on = irplib_detmon_tests_imlist(8, ON);
00904 imlist_off = irplib_detmon_tests_imlist(8, OFF);
00905
00906 exptimes = cpl_vector_new(16);
00907
00908 for(i = 0; i < 16; i++) {
00909 cpl_vector_set(exptimes, i, (double)(i/2 + 1));
00910 }
00911
00912 qclist = cpl_propertylist_new();
00913
00914 gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 1, 1,
00915 IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
00916 qclist, IRPLIB_GAIN_NO_COLLAPSE,
00917 NULL, NULL);
00918 cpl_test_nonnull(gain_table);
00919 cpl_test_error(CPL_ERROR_NONE);
00920
00921
00922 gain = cpl_propertylist_get_double(qclist, DETMON_QC_GAIN);
00923 cpl_test(gain > 220.0 && gain < 240.0);
00924
00925 cpl_table_delete(gain_table);
00926 cpl_propertylist_delete(qclist);
00927
00928
00929 qclist = cpl_propertylist_new();
00930
00931 gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 1, 1,
00932 IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
00933 qclist, IRPLIB_GAIN_NO_COLLAPSE |
00934 IRPLIB_GAIN_PTC,
00935 NULL, NULL);
00936 cpl_test_nonnull(gain_table);
00937 cpl_test_error(CPL_ERROR_NONE);
00938
00939
00940 gain = cpl_propertylist_get_double(qclist, DETMON_QC_GAIN);
00941 cpl_test(gain > 160.0 && gain < 180.0);
00942
00943 cpl_table_delete(gain_table);
00944 cpl_propertylist_delete(qclist);
00945
00946 qclist = cpl_propertylist_new();
00947
00948 diff = NULL;
00949 corr = NULL;
00950
00951 gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 1, 1,
00952 IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
00953 qclist, IRPLIB_GAIN_NO_COLLAPSE |
00954 IRPLIB_GAIN_WITH_AUTOCORR, &diff, &corr);
00955 cpl_test_nonnull(gain_table);
00956 cpl_test_nonnull(diff);
00957 cpl_test_nonnull(corr);
00958 cpl_test_error(CPL_ERROR_NONE);
00959
00960 cpl_imagelist_delete(diff);
00961 cpl_imagelist_delete(corr);
00962 cpl_table_delete(gain_table);
00963 cpl_propertylist_delete(qclist);
00964
00965 qclist = cpl_propertylist_new();
00966
00967 gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 1, 1,
00968 IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
00969 qclist, IRPLIB_GAIN_NO_COLLAPSE |
00970 IRPLIB_GAIN_WITH_AUTOCORR, NULL, NULL);
00971 cpl_test_nonnull(gain_table);
00972 cpl_test_error(CPL_ERROR_NONE);
00973
00974 cpl_imagelist_delete(imlist_on);
00975 cpl_imagelist_delete(imlist_off);
00976 cpl_propertylist_delete(qclist);
00977 cpl_vector_delete(exptimes);
00978 cpl_table_delete(gain_table);
00979 }
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992 cpl_frameset * irplib_detmon_tests_fill_frameset(const char * tag_on,
00993 const char * tag_off,
00994 int non,
00995 cpl_boolean opt_nir,
00996 cpl_boolean with_exts,
00997 int nexts,
00998 int nsettings)
00999 {
01000 cpl_frameset * frameset;
01001 cpl_frame * frame;
01002 int i, h;
01003 char frame_name[20];
01004 cpl_propertylist * plist;
01005 cpl_image * image;
01006 frameset = cpl_frameset_new();
01007
01008 for (h = 0; h < nsettings; h++) {
01009 for (i=0; i<non; i++) {
01010 frame = cpl_frame_new();
01011 sprintf(frame_name, "dummyon%d%d.fits",i,h);
01012 cpl_frame_set_filename(frame, frame_name);
01013 cpl_frame_set_tag(frame, tag_on);
01014 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01015 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01016
01017 cpl_frameset_insert(frameset, frame);
01018
01019 plist = cpl_propertylist_new();
01020 if(opt_nir == TRUE) {
01021 cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01022 } else {
01023 cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01024 }
01025
01026 cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2 + 1) );
01027 cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01028
01029 cpl_propertylist_append_double(plist, "SETTING", h+1);
01030 if(with_exts == TRUE) {
01031 int j;
01032 cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01033 for(j = 0; j < nexts; j++) {
01034 image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01035 cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01036 cpl_image_add_scalar(image,300* i);
01037 cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01038
01039 cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01040 cpl_image_delete(image);
01041 }
01042 } else {
01043 image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01044 cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01045 cpl_image_add_scalar(image,300* i);
01046 cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01047
01048 cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01049
01050
01051 cpl_image_delete(image);
01052 }
01053 cpl_propertylist_delete(plist);
01054 }
01055 for (i=0; i<non; i++) {
01056
01057
01058 frame = cpl_frame_new();
01059 sprintf(frame_name, "dummyoff%d%d.fits",i,h);
01060 cpl_frame_set_filename(frame, frame_name);
01061 cpl_frame_set_tag(frame, tag_off);
01062 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01063 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01064
01065 cpl_frameset_insert(frameset, frame);
01066
01067 plist = cpl_propertylist_new();
01068 if(opt_nir == TRUE) {
01069 cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01070 } else {
01071 cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01072 }
01073 cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01074 cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2 + 1));
01075 cpl_propertylist_append_double(plist, "SETTING", h+1);
01076
01077 if(with_exts == TRUE) {
01078 int j;
01079 cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01080 for(j = 0; j < nexts; j++) {
01081 image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01082 cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01083 cpl_image_add_scalar(image, i);
01084 cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01085
01086 cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01087 cpl_image_delete(image);
01088 }
01089 } else {
01090 image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01091 cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01092 cpl_image_add_scalar(image, i);
01093 cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01094
01095 cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01096
01097
01098 cpl_image_delete(image);
01099 }
01100 cpl_propertylist_delete(plist);
01101 }
01102 }
01103
01104 return frameset;
01105 }
01106
01107
01108 cpl_frameset * irplib_detmon_tests_fill_frameset_oct(const char * tag_on,
01109 const char * tag_off,
01110 int non,
01111 cpl_boolean opt_nir,
01112 cpl_boolean with_exts,
01113 int nexts)
01114 {
01115 cpl_frameset * frameset;
01116 cpl_frame * frame;
01117 int i;
01118 char frame_name[20];
01119 cpl_propertylist * plist;
01120 cpl_image * image;
01121 frameset = cpl_frameset_new();
01122
01123 for (i=0; i<non; i++) {
01124 frame = cpl_frame_new();
01125 sprintf(frame_name, "dummyon%d.fits",i);
01126 cpl_frame_set_filename(frame, frame_name);
01127 cpl_frame_set_tag(frame, tag_on);
01128 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01129 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01130
01131 cpl_frameset_insert(frameset, frame);
01132
01133 plist = cpl_propertylist_new();
01134 if(opt_nir == TRUE) {
01135 if( i == 2 || i == 3) {
01136 cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(1));
01137 cpl_propertylist_append_double(plist, "EXPTIME", (double)(1));
01138 cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01139 } else {
01140 cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01141 cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2+1));
01142 cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01143 }
01144 } else {
01145 cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01146 cpl_propertylist_append_double(plist, "EXPTIME", (double)((i+1)/2));
01147 cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01148 }
01149
01150 if(with_exts == TRUE) {
01151 int j;
01152 cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01153 for(j = 0; j < nexts; j++) {
01154 image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01155 cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01156 if(i == 0 || i == 1 || i== 2 || i == 3) {
01157 cpl_image_add_scalar(image,300);
01158 } else
01159 cpl_image_add_scalar(image,300* i);
01160 cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01161
01162 cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01163 cpl_image_delete(image);
01164 }
01165 } else {
01166 image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01167 cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01168 if(i == 0 || i == 1 || i== 2 || i == 3) {
01169 cpl_image_add_scalar(image,300);
01170 } else
01171 cpl_image_add_scalar(image,300* i);
01172
01173 cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01174
01175 cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01176
01177
01178 cpl_image_delete(image);
01179 }
01180 cpl_propertylist_delete(plist);
01181 }
01182
01183 for (i=0; i<non; i++) {
01184
01185
01186 frame = cpl_frame_new();
01187 sprintf(frame_name, "dummyoff%d.fits",i);
01188 cpl_frame_set_filename(frame, frame_name);
01189 cpl_frame_set_tag(frame, tag_off);
01190 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01191 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01192
01193 cpl_frameset_insert(frameset, frame);
01194
01195 plist = cpl_propertylist_new();
01196 if(opt_nir == TRUE) {
01197 if( i == 2 || i == 3) {
01198 cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(1));
01199 cpl_propertylist_append_double(plist, "EXPTIME", (double)(1));
01200 cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01201 } else {
01202 cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01203 cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2+1));
01204 cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01205 }
01206 } else {
01207 cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01208 cpl_propertylist_append_double(plist, "EXPTIME", (double)((i+1)/2));
01209 cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01210 }
01211
01212 if(with_exts == TRUE) {
01213 int j;
01214 cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01215 for(j = 0; j < nexts; j++) {
01216 image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01217 cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01218 if(i == 0 || i == 1 || i== 2 || i == 3) {
01219 cpl_image_add_scalar(image,300);
01220 } else
01221 cpl_image_add_scalar(image,300* i);
01222
01223 cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01224
01225 cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01226 cpl_image_delete(image);
01227 }
01228 } else {
01229 image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01230 cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01231 if(i == 0 || i == 1 || i== 2 || i == 3) {
01232 cpl_image_add_scalar(image,300);
01233 } else
01234 cpl_image_add_scalar(image,300* i);
01235
01236 cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01237
01238 cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01239
01240
01241 cpl_image_delete(image);
01242 }
01243 cpl_propertylist_delete(plist);
01244 }
01245
01246 return frameset;
01247 }
01248
01249
01250 int compare_settings(const cpl_frame * frame1, const cpl_frame * frame2)
01251 {
01252 int comparison;
01253 cpl_propertylist *plist1;
01254 cpl_propertylist *plist2;
01255 double dval1, dval2;
01256
01257
01258 if(frame1 == NULL || frame2 == NULL)
01259 return -1;
01260
01261
01262 if((plist1 = cpl_propertylist_load(cpl_frame_get_filename(frame1),
01263 0)) == NULL) {
01264 cpl_msg_error(cpl_func, "getting header from reference frame");
01265 return -1;
01266 }
01267 if((plist2 = cpl_propertylist_load(cpl_frame_get_filename(frame2),
01268 0)) == NULL) {
01269 cpl_msg_error(cpl_func, "getting header from reference frame");
01270 cpl_propertylist_delete(plist1);
01271 return -1;
01272 }
01273
01274
01275 if(cpl_error_get_code()) {
01276 cpl_propertylist_delete(plist1);
01277 cpl_propertylist_delete(plist2);
01278 return -1;
01279 }
01280
01281
01282 comparison = 1;
01283 dval1 = cpl_propertylist_get_double(plist1, "SETTING");
01284 dval2 = cpl_propertylist_get_double(plist2, "SETTING");
01285 if(cpl_error_get_code()) {
01286 cpl_msg_error(cpl_func, "cannot get exposure time");
01287 cpl_propertylist_delete(plist1);
01288 cpl_propertylist_delete(plist2);
01289 return -1;
01290 }
01291 if( dval1 != dval2)
01292 comparison = 0;
01293
01294
01295 cpl_propertylist_delete(plist1);
01296 cpl_propertylist_delete(plist2);
01297 return comparison;
01298
01299 }
01300
01301 cpl_imagelist * irplib_detmon_tests_imlist(int ndits, cpl_boolean onoff)
01302 {
01303 cpl_imagelist * imlist = cpl_imagelist_new();
01304 int i;
01305
01306 double levelstep = onoff ? ON_LEVEL : OFF_LEVEL;
01307 double factor = onoff ? 1.0 : 0.5;
01308
01309 for (i = 1; i <= ndits; i++) {
01310 cpl_image * im1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01311 cpl_image * im2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01312 double noise_min = NOISE_MIN * sqrt(i) / (double) ndits * factor;
01313 double noise_max = NOISE_MAX * sqrt(i) / (double) ndits * factor;
01314 cpl_image_fill_noise_uniform(im1, noise_min, noise_max);
01315 cpl_image_fill_noise_uniform(im2, noise_min, noise_max);
01316 cpl_image_add_scalar(im1, levelstep * i);
01317 cpl_image_add_scalar(im2, levelstep * i);
01318 cpl_imagelist_set(imlist, im1, 2 * (i - 1));
01319 cpl_imagelist_set(imlist, im2, 2 * (i - 1) + 1);
01320 }
01321
01322 return imlist;
01323 }
01324