00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030
00036
00039
00040
00041
00042 #include <xsh_utils.h>
00043 #include <xsh_error.h>
00044 #include <xsh_msg.h>
00045 #include <xsh_data_instrument.h>
00046 #include <xsh_data_pre.h>
00047 #include <xsh_fit.h>
00048 #include <xsh_pfits.h>
00049 #include <tests.h>
00050 #include <cpl.h>
00051 #include <math.h>
00052 #include <time.h>
00053 #include <sys/time.h>
00054 #include <xsh_cpl_size.h>
00055
00056
00057
00058 #define MODULE_ID "XSH_DETECT_LINE_POS"
00059
00060 static cpl_error_code
00061 xsh_add_fits_key_min_set(cpl_propertylist* plist)
00062 {
00063
00064 cpl_propertylist_append_double(plist,XSH_EXPTIME,10.);
00065 cpl_propertylist_append_double(plist,XSH_RON,1.);
00066 cpl_propertylist_append_double(plist,XSH_CONAD,1.);
00067 cpl_propertylist_append_double(plist,XSH_DET_GAIN,1.);
00068 cpl_propertylist_append_int(plist,XSH_WIN_BINX,1);
00069 cpl_propertylist_append_int(plist,XSH_WIN_BINY,1);
00070 cpl_propertylist_append_double(plist,XSH_PSZX,15.);
00071 cpl_propertylist_append_double(plist,XSH_PSZY,15.);
00072
00073 cpl_propertylist_append_double(plist,XSH_DET_PXSPACE,1.800e-05);
00074 cpl_propertylist_append_int(plist,XSH_CHIP_NY,2048);
00075
00076
00077 return cpl_error_get_code();
00078
00079 }
00080
00081
00087
00088 int main( int argc, char** argv)
00089 {
00090 int ret = 0;
00091 int sx=4096;
00092 int sy=4096;
00093
00094
00095 cpl_image* image = NULL;
00096 cpl_image* gauss = NULL;
00097 cpl_image* img_raw = NULL;
00098 cpl_image* img_bias = NULL;
00099
00100
00101
00102 double min_noise=-10;
00103 double max_noise=10;
00104 double mean_level=100;
00105
00106 double gauss_a=1.e5;
00107 double gauss_sx=4;
00108 double gauss_sy=4;
00109
00110 cpl_size xpos=sx/2;
00111 cpl_size ypos=sy/2;
00112 int size=1+2*(gauss_sx+gauss_sy);
00113
00114 double norm=0;
00115 double cen_x=0;
00116 double cen_y=0;
00117 double sig_x=0;
00118 double sig_y=0;
00119 double fwhm_x=0;
00120 double fwhm_y=0;
00121 cpl_frame* frm_raw=NULL;
00122 cpl_frame* frm_bias=NULL;
00123 xsh_instrument* instrument=NULL;
00124 const char* name_bias="bias.fits";
00125 const char* name_raw="raw.fits";
00126 xsh_pre* pre = NULL;
00127 cpl_propertylist* plist=NULL;
00128
00129
00130 TESTS_INIT( MODULE_ID);
00131 cpl_msg_set_level( CPL_MSG_DEBUG);
00132 xsh_debug_level_set( XSH_DEBUG_LEVEL_MEDIUM) ;
00133
00134 instrument=xsh_instrument_new();
00135 xsh_instrument_set_arm(instrument,XSH_ARM_UVB);
00136
00137 check(img_bias=cpl_image_new(sx, sy,CPL_TYPE_FLOAT));
00138 check(cpl_image_fill_noise_uniform(img_bias,min_noise,max_noise));
00139 check(cpl_image_add_scalar(img_bias,mean_level));
00140 check(img_raw=cpl_image_duplicate(img_bias));
00141
00142 plist=cpl_propertylist_new();
00143 xsh_add_fits_key_min_set(plist);
00144
00145
00146 check(cpl_image_save(img_bias,name_bias,
00147 CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
00148
00149 xsh_free_propertylist(&plist);
00150
00151 check(frm_bias=xsh_frame_product(name_bias,"BIAS",
00152 CPL_FRAME_TYPE_IMAGE,
00153 CPL_FRAME_GROUP_RAW,
00154 CPL_FRAME_LEVEL_FINAL));
00155
00156
00157 check(gauss=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
00158 check(cpl_image_fill_gaussian(gauss,xpos,ypos,gauss_a,gauss_sx,gauss_sy));
00159 check(cpl_image_add(img_raw,gauss));
00160
00161 plist=cpl_propertylist_new();
00162 xsh_add_fits_key_min_set(plist);
00163
00164 check(cpl_image_save(img_raw,name_raw,
00165 CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
00166
00167 check(frm_raw=xsh_frame_product(name_raw,"RAW",
00168 CPL_FRAME_TYPE_IMAGE,
00169 CPL_FRAME_GROUP_RAW,
00170 CPL_FRAME_LEVEL_FINAL));
00171
00172 xsh_free_propertylist(&plist);
00173
00174 xsh_msg("Predicted Pos: [%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT "], Amp: %f Sigma: [%f,%f]",
00175 xpos,ypos,gauss_a,gauss_sx,gauss_sy);
00176
00177 xsh_msg("Fit box params: pos=[%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT "] size=%d",xpos,ypos,size);
00178
00179 check(cpl_image_fit_gaussian(img_raw, xpos, ypos,size,&norm, &cen_x, &cen_y,
00180 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
00181
00182 xsh_msg("G Measured Pos: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
00183 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
00184
00185 check(xsh_image_find_barycenter(img_raw,xpos,ypos,size,&norm,&cen_x,&cen_y,
00186 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
00187
00188 xsh_msg("B Measured Pos: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
00189 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
00190
00191
00192 check(pre=xsh_pre_create(frm_raw,NULL,img_bias,instrument,0,CPL_FALSE));
00193
00194 check(cpl_image_save(pre->data,"pre_ima_raw.fits",
00195 CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
00196
00197 check(cpl_image_get_maxpos(pre->data,&xpos,&ypos));
00198
00199 xsh_msg("Pos Max: [%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT "]",xpos,ypos);
00200
00201 check(cpl_image_fit_gaussian(pre->data, xpos, ypos,size,&norm, &cen_x, &cen_y,
00202 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
00203
00204 xsh_msg("G Measured Pos: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
00205 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
00206
00207
00208
00209 check(xsh_image_find_barycenter(pre->data,xpos,ypos,size,&norm,&cen_x,&cen_y,
00210 &sig_x, &sig_y, &fwhm_x, &fwhm_y));
00211
00212 xsh_msg("B Measured Pos: [%f,%f], Amp: %f Sigma: [%f,%f] FWHM: [%f,%f]",
00213 cen_x,cen_y,norm,sig_x,sig_y,fwhm_x,fwhm_y);
00214
00215 cleanup:
00216
00217 xsh_free_image(&image);
00218 xsh_free_image(&gauss);
00219 xsh_free_image(&img_raw);
00220 xsh_free_image(&img_bias);
00221 xsh_free_frame(&frm_raw);
00222 xsh_free_frame(&frm_bias);
00223 xsh_free_propertylist(&plist);
00224
00225
00226 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00227 xsh_error_dump(CPL_MSG_ERROR);
00228 ret = 1;
00229 }
00230 return ret;
00231 }
00232