58#define MODULE_ID "XSH_DETECT_LINE_POS"
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.);
71 cpl_propertylist_append_double(plist,
XSH_PSZX,15.);
72 cpl_propertylist_append_double(plist,
XSH_PSZY,15.);
75 cpl_propertylist_append_int(plist,
XSH_CHIP_NY,2048);
78 return cpl_error_get_code();
96 cpl_image* image = NULL;
97 cpl_image* gauss = NULL;
98 cpl_image* img_raw = 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);
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));
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);
187 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
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);
195 check(cpl_image_save(pre->
data,
"pre_ima_raw.fits",
196 CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
198 check(cpl_image_get_maxpos(pre->
data,&xpos,&ypos));
200 xsh_msg(
"Pos Max: [%" CPL_SIZE_FORMAT
",%" CPL_SIZE_FORMAT
"]",xpos,ypos);
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));
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);
211 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
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);
229 if (cpl_error_get_code() != CPL_ERROR_NONE) {
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.