33 #include <fors_tools.h>
35 #include <fors_pfits.h>
36 #include <fors_utils.h>
53 cpl_propertylist_delete(header); \
69 const cpl_frame *raw_frame)
71 cpl_propertylist *header = NULL;
74 cpl_msg_info(cpl_func,
"Extinction correction");
76 assure( cpl_frame_get_filename(raw_frame) != NULL,
return -1, NULL );
78 header = cpl_propertylist_load(cpl_frame_get_filename(raw_frame), 0);
79 assure( !cpl_error_get_code(),
return -1,
80 "Failed to load %s primary header",
81 cpl_frame_get_filename(raw_frame));
85 assure( !cpl_error_get_code(),
return -1,
86 "%s: Could not read airmass",
87 cpl_frame_get_filename(raw_frame));
89 cpl_msg_indent_more();
90 cpl_msg_info(cpl_func,
"Exposure time = %f s", setting->exposure_time);
91 cpl_msg_info(cpl_func,
"Gain = %f ADU/e-", setting->average_gain);
92 cpl_msg_info(cpl_func,
"Ext. coeff. = %f +- %f mag/airmass",
93 ext_coeff, dext_coeff);
94 cpl_msg_info(cpl_func,
"Avg. airmass = %f airmass", avg_airmass);
97 cpl_msg_indent_less();
102 for (star = fors_star_list_first(stars);
104 star = fors_star_list_next(stars)) {
105 star->magnitude_corr = star->magnitude
106 + 2.5*log(setting->average_gain)/log(10)
107 + 2.5*log(setting->exposure_time)/log(10)
108 - ext_coeff * avg_airmass;
113 star->dmagnitude_corr = sqrt(star->dmagnitude * star->dmagnitude
114 + dext_coeff*dext_coeff * avg_airmass*avg_airmass);
134 t = cpl_table_new(fors_star_list_size(sources));
135 cpl_table_new_column(t,
"X", CPL_TYPE_DOUBLE);
136 cpl_table_new_column(t,
"Y", CPL_TYPE_DOUBLE);
137 cpl_table_new_column(t,
"FWHM", CPL_TYPE_DOUBLE);
138 cpl_table_new_column(t,
"A", CPL_TYPE_DOUBLE);
139 cpl_table_new_column(t,
"B", CPL_TYPE_DOUBLE);
140 cpl_table_new_column(t,
"THETA", CPL_TYPE_DOUBLE);
141 cpl_table_new_column(t,
"ELL", CPL_TYPE_DOUBLE);
142 cpl_table_new_column(t,
"INSTR_MAG", CPL_TYPE_DOUBLE);
143 cpl_table_new_column(t,
"DINSTR_MAG", CPL_TYPE_DOUBLE);
144 cpl_table_new_column(t,
"INSTR_CMAG", CPL_TYPE_DOUBLE);
145 cpl_table_new_column(t,
"DINSTR_CMAG", CPL_TYPE_DOUBLE);
146 cpl_table_new_column(t,
"CLASS_STAR", CPL_TYPE_DOUBLE);
148 cpl_table_new_column(t,
"OBJECT", CPL_TYPE_STRING);
149 cpl_table_new_column(t,
"RA", CPL_TYPE_DOUBLE);
150 cpl_table_new_column(t,
"DEC", CPL_TYPE_DOUBLE);
151 cpl_table_new_column(t,
"MAG", CPL_TYPE_DOUBLE);
152 cpl_table_new_column(t,
"DMAG", CPL_TYPE_DOUBLE);
153 cpl_table_new_column(t,
"CAT_MAG", CPL_TYPE_DOUBLE);
154 cpl_table_new_column(t,
"DCAT_MAG", CPL_TYPE_DOUBLE);
155 cpl_table_new_column(t,
"COLOR", CPL_TYPE_DOUBLE);
156 cpl_table_new_column(t,
"DCOLOR", CPL_TYPE_DOUBLE);
157 cpl_table_new_column(t,
"COV_CATM_COL", CPL_TYPE_DOUBLE);
158 cpl_table_new_column(t,
"USE_CAT", CPL_TYPE_INT);
161 cpl_table_new_column(t,
"SHIFT_X", CPL_TYPE_DOUBLE);
162 cpl_table_new_column(t,
"SHIFT_Y", CPL_TYPE_DOUBLE);
163 cpl_table_new_column(t,
"ZEROPOINT", CPL_TYPE_DOUBLE);
164 cpl_table_new_column(t,
"DZEROPOINT", CPL_TYPE_DOUBLE);
165 cpl_table_new_column(t,
"WEIGHT", CPL_TYPE_DOUBLE);
170 for (s = fors_star_list_first(sources), i = 0;
172 s = fors_star_list_next(sources), i++) {
174 const fors_std_star *
id = s->id;
176 cpl_table_set_double(t,
"X", i, s->pixel->x);
177 cpl_table_set_double(t,
"Y", i, s->pixel->y);
178 cpl_table_set_double(t,
"FWHM", i, s->fwhm);
179 cpl_table_set_double(t,
"A", i, s->semi_major);
180 cpl_table_set_double(t,
"B", i, s->semi_minor);
181 cpl_table_set_double(t,
"THETA", i, s->orientation);
183 cpl_table_set_double(t,
"INSTR_MAG", i, s->magnitude);
184 cpl_table_set_double(t,
"DINSTR_MAG", i, s->dmagnitude);
185 cpl_table_set_double(t,
"INSTR_CMAG", i, s->magnitude_corr);
186 cpl_table_set_double(t,
"DINSTR_CMAG", i, s->dmagnitude_corr);
187 cpl_table_set_double(t,
"CLASS_STAR", i, s->stellarity_index);
188 cpl_table_set_double(t,
"WEIGHT", i, s->weight);
192 cpl_table_set_string(t,
"OBJECT", i, id->name);
193 cpl_table_set_double(t,
"RA", i, id->ra);
194 cpl_table_set_double(t,
"DEC", i, id->dec);
195 cpl_table_set_double(t,
"MAG", i, id->magnitude);
196 cpl_table_set_double(t,
"DMAG", i, id->dmagnitude);
197 cpl_table_set_double(t,
"CAT_MAG", i, id->cat_magnitude);
198 cpl_table_set_double(t,
"DCAT_MAG", i, id->dcat_magnitude);
199 cpl_table_set_double(t,
"COLOR", i, id->color);
200 cpl_table_set_double(t,
"DCOLOR", i, id->dcolor);
201 cpl_table_set_double(t,
"COV_CATM_COL", i, id->cov_catm_color);
202 cpl_table_set_double(t,
"SHIFT_X", i, s->pixel->x
204 cpl_table_set_double(t,
"SHIFT_Y", i, s->pixel->y
206 cpl_table_set_double(t,
"ZEROPOINT", i,
208 cpl_table_set_double(t,
"DZEROPOINT", i,
211 cpl_table_set_int (t,
"USE_CAT", i,
212 ((id->trusted) ? 1 : 0));
215 cpl_table_set_invalid(t,
"RA" , i);
216 cpl_table_set_invalid(t,
"DEC", i);
217 cpl_table_set_invalid(t,
"MAG", i);
218 cpl_table_set_invalid(t,
"DMAG", i);
219 cpl_table_set_invalid(t,
"SHIFT_X", i);
220 cpl_table_set_invalid(t,
"SHIFT_Y", i);
221 cpl_table_set_invalid(t,
"ZEROPOINT", i);
222 cpl_table_set_invalid(t,
"DZEROPOINT", i);
233 fors_image_delete(&image); \
234 fors_image_delete(&image2); \
248 double master_fixed_pattern_noise;
252 assure( master != NULL,
return -1, NULL );
265 mid_x - 50, mid_y - 50,
266 mid_x + 50, mid_y + 50);
270 mid_x + 10 - 50, mid_y + 10 - 50,
271 mid_x + 10 + 50, mid_y + 10 + 50);
275 master_fixed_pattern_noise =
279 master_fixed_pattern_noise *= convert_ADU;
282 if (master_fixed_pattern_noise >= master_noise) {
284 master_fixed_pattern_noise = sqrt(master_fixed_pattern_noise*
285 master_fixed_pattern_noise
291 cpl_msg_warning(cpl_func,
292 "Zero-shift noise (%f ADU) is greater than "
293 "accumulated zero-shift and fixed pattern noise (%f ADU), "
294 "setting fixed pattern noise to zero",
296 master_fixed_pattern_noise);
297 master_fixed_pattern_noise = 0;
301 cpl_msg_warning(cpl_func,
302 "Master flat too small (%dx%d), "
303 "need size 121x121 to compute master flat "
304 "fixed pattern noise",
307 master_fixed_pattern_noise = -1;
311 return master_fixed_pattern_noise;
318 fors_image_delete(&image); \
319 fors_image_delete(&image2); \
333 double bias_fixed_pattern_noise;
338 assure( first_raw != NULL,
return -1, NULL );
339 assure( second_raw != NULL,
return -1, NULL );
367 if (bias_fixed_pattern_noise > ron) {
369 bias_fixed_pattern_noise = sqrt(bias_fixed_pattern_noise *
370 bias_fixed_pattern_noise
375 cpl_msg_warning(cpl_func,
376 "Zero-shift noise (%f ADU) is greater than "
377 "accumulated zero-shift and fixed pattern "
379 "setting fixed pattern noise to zero",
381 bias_fixed_pattern_noise);
382 bias_fixed_pattern_noise = 0;
386 return bias_fixed_pattern_noise;
400 double airmass_start, airmass_end;
401 airmass_start = cpl_propertylist_get_double(header, FORS_PFITS_AIRMASS_START);
402 assure( !cpl_error_get_code(),
return -1,
403 "Could not read %s from header",
404 FORS_PFITS_AIRMASS_START);
406 airmass_end = cpl_propertylist_get_double(header, FORS_PFITS_AIRMASS_END);
407 if(cpl_error_get_code())
409 cpl_msg_warning(cpl_func,
"Could not read %s. Using only keyword %s",
410 FORS_PFITS_AIRMASS_END, FORS_PFITS_AIRMASS_START);
412 return airmass_start;
415 return 0.5 * (airmass_start + airmass_end);
418 int fors_isnan(
double x)
double fors_image_get_stdev_robust(const fors_image *image, double cut, double *dstdev)
Get robust empirical stdev of data.
double fors_star_ellipticity(const fors_star *s, void *data)
Get star ellipticity.
void fors_image_subtract(fors_image *left, const fors_image *right)
Subtract images.
void fors_image_crop(fors_image *image, int xlo, int ylo, int xhi, int yhi)
Crop image.
double fors_image_get_stdev(const fors_image *image, double *dstdev)
Get empirical stdev of data.
cpl_size fors_image_get_size_y(const fors_image *image)
Get image height.
double fors_star_get_zeropoint_err(const fors_star *s, void *data)
Get zeropoint error.
cpl_size fors_image_get_size_x(const fors_image *image)
Get image width.
double fors_star_get_zeropoint(const fors_star *s, void *data)
Get zeropoint.
fors_image * fors_image_duplicate(const fors_image *image)
Copy constructor.