CR2RE Pipeline Reference Manual 1.7.0
hdrl_barycorr-test.c
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2022 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20
21#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
25/*----------------------------------------------------------------------------*/
29/*----------------------------------------------------------------------------*/
30
31#include "hdrl_barycorr.h"
32
33/*----------------------------------------------------------------------------*/
37/*----------------------------------------------------------------------------*/
38
39
40static cpl_table * hdrl_create_eoptable(void){
41
42 cpl_table * eop_table = cpl_table_new(4);
43 cpl_table_new_column(eop_table, "MJD", CPL_TYPE_DOUBLE);
44 cpl_table_new_column(eop_table, "PMX", CPL_TYPE_DOUBLE);
45 cpl_table_new_column(eop_table, "PMY", CPL_TYPE_DOUBLE);
46 cpl_table_new_column(eop_table, "DUT", CPL_TYPE_DOUBLE);
47 cpl_table_new_column(eop_table, "FLAG", CPL_TYPE_STRING);
48
49 cpl_table_set_double(eop_table, "MJD", 0, 5.884300000000E+04);
50 cpl_table_set_double(eop_table, "MJD", 1, 5.884400000000E+04);
51 cpl_table_set_double(eop_table, "MJD", 2, 5.884500000000E+04);
52 cpl_table_set_double(eop_table, "MJD", 3, 5.884600000000E+04);
53
54 cpl_table_set_double(eop_table, "PMX", 0, 8.855900000000E-02);
55 cpl_table_set_double(eop_table, "PMX", 1, 8.687500000000E-02);
56 cpl_table_set_double(eop_table, "PMX", 2, 8.503000000000E-02);
57 cpl_table_set_double(eop_table, "PMX", 3, 8.285400000000E-02);
58
59 cpl_table_set_double(eop_table, "PMY", 0, 2.800810000000E-01);
60 cpl_table_set_double(eop_table, "PMY", 1, 2.806870000000E-01);
61 cpl_table_set_double(eop_table, "PMY", 2, 2.812910000000E-01);
62 cpl_table_set_double(eop_table, "PMY", 3, 2.816470000000E-01);
63
64 cpl_table_set_double(eop_table, "DUT", 0, -1.761465000000E-01);
65 cpl_table_set_double(eop_table, "DUT", 1, -1.762087000000E-01);
66 cpl_table_set_double(eop_table, "DUT", 2, -1.762508000000E-01);
67 cpl_table_set_double(eop_table, "DUT", 3, -1.763259000000E-01);
68
69 cpl_table_set_string(eop_table, "FLAG", 0, "I");
70 cpl_table_set_string(eop_table, "FLAG", 1, "I");
71 cpl_table_set_string(eop_table, "FLAG", 2, "I");
72 cpl_table_set_string(eop_table, "FLAG", 3, "I");
73
74 return eop_table;
75
76}
77
78static cpl_error_code hdrl_barycorr_compute_test(void) {
79
80/*
81 This unittest has been extracted from a regression tests using the following
82 ESPRESSO file: ADP.2021-04-15T13:14:18.089.fits
83
84 Results from espresso and hdrl read as follows:
85 hdrl barycorr recipe: 22.814877482069
86 ESPRESSO pipeline: 22.814548243970
87*/
88 cpl_table * eop_table = hdrl_create_eoptable();
89
90 double ra = 149.823138;
91 double dec = -27.39211;
92 double mjdobs = 58844.22531243;
93 double time_to_mid_exposure = 900.;
94 double longitude = -70.4045;
95 double latitude = -24.6268;
96 double elevation = 2648.;
97 double pressure = 0.;
98 double temperature = 0.;
99 double humidity = 0.;
100 double wavelength = 0.;
101
102 double barycorr = 0.;
103
104 hdrl_barycorr_compute(ra, dec, eop_table, mjdobs, time_to_mid_exposure,
105 longitude, latitude, elevation, pressure, temperature,
106 humidity, wavelength, &barycorr);
107
108 cpl_test_error(CPL_ERROR_NONE);
109 cpl_test_abs(barycorr, 22814.877482069, FLT_EPSILON);
110
111 hdrl_barycorr_compute(-1., dec, eop_table, mjdobs, time_to_mid_exposure,
112 longitude, latitude, elevation, pressure, temperature,
113 humidity, wavelength, &barycorr);
114 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
115
116 hdrl_barycorr_compute(ra, 100., eop_table, mjdobs, time_to_mid_exposure,
117 longitude, latitude, elevation, pressure, temperature,
118 humidity, wavelength, &barycorr);
119 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
120
121 hdrl_barycorr_compute(ra, dec, eop_table, mjdobs, time_to_mid_exposure,
122 -200., latitude, elevation, pressure, temperature,
123 humidity, wavelength, &barycorr);
124 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
125
126 hdrl_barycorr_compute(ra, dec, eop_table, mjdobs, time_to_mid_exposure,
127 longitude, 100, elevation, pressure, temperature,
128 humidity, wavelength, &barycorr);
129 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
130
131 hdrl_barycorr_compute(ra, dec, NULL, mjdobs, time_to_mid_exposure,
132 longitude, latitude, elevation, pressure, temperature,
133 humidity, wavelength, &barycorr);
134 cpl_test_error(CPL_ERROR_NULL_INPUT);
135
136
137 cpl_table_delete(eop_table);
138 return cpl_error_get_code();
139}
140
141static cpl_error_code hdrl_eop_interpolate_test(void) {
142
143 /*
144 This unittest has been extracted from a regression tests using the following
145 ESPRESSO file: ADP.2021-04-15T13:14:18.089.fits
146 See also unit test above
147 */
148
149 cpl_table * eop_table = hdrl_create_eoptable();
150
151 /* Compute Earth Orientation Parameters for the mean MJD */
152 double mean_mjd = 58844.235729096661089;
153 double dut1 = 0., pmx = 0., pmy = 0.;
154
155 hdrl_parameter * resample_par =
156 hdrl_spectrum1D_resample_interpolate_parameter_create(hdrl_spectrum1D_interp_linear);
157
158 hdrl_eop_interpolate(mean_mjd, eop_table, resample_par, &pmx, &pmy, &dut1) ;
159 cpl_test_error(CPL_ERROR_NONE);
160
161 /* Interpolated Earth Orientation Parameter for MJD-OBS 58844.235729096661089:
162 * pmx: 0.086440079816660284062,
163 * pmy: 0.28082938037438331946,
164 * dut1: -0.17621862419496941987*/
165 cpl_test_abs(pmx, 0.08644007981666028406, FLT_EPSILON);
166 cpl_test_abs(pmy, 0.28082938037438331946, FLT_EPSILON);
167 cpl_test_abs(dut1, -0.17621862419496941987, FLT_EPSILON);
168
169 hdrl_eop_interpolate(mean_mjd, NULL, resample_par, &pmx, &pmy, &dut1) ;
170 cpl_test_error(CPL_ERROR_NULL_INPUT);
171
172 hdrl_eop_interpolate(mean_mjd, eop_table, NULL, &pmx, &pmy, &dut1) ;
173 cpl_test_error(CPL_ERROR_NULL_INPUT);
174
175 hdrl_eop_interpolate(mean_mjd, NULL, resample_par, NULL, &pmy, &dut1) ;
176 cpl_test_error(CPL_ERROR_NULL_INPUT);
177 hdrl_eop_interpolate(mean_mjd, NULL, resample_par, &pmx, NULL, &dut1) ;
178 cpl_test_error(CPL_ERROR_NULL_INPUT);
179 hdrl_eop_interpolate(mean_mjd, NULL, resample_par, &pmx, &pmy, NULL) ;
180 cpl_test_error(CPL_ERROR_NULL_INPUT);
181
182 hdrl_eop_interpolate(-100., eop_table, resample_par, &pmx, &pmy, &dut1) ;
183 cpl_test_error(CPL_ERROR_NONE);
184
185
186 cpl_table * eop_table_with_invalid = cpl_table_duplicate(eop_table);
187
188 cpl_table_set_column_invalid(eop_table_with_invalid,"DUT", 0, 2);
189 hdrl_eop_interpolate(1., eop_table_with_invalid, resample_par, &pmx, &pmy, &dut1) ;
190 cpl_test_error(CPL_ERROR_NONE);
191 cpl_table_delete(eop_table_with_invalid);
192
193 eop_table_with_invalid = cpl_table_duplicate(eop_table);
194 cpl_table_set_column_invalid(eop_table_with_invalid,"DUT", 0, 4);
195 hdrl_eop_interpolate(1., eop_table_with_invalid, resample_par, &pmx, &pmy, &dut1) ;
196 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
197 cpl_table_delete(eop_table_with_invalid);
198
199 cpl_table_erase_column(eop_table, "PMY");
200 hdrl_eop_interpolate(mean_mjd, eop_table, resample_par, &pmx, &pmy, &dut1) ;
201 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
202
203 cpl_table_delete(eop_table);
204 hdrl_parameter_delete(resample_par);
205 return cpl_error_get_code();
206}
207
208
209
210/*----------------------------------------------------------------------------*/
217/*----------------------------------------------------------------------------*/
218
219int main(void)
220{
221 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
222
223 hdrl_barycorr_compute_test();
224 hdrl_eop_interpolate_test();
225
226 return cpl_test_end(0);
227}
228
229
230
231
cpl_error_code hdrl_barycorr_compute(double ra, double dec, const cpl_table *eop_table, double mjdobs, double time_to_mid_exposure, double longitude, double latitude, double elevation, double pressure, double temperature, double humidity, double wavelength, double *barycorr)
Derives the barycentric correction using the erfa function eraApco13(). The latter For a terrestrial ...
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter
hdrl_parameter * hdrl_spectrum1D_resample_interpolate_parameter_create(const hdrl_spectrum1D_interpolation_method method)
constructor for the hdrl_parameter in the case of interpolation