58#define MODULE_ID "XSH_DETECT_LINE_POS2"
63 cpl_propertylist_append_string(plist,
XSH_DPR_TYPE,
"TEST");
64 cpl_propertylist_append_double(plist,
XSH_EXPTIME,10.);
65 cpl_propertylist_append_double(plist,
XSH_RON,1.);
66 cpl_propertylist_append_double(plist,
XSH_CONAD,1.);
70 cpl_propertylist_append_double(plist,
XSH_PSZX,15.);
71 cpl_propertylist_append_double(plist,
XSH_PSZY,15.);
74 cpl_propertylist_append_int(plist,
XSH_CHIP_NY,2048);
77 return cpl_error_get_code();
95 cpl_image* image = NULL;
96 cpl_image* gauss = NULL;
97 cpl_image* img_raw = NULL;
98 cpl_image* img_err = NULL;
99 cpl_image* img_bias = NULL;
103 double min_noise=-10;
105 double mean_level=100;
113 int size=1+2*(gauss_sx+gauss_sy);
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";
128 cpl_propertylist* plist=NULL;
132 cpl_msg_set_level( CPL_MSG_DEBUG);
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));
143 plist=cpl_propertylist_new();
147 check(cpl_image_save(img_bias,name_bias,
148 CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
153 CPL_FRAME_TYPE_IMAGE,
155 CPL_FRAME_LEVEL_FINAL));
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));
162 plist=cpl_propertylist_new();
165 check(cpl_image_save(img_raw,name_raw,
166 CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
169 CPL_FRAME_TYPE_IMAGE,
171 CPL_FRAME_LEVEL_FINAL));
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);
178 xsh_msg(
"Fit box params: pos=[%" CPL_SIZE_FORMAT
",%" CPL_SIZE_FORMAT
"] size=%d",xpos,ypos,
size);
179 img_err=cpl_image_duplicate(img_raw);
180 cpl_image_power(img_err,0.5);
182 cpl_array* parameters=cpl_array_new(7, CPL_TYPE_DOUBLE);
183 cpl_array* err_params=cpl_array_new(7, CPL_TYPE_DOUBLE);
184 cpl_array* fit_params=cpl_array_new(7, CPL_TYPE_INT);
187 for (i = 0; i < 7; i++)
188 cpl_array_set(fit_params, i, 1);
192 cpl_matrix* covariance=NULL;
193 cpl_matrix* phys_cov=NULL;
208 check(cpl_fit_image_gaussian(img_raw, img_err, xpos, ypos,
size,
size,
209 parameters,err_params,fit_params,
210 &rms,&red_chisq,&covariance,
211 &major,&minor,&angle,&phys_cov));
218 for (i = 0; i < 7; i++){
219 cpl_msg_info(cpl_func,
"%s: %f",
220 p[i], cpl_array_get(parameters,i,NULL));
223 xsh_msg(
"G Results: rms: %f red_chisq: %f major: %f minor: %f angle: %f",
224 rms,red_chisq,major,minor,angle);
226 cen_x=cpl_array_get(parameters,3,NULL);
227 cen_y=cpl_array_get(parameters,4,NULL);
228 sig_x=cpl_array_get(parameters,5,NULL);
229 sig_y=cpl_array_get(parameters,6,NULL);
231 xsh_msg(
"G Results: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
232 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
235 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
237 xsh_msg(
"B Measured Pos: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
238 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
243 check(cpl_image_save(pre->
data,
"pre_ima_raw.fits",
244 CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
246 check(cpl_image_get_maxpos(pre->
data,&xpos,&ypos));
248 xsh_msg(
"Pos Max: [%" CPL_SIZE_FORMAT
",%" CPL_SIZE_FORMAT
"]",xpos,ypos);
250 check(cpl_image_fit_gaussian(pre->
data, xpos, ypos,
size,&norm, &cen_x, &cen_y,
251 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
253 xsh_msg(
"G Measured Pos: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
254 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
259 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
261 xsh_msg(
"B Measured Pos: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
262 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
266 cpl_array_delete(parameters);
267 cpl_array_delete(err_params);
268 cpl_array_delete(fit_params);
269 cpl_matrix_delete(covariance);
270 cpl_matrix_delete(phys_cov);
283 if (cpl_error_get_code() != CPL_ERROR_NONE) {
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
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.
#define xsh_error_dump(level)
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.
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
#define xsh_msg(...)
Print a message on info level.
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
int xsh_debug_level_set(int level)
set debug level
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
static cpl_error_code xsh_add_fits_key_min_set(cpl_propertylist *plist)
#define TESTS_CLEAN_WORKSPACE(DRL_ID)
#define TESTS_INIT_WORKSPACE(DRL_ID)
#define TESTS_INIT(DRL_ID)
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.