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);
290 for (y = 1; y <= ny; y++)
291 for (x = 1; x <= nx; x++) {
292 cpl_image_set(data , x, y,
294 cpl_image_set(variance, x, y, ron*ron);
301 assure( !cpl_error_get_code(),
return NULL,
302 "Saving master bias to %s failed", filename );
311 fors_image_delete(&dark); \
312 cpl_propertylist_delete(header); \
326 create_dark(
const char *filename,
const char *tag, cpl_frame_group group)
328 int nx = det_nx / binx + pres_nx;
329 int ny = det_ny / biny;
330 double exptime = 3.0;
332 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
333 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
335 cpl_propertylist *header = cpl_propertylist_new();
341 for (y = 1; y <= ny; y++)
342 for (x = 1; x <= nx; x++) {
343 double var = ron*ron + dark_avg/conad;
345 cpl_image_set(data , x, y,
346 (
int)(bias_avg + dark_avg +
349 cpl_image_set(variance, x, y, var);
352 for (y = 1; y <= ny; y++)
353 for (x = 1; x <= pres_nx; x++)
355 cpl_image_set(data , x, y,
357 cpl_image_set(variance, x, y, ron*ron);
364 assure( !cpl_error_get_code(),
return NULL,
365 "Saving dark to %s failed", filename );
375 fors_image_delete(&sflat); \
376 cpl_propertylist_delete(header); \
391 int nx = det_nx / binx + pres_nx;
392 int ny = det_ny / biny;
393 double exptime = 3.0;
395 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
396 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
398 cpl_propertylist *header = cpl_propertylist_new();
404 for (y = 1; y <= ny; y++)
405 for (x = 1; x <= nx; x++) {
406 double medium_scale_structure = 1000*(2 + sin(x*30.0/nx + y*30.0/ny));
407 double large_scale_structure = 1000*(1 + sin(x*4.0/nx));
408 double flat = 5000 + medium_scale_structure + large_scale_structure;
409 double var = ron*ron + flat/conad;
411 cpl_image_set(data , x, y,
413 cpl_image_set(variance, x, y, var);
416 for (y = 1; y <= ny; y++)
417 for (x = 1; x <= pres_nx; x++)
419 cpl_image_set(data , x, y,
421 cpl_image_set(variance, x, y, ron*ron);
428 assure( !cpl_error_get_code(),
return NULL,
429 "Saving screen flat to %s failed", filename );
438 fors_image_delete(&sflat); \
439 cpl_propertylist_delete(header); \
456 int nx = det_nx / binx + pres_nx;
457 int ny = det_ny / biny;
459 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
460 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
462 cpl_propertylist *header = cpl_propertylist_new();
468 for (y = 1; y <= ny; y++)
469 for (x = 1; x <= nx; x++) {
470 double medium_scale_structure = 1000*(2 + sin(x*30.0/nx - y*10.0/ny));
471 double large_scale_structure = 1000*(1 + sin(x*4.0/nx));
472 double flat = exptime*(5000 +
473 medium_scale_structure +
474 large_scale_structure);
475 double var = ron*ron + flat/conad;
477 cpl_image_set(data , x, y,
479 cpl_image_set(variance, x, y, var);
482 for (y = 1; y <= ny; y++)
483 for (x = 1; x <= pres_nx; x++)
485 cpl_image_set(data , x, y,
487 cpl_image_set(variance, x, y, ron*ron);
494 assure( !cpl_error_get_code(),
return NULL,
495 "Saving sky flat to %s failed", filename );
514 const char *tag, cpl_frame_group group,
517 int nx = det_nx / binx;
518 int ny = det_ny / biny;
520 cpl_image *data = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
521 cpl_image *variance = cpl_image_new(nx, ny, FORS_IMAGE_TYPE);
523 cpl_propertylist *header = cpl_propertylist_new();
529 for (y = 1; y <= ny; y++)
530 for (x = 1; x <= nx; x++) {
531 double medium_scale_structure = 1000*(2 + sin(x*30.0/nx - y*10.0/ny));
532 double large_scale_structure = 1000*(1 + sin(x*4.0/nx));
533 double flat = exptime*(5000 +
534 medium_scale_structure +
535 large_scale_structure);
536 double var = ron*ron + flat/conad;
538 cpl_image_set(data , x, y,
540 cpl_image_set(variance, x, y, var);
547 assure( !cpl_error_get_code(),
return NULL,
548 "Saving sky flat to %s failed", filename );
565 double exptime = 1.0;
573 cpl_table_delete(t); \
589 double magnitude, dmagnitude;
594 {8.15958, -47.0347, 15.824000, 0.001, 0.8,
"object 1"},
595 {8.14792, -46.9664, 12.895000, 0.002, -0.2,
""},
596 {8.15083, -47.0092, 12.861000, 0.003, -0.3,
" dff bject 1"},
597 {8.15583, -47.0222, 16.540001, 0.001, 0.7,
"-9"},
598 {8.17167, -47.10 , 11.970000, 0.005, 0.12, NULL},
599 {8.14833, -47.0567, 13.861000, 0.003, -0.2,
""},
600 {8.1475 , -47.0411, 13.903000, 0.001, -0.8,
"dddddddobject 1"},
601 {7.92542, 2.62917, 15.446000, 0.002, -0.2,
"start 1"},
604 int N =
sizeof(data) /
sizeof(*data);
607 t = cpl_table_new(N);
608 cpl_table_new_column(t, FORS_DATA_STD_RA , CPL_TYPE_DOUBLE);
609 cpl_table_new_column(t, FORS_DATA_STD_DEC, CPL_TYPE_DOUBLE);
610 cpl_table_new_column(t, FORS_DATA_STD_NAME, CPL_TYPE_STRING);
612 for (i = 0; i < FORS_NUM_FILTER; i++) {
613 if (!cpl_table_has_column(t, FORS_DATA_STD_MAG[i])) {
614 cpl_table_new_column(t, FORS_DATA_STD_MAG[i], CPL_TYPE_FLOAT);
616 if (!cpl_table_has_column(t, FORS_DATA_STD_DMAG[i])) {
617 cpl_table_new_column(t, FORS_DATA_STD_DMAG[i], CPL_TYPE_FLOAT);
619 if (!cpl_table_has_column(t, FORS_DATA_STD_COL[i])) {
620 cpl_table_new_column(t, FORS_DATA_STD_COL[i], CPL_TYPE_FLOAT);
624 for (i = 0; i < N; i++) {
627 cpl_table_set_double(t, FORS_DATA_STD_RA , i, data[i].ra);
628 cpl_table_set_double(t, FORS_DATA_STD_DEC , i, data[i].dec);
629 cpl_table_set_string(t, FORS_DATA_STD_NAME, i, data[i].name);
631 for (j = 0; j < FORS_NUM_FILTER; j++) {
632 cpl_table_set_float (t, FORS_DATA_STD_MAG[j], i, data[i].magnitude);
633 cpl_table_set_float (t, FORS_DATA_STD_DMAG[j], i, data[i].dmagnitude);
634 cpl_table_set_float (t, FORS_DATA_STD_COL[j], i, data[i].col);
638 cpl_table_save(t, NULL, NULL, filename, CPL_IO_DEFAULT);
639 assure( !cpl_error_get_code(),
return NULL,
640 "Failed to save standard catalogue to %s", filename );
651 cpl_table_delete(t); \
667 double ext_coeff, dext_coeff;
668 double color_term, dcolor_term;
669 double expected_zeropoint, dexpected_zeropoint;
671 data[FORS_NUM_FILTER] = {
672 {
'U', 0.4 , 0.01, -0.076, 0.001, 20, 0.2},
673 {
'B', 0.05 , 0.01, 0.033, 0.001, 21.123456, 0.2},
674 {
'G', 0.1 , 0.01, 0.01 , 0.001, 22, 0.2},
675 {
'V', 0.09 , 0.01, -0.02 , 0.001, -18, 0.2},
676 {
'R', 0.2 , 0.01, 0.03 , 0.001, 0, 0.2},
677 {
'I', 0.000, 0.01, -0.04 , 0.001, 1.0, 0.2},
680 int N = fors_instrument_known_filters_get_number();
683 t = cpl_table_new(N);
684 cpl_table_new_column(t, FORS_DATA_PHOT_FILTER , CPL_TYPE_STRING);
685 cpl_table_new_column(t, FORS_DATA_PHOT_EXTCOEFF , CPL_TYPE_DOUBLE);
686 cpl_table_new_column(t, FORS_DATA_PHOT_DEXTCOEFF , CPL_TYPE_DOUBLE);
687 cpl_table_new_column(t, FORS_DATA_PHOT_COLORTERM, CPL_TYPE_DOUBLE);
688 cpl_table_new_column(t, FORS_DATA_PHOT_DCOLORTERM, CPL_TYPE_DOUBLE);
689 cpl_table_new_column(t, FORS_DATA_PHOT_ZEROPOINT, CPL_TYPE_DOUBLE);
690 cpl_table_new_column(t, FORS_DATA_PHOT_DZEROPOINT, CPL_TYPE_DOUBLE);
693 for (i = 0; i < N; i++) {
694 cpl_table_set_string( t,
695 FORS_DATA_PHOT_FILTER,
697 fors_instrument_known_filters_get_name(i));
700 for (j = 0; j < FORS_NUM_FILTER; j++) {
701 if (fors_instrument_known_filters_get_band(i) == data[j].band)
703 cpl_table_set_double(t, FORS_DATA_PHOT_EXTCOEFF , i, data[j].ext_coeff);
704 cpl_table_set_double(t, FORS_DATA_PHOT_DEXTCOEFF , i, data[j].dext_coeff);
705 cpl_table_set_double(t, FORS_DATA_PHOT_COLORTERM, i, data[j].color_term);
706 cpl_table_set_double(t, FORS_DATA_PHOT_DCOLORTERM, i, data[j].dcolor_term);
707 cpl_table_set_double(t, FORS_DATA_PHOT_ZEROPOINT, i, data[j].expected_zeropoint);
708 cpl_table_set_double(t, FORS_DATA_PHOT_DZEROPOINT, i, data[j].dexpected_zeropoint);
713 cpl_table_save(t, NULL, NULL, filename, CPL_IO_DEFAULT);
714 assure( !cpl_error_get_code(),
return NULL,
715 "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.
void fors_image_save(const fors_image *image, const cpl_propertylist *header, const char *filename)
Save image.
cpl_frame * create_standard(const char *filename, const char *tag, cpl_frame_group group)
Create standard star image.