32 #include <test_simulate.h>
34 #include <fors_instrument.h>
35 #include <fors_image.h>
37 #include <fors_data.h>
38 #include <fors_pfits.h>
39 #include <fors_utils.h>
51 const char *
const FORS_DATA_STD_MAG[FORS_NUM_FILTER] =
61 const char *
const FORS_DATA_STD_DMAG[FORS_NUM_FILTER] =
71 const char *
const FORS_DATA_STD_COL[FORS_NUM_FILTER] =
80 const char *
const FORS_DATA_STD_RA =
"RA";
81 const char *
const FORS_DATA_STD_DEC =
"DEC";
82 const char *
const FORS_DATA_STD_NAME =
"OBJECT";
94 static const int det_nx = 400;
95 static const int det_ny = 400;
96 static const int pres_nx = 5;
97 static const int binx = 2;
98 static const int biny = 2;
99 static const double ron = 4.0;
100 static const double conad = 0.78;
102 static const double bias_avg = 200;
103 static const double dark_avg = 50;
104 static const char *
const instrume =
"fors2";
105 static const char *
const chip_id =
"Test chip 234";
106 static const char *
const read_clock =
"200Kps/2ports/low_gain";
116 frame_new(
const char *filename,
const char *tag, cpl_frame_group group)
118 cpl_frame *f = cpl_frame_new();
120 cpl_frame_set_filename(f, filename);
121 cpl_frame_set_tag (f, tag);
122 cpl_frame_set_group (f, group);
135 int nx = det_nx / binx;
136 int ny = det_ny / biny;
138 cpl_propertylist_update_string(header,
"ESO DPR TYPE",
"some");
139 cpl_propertylist_update_string(header,
"ESO TPL ID",
"tpl id.");
140 cpl_propertylist_update_string(header,
"ESO INS COLL NAME",
"collimator name");
141 cpl_propertylist_update_string(header,
"ARCFILE",
"archive filename");
143 cpl_propertylist_update_string(header, FORS_PFITS_INSTRUME, instrume);
144 cpl_propertylist_update_string(header, FORS_PFITS_FILTER_NAME,
"R_SPECIAL");
146 cpl_propertylist_update_double(header, FORS_PFITS_AIRMASS_START, 1.156);
147 cpl_propertylist_update_double(header, FORS_PFITS_AIRMASS_END , 1.619);
149 cpl_propertylist_update_int (header,
"HIERARCH ESO DET CHIP1 NX", nx);
150 cpl_propertylist_update_int (header,
"HIERARCH ESO DET CHIP1 NY", ny);
151 cpl_propertylist_update_int (header,
"HIERARCH ESO DET OUT1 X", 1);
152 cpl_propertylist_update_int (header,
"HIERARCH ESO DET OUT1 Y", 1);
153 cpl_propertylist_update_double(header,
"HIERARCH ESO DET CHIP1 PSZX", 15.0);
154 cpl_propertylist_update_double(header,
"HIERARCH ESO DET CHIP1 PSZY", 15.0);
155 cpl_propertylist_update_int (header, FORS_PFITS_DET_NY, ny);
156 cpl_propertylist_update_int (header, FORS_PFITS_DET_NX, nx);
157 cpl_propertylist_update_int (header, FORS_PFITS_DET_NY, ny);
158 cpl_propertylist_update_int (header, FORS_PFITS_BINX, binx);
159 cpl_propertylist_update_int (header, FORS_PFITS_BINY, biny);
160 cpl_propertylist_update_int (header, FORS_PFITS_OVERSCANX, 0);
161 cpl_propertylist_update_int (header, FORS_PFITS_OVERSCANY, 0);
162 cpl_propertylist_update_int (header, FORS_PFITS_PRESCANX, pres_nx);
163 cpl_propertylist_update_int (header, FORS_PFITS_PRESCANY, 0);
165 cpl_propertylist_update_double(header, FORS_PFITS_PIXSCALE, 0.126);
167 cpl_propertylist_update_int(header, FORS_PFITS_OUTPUTS, 1);
168 cpl_propertylist_update_double(header, FORS_PFITS_CONAD[0], conad);
169 cpl_propertylist_update_double(header,
"HIERARCH ESO DET OUT1 GAIN", 1./conad);
172 cpl_propertylist_update_double(header, FORS_PFITS_RON[0], ron*conad);
173 cpl_propertylist_update_double(header, FORS_PFITS_EXPOSURE_TIME, exptime);
175 cpl_propertylist_update_string(header, FORS_PFITS_CHIP_ID, chip_id);
176 cpl_propertylist_update_string(header, FORS_PFITS_READ_CLOCK, read_clock);
184 {
"CRVAL1", 8.1368333333},
185 {
"CRVAL2", -46.9576388889},
192 {
"CD1_1", 5.81347849634012E-20},
193 {
"CD1_2", 9.49444444444444E-04},
194 {
"CD2_1",-9.49444444444444E-04},
195 {
"CD2_2",-5.81347849634012E-20},
204 for (i = 0; i <
sizeof(data) /
sizeof(*data); i++) {
205 cpl_propertylist_append_double(header, data[i].name, data[i].value);
216 fors_image_delete(&bias); \
217 cpl_propertylist_delete(header); \
230 create_bias(
const char *filename,
const char *tag, cpl_frame_group group)
232 int nx = det_nx / binx + pres_nx;
233 int ny = det_ny / biny;
234 double exptime = 0.0;
236 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
237 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
239 cpl_propertylist *header = cpl_propertylist_new();
242 cpl_propertylist_erase(header, FORS_PFITS_FILTER_NAME);
246 for (y = 1; y <= ny; y++)
247 for (x = 1; x <= nx; x++) {
248 cpl_image_set(data , x, y,
250 cpl_image_set(variance, x, y, ron*ron);
257 assure( !cpl_error_get_code(),
return NULL,
258 "Saving bias to %s failed", filename );
276 int nx = det_nx / binx;
277 int ny = det_ny / biny;
278 double exptime = 0.0;
280 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
281 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
283 cpl_propertylist *header = cpl_propertylist_new();
286 cpl_propertylist_erase(header, FORS_PFITS_FILTER_NAME);
287 cpl_propertylist_append_double(header,
"ESO QC DET OUT1 RON",4.44);
291 for (y = 1; y <= ny; y++)
292 for (x = 1; x <= nx; x++) {
293 cpl_image_set(data , x, y,
295 cpl_image_set(variance, x, y, ron*ron);
302 assure( !cpl_error_get_code(),
return NULL,
303 "Saving master bias to %s failed", filename );
312 fors_image_delete(&dark); \
313 cpl_propertylist_delete(header); \
327 create_dark(
const char *filename,
const char *tag, cpl_frame_group group)
329 int nx = det_nx / binx + pres_nx;
330 int ny = det_ny / biny;
331 double exptime = 3.0;
333 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
334 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
336 cpl_propertylist *header = cpl_propertylist_new();
342 for (y = 1; y <= ny; y++)
343 for (x = 1; x <= nx; x++) {
344 double var = ron*ron + dark_avg/conad;
346 cpl_image_set(data , x, y,
347 (
int)(bias_avg + dark_avg +
350 cpl_image_set(variance, x, y, var);
353 for (y = 1; y <= ny; y++)
354 for (x = 1; x <= pres_nx; x++)
356 cpl_image_set(data , x, y,
358 cpl_image_set(variance, x, y, ron*ron);
365 assure( !cpl_error_get_code(),
return NULL,
366 "Saving dark to %s failed", filename );
376 fors_image_delete(&sflat); \
377 cpl_propertylist_delete(header); \
392 int nx = det_nx / binx + pres_nx;
393 int ny = det_ny / biny;
394 double exptime = 3.0;
396 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
397 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
399 cpl_propertylist *header = cpl_propertylist_new();
405 for (y = 1; y <= ny; y++)
406 for (x = 1; x <= nx; x++) {
407 double medium_scale_structure = 1000*(2 + sin(x*30.0/nx + y*30.0/ny));
408 double large_scale_structure = 1000*(1 + sin(x*4.0/nx));
409 double flat = 5000 + medium_scale_structure + large_scale_structure;
410 double var = ron*ron + flat/conad;
412 cpl_image_set(data , x, y,
414 cpl_image_set(variance, x, y, var);
417 for (y = 1; y <= ny; y++)
418 for (x = 1; x <= pres_nx; x++)
420 cpl_image_set(data , x, y,
422 cpl_image_set(variance, x, y, ron*ron);
429 assure( !cpl_error_get_code(),
return NULL,
430 "Saving screen flat to %s failed", filename );
439 fors_image_delete(&sflat); \
440 cpl_propertylist_delete(header); \
457 int nx = det_nx / binx + pres_nx;
458 int ny = det_ny / biny;
460 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
461 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
463 cpl_propertylist *header = cpl_propertylist_new();
469 for (y = 1; y <= ny; y++)
470 for (x = 1; x <= nx; x++) {
471 double medium_scale_structure = 1000*(2 + sin(x*30.0/nx - y*10.0/ny));
472 double large_scale_structure = 1000*(1 + sin(x*4.0/nx));
473 double flat = exptime*(5000 +
474 medium_scale_structure +
475 large_scale_structure);
476 double var = ron*ron + flat/conad;
478 cpl_image_set(data , x, y,
480 cpl_image_set(variance, x, y, var);
483 for (y = 1; y <= ny; y++)
484 for (x = 1; x <= pres_nx; x++)
486 cpl_image_set(data , x, y,
488 cpl_image_set(variance, x, y, ron*ron);
495 assure( !cpl_error_get_code(),
return NULL,
496 "Saving sky flat to %s failed", filename );
515 const char *tag, cpl_frame_group group,
518 int nx = det_nx / binx;
519 int ny = det_ny / biny;
521 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
522 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
524 cpl_propertylist *header = cpl_propertylist_new();
530 for (y = 1; y <= ny; y++)
531 for (x = 1; x <= nx; x++) {
532 double medium_scale_structure = 1000*(2 + sin(x*30.0/nx - y*10.0/ny));
533 double large_scale_structure = 1000*(1 + sin(x*4.0/nx));
534 double flat = exptime*(5000 +
535 medium_scale_structure +
536 large_scale_structure);
537 double var = ron*ron + flat/conad;
539 cpl_image_set(data , x, y,
541 cpl_image_set(variance, x, y, var);
548 assure( !cpl_error_get_code(),
return NULL,
549 "Saving sky flat to %s failed", filename );
566 double exptime = 1.0;
574 cpl_table_delete(t); \
590 double magnitude, dmagnitude;
595 {8.15958, -47.0347, 15.824000, 0.001, 0.8,
"object 1"},
596 {8.14792, -46.9664, 12.895000, 0.002, -0.2,
""},
597 {8.15083, -47.0092, 12.861000, 0.003, -0.3,
" dff bject 1"},
598 {8.15583, -47.0222, 16.540001, 0.001, 0.7,
"-9"},
599 {8.17167, -47.10 , 11.970000, 0.005, 0.12, NULL},
600 {8.14833, -47.0567, 13.861000, 0.003, -0.2,
""},
601 {8.1475 , -47.0411, 13.903000, 0.001, -0.8,
"dddddddobject 1"},
602 {7.92542, 2.62917, 15.446000, 0.002, -0.2,
"start 1"},
605 int N =
sizeof(data) /
sizeof(*data);
608 t = cpl_table_new(N);
609 cpl_table_new_column(t, FORS_DATA_STD_RA , CPL_TYPE_DOUBLE);
610 cpl_table_new_column(t, FORS_DATA_STD_DEC, CPL_TYPE_DOUBLE);
611 cpl_table_new_column(t, FORS_DATA_STD_NAME, CPL_TYPE_STRING);
613 for (i = 0; i < FORS_NUM_FILTER; i++) {
614 if (!cpl_table_has_column(t, FORS_DATA_STD_MAG[i])) {
615 cpl_table_new_column(t, FORS_DATA_STD_MAG[i], CPL_TYPE_FLOAT);
617 if (!cpl_table_has_column(t, FORS_DATA_STD_DMAG[i])) {
618 cpl_table_new_column(t, FORS_DATA_STD_DMAG[i], CPL_TYPE_FLOAT);
620 if (!cpl_table_has_column(t, FORS_DATA_STD_COL[i])) {
621 cpl_table_new_column(t, FORS_DATA_STD_COL[i], CPL_TYPE_FLOAT);
625 for (i = 0; i < N; i++) {
628 cpl_table_set_double(t, FORS_DATA_STD_RA , i, data[i].ra);
629 cpl_table_set_double(t, FORS_DATA_STD_DEC , i, data[i].dec);
630 cpl_table_set_string(t, FORS_DATA_STD_NAME, i, data[i].name);
632 for (j = 0; j < FORS_NUM_FILTER; j++) {
633 cpl_table_set_float (t, FORS_DATA_STD_MAG[j], i, data[i].magnitude);
634 cpl_table_set_float (t, FORS_DATA_STD_DMAG[j], i, data[i].dmagnitude);
635 cpl_table_set_float (t, FORS_DATA_STD_COL[j], i, data[i].col);
639 cpl_table_save(t, NULL, NULL, filename, CPL_IO_DEFAULT);
640 assure( !cpl_error_get_code(),
return NULL,
641 "Failed to save standard catalogue to %s", filename );
652 cpl_table_delete(t); \
668 double ext_coeff, dext_coeff;
669 double color_term, dcolor_term;
670 double expected_zeropoint, dexpected_zeropoint;
672 data[FORS_NUM_FILTER] = {
673 {
'U', 0.4 , 0.01, -0.076, 0.001, 20, 0.2},
674 {
'B', 0.05 , 0.01, 0.033, 0.001, 21.123456, 0.2},
675 {
'G', 0.1 , 0.01, 0.01 , 0.001, 22, 0.2},
676 {
'V', 0.09 , 0.01, -0.02 , 0.001, -18, 0.2},
677 {
'R', 0.2 , 0.01, 0.03 , 0.001, 0, 0.2},
678 {
'I', 0.000, 0.01, -0.04 , 0.001, 1.0, 0.2},
681 int N = fors_instrument_known_filters_get_number();
684 t = cpl_table_new(N);
685 cpl_table_new_column(t, FORS_DATA_PHOT_FILTER , CPL_TYPE_STRING);
686 cpl_table_new_column(t, FORS_DATA_PHOT_EXTCOEFF , CPL_TYPE_DOUBLE);
687 cpl_table_new_column(t, FORS_DATA_PHOT_DEXTCOEFF , CPL_TYPE_DOUBLE);
688 cpl_table_new_column(t, FORS_DATA_PHOT_COLORTERM, CPL_TYPE_DOUBLE);
689 cpl_table_new_column(t, FORS_DATA_PHOT_DCOLORTERM, CPL_TYPE_DOUBLE);
690 cpl_table_new_column(t, FORS_DATA_PHOT_ZEROPOINT, CPL_TYPE_DOUBLE);
691 cpl_table_new_column(t, FORS_DATA_PHOT_DZEROPOINT, CPL_TYPE_DOUBLE);
694 for (i = 0; i < N; i++) {
695 cpl_table_set_string( t,
696 FORS_DATA_PHOT_FILTER,
698 fors_instrument_known_filters_get_name(i));
701 for (j = 0; j < FORS_NUM_FILTER; j++) {
702 if (fors_instrument_known_filters_get_band(i) == data[j].band)
704 cpl_table_set_double(t, FORS_DATA_PHOT_EXTCOEFF , i, data[j].ext_coeff);
705 cpl_table_set_double(t, FORS_DATA_PHOT_DEXTCOEFF , i, data[j].dext_coeff);
706 cpl_table_set_double(t, FORS_DATA_PHOT_COLORTERM, i, data[j].color_term);
707 cpl_table_set_double(t, FORS_DATA_PHOT_DCOLORTERM, i, data[j].dcolor_term);
708 cpl_table_set_double(t, FORS_DATA_PHOT_ZEROPOINT, i, data[j].expected_zeropoint);
709 cpl_table_set_double(t, FORS_DATA_PHOT_DZEROPOINT, i, data[j].dexpected_zeropoint);
714 cpl_table_save(t, NULL, NULL, filename, CPL_IO_DEFAULT);
715 assure( !cpl_error_get_code(),
return NULL,
716 "Failed to save photometry table to %s", filename );
double fors_rand_gauss(void)
Pseudo-random gaussian distributed number.
cpl_frame * create_bias(const char *filename, const char *tag, cpl_frame_group group)
Simulate bias image.
fors_image * fors_image_new(cpl_image *data, cpl_image *variance)
Create image.
cpl_frame * create_dark(const char *filename, const char *tag, cpl_frame_group group)
Simulate dark image.
cpl_frame * create_master_sky_flat(const char *filename, const char *tag, cpl_frame_group group, double exptime)
Simulate master sky flat image.
cpl_frame * create_master_bias(const char *filename, const char *tag, cpl_frame_group group)
Simulate master bias image.
void create_standard_keys(cpl_propertylist *header, double exptime)
Write FORS standard keywords to simulated header.
cpl_frame * create_std_cat(const char *filename, const char *tag, cpl_frame_group group)
Create standard star catalogue.
static cpl_frame * frame_new(const char *filename, const char *tag, cpl_frame_group group)
Frame constructor.
cpl_frame * create_sky_flat(const char *filename, const char *tag, cpl_frame_group group, double exptime)
Simulate sky flat image.
cpl_frame * create_screen_flat(const char *filename, const char *tag, cpl_frame_group group)
Simulate screen flat image.
cpl_frame * create_phot_table(const char *filename, const char *tag, cpl_frame_group group)
Create photometry table.
cpl_frame * create_standard(const char *filename, const char *tag, cpl_frame_group group)
Create standard star image.
void fors_image_save(const fors_image *image, const cpl_propertylist *header, const cpl_propertylist *err_header, const char *filename)
Save image.