FORS Pipeline Reference Manual 4.9.9
|
00001 /* $Id: test_simulate.c,v 1.34 2009/02/25 15:34:48 hlorch Exp $ 00002 * 00003 * This file is part of the FORS Library 00004 * Copyright (C) 2002-2006 European Southern Observatory 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 /* 00022 * $Author: hlorch $ 00023 * $Date: 2009/02/25 15:34:48 $ 00024 * $Revision: 1.34 $ 00025 * $Name: fors-4_9_9 $ 00026 */ 00027 00028 #ifdef HAVE_CONFIG_H 00029 #include <config.h> 00030 #endif 00031 00032 #include <test_simulate.h> 00033 00034 #include <fors_instrument.h> 00035 #include <fors_image.h> 00036 #include <fors_dfs.h> 00037 #include <fors_data.h> 00038 #include <fors_pfits.h> 00039 #include <fors_utils.h> 00040 00041 #include <cpl.h> 00042 00043 #include <math.h> 00044 00045 /* FIXME: - remove FORS_DATA_STD_* !!! 00046 * - replace below in create_std_cat() 00047 * 1.) by creation of a standard star list, and 00048 * 2.) and a new function fors_std_cat_test_create_stetson() 00049 * in fors_std_cat.c 00050 */ 00051 const char *const FORS_DATA_STD_MAG[FORS_NUM_FILTER] = 00052 {"U", 00053 "B", 00054 //"G", 00055 "V", /* G uses V */ 00056 "V", 00057 "R", 00058 "I", 00059 "Z"}; 00060 00061 const char *const FORS_DATA_STD_DMAG[FORS_NUM_FILTER] = 00062 {"ERR_U", 00063 "ERR_B", 00064 //"ERR_G", 00065 "ERR_V", /* G uses V */ 00066 "ERR_V", 00067 "ERR_R", 00068 "ERR_I", 00069 "ERR_Z"}; 00070 00071 const char *const FORS_DATA_STD_COL[FORS_NUM_FILTER] = 00072 {"U_B", 00073 "B_V", 00074 "B_V", 00075 "B_V", 00076 "V_R", 00077 "V_R", 00078 "?Z?"}; 00079 00080 const char *const FORS_DATA_STD_RA = "RA"; 00081 const char *const FORS_DATA_STD_DEC = "DEC"; 00082 const char *const FORS_DATA_STD_NAME = "OBJECT"; 00083 00094 static const int det_nx = 400; /* Unbinned detector pixels */ 00095 static const int det_ny = 400; 00096 static const int binx = 2; 00097 static const int biny = 2; 00098 static const double ron = 4.0; /* ADU */ 00099 static const double conad = 0.78; /* e- / ADU */ 00100 00101 static const double bias_avg = 200; /* ADU */ 00102 static const double dark_avg = 50; /* ADU */ 00103 static const char *const instrume = "fors2"; 00104 static const char *const chip_id = "Test chip 234"; 00105 static const char *const read_clock = "200Kps/2ports/low_gain"; 00106 00114 static cpl_frame * 00115 frame_new(const char *filename, const char *tag, cpl_frame_group group) 00116 { 00117 cpl_frame *f = cpl_frame_new(); 00118 00119 cpl_frame_set_filename(f, filename); 00120 cpl_frame_set_tag (f, tag); 00121 cpl_frame_set_group (f, group); 00122 00123 return f; 00124 } 00125 00131 void 00132 create_standard_keys(cpl_propertylist *header, double exptime) 00133 { 00134 int nx = det_nx / binx; 00135 int ny = det_ny / biny; 00136 00137 cpl_propertylist_update_string(header, "ESO DPR TYPE", "some"); 00138 cpl_propertylist_update_string(header, "ESO TPL ID", "tpl id."); 00139 cpl_propertylist_update_string(header, "ESO INS COLL NAME", "collimator name"); 00140 cpl_propertylist_update_string(header, "ARCFILE", "archive filename"); 00141 00142 cpl_propertylist_update_string(header, FORS_PFITS_INSTRUME, instrume); 00143 cpl_propertylist_update_string(header, FORS_PFITS_FILTER_NAME, "R_SPECIAL"); 00144 00145 cpl_propertylist_update_double(header, FORS_PFITS_AIRMASS_START, 1.156); 00146 cpl_propertylist_update_double(header, FORS_PFITS_AIRMASS_END , 1.619); 00147 00148 cpl_propertylist_update_int (header, FORS_PFITS_DET_NX, nx); 00149 cpl_propertylist_update_int (header, FORS_PFITS_DET_NY, ny); 00150 cpl_propertylist_update_int (header, FORS_PFITS_BINX, binx); 00151 cpl_propertylist_update_int (header, FORS_PFITS_BINY, biny); 00152 cpl_propertylist_update_int (header, FORS_PFITS_OVERSCANX, 0); 00153 cpl_propertylist_update_int (header, FORS_PFITS_OVERSCANY, 0); 00154 cpl_propertylist_update_int (header, FORS_PFITS_PRESCANX, 0); 00155 cpl_propertylist_update_int (header, FORS_PFITS_PRESCANY, 0); 00156 00157 cpl_propertylist_update_double(header, FORS_PFITS_PIXSCALE, 0.126); 00158 00159 cpl_propertylist_update_int(header, FORS_PFITS_OUTPUTS, 1); 00160 cpl_propertylist_update_double(header, FORS_PFITS_CONAD[0], conad); 00161 00162 /* Convert RON to e- units */ 00163 cpl_propertylist_update_double(header, FORS_PFITS_RON[0], ron*conad); 00164 cpl_propertylist_update_double(header, FORS_PFITS_EXPOSURE_TIME, exptime); 00165 00166 cpl_propertylist_update_string(header, FORS_PFITS_CHIP_ID, chip_id); 00167 cpl_propertylist_update_string(header, FORS_PFITS_READ_CLOCK, read_clock); 00168 00169 /* WCS info, fine tuned to match simulated catalogue */ 00170 { 00171 struct { 00172 const char *name; 00173 double value; 00174 } data[] = { 00175 {"CRVAL1", 8.1368333333}, 00176 {"CRVAL2", -46.9576388889}, 00177 {"CRPIX1", 1}, 00178 {"CRPIX2", 1}, 00179 // {"CD1_1", 5.81347849634012E-21}, 00180 // {"CD1_2", 9.49444444444444E-05}, 00181 // {"CD2_1",-9.49444444444444E-05}, 00182 // {"CD2_2",-5.81347849634012E-21}, 00183 {"CD1_1", 5.81347849634012E-20}, 00184 {"CD1_2", 9.49444444444444E-04}, 00185 {"CD2_1",-9.49444444444444E-04}, 00186 {"CD2_2",-5.81347849634012E-20}, 00187 {"PV2_1", 1.0}, 00188 {"PV2_2", 0.0}, 00189 {"PV2_3", 42.0}, 00190 {"PV2_4", 0.0}, 00191 {"PV2_5", 0.0} 00192 }; 00193 00194 unsigned i; 00195 for (i = 0; i < sizeof(data) / sizeof(*data); i++) { 00196 cpl_propertylist_append_double(header, data[i].name, data[i].value); 00197 } 00198 } 00199 00200 return; 00201 } 00202 00203 00204 #undef cleanup 00205 #define cleanup \ 00206 do { \ 00207 fors_image_delete(&bias); \ 00208 cpl_propertylist_delete(header); \ 00209 } while(0) 00210 00220 cpl_frame * 00221 create_bias(const char *filename, const char *tag, cpl_frame_group group) 00222 { 00223 int nx = det_nx / binx; 00224 int ny = det_ny / biny; 00225 double exptime = 0.0; 00226 00227 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE); 00228 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE); 00229 fors_image *bias = NULL; 00230 cpl_propertylist *header = cpl_propertylist_new(); 00231 00232 create_standard_keys(header, exptime); 00233 cpl_propertylist_erase(header, FORS_PFITS_FILTER_NAME); /* No filter */ 00234 00235 { 00236 int x, y; 00237 for (y = 1; y <= ny; y++) 00238 for (x = 1; x <= nx; x++) { 00239 cpl_image_set(data , x, y, 00240 (int)(bias_avg + ron*fors_rand_gauss() + 0.5)); 00241 cpl_image_set(variance, x, y, ron*ron); 00242 } 00243 } 00244 00245 bias = fors_image_new(data, variance); 00246 fors_image_save(bias, header, filename); 00247 00248 assure( !cpl_error_get_code(), return NULL, 00249 "Saving bias to %s failed", filename ); 00250 00251 cleanup; 00252 return frame_new(filename, tag, group); 00253 } 00254 00255 #undef cleanup 00256 #define cleanup \ 00257 do { \ 00258 fors_image_delete(&dark); \ 00259 cpl_propertylist_delete(header); \ 00260 } while(0) 00261 00272 cpl_frame * 00273 create_dark(const char *filename, const char *tag, cpl_frame_group group) 00274 { 00275 int nx = det_nx / binx; 00276 int ny = det_ny / biny; 00277 double exptime = 3.0; 00278 00279 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE); 00280 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE); 00281 fors_image *dark = NULL; 00282 cpl_propertylist *header = cpl_propertylist_new(); 00283 00284 create_standard_keys(header, exptime); 00285 00286 { 00287 int x, y; 00288 for (y = 1; y <= ny; y++) 00289 for (x = 1; x <= nx; x++) { 00290 double var = ron*ron + dark_avg/conad; 00291 00292 cpl_image_set(data , x, y, 00293 (int)(bias_avg + dark_avg + 00294 sqrt(var)*fors_rand_gauss() 00295 + 0.5)); 00296 cpl_image_set(variance, x, y, var); 00297 } 00298 } 00299 00300 dark = fors_image_new(data, variance); 00301 fors_image_save(dark, header, filename); 00302 00303 assure( !cpl_error_get_code(), return NULL, 00304 "Saving dark to %s failed", filename ); 00305 00306 cleanup; 00307 return frame_new(filename, tag, group); 00308 } 00309 00310 00311 #undef cleanup 00312 #define cleanup \ 00313 do { \ 00314 fors_image_delete(&sflat); \ 00315 cpl_propertylist_delete(header); \ 00316 } while(0) 00317 00327 cpl_frame * 00328 create_screen_flat(const char *filename, const char *tag, cpl_frame_group group) 00329 { 00330 int nx = det_nx / binx; 00331 int ny = det_ny / biny; 00332 double exptime = 3.0; 00333 00334 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE); 00335 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE); 00336 fors_image *sflat = NULL; 00337 cpl_propertylist *header = cpl_propertylist_new(); 00338 00339 create_standard_keys(header, exptime); 00340 00341 { 00342 int x, y; 00343 for (y = 1; y <= ny; y++) 00344 for (x = 1; x <= nx; x++) { 00345 double medium_scale_structure = 1000*(2 + sin(x*30.0/nx + y*30.0/ny)); 00346 double large_scale_structure = 1000*(1 + sin(x*4.0/nx)); 00347 double flat = 5000 + medium_scale_structure + large_scale_structure; 00348 double var = ron*ron + flat/conad; 00349 00350 cpl_image_set(data , x, y, 00351 (int)(bias_avg + flat + sqrt(var)*fors_rand_gauss() + 0.5)); 00352 cpl_image_set(variance, x, y, var); 00353 } 00354 } 00355 00356 sflat = fors_image_new(data, variance); 00357 fors_image_save(sflat, header, filename); 00358 00359 assure( !cpl_error_get_code(), return NULL, 00360 "Saving screen flat to %s failed", filename ); 00361 00362 cleanup; 00363 return frame_new(filename, tag, group); 00364 } 00365 00366 #undef cleanup 00367 #define cleanup \ 00368 do { \ 00369 fors_image_delete(&sflat); \ 00370 cpl_propertylist_delete(header); \ 00371 } while(0) 00372 00383 cpl_frame * 00384 create_sky_flat(const char *filename, const char *tag, cpl_frame_group group, 00385 double exptime) 00386 { 00387 int nx = det_nx / binx; 00388 int ny = det_ny / biny; 00389 00390 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE); 00391 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE); 00392 fors_image *sflat = NULL; 00393 cpl_propertylist *header = cpl_propertylist_new(); 00394 00395 create_standard_keys(header, exptime); 00396 00397 { 00398 int x, y; 00399 for (y = 1; y <= ny; y++) 00400 for (x = 1; x <= nx; x++) { 00401 double medium_scale_structure = 1000*(2 + sin(x*30.0/nx - y*10.0/ny)); 00402 double large_scale_structure = 1000*(1 + sin(x*4.0/nx)); 00403 double flat = exptime*(5000 + 00404 medium_scale_structure + 00405 large_scale_structure); 00406 double var = ron*ron + flat/conad; 00407 00408 cpl_image_set(data , x, y, 00409 (int)(bias_avg + flat + sqrt(var)*fors_rand_gauss() + 0.5)); 00410 cpl_image_set(variance, x, y, var); 00411 } 00412 } 00413 00414 sflat = fors_image_new(data, variance); 00415 fors_image_save(sflat, header, filename); 00416 00417 assure( !cpl_error_get_code(), return NULL, 00418 "Saving sky flat to %s failed", filename ); 00419 00420 cleanup; 00421 return frame_new(filename, tag, group); 00422 } 00423 00431 cpl_frame * 00432 create_standard(const char *filename, const char *tag, cpl_frame_group group) 00433 { 00434 // fixme: add stars 00435 double exptime = 1.0; 00436 return create_sky_flat(filename, tag, group, exptime); 00437 } 00438 00439 00440 #undef cleanup 00441 #define cleanup \ 00442 do { \ 00443 cpl_table_delete(t); \ 00444 } while(0) 00445 00453 cpl_frame * 00454 create_std_cat(const char *filename, const char *tag, cpl_frame_group group) 00455 { 00456 cpl_table *t; 00457 struct { 00458 double ra, dec; 00459 double magnitude, dmagnitude; 00460 double col; 00461 const char *name; 00462 } 00463 data[] = { 00464 {8.15958, -47.0347, 15.824000, 0.001, 0.8, "object 1"}, 00465 {8.14792, -46.9664, 12.895000, 0.002, -0.2, ""}, 00466 {8.15083, -47.0092, 12.861000, 0.003, -0.3, " dff bject 1"}, 00467 {8.15583, -47.0222, 16.540001, 0.001, 0.7, "-9"}, 00468 {8.17167, -47.10 , 11.970000, 0.005, 0.12, NULL}, 00469 {8.14833, -47.0567, 13.861000, 0.003, -0.2, ""}, 00470 {8.1475 , -47.0411, 13.903000, 0.001, -0.8, "dddddddobject 1"}, 00471 {7.92542, 2.62917, 15.446000, 0.002, -0.2, "start 1"}, 00472 }; 00473 00474 int N = sizeof(data) / sizeof(*data); 00475 int i; 00476 00477 t = cpl_table_new(N); 00478 cpl_table_new_column(t, FORS_DATA_STD_RA , CPL_TYPE_DOUBLE); 00479 cpl_table_new_column(t, FORS_DATA_STD_DEC, CPL_TYPE_DOUBLE); 00480 cpl_table_new_column(t, FORS_DATA_STD_NAME, CPL_TYPE_STRING); 00481 00482 for (i = 0; i < FORS_NUM_FILTER; i++) { 00483 if (!cpl_table_has_column(t, FORS_DATA_STD_MAG[i])) { 00484 cpl_table_new_column(t, FORS_DATA_STD_MAG[i], CPL_TYPE_FLOAT); 00485 } 00486 if (!cpl_table_has_column(t, FORS_DATA_STD_DMAG[i])) { 00487 cpl_table_new_column(t, FORS_DATA_STD_DMAG[i], CPL_TYPE_FLOAT); 00488 } 00489 if (!cpl_table_has_column(t, FORS_DATA_STD_COL[i])) { 00490 cpl_table_new_column(t, FORS_DATA_STD_COL[i], CPL_TYPE_FLOAT); 00491 } 00492 } 00493 00494 for (i = 0; i < N; i++) { 00495 int j; 00496 00497 cpl_table_set_double(t, FORS_DATA_STD_RA , i, data[i].ra); 00498 cpl_table_set_double(t, FORS_DATA_STD_DEC , i, data[i].dec); 00499 cpl_table_set_string(t, FORS_DATA_STD_NAME, i, data[i].name); 00500 00501 for (j = 0; j < FORS_NUM_FILTER; j++) { 00502 cpl_table_set_float (t, FORS_DATA_STD_MAG[j], i, data[i].magnitude); 00503 cpl_table_set_float (t, FORS_DATA_STD_DMAG[j], i, data[i].dmagnitude); 00504 cpl_table_set_float (t, FORS_DATA_STD_COL[j], i, data[i].col); 00505 } 00506 } 00507 00508 cpl_table_save(t, NULL, NULL, filename, CPL_IO_DEFAULT); 00509 assure( !cpl_error_get_code(), return NULL, 00510 "Failed to save standard catalogue to %s", filename ); 00511 00512 cleanup; 00513 return frame_new(filename, tag, group); 00514 } 00515 00516 00517 00518 #undef cleanup 00519 #define cleanup \ 00520 do { \ 00521 cpl_table_delete(t); \ 00522 } while(0) 00523 00531 cpl_frame * 00532 create_phot_table(const char *filename, const char *tag, cpl_frame_group group) 00533 { 00534 cpl_table *t; 00535 struct { 00536 char band; 00537 double ext_coeff, dext_coeff; 00538 double color_term, dcolor_term; 00539 double expected_zeropoint, dexpected_zeropoint; 00540 } 00541 data[FORS_NUM_FILTER] = { 00542 {'U', 0.4 , 0.01, -0.076, 0.001, 20, 0.2}, 00543 {'B', 0.05 , 0.01, 0.033, 0.001, 21.123456, 0.2}, 00544 {'G', 0.1 , 0.01, 0.01 , 0.001, 22, 0.2}, 00545 {'V', 0.09 , 0.01, -0.02 , 0.001, -18, 0.2}, 00546 {'R', 0.2 , 0.01, 0.03 , 0.001, 0, 0.2}, 00547 {'I', 0.000, 0.01, -0.04 , 0.001, 1.0, 0.2}, 00548 }; 00549 00550 int N = fors_instrument_known_filters_get_number(); 00551 int i; 00552 00553 t = cpl_table_new(N); 00554 cpl_table_new_column(t, FORS_DATA_PHOT_FILTER , CPL_TYPE_STRING); 00555 cpl_table_new_column(t, FORS_DATA_PHOT_EXTCOEFF , CPL_TYPE_DOUBLE); 00556 cpl_table_new_column(t, FORS_DATA_PHOT_DEXTCOEFF , CPL_TYPE_DOUBLE); 00557 cpl_table_new_column(t, FORS_DATA_PHOT_COLORTERM, CPL_TYPE_DOUBLE); 00558 cpl_table_new_column(t, FORS_DATA_PHOT_DCOLORTERM, CPL_TYPE_DOUBLE); 00559 cpl_table_new_column(t, FORS_DATA_PHOT_ZEROPOINT, CPL_TYPE_DOUBLE); 00560 cpl_table_new_column(t, FORS_DATA_PHOT_DZEROPOINT, CPL_TYPE_DOUBLE); 00561 00562 /* For each filtername (e.g. "U_BESS") find the matching filter (e.g. FILTER_U) */ 00563 for (i = 0; i < N; i++) { 00564 cpl_table_set_string( t, 00565 FORS_DATA_PHOT_FILTER, 00566 i, 00567 fors_instrument_known_filters_get_name(i)); 00568 00569 unsigned j; 00570 for (j = 0; j < FORS_NUM_FILTER; j++) { 00571 if (fors_instrument_known_filters_get_band(i) == data[j].band) 00572 { 00573 cpl_table_set_double(t, FORS_DATA_PHOT_EXTCOEFF , i, data[j].ext_coeff); 00574 cpl_table_set_double(t, FORS_DATA_PHOT_DEXTCOEFF , i, data[j].dext_coeff); 00575 cpl_table_set_double(t, FORS_DATA_PHOT_COLORTERM, i, data[j].color_term); 00576 cpl_table_set_double(t, FORS_DATA_PHOT_DCOLORTERM, i, data[j].dcolor_term); 00577 cpl_table_set_double(t, FORS_DATA_PHOT_ZEROPOINT, i, data[j].expected_zeropoint); 00578 cpl_table_set_double(t, FORS_DATA_PHOT_DZEROPOINT, i, data[j].dexpected_zeropoint); 00579 } 00580 } 00581 } 00582 00583 cpl_table_save(t, NULL, NULL, filename, CPL_IO_DEFAULT); 00584 assure( !cpl_error_get_code(), return NULL, 00585 "Failed to save photometry table to %s", filename ); 00586 00587 cleanup; 00588 return frame_new(filename, tag, group); 00589 }