X-shooter Pipeline Reference Manual 3.8.15
xsh_model_kernel.h
Go to the documentation of this file.
1/* $Id: xsh_model_kernel.h,v 1.47 2011-12-02 14:15:28 amodigli Exp $
2 *
3 * This file is part of the X-shooter Pipeline
4 * Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: amodigli $
23 * $Date: 2011-12-02 14:15:28 $
24 * $Revision: 1.47 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifndef XSH_MODEL_KERNEL_H
29#define XSH_MODEL_KERNEL_H
30
31//#define FCCDD_FLAG
32//#define CCCDD_FLAG
33//#define XCCCDD_FLAG
34//#define DEBUG
35
36/*-----------------------------------------------------------------------------
37 Includes
38 -----------------------------------------------------------------------------*/
39
40#include <math.h>
41#include <string.h>
42#include <cpl.h>
43#include <xsh_data_instrument.h>
44#include <xsh_data_order.h>
45
46/*-----------------------------------------------------------------------------
47 Define
48 -----------------------------------------------------------------------------*/
49/*This is the number of extra rows to be added to the top due to the wrong
50default for the NIR array size in xsh_data_instrument.c */
51#define NIR_FIX 36
52
53/*-----------------------------------------------------------------------------
54 New types
55 -----------------------------------------------------------------------------*/
56
57typedef double DOUBLE;
58
59/* the following three lines are the only one you have to change to modify the vector/matrix default size */
60typedef DOUBLE vec[4];
61typedef DOUBLE cvec[4];
62typedef DOUBLE mat[4][4];
63
64typedef int detloc[3];
65typedef int XY[3];
66
67typedef struct {
69 int flag;
70 char name[20];
72
73typedef struct
74 {
75 int counter;
76 double x;
77 double y;
78 int arm;
79 double wave;
80 double flux;
82 int order;
83 } coord ;
84
85struct xs_3
86{
87 /* parameterlist */
88 int arm;
94 DOUBLE temper, t_ir_p2, t_ir_p3; /* T in K */
95 DOUBLE mues, nues, taues, slit_scale, es_s, es_w, es_x, es_xf, es_y, es_y_tot; /* for entrance slit */
97 DOUBLE mup1, cmup1, nup1, taup1; /* for prism crossdiperser entrance/final exit surface */
99 DOUBLE rind_delta;/*extra param to allow ref_ind change in annealing*/
100 DOUBLE mup2, nup2, taup2; /* for prism crossdiperser first exit/re-entrance surface */
101 DOUBLE mup3, nup3, taup3; /* for 2nd prism crossdiperser entrance/final exit surface */
102 DOUBLE mup4, nup4, taup4; /* for 2nd prism crossdiperser first exit/re-entrance surface */
103 DOUBLE mup5, nup5, taup5; /* for 3rd prism crossdiperser entrance/final exit surface */
104 DOUBLE mup6, nup6, taup6; /* for 3rd prism crossdiperser first exit/re-entrance surface */
105
106 DOUBLE mug, nug, taug, sg, grat_alpha, grat_beta; /* for grating */
107 DOUBLE mud, nud, taud, pix, pix_X, pix_Y, offx, offy, flipx, flipy, xpospix, ypospix, fdet; /* for detector */
108
110 double xdet,ydet;
111
113
114 /* pin cushion distortion coeffs*/
117 /*4th order for NIR only*/
120
121 /*UVB/VIS extra distortion*/
122 double d2_x3, d2_x2, d2_x1;
124 /*NIR Chromatic distortion*/
126
127/* matrices which can be computed without order, wavelength and slitposition */
132
133 /* Pedigree of config file */
135};
136typedef struct xs_3 xsh_xs_3;
137
138/*-----------------------------------------------------------------------------
139 Prototypes
140 -----------------------------------------------------------------------------*/
141
142
143int xsh_3_readfile(double * abest, double * amin, double * amax, int * aname, const char *, struct xs_3 *, ann_all_par *);
144void xsh_3_init(struct xs_3 *);
145void xsh_ref_ind_read_old(const char * ref_ind_file, DOUBLE ** ref_ind, DOUBLE temper);
146void xsh_ref_ind_read(int arm, DOUBLE ** ref_ind, DOUBLE temper);
147void xsh_3_eval(DOUBLE lambda, int morder, DOUBLE ** ref_ind, struct xs_3 *p_xs_3);
148void xsh_3_eval_check(DOUBLE lambda, int morder, DOUBLE ** ref_ind, struct xs_3 *p_xs_3);
149void xsh_3_detpix(struct xs_3 *p_xs_3);
150void xsh_3_detpix_check(struct xs_3 *p_xs_3);
151
152DOUBLE *xsh_alloc1Darray(int asize);
153int * xsh_alloc1Darray_INT(int asize);
154double** xsh_alloc2Darray( int asize, int bsize);
155double *** xsh_alloc3Darray2(int asize,int bsize,int csize);
156double *** xsh_alloc3Darray(int asize,int bsize,int csize);
157int ** xsh_alloc2Darray_i(int asize, int bsize);
158float ** xsh_alloc2Darray_f(int asize, int bsize);
159int xsh_free2Darray(double ** ccdtemp, int asize);
160int xsh_free3Darray(double *** ccdtemp, int asize,int bsize);
161int xsh_free2Darray_i(int ** ccdtemp, int asize);
162int xsh_free2Darray_f(float ** ccdtemp, int asize);
163double * xsh_copy2D_to_1D(double ** ccdtemp, int asize, int bsize);
164double** xsh_copy1D_to_2D(double * oneDccdtemp, int asize, int bsize);
165
166void xsh_addvectors(vec, vec);
167void xsh_addvectors3D(vec, vec);
170void xsh_multiply(vec a, DOUBLE k);
171void xsh_multiplythreematrix(mat A, mat B, mat C,mat D);
172void xsh_showvector(vec a);
173//void xsh_nullvector(vec a);
174//void xsh_copyvector(vec, vec);
175void xsh_normz(vec a);
176void xsh_normall(vec a);
177
178void xsh_showmatrix(mat A);
180void xsh_multiplymatrix(mat A,mat B, mat C);
181//void xsh_nullmatrix(mat A);
182//void xsh_copymatrix(mat A, mat B);
183void xsh_matrixforvector(vec a,mat B,vec c);
184void xsh_transpose(mat A,mat B);
185
186void xsh_rotationmatrix(mat A, const char axis, const DOUBLE angle);
187void xsh_rotin(mat A,const DOUBLE x_angle, const DOUBLE y_angle,
188 const DOUBLE z_angle);
189void xsh_refract(vec, DOUBLE, vec);
190
191void xsh_model_get_xy(xsh_xs_3* p_xs_3,
192 xsh_instrument* instr,
193 double lambda_nm,
194 int morder,
195 double slit,
196 double* x,
197 double* y);
198cpl_vector** xsh_model_locus(struct xs_3* p_xs_3,
199 xsh_instrument* instr,
200 double ent_slit_pos);
201cpl_frame* xsh_model_spectralformat_create(struct xs_3* p_xs_3,
202 const char* tab_filename);
203cpl_table* xsh_model_THE(struct xs_3* p_xs_3,
204 const char* line_list,
205 xsh_instrument* instr,
206 int num_ph,
207 double sep_ph);
208cpl_frame* xsh_model_THE_create(struct xs_3* p_xs_3,
209 xsh_instrument* instr,
210 const char* line_list,
211 int num_ph,
212 double sep_ph,
213 const char* THE_filename);
214
215cpl_frame* xsh_model_pipe_anneal(cpl_frame* cfg_frame,
216 cpl_frame* resid_frame,
217 int maxit,
218 double ann_fac,
219 int scenario,int rec_id);
220
221double xsh_model_sellmeier_ext(int arm, double temper, double lam_sqr);
222double xsh_model_ref_ind_air(double temper, double lam_sqr);
223
224void xsh_model_binxy(struct xs_3* p_xs_3,
225 int bin_X,
226 int bin_Y);
227cpl_vector * xsh_model_refining_detect(const cpl_vector* in,
228 int fwhm,
229 double sigma,
230 int display);
232 cpl_parameterlist* parlist,
233 cpl_frameset* frameset);
234
235int xsh_model_first_anneal_save(const cpl_table *, xsh_instrument*,
236 cpl_parameterlist *,cpl_frameset *) ;
237
238int xsh_model_map_ifu(double xifu,
239 double yifu,
240 xsh_xs_3* p_xs_3);
241
242int xsh_model_offset(DOUBLE disp_pix_shift,
243 DOUBLE slit_pix_shift,
244 struct xs_3* p_xs_3);
245
246void xsh_order_edge_list_fit(xsh_order_list *list, int size, double* order,
247 double* posx, double* posy,
248 int deg_poly, int edge);
249
251 const char* tab_filename);
252cpl_error_code
254 xsh_instrument* instr,
255 const char * wtag,
256 const char * stag,
257 cpl_frame** wmap_frame,
258 cpl_frame** smap_frame,const int save_tmp);
259
260#endif
static double sigma
void xsh_transpose(mat A, mat B)
matrix transposal
void xsh_refract(vec, DOUBLE, vec)
Calculate the new vector after a given incident vector passes a boundary between two materials.
double * xsh_copy2D_to_1D(double **ccdtemp, int asize, int bsize)
copy 2D to 1D array
int ** xsh_alloc2Darray_i(int asize, int bsize)
allocates memory for a 2D array of integers
int xsh_model_offset(DOUBLE disp_pix_shift, DOUBLE slit_pix_shift, struct xs_3 *p_xs_3)
convert a pixel shift measured on the detector to a shift in detector centroid
double xsh_model_sellmeier_ext(int arm, double temper, double lam_sqr)
Get the refractive index for a given temperature and wavelength from the (hard coded) extended Sellme...
float ** xsh_alloc2Darray_f(int asize, int bsize)
allocates memory for a 2D array of floats
void xsh_ref_ind_read(int arm, DOUBLE **ref_ind, DOUBLE temper)
Load the refractive index coeffs for a given arm and temperature.
void xsh_matrixforvector(vec a, mat B, vec c)
Realize a*B*c.
void xsh_ref_ind_read_old(const char *ref_ind_file, DOUBLE **ref_ind, DOUBLE temper)
Load the refractive index array for a given arm and temperature. This old routine is only retained to...
cpl_vector * xsh_model_refining_detect(const cpl_vector *in, int fwhm, double sigma, int display)
Detect the brightest features in a spectrum.
void xsh_addvectors3D(vec, vec)
add 2 vectors a+=b
void xsh_subtractvectors(vec, vec)
subtract 2 vectors a-=b
void xsh_model_get_xy(xsh_xs_3 *p_xs_3, xsh_instrument *instr, double lambda_nm, int morder, double slit, double *x, double *y)
Compute the detector location (floating point pixels) of a given wavelength/entrance slit position.
int xsh_model_map_ifu(double xifu, double yifu, xsh_xs_3 *p_xs_3)
Map the IFU position to spectrograph slit position using transformation provided by Ana for IFU2.
int xsh_free2Darray_f(float **ccdtemp, int asize)
free memory for a 2D array of floats
void xsh_3_detpix(struct xs_3 *p_xs_3)
Takes the physical x,y position at the detector array and converts this to a pixel position.
cpl_frame * xsh_model_order_edges_tab_create(xsh_xs_3 *p_xs_3, const char *tab_filename)
Create an order edges table using the phys mod.
void xsh_model_binxy(struct xs_3 *p_xs_3, int bin_X, int bin_Y)
corrects model for detector's binning
double *** xsh_alloc3Darray(int asize, int bsize, int csize)
allocate 3D array
int xsh_model_first_anneal_save(const cpl_table *, xsh_instrument *, cpl_parameterlist *, cpl_frameset *)
Save the product of the recipe.
void xsh_3_eval(DOUBLE lambda, int morder, DOUBLE **ref_ind, struct xs_3 *p_xs_3)
Compute the physical x,y position at the detector array for a given wavelength, order and parameter c...
void xsh_normz(vec a)
normalize vector
double *** xsh_alloc3Darray2(int asize, int bsize, int csize)
allocate 3D array
DOUBLE xsh_scalarproduct(vec, vec)
implements scalar product
void xsh_initializematrix(mat A)
initialize matrix A
int xsh_free3Darray(double ***ccdtemp, int asize, int bsize)
free 3D array
double ** xsh_copy1D_to_2D(double *oneDccdtemp, int asize, int bsize)
copy 1D to 2D array
cpl_frame * xsh_model_spectralformat_create(struct xs_3 *p_xs_3, const char *tab_filename)
creates the model spectral format table
double xsh_model_ref_ind_air(double temper, double lam_sqr)
Return the refractive index of air at a given wavelength and temperature.
void xsh_multiplymatrix(mat A, mat B, mat C)
multiply three matrixes A=B*C
void xsh_showmatrix(mat A)
Show matrix.
int xsh_model_first_anneal(cpl_parameterlist *parlist, cpl_frameset *frameset)
Interpret the command line options and execute the data processing.
DOUBLE * xsh_alloc1Darray(int asize)
allocates memory for an array of doubles
int xsh_free2Darray(double **ccdtemp, int asize)
free memory for a 2D array of doubles
int * xsh_alloc1Darray_INT(int asize)
allocates memory for an array of integers
void xsh_3_init(struct xs_3 *)
Pre-compute a number of non-wavelength dependent secondary parameters required by the model.
void xsh_showvector(vec a)
show vector content
cpl_error_code xsh_model_maps_create(xsh_xs_3 *p_xs_3, xsh_instrument *instr, const char *wtag, const char *stag, cpl_frame **wmap_frame, cpl_frame **smap_frame, const int save_tmp)
Compute the wavelength and slit maps.
void xsh_multiplythreematrix(mat A, mat B, mat C, mat D)
multiply three matrixes A=B*C*D
void xsh_order_edge_list_fit(xsh_order_list *list, int size, double *order, double *posx, double *posy, int deg_poly, int edge)
Fit edge of an order.
cpl_frame * xsh_model_THE_create(struct xs_3 *p_xs_3, xsh_instrument *instr, const char *line_list, int num_ph, double sep_ph, const char *THE_filename)
Compute the THE table (centroid for each feature in lamp spectrum)
double ** xsh_alloc2Darray(int asize, int bsize)
allocates memory for a 2D array of doubles
cpl_vector ** xsh_model_locus(struct xs_3 *p_xs_3, xsh_instrument *instr, double ent_slit_pos)
Compute the locus of the spectrum.
void xsh_addvectors(vec, vec)
add 2 vectors a+=b
void xsh_rotationmatrix(mat A, const char axis, const DOUBLE angle)
matrix rotation
void xsh_multiply(vec a, DOUBLE k)
applies scalar product to vector
void xsh_normall(vec a)
normalize vector
void xsh_rotin(mat A, const DOUBLE x_angle, const DOUBLE y_angle, const DOUBLE z_angle)
matrix rotation
int xsh_free2Darray_i(int **ccdtemp, int asize)
free memory for a 2D array of integers
cpl_frame * xsh_model_pipe_anneal(cpl_frame *cfg_frame, cpl_frame *resid_frame, int maxit, double ann_fac, int scenario, int rec_id)
Run the annealing (optimisation) algoritm to improve the fit of the model parameter set to a given wa...
int size
int * y
int * x
int slit_pos
double x
double y
double flux
double wave
DOUBLE mup2
DOUBLE taup1
double ca_x0
DOUBLE fcol
DOUBLE es_x
DOUBLE rind_b1
double d2_y1x0
double d2_y2x0
double d2_y1x3
DOUBLE rind_delta
double pc4_y_x3y
double config_mjd
DOUBLE nup4
DOUBLE pix
DOUBLE rind_a3
DOUBLE mup1
double chipyup
double pc4_y_y4
DOUBLE mup5
DOUBLE rind_lm3
DOUBLE mud
DOUBLE rind3
DOUBLE xpospix
mat ret_prism3
double pc_x_y3
double d2_y1x2
DOUBLE rind_wtb2
DOUBLE pix_Y
DOUBLE rind_a2
double pc4_y_xy3
DOUBLE es_w
double chipx
DOUBLE nup3
DOUBLE blaze_pad
DOUBLE taug
double chipydown
double pc_x_x3
double pc_x_x2y
double pc4_y_x4
DOUBLE rind
double pc4_y_x2y2
double d2_y3x0
double pc_y_y1
double d2_y2x2
mat ret_prism2
double d2_x1
double d2_y3x2
DOUBLE nud
int morder_max
double pc4_x_xy3
DOUBLE t_ir_p3
DOUBLE pix_X
double pc_x_xy
double ydet
mat toprism2
double pc_x_y1
double ca_x1
DOUBLE taud
double chipypix
DOUBLE fdet
mat ret_prism_out2
DOUBLE nup1
DOUBLE grat_beta
DOUBLE taup5
double d2_y2x3
double xsize_corr
double chipxdown
DOUBLE taup4
double d2_y1x1
DOUBLE nup2
double pc_y_x1
DOUBLE t_ir_p2
double d2_y2x1
mat ret_prism1
DOUBLE cmup1
mat ret_prism6
double pc4_x_x3y
mat grat_out
DOUBLE rind_wta1
mat toprism3
double xdet
DOUBLE slit[10]
DOUBLE flipy
mat ret_prism_out3
double pc_x_y2x
double chipy
DOUBLE grat_alpha
DOUBLE slit_scale
double pc_y_y3
DOUBLE rind_wta2
DOUBLE mues
mat ret_prism5
DOUBLE rind2
DOUBLE taup6
DOUBLE flipx
DOUBLE ypospix
mat mup_ir_cor_out
DOUBLE offx
DOUBLE nues
double ca_y1
double pc_x_x1
DOUBLE mup3
DOUBLE es_y
double ca_y0
double pc_x_xx
DOUBLE mup4
DOUBLE temper
double pc4_x_x2y2
mat ret_prism_out1
mat toprism4
mat toprism6
DOUBLE rind_wtb1
double d2_x2
int morder_min
mat toprism5
DOUBLE rind_lm2
DOUBLE rind_b2
double pc4_x_y4
double ysize_corr
DOUBLE nup6
DOUBLE offy
DOUBLE rind_wtb0
DOUBLE rind_lm1
DOUBLE es_y_tot
double d2_x3
mat toprism1
double pc4_x_x4
mat mup_ir_cor
double d2_y3x1
DOUBLE nug
double chiprot
double pc_y_x3
detloc chippix
double d2_y3x3
double pc_y_y2x
mat prism_out
double pc_y_x2y
DOUBLE sg
DOUBLE nup5
mat ret_prism4
double chipxup
DOUBLE taup3
DOUBLE mup6
DOUBLE rind_a1
DOUBLE rind_wta0
double pc_y_xx
double pc_x_yy
double pc_y_xy
mat todetector
DOUBLE es_s
int morder
DOUBLE taup2
DOUBLE es_xf
double pc_y_yy
double chipxpix
DOUBLE mug
DOUBLE taues
int order
Definition: xsh_detmon_lg.c:80
#define C(i)
#define max(a, b)
void xsh_3_eval_check(DOUBLE lambda, int morder, DOUBLE **ref_ind, struct xs_3 *p_xs_3)
void xsh_3_detpix_check(struct xs_3 *p_xs_3)
int XY[3]
int xsh_3_readfile(double *abest, double *amin, double *amax, int *aname, const char *, struct xs_3 *, ann_all_par *)
DOUBLE mat[4][4]
int detloc[3]
DOUBLE cvec[4]
cpl_table * xsh_model_THE(struct xs_3 *p_xs_3, const char *line_list, xsh_instrument *instr, int num_ph, double sep_ph)
DOUBLE vec[4]
double DOUBLE