FORS Pipeline Reference Manual  5.0.9
fors_std_star-test.c
1 /* $Id: fors_std_star-test.c,v 1.22 2009-03-26 20:23:48 hlorch Exp $
2  *
3  * This file is part of the FORS Library
4  * Copyright (C) 2002-2006 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  * $Author: hlorch $
23  * $Date: 2009-03-26 20:23:48 $
24  * $Revision: 1.22 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <fors_data.h>
33 #include <fors_dfs.h>
34 #include <fors_instrument.h>
35 #include <fors_std_cat.h>
36 
37 #include <test_simulate.h>
38 #include <test.h>
39 
40 #include <cpl.h>
41 #include <math.h>
42 
50 #undef cleanup
51 #define cleanup \
52 do { \
53  cpl_frameset_delete(cat_frames); \
54  cpl_frame_delete(raw_frame); \
55  cpl_frame_delete(phot_table); \
56  fors_std_star_list_delete(&cat, fors_std_star_delete); \
57  fors_setting_delete(&setting); \
58  cpl_propertylist_delete(raw_header); raw_header = NULL; \
59 } while (0)
60 
64 static void
65 test_new(void)
66 {
67  cpl_frameset *cat_frames = NULL;
68  cpl_frame *phot_table = NULL;
69  const char *filename = "std_cat.fits";
70  fors_std_star_list *cat = NULL;
71  fors_setting *setting = NULL;
72  cpl_propertylist *raw_header = NULL;
73  double color_term, dcolor_term;
74  double ext_coeff, dext_coeff;
75  double expected_zeropoint, dexpected_zeropoint;
76  char band;
77 
78  /* Simulate */
79  cpl_frame *raw_frame = create_standard("std_cat_raw.fits",
80  STANDARD_IMG, CPL_FRAME_GROUP_RAW);
81 
82  phot_table = create_phot_table("std_cat_phot_table.fits",
83  PHOT_TABLE, CPL_FRAME_GROUP_CALIB);
84 
85  cat_frames = cpl_frameset_new();
86  cpl_frameset_insert(cat_frames,
87  create_std_cat(filename,
88  FLX_STD_IMG, CPL_FRAME_GROUP_CALIB));
89 
90  setting = fors_setting_new(raw_frame);
91 
92  fors_phot_table_load(phot_table, setting,
93  &color_term, &dcolor_term,
94  &ext_coeff, &dext_coeff,
95  &expected_zeropoint, &dexpected_zeropoint);
96 
97  /* Call function */
98  band = fors_instrument_filterband_get_by_setting(setting);
99  cat = fors_std_cat_load( cat_frames,
100  band,
101  0,
102  color_term,
103  dcolor_term);
104  raw_header = cpl_propertylist_load(cpl_frame_get_filename(raw_frame), 0);
105  fors_std_star_list_apply_wcs(cat, raw_header);
106 
107  /* Test results (TBI) */
108 
109  fors_std_star_print_list(CPL_MSG_DEBUG, cat);
110  fors_std_star_print_list(CPL_MSG_INFO, cat);
111 
112  cleanup;
113  return;
114 }
115 
116 
117 static void
118 test_dist(void)
119 {
120  double ra = 34.5;
121  double dec = -0.4;
122  double mag = 15;
123  double dmag = 0.51;
124  double cmag = 15.2;
125  double dcmag = 0.21;
126  double color = 0.2;
127  double dcolor = dcmag;
128  double cov_catm_col = dcolor;
129 
130  double shift_arcsecs;
131 
132  for (shift_arcsecs = 0.1; shift_arcsecs <= 100; shift_arcsecs *= 2) {
133 
134  fors_std_star *s = fors_std_star_new(ra, dec, mag, dmag,
135  cmag, dcmag,
136  color, dcolor,
137  cov_catm_col,
138  "some");
139  fors_std_star *t = fors_std_star_new(ra + shift_arcsecs/3600,
140  dec + shift_arcsecs/3600,
141  mag, dmag,
142  cmag, dcmag,
143  color, dcolor,
144  cov_catm_col,
145  "star");
146 
147  /* At arcsecond scale and DEC ~= 0, RA and DEC directions
148  are very perpendicular, so
149  expect distance = sqrt(2) * shift_arcsecs
150  */
151  test_rel( fors_std_star_dist_arcsec(s, t), sqrt(2)*shift_arcsecs, 0.01 );
152 
153  fors_std_star_delete(&s);
154  fors_std_star_delete(&t);
155  }
156 
157  return;
158 }
159 
163 int main(void)
164 {
165  TEST_INIT;
166 
167  /* cpl_msg_set_level(CPL_MSG_DEBUG); */
168  test_new();
169 
170  test_new(); /* The second call tests the reentrancy of WCSLIB and flex,
171  which is non-trivial */
172 
173  test_dist();
174 
175  TEST_END;
176 }
177 
static void test_new(void)
Test loading catalogue.
fors_setting * fors_setting_new(const cpl_frame *raw)
Create setting from FITS header.
Definition: fors_setting.c:64
int main(void)
Test of QC module.
cpl_frame * create_std_cat(const char *filename, const char *tag, cpl_frame_group group)
Create standard star catalogue.
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.