32 #include <fors_data.h>
35 #include <fors_star.h>
36 #include <fors_instrument.h>
37 #include <fors_std_star.h>
38 #include <fors_utils.h>
45 const char *
const FORS_DATA_PHOT_FILTER =
"FILTER";
46 const char *
const FORS_DATA_PHOT_EXTCOEFF =
"EXT";
47 const char *
const FORS_DATA_PHOT_DEXTCOEFF =
"DEXT";
48 const char *
const FORS_DATA_PHOT_ZEROPOINT =
"ZPOINT";
49 const char *
const FORS_DATA_PHOT_DZEROPOINT =
"DZPOINT";
50 const char *
const FORS_DATA_PHOT_COLORTERM =
"COL";
51 const char *
const FORS_DATA_PHOT_DCOLORTERM =
"DCOL";
57 cpl_wcs_delete(wcs); \
58 cpl_matrix_delete(from); \
59 cpl_matrix_delete(to); \
60 cpl_array_delete(status); \
68 fors_std_star_list_apply_wcs( fors_std_star_list *stars,
69 const cpl_propertylist *header)
73 cpl_matrix *from = NULL;
74 cpl_matrix *to = NULL;
75 cpl_array *status = NULL;
77 cassure_automsg( stars != NULL,
80 cassure_automsg( header != NULL,
84 if (fors_std_star_list_size(stars) == 0) {
89 wcs = cpl_wcs_new_from_propertylist(header);
90 assure( !cpl_error_get_code(),
return,
91 "Failed to get WCS from header");
97 from = cpl_matrix_new(fors_std_star_list_size(stars), 2);
99 for (star = fors_std_star_list_first(stars), i = 0;
101 star = fors_std_star_list_next(stars), i++) {
103 cpl_matrix_set(from, i, 0, star->ra);
104 cpl_matrix_set(from, i, 1, star->dec);
107 cpl_wcs_convert(wcs, from,
115 if (cpl_error_get_code() == CPL_ERROR_UNSPECIFIED) {
116 cpl_msg_warning(cpl_func,
117 "Ignoring WCSLIB unspecified error");
121 assure( !cpl_error_get_code(),
return,
122 "Failed to convert from world to physical coordinates");
124 assure( cpl_matrix_get_ncol(to) == 2,
125 return,
"%"CPL_SIZE_FORMAT
" columns, 2 expected",
126 cpl_matrix_get_ncol(to));
128 assure( cpl_matrix_get_nrow(to) == fors_std_star_list_size(stars),
129 return,
"%"CPL_SIZE_FORMAT
" rows, %d expected",
130 cpl_matrix_get_nrow(to), fors_std_star_list_size(stars));
132 assure( status != NULL,
return, NULL );
134 assure( cpl_array_get_size(status) == fors_std_star_list_size(stars),
135 return,
"Status array size is %"CPL_SIZE_FORMAT
", %d expected",
136 cpl_array_get_size(status), fors_std_star_list_size(stars));
138 for (star = fors_std_star_list_first(stars), i = 0;
140 star = fors_std_star_list_next(stars), i++) {
142 if (cpl_array_get_int(status, i, NULL) != 0) {
143 cpl_msg_warning(cpl_func,
"Catalogue star %d: "
144 "non-zero status = %d from WCSLIB",
145 i, cpl_array_get_int(status, i, NULL));
147 star->pixel->x = cpl_matrix_get(to, i, 0);
148 star->pixel->y = cpl_matrix_get(to, i, 1);
153 double deg_pr_pixel = 0.1/3600;
156 cpl_msg_warning(cpl_func,
157 "WCSLIB not available, "
158 "applying fake transformation");
160 for (star = fors_std_star_list_first(stars);
162 star = fors_std_star_list_next(stars)) {
164 star->pixel->x = (star->ra / deg_pr_pixel - 293000)/10;
165 star->pixel->y = (star->dec / deg_pr_pixel / 10 + 169800)/10;
177 cpl_table_delete(t); \
192 void fors_phot_table_load(
const cpl_frame *phot_table_frame,
198 double *expected_zeropoint,
199 double *dexpected_zeropoint)
203 assure( setting != NULL,
return, NULL );
207 assure( phot_table_frame != NULL,
return, NULL );
212 assure( (color_term == NULL) == (dcolor_term == NULL),
return, NULL );
213 assure( (ext_coeff == NULL) == (dext_coeff == NULL),
return, NULL );
214 assure( (expected_zeropoint == NULL) == (dexpected_zeropoint == NULL),
217 assure( cpl_frame_get_filename(phot_table_frame) != NULL,
return, NULL );
227 if (expected_zeropoint) {
228 *expected_zeropoint = 0.0;
229 *dexpected_zeropoint = 0.0;
232 if (setting->filter_name == NULL) {
233 cpl_msg_warning(cpl_func,
"Zeropoint computation is not supported "
234 "for non-standard filters");
243 assure( !cpl_error_get_code(),
return,
244 "Could not verify %s setting",
245 cpl_frame_get_filename(phot_table_frame));
248 t = cpl_table_load(cpl_frame_get_filename(phot_table_frame), 1, 1);
250 assure( !cpl_error_get_code(),
return,
"Could not load %s",
251 cpl_frame_get_filename(phot_table_frame));
253 assure( cpl_table_get_nrow(t) > 0,
return,
254 "Empty table %s", cpl_frame_get_filename(phot_table_frame));
257 const char *
const colname[] = {
258 FORS_DATA_PHOT_FILTER,
259 FORS_DATA_PHOT_EXTCOEFF,
260 FORS_DATA_PHOT_DEXTCOEFF,
261 FORS_DATA_PHOT_ZEROPOINT,
262 FORS_DATA_PHOT_DZEROPOINT,
263 FORS_DATA_PHOT_COLORTERM,
264 FORS_DATA_PHOT_DCOLORTERM};
266 const cpl_type coltype[] = {CPL_TYPE_STRING,
277 colrequired[1] = ext_coeff ? 1 : 0;
278 colrequired[2] = ext_coeff ? 1 : 0;
279 colrequired[3] = expected_zeropoint ? 1 : 0;
280 colrequired[4] = expected_zeropoint ? 1 : 0;
281 colrequired[5] = color_term ? 1 : 0;
282 colrequired[6] = color_term ? 1 : 0;
285 for (i = 0; i <
sizeof(colname) /
sizeof(*colname); i++) {
287 if (colrequired[i]) {
288 assure( cpl_table_has_column(t, colname[i]),
return,
289 "%s: Missing column %s",
290 cpl_frame_get_filename(phot_table_frame), colname[i]);
292 assure( cpl_table_get_column_type(t, colname[i]) == coltype[i],
294 "%s column %s type is %s, %s expected",
295 cpl_frame_get_filename(phot_table_frame),
301 assure( cpl_table_count_invalid(t, colname[i]) == 0,
return,
302 "%s column %s has invalid values",
303 cpl_frame_get_filename(phot_table_frame),
310 cpl_msg_debug(cpl_func,
"Searching for filter: %s", setting->filter_name);
314 for (i = 0; i < cpl_table_get_nrow(t) && !found; i++) {
315 const char *phot_filter = cpl_table_get_string(t, FORS_DATA_PHOT_FILTER, i);
317 assure( phot_filter != NULL,
return,
"%s, row %d: Null %s",
318 cpl_frame_get_filename(phot_table_frame), i+1, FORS_DATA_PHOT_FILTER);
320 if (strcmp(setting->filter_name, phot_filter) == 0) {
324 if (color_term != NULL) {
325 *color_term = cpl_table_get_double(t, FORS_DATA_PHOT_COLORTERM, i, NULL);
326 *dcolor_term = cpl_table_get_double(t, FORS_DATA_PHOT_DCOLORTERM, i, NULL);
329 if (ext_coeff != NULL) {
330 *ext_coeff = cpl_table_get_double(t, FORS_DATA_PHOT_EXTCOEFF, i, NULL);
331 *dext_coeff = cpl_table_get_double(t, FORS_DATA_PHOT_DEXTCOEFF, i, NULL);
334 if (expected_zeropoint != NULL) {
335 *expected_zeropoint =
336 cpl_table_get_double(t, FORS_DATA_PHOT_ZEROPOINT, i, NULL);
337 *dexpected_zeropoint =
338 cpl_table_get_double(t, FORS_DATA_PHOT_DZEROPOINT, i, NULL);
343 if (found ==
false) {
344 cpl_msg_warning(cpl_func,
"Entry for filter %s missing in input "
345 "photometric table (%s): assuming all photometric "
346 "coefficients Z, E, and color term, equal to zero.",
347 setting->filter_name,
348 cpl_frame_get_filename(phot_table_frame));
353 *expected_zeropoint = 0.0;
354 *dexpected_zeropoint = 0.0;
370 cpl_table_delete(table); \
389 cpl_table *fors_phot_coeff_create(
const fors_setting *setting,
397 cpl_table *table = cpl_table_new(1);
403 if (dcolor_term > 0.0 || dext_coeff > 0.0 || dzeropoint > 0.0) {
404 cpl_table_new_column(table, FORS_DATA_PHOT_FILTER, CPL_TYPE_STRING);
405 cpl_table_set_string(table, FORS_DATA_PHOT_FILTER,
406 0, setting->filter_name);
417 if (dext_coeff > 0.0) {
418 cpl_table_new_column(table, FORS_DATA_PHOT_EXTCOEFF, CPL_TYPE_DOUBLE);
419 cpl_table_new_column(table, FORS_DATA_PHOT_DEXTCOEFF, CPL_TYPE_DOUBLE);
420 cpl_table_set_double(table, FORS_DATA_PHOT_EXTCOEFF, 0, ext_coeff);
421 cpl_table_set_double(table, FORS_DATA_PHOT_DEXTCOEFF, 0, dext_coeff);
424 if (dzeropoint > 0.0) {
425 cpl_table_new_column(table, FORS_DATA_PHOT_ZEROPOINT, CPL_TYPE_DOUBLE);
426 cpl_table_new_column(table, FORS_DATA_PHOT_DZEROPOINT, CPL_TYPE_DOUBLE);
427 cpl_table_set_double(table, FORS_DATA_PHOT_ZEROPOINT, 0, zeropoint);
428 cpl_table_set_double(table, FORS_DATA_PHOT_DZEROPOINT, 0, dzeropoint);
431 if (dcolor_term > 0.0) {
432 cpl_table_new_column(table, FORS_DATA_PHOT_COLORTERM, CPL_TYPE_DOUBLE);
433 cpl_table_new_column(table, FORS_DATA_PHOT_DCOLORTERM, CPL_TYPE_DOUBLE);
434 cpl_table_set_double(table, FORS_DATA_PHOT_COLORTERM, 0, color_term);
435 cpl_table_set_double(table, FORS_DATA_PHOT_DCOLORTERM, 0, dcolor_term);
const char * fors_type_get_string(cpl_type t)
Textual representation of CPL type.
void fors_setting_verify(const fors_setting *ref_setting, const cpl_frame *frame, fors_setting **setting)
Verify that instrument settings are compatible.