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
00031
00036
00039
00040
00041
00042 #include <xsh_utils.h>
00043 #include <xsh_error.h>
00044 #include <xsh_fit.h>
00045 #include <xsh_msg.h>
00046 #include <tests.h>
00047 #include <cpl.h>
00048 #include <math.h>
00049
00050 #include <time.h>
00051 #include <sys/time.h>
00052
00053
00054
00055 #define MODULE_ID "XSH_CPL_FIT"
00056
00057
00058 static void xsh_gfit_tests(void);
00059
00060
00066
00067 int main( int argc, char** argv)
00068 {
00069 TESTS_INIT(MODULE_ID);
00070
00071 check( xsh_gfit_tests() );
00072
00073 cleanup:
00074 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00075 xsh_error_dump(CPL_MSG_ERROR);
00076 return 1;
00077 } else {
00078 return 0;
00079 }
00080 }
00081
00082
00083 static void xsh_gfit_tests(void)
00084 {
00085 cpl_image* img_raw=NULL;
00086 cpl_image* img_raw1=NULL;
00087 cpl_image* img_noise=NULL;
00088 double sx=128;
00089 double sy=128;
00090 double sigx=4;
00091 double sigy=4;
00092 double sigx1=2;
00093 double sigy1=2;
00094
00095 int xc=sx/2;
00096 int yc=sy/2;
00097 int offx1=20;
00098 int offy1=20;
00099
00100 int xc1=sx/2+offx1;
00101 int yc1=sy/2+offy1;
00102 double flux1=5.e4;
00103 double flux=5.e4;
00104
00105 double noise=1.e2;
00106 double min=-noise;
00107 double max=+noise;
00108 const char* name="raw_ima.fits";
00109 int offx=12;
00110 int offy=12;
00111 int size=20;
00112 int xg=(int)(xc+offx);
00113 int yg=(int)(yc+offy);
00114 double fwhm_x=0;
00115 double fwhm_y=0;
00116 double xcen=0;
00117 double ycen=0;
00118 double sig_x=0;
00119 double sig_y=0;
00120 double norm=0;
00121
00122 check(img_raw=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
00123 check(img_raw1=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
00124 check(img_noise=cpl_image_new(sx,sy,CPL_TYPE_FLOAT));
00125
00126
00127 check(cpl_image_fill_gaussian(img_raw,xc,yc,flux,sigx,sigy));
00128 check(cpl_image_fill_gaussian(img_raw1,xc1,yc1,flux1,sigx1,sigy1));
00129 check(cpl_image_fill_noise_uniform(img_noise,min,max));
00130 check(cpl_image_add(img_raw,img_noise));
00131 check(cpl_image_add(img_raw,img_raw1));
00132
00133 check(cpl_image_save(img_raw,name,CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00134
00135
00136
00137 check(xsh_image_find_barycenter(img_raw,xg,yg,size,&norm,&xcen,&ycen,
00138 &sig_x,&sig_y,&fwhm_x,&fwhm_y));
00139 xsh_msg("xc=%d yc=%d xg=%d yg=%d xcen=%f ycen=%f S/N=%f",
00140 xc,yc,xg,yg,xcen,ycen,norm/noise);
00141
00142 xsh_free_image(&img_raw);
00143 xsh_free_image(&img_raw1);
00144 xsh_free_image(&img_noise);
00145
00146 cleanup:
00147 return;
00148 }
00149
00150
00151