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