X-shooter Pipeline Reference Manual 3.8.15
test-xsh_detect_line_pos.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library 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, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18 * */
19
20/*
21 * $Author: amodigli $
22 * $Date: 2012-04-26 14:10:08 $
23 * $Revision: 1.8 $
24 * $Name: not supported by cvs2svn $
25 */
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*--------------------------------------------------------------------------*/
36/*--------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------
40 Includes
41 ---------------------------------------------------------------------------*/
42#include <xsh_utils.h>
43#include <xsh_error.h>
44#include <xsh_msg.h>
45#include <xsh_data_instrument.h>
46#include <xsh_data_pre.h>
47#include <xsh_fit.h>
48#include <xsh_pfits.h>
49#include <tests.h>
50#include <cpl.h>
51#include <math.h>
52#include <time.h>
53#include <sys/time.h>
54#include <xsh_cpl_size.h>
55/*---------------------------------------------------------------------------
56 Defines
57 ---------------------------------------------------------------------------*/
58#define MODULE_ID "XSH_DETECT_LINE_POS"
59
60static cpl_error_code
61xsh_add_fits_key_min_set(cpl_propertylist* plist)
62{
63
64 cpl_propertylist_append_string(plist,XSH_DPR_TYPE,"TEST");
65 cpl_propertylist_append_double(plist,XSH_EXPTIME,10.);
66 cpl_propertylist_append_double(plist,XSH_RON,1.);
67 cpl_propertylist_append_double(plist,XSH_CONAD,1.);
68 cpl_propertylist_append_double(plist,XSH_DET_GAIN,1.);
69 cpl_propertylist_append_int(plist,XSH_WIN_BINX,1);
70 cpl_propertylist_append_int(plist,XSH_WIN_BINY,1);
71 cpl_propertylist_append_double(plist,XSH_PSZX,15.);
72 cpl_propertylist_append_double(plist,XSH_PSZY,15.);
73 //Only for NIR:
74 cpl_propertylist_append_double(plist,XSH_DET_PXSPACE,1.800e-05);
75 cpl_propertylist_append_int(plist,XSH_CHIP_NY,2048);
76
77
78 return cpl_error_get_code();
79
80}
81
82/*--------------------------------------------------------------------------*/
88/*--------------------------------------------------------------------------*/
89int main()
90{
91 int ret = 0;
92 int sx=4096;
93 int sy=4096;
94
95 //char *image_name = NULL;
96 cpl_image* image = NULL;
97 cpl_image* gauss = NULL;
98 cpl_image* img_raw = NULL;
99 cpl_image* img_bias = NULL;
100
101
102
103 double min_noise=-10;
104 double max_noise=10;
105 double mean_level=100;
106
107 double gauss_a=1.e5;
108 double gauss_sx=4;
109 double gauss_sy=4;
110 //const int dim=2;
111 cpl_size xpos=sx/2;
112 cpl_size ypos=sy/2;
113 int size=1+2*(gauss_sx+gauss_sy);
114
115 double norm=0;
116 double cen_x=0;
117 double cen_y=0;
118 double sig_x=0;
119 double sig_y=0;
120 double fwhm_x=0;
121 double fwhm_y=0;
122 cpl_frame* frm_raw=NULL;
123 cpl_frame* frm_bias=NULL;
125 const char* name_bias="bias.fits";
126 const char* name_raw="raw.fits";
127 xsh_pre* pre = NULL;
128 cpl_propertylist* plist=NULL;
129
132 cpl_msg_set_level( CPL_MSG_DEBUG);
134
137
138 check(img_bias=cpl_image_new(sx, sy,CPL_TYPE_FLOAT));
139 check(cpl_image_fill_noise_uniform(img_bias,min_noise,max_noise));
140 check(cpl_image_add_scalar(img_bias,mean_level));
141 check(img_raw=cpl_image_duplicate(img_bias));
142
143 plist=cpl_propertylist_new();
145
146
147 check(cpl_image_save(img_bias,name_bias,
148 CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
149
150 xsh_free_propertylist(&plist);
151
152 check(frm_bias=xsh_frame_product(name_bias,"BIAS",
153 CPL_FRAME_TYPE_IMAGE,
154 CPL_FRAME_GROUP_RAW,
155 CPL_FRAME_LEVEL_FINAL));
156
157
158 check(gauss=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
159 check(cpl_image_fill_gaussian(gauss,xpos,ypos,gauss_a,gauss_sx,gauss_sy));
160 check(cpl_image_add(img_raw,gauss));
161
162 plist=cpl_propertylist_new();
164
165 check(cpl_image_save(img_raw,name_raw,
166 CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
167
168 check(frm_raw=xsh_frame_product(name_raw,"RAW",
169 CPL_FRAME_TYPE_IMAGE,
170 CPL_FRAME_GROUP_RAW,
171 CPL_FRAME_LEVEL_FINAL));
172
173 xsh_free_propertylist(&plist);
174
175 xsh_msg("Predicted Pos: [%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT "], Amp: %f Sigma: [%f,%f]",
176 xpos,ypos,gauss_a,gauss_sx,gauss_sy);
177
178 xsh_msg("Fit box params: pos=[%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT "] size=%d",xpos,ypos,size);
179
180 check(cpl_image_fit_gaussian(img_raw, xpos, ypos,size,&norm, &cen_x, &cen_y,
181 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
182
183 xsh_msg("G Measured Pos: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
184 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
185
186 check(xsh_image_find_barycenter(img_raw,xpos,ypos,size,&norm,&cen_x,&cen_y,
187 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
188
189 xsh_msg("B Measured Pos: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
190 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
191
192
193 check(pre=xsh_pre_create(frm_raw,NULL,img_bias,instrument,0,CPL_FALSE));
194
195 check(cpl_image_save(pre->data,"pre_ima_raw.fits",
196 CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
197
198 check(cpl_image_get_maxpos(pre->data,&xpos,&ypos));
199
200 xsh_msg("Pos Max: [%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT "]",xpos,ypos);
201
202 check(cpl_image_fit_gaussian(pre->data, xpos, ypos,size,&norm, &cen_x, &cen_y,
203 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
204
205 xsh_msg("G Measured Pos: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
206 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
207
208
209
210 check(xsh_image_find_barycenter(pre->data,xpos,ypos,size,&norm,&cen_x,&cen_y,
211 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
212
213 xsh_msg("B Measured Pos: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
214 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
215
216 cleanup:
217
218 xsh_pre_free(&pre);
219 xsh_free_image(&image);
220 xsh_free_image(&gauss);
221 xsh_free_image(&img_raw);
222 xsh_free_image(&img_bias);
223 xsh_free_frame(&frm_raw);
224 xsh_free_frame(&frm_bias);
225 xsh_free_propertylist(&plist);
227
229 if (cpl_error_get_code() != CPL_ERROR_NONE) {
230 xsh_error_dump(CPL_MSG_ERROR);
231 ret = 1;
232 }
233 return ret;
234}
235
static xsh_instrument * instrument
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
Definition: xsh_data_pre.c:823
xsh_pre * xsh_pre_create(cpl_frame *raw, cpl_frame *bpmap, cpl_image *bias_data, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
Create a XSH_PRE from a raw frame.
Definition: xsh_data_pre.c:450
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
cpl_error_code xsh_image_find_barycenter(const cpl_image *im, int xpos, int ypos, int size, double *norm, double *xcen, double *ycen, double *sig_x, double *sig_y, double *fwhm_x, double *fwhm_y)
Apply a gaussian fit on an image sub window.
Definition: xsh_fit.c:696
void xsh_instrument_set_arm(xsh_instrument *i, XSH_ARM arm)
Set an arm on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
int size
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
#define MODULE_ID
int main()
Some test about performances.
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
Definition: xsh_utils.c:2116
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
cpl_image * data
Definition: xsh_data_pre.h:65
static cpl_error_code xsh_add_fits_key_min_set(cpl_propertylist *plist)
#define TESTS_CLEAN_WORKSPACE(DRL_ID)
Definition: tests.h:139
#define TESTS_INIT_WORKSPACE(DRL_ID)
Definition: tests.h:133
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_ARM_UVB
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
Definition: xsh_dfs.c:930
#define XSH_PSZY
Definition: xsh_pfits.h:171
#define XSH_EXPTIME
Definition: xsh_pfits.h:125
#define XSH_CHIP_NY
Definition: xsh_pfits.h:152
#define XSH_PSZX
Definition: xsh_pfits.h:170
#define XSH_DET_PXSPACE
Definition: xsh_pfits.h:164
#define XSH_WIN_BINY
Definition: xsh_pfits.h:156
#define XSH_WIN_BINX
Definition: xsh_pfits.h:155
#define XSH_RON
Definition: xsh_pfits.h:161
#define XSH_DPR_TYPE
Definition: xsh_pfits.h:147
#define XSH_DET_GAIN
Definition: xsh_pfits.h:165
#define XSH_CONAD
Definition: xsh_pfits.h:162
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138