33 #include <sinfo_msg.h>
34 #include <sinfo_utils_wrappers.h>
35 #include "sinfo_atmo_disp.h"
36 #include "sinfo_resampling.h"
37 #include "sinfo_image_ops.h"
46 double parallactic_shiftX;
47 double parallactic_shiftY;
49 typedef struct _disp_data disp_data;
50 static double sinfo_disp_calc_N(
const disp_data* pdata,
double lambda);
52 sinfo_disp_prepare_data(disp_data* pdata,
62 sinfo_disp_calc(disp_data* pdata,
double lambda,
double *shiftx,
double *shiftY);
64 sinfo_atmo_rotate_point(
double* x_value,
double * y_value,
double rot_angle);
68 sinfo_disp_calc_N(
const disp_data* pdata,
double lambda)
70 double s = 1.0 /lambda;
77 double a = 83939.7/(130 - s2);
78 double b = 4547.3/(38.99 - s2);
79 double c = 6487.31 + 58.058*s2 - 0.71150*s4 + 0.08851*s6;
80 double N = 1e-8 * ( ((2371.34 + a + b) * pdata->d1) + ( c * pdata->d2));
86 sinfo_disp_prepare_data(disp_data* pdata,
95 double ps,p2,p1,T,T2,T3;
99 T = Tc + 273.15;T2 = T * T; T3 = T2 * T;
100 ps = -10474 + (116.43 * T) - (0.43284 *T2) + (0.00053840 * T3);
103 pdata->d1 = (p1/T)*(1+p1*( (57.90e-8) - ((9.3250e-4)/T) + (0.25844/T2)));
104 pdata->d2 = (p2/T)*(1+p2*(1+3.7e-4*p2)*( (-2.37321e-3) + (2.23366/T) - (710.792/T2) + ((7.75141e-4)/T3) )) ;
105 pdata->N0 = sinfo_disp_calc_N(pdata, lambda0);
106 zenith = acos(1/airm);
107 pdata->predelta = ((tan(zenith)) / (PI_NUMB/180)) * 3600;
108 pdata->parallactic_shiftX = sin ( (parallactic)* (PI_NUMB/180) ) / pixelscale;
109 pdata->parallactic_shiftY = cos ( (parallactic)* (PI_NUMB/180) ) / pixelscale;
111 pdata->N0,pdata->d1, pdata->d2, pdata->parallactic_shiftX ,
112 pdata->parallactic_shiftY);
116 sinfo_disp_calc(disp_data* pdata,
double lambda,
double *shiftx,
double *shifty)
118 double n = sinfo_disp_calc_N(pdata, lambda);
119 double delta = pdata->predelta * (n - pdata->N0);
120 *shiftx = -delta * pdata->parallactic_shiftX;
121 *shifty = delta * pdata->parallactic_shiftY ;
125 sinfo_atmo_rotate_point(
double* x_value,
double * y_value,
double rot_angle)
127 double newx = *x_value * cos(rot_angle) - *y_value * sin(rot_angle);
128 double newy = *x_value * sin(rot_angle) + *y_value * cos(rot_angle);
154 sinfo_atm_dispersion_cube(cpl_imagelist* pCube,
166 cpl_error_code err = CPL_ERROR_NONE;
167 int cubesize = cpl_imagelist_get_size(pCube);
168 double * kernel = sinfo_generate_interpolation_kernel(
"default");
172 sinfo_disp_prepare_data(&ddata, centlambda, Tc, Rh, airm, p, parallactic, pixelscale);
174 for (i = 0; i < cubesize; i++)
179 cpl_image* pnewImage = 0;
181 cpl_image* plane = cpl_imagelist_get(pCube, i);
184 double lambda = centlambda - (centpix - i) * pixelsz;
185 sinfo_disp_calc(&ddata, lambda, &shiftx, &shifty);
191 pnewImage = sinfo_new_shift_image(
196 err = cpl_imagelist_set(pCube, pnewImage, i);
197 if (err != CPL_ERROR_NONE)
216 sinfo_atmo_load_polynom(
const char* filename)
219 cpl_polynomial* poly = NULL;
220 cpl_table* ptable = NULL;
222 ptable = cpl_table_load(filename, 1, 0);
228 cpl_size* expo = NULL;
230 dim = cpl_table_get_ncol(ptable) - 1;
231 poly = cpl_polynomial_new(dim );
232 nrows = cpl_table_get_nrow(ptable);
233 expo = cpl_malloc(dim *
sizeof(expo[0]));
234 memset(&expo[0], 0, dim *
sizeof(expo[0]));
235 const char* COL_NAME_TEMPLATE =
"col_%d";
236 const char* COL_NAME_VALUE =
"value";
237 for (i = 0; i < nrows; i++)
242 for (j = 0; j < dim; j++)
245 sprintf(col_name, COL_NAME_TEMPLATE, j);
246 expo[j] = cpl_table_get_int(ptable, col_name, i, &inull);
248 value = cpl_table_get(ptable, COL_NAME_VALUE, i, &inull);
249 cpl_polynomial_set_coeff(poly, expo, value);
250 if (cpl_error_get_code() != CPL_ERROR_NONE)
254 sinfo_free_polynomial(&poly);
261 sinfo_free_table(&ptable);
283 sinfo_atmo_apply_cube_polynomial_shift(
284 cpl_polynomial* poly,
285 cpl_imagelist* pCube,
292 cpl_imagelist* retcube = NULL;
294 cpl_vector* vparams = NULL;
295 double * kernel = sinfo_generate_interpolation_kernel(
"default");
300 double l0_shift_x = 0;
301 double l0_shift_y = 0;
303 vparams = cpl_vector_new(2);
304 cpl_vector_set(vparams, 0, airmass);
305 cpl_vector_set(vparams, 1, lambda0);
307 if (CPL_ERROR_NONE == cpl_error_get_code())
310 l0_shift_y = cpl_polynomial_eval(poly, vparams);
313 sinfo_atmo_rotate_point(&l0_shift_x, &l0_shift_y, parallactic);
314 cubesize = cpl_imagelist_get_size(pCube);
317 if (CPL_ERROR_NONE == cpl_error_get_code())
319 retcube = cpl_imagelist_new();
320 for (
int i = 0; i < cubesize; i++)
323 double lambda = lambda0 - (centpix - i) * pixelsz;
326 cpl_vector_set(vparams, 1, lambda);
329 double shift_y = cpl_polynomial_eval(poly, vparams);
331 if (CPL_ERROR_NONE == cpl_error_get_code())
333 double res_shift_x = -(shift_x - l0_shift_x);
334 double res_shift_y = -(shift_y - l0_shift_y);
335 cpl_image* plane = NULL;
336 cpl_image* pimresult = NULL;
338 sinfo_atmo_rotate_point(&res_shift_x, &res_shift_y, parallactic);
339 plane = cpl_imagelist_get(pCube, i);
340 pimresult = sinfo_new_shift_image(
345 if (CPL_ERROR_NONE == cpl_error_get_code())
347 cpl_imagelist_set(retcube, pimresult, i);
352 cpl_error_get_where());
354 if (CPL_ERROR_NONE != cpl_error_get_code())
360 cpl_error_get_where());
362 if (CPL_ERROR_NONE != cpl_error_get_code())
366 if (CPL_ERROR_NONE != cpl_error_get_code())
368 sinfo_free_imagelist(&retcube);
370 cpl_error_get_where());
372 sinfoni_free_vector(&vparams);
#define sinfo_msg_error(...)
Print an error message.
#define sinfo_msg_warning(...)
Print an warning message.