Changeset e575db9 in sasview for sansview/perspectives/fitting
- Timestamp:
- Mar 12, 2010 1:16:01 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 00d3528
- Parents:
- 3080527
- Location:
- sansview/perspectives/fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/basepage.py
rb324aa9 re575db9 54 54 ## data 55 55 self.data = None 56 self.mask = None 56 57 self.state = PageState(parent=parent) 57 58 ## dictionary containing list of models -
sansview/perspectives/fitting/fitpage.py
rb324aa9 re575db9 916 916 qmin,qmax = self.get_range() 917 917 if self.data.__class__.__name__ =="Data2D": 918 for qx in self.data.x_bins: 919 for qy in self.data.y_bins: 920 if math.sqrt((qx*qx)+(qy*qy)) >= qmin \ 921 and math.sqrt((qx*qx)+(qy*qy)) <= qmax: 922 npts2fit += 1 918 npts2fit = len(self.data[self.mask]) 923 919 else: 924 920 for qx in self.data.x: … … 966 962 #Check if chi2 is finite 967 963 if chisqr != None or numpy.isfinite(chisqr): 968 #format chi2 969 npt_fit = float(self.get_npts2fit())970 if self.engine_type == "park" and npt_fit > 0:964 #format chi2 965 if self.engine_type == "park" and npt_fit > 0: 966 npt_fit = float(self.get_npts2fit()) 971 967 chisqr =chisqr/npt_fit 972 968 chi2 = format_number(chisqr) … … 1057 1053 1058 1054 has_error = True 1059 1055 i += 1 1060 1056 #Show error title when any errors displayed 1061 1057 if has_error: … … 1086 1082 return 1087 1083 temp_smearer = None 1084 # make sure once more if it is smearer 1085 self.smearer = smear_selection(self.data) 1086 1088 1087 if self.enable_smearer.GetValue(): 1089 1088 temp_smearer= self.smearer -
sansview/perspectives/fitting/fitting.py
rb324aa9 re575db9 965 965 966 966 detector = Detector() 967 theory.detector.append(detector) 968 969 theory.detector[0].distance=1e+32 967 theory.detector.append(detector) 970 968 theory.source= Source() 971 theory.source.wavelength=2*math.pi/1e+32 972 973 ## Create detector for Model 2D 974 xmax=2*theory.detector[0].distance*math.atan(\ 975 qmax/(4*math.pi/theory.source.wavelength)) 976 977 theory.detector[0].pixel_size.x= xmax/(qstep/2-0.5) 978 theory.detector[0].pixel_size.y= xmax/(qstep/2-0.5) 969 970 ## Default values 971 theory.detector[0].distance= 8000 # mm 972 theory.source.wavelength= 6 # A 973 theory.detector[0].pixel_size.x= 5 # mm 974 theory.detector[0].pixel_size.y= 5 # mm 975 979 976 theory.detector[0].beam_center.x= qmax 980 977 theory.detector[0].beam_center.y= qmax 978 979 981 980 ## create x_bins and y_bins of the model 2D 982 distance = theory.detector[0].distance983 pixel = qstep/2-1984 theta = pixel / distance / qstep#100.0985 wavelength = theory.source.wavelength986 981 pixel_width_x = theory.detector[0].pixel_size.x 987 982 pixel_width_y = theory.detector[0].pixel_size.y 988 983 center_x = theory.detector[0].beam_center.x/pixel_width_x 989 984 center_y = theory.detector[0].beam_center.y/pixel_width_y 990 991 992 size_x, size_y= numpy.shape(theory.data) 993 for i_x in range(size_x): 994 theta = (i_x-center_x)*pixel_width_x / distance 995 qx = 4.0*math.pi/wavelength * math.tan(theta/2.0) 996 theory.x_bins.append(qx) 997 for i_y in range(size_y): 998 theta = (i_y-center_y)*pixel_width_y / distance 999 qy =4.0*math.pi/wavelength * math.tan(theta/2.0) 1000 theory.y_bins.append(qy) 1001 985 986 # theory default: assume the beam center is located at the center of sqr detector 987 xmax = qmax 988 xmin = -qmax 989 ymax = qmax 990 ymin = -qmax 991 992 x= numpy.linspace(start= -1*qmax, 993 stop= qmax, 994 num= qstep, 995 endpoint=True ) 996 y = numpy.linspace(start= -1*qmax, 997 stop= qmax, 998 num= qstep, 999 endpoint=True ) 1000 1001 ## use data info instead 1002 new_x = numpy.tile(x, (len(y),1)) 1003 new_y = numpy.tile(y, (len(x),1)) 1004 new_y = new_y.swapaxes(0,1) 1005 1006 # all data reuire now in 1d array 1007 qx_data = new_x.flatten() 1008 qy_data = new_y.flatten() 1009 1010 q_data = numpy.sqrt(qx_data*qx_data+qy_data*qy_data) 1011 # set all True (standing for unmasked) as default 1012 mask = numpy.ones(len(qx_data), dtype = bool) 1013 1014 # calculate the range of qx and qy: this way, it is a little more independent 1015 x_size = xmax- xmin 1016 y_size = ymax -ymin 1017 1018 # store x and y bin centers in q space 1019 x_bins = x 1020 y_bins = y 1021 # bin size: x- & y-directions 1022 xstep = x_size/len(x_bins-1) 1023 ystep = y_size/len(y_bins-1) 1024 1025 #theory.data = numpy.zeros(len(mask)) 1026 theory.err_data = numpy.zeros(len(mask)) 1027 theory.qx_data = qx_data 1028 theory.qy_data = qy_data 1029 theory.q_data = q_data 1030 theory.mask = mask 1031 theory.x_bins = x_bins 1032 theory.y_bins = y_bins 1033 1034 # max and min taking account of the bin sizes 1035 theory.xmin= xmin - xstep/2 1036 theory.xmax= xmax + xstep/2 1037 theory.ymin= ymin - ystep/2 1038 theory.ymax= ymax + ystep/2 1002 1039 theory.group_id ="Model" 1003 1040 theory.id ="Model" 1004 ## determine plot boundaries1005 theory.xmin= -qmax1006 theory.xmax= qmax1007 theory.ymin= -qmax1008 theory.ymax= qmax1009 1041 1010 1042 … … 1103 1135 theory.source= data.source 1104 1136 theory.is_data =False 1137 theory.qx_data = data.qx_data 1138 theory.qy_data = data.qy_data 1139 theory.q_data = data.q_data 1140 theory.err_data = data.err_data 1141 theory.mask = data.mask 1105 1142 ## plot boundaries 1106 1143 theory.ymin= data.ymin … … 1151 1188 x= data.x_bins 1152 1189 y= data.y_bins 1153 1190 1154 1191 if not enable2D: 1155 1192 return -
sansview/perspectives/fitting/model_thread.py
re627f19 re575db9 25 25 self.qmax= qmax 26 26 self.qstep= qstep 27 # Reshape dimensions of x and y to call evalDistribution 28 #self.x_array = numpy.reshape(x,[len(x),1]) 29 #self.y_array = numpy.reshape(y,[1,len(y)]) 30 self.x_array = numpy.reshape(x,[1,len(x)]) 31 self.y_array = numpy.reshape(y,[len(y),1]) 32 # Numpy array of dimensions 1 used for model.run method 33 self.x= numpy.array(x) 34 self.y= numpy.array(y) 27 28 self.x = x 29 self.y = y 35 30 self.data= data 36 31 # the model on to calculate … … 51 46 newy= math.pow(max(math.fabs(self.data.ymax),math.fabs(self.data.ymin)),2) 52 47 self.qmax=math.sqrt( newx + newy ) 53 # Define matrix where data will be plotted 54 radius= numpy.sqrt( self.x_array**2 + self.y_array**2 ) 55 index_data= (self.qmin<= radius) 56 index_model = (self.qmin <= radius)&(radius<= self.qmax) 57 58 output = numpy.zeros((len(self.x),len(self.y))) 59 60 ## receive only list of 2 numpy array 61 ## One must reshape to vertical and the other to horizontal 62 value = self.model.evalDistribution([self.x_array,self.y_array] ) 63 ## for data ignore the qmax 64 if self.data == None: 48 49 if self.data != None: 50 self.qx_data = self.data.qx_data 51 self.qy_data = self.data.qy_data 52 self.mask = self.data.mask 53 else: 54 xbin = numpy.linspace(start= -1*self.qmax, 55 stop= self.qmax, 56 num= self.qstep, 57 endpoint=True ) 58 ybin = numpy.linspace(start= -1*self.qmax, 59 stop= self.qmax, 60 num= self.qstep, 61 endpoint=True ) 62 63 new_xbin = numpy.tile(xbin, (len(ybin),1)) 64 new_ybin = numpy.tile(ybin, (len(xbin),1)) 65 new_ybin = new_ybin.swapaxes(0,1) 66 new_xbin = new_xbin.flatten() 67 new_ybin = new_ybin.flatten() 68 self.qy_data = new_ybin 69 self.qx_data = new_xbin 70 71 self.mask = numpy.ones(len(self.qx_data),dtype=bool) 72 73 # Define matrix where data will be plotted 74 radius= numpy.sqrt( self.qx_data*self.qx_data + self.qy_data*self.qy_data ) 75 index_data= (self.qmin<= radius)&(self.mask) 76 77 # For theory, qmax is based on 1d qmax 78 # so that must be mulitified by sqrt(2) to get actual max for 2d 79 index_model = ((self.qmin <= radius)&(radius<= self.qmax)) 80 self.mask = (index_model)&(self.mask) 81 82 if self.data ==None: 65 83 # Only qmin value will be consider for the detector 66 output = value *index_data 67 else: 68 # The user can define qmin and qmax for the detector 69 output = index_model*value 70 84 self.mask = index_data 85 86 value = self.model.evalDistribution([self.qx_data[self.mask],self.qy_data[self.mask]] ) 87 88 output = numpy.zeros(len(self.mask)) 89 output[self.mask] = value 90 71 91 elapsed = time.time()-self.starttime 72 92 self.complete( image = output, … … 75 95 elapsed = elapsed, 76 96 qmin = self.qmin, 77 qmax = self.qmax,97 qmax = self.qmax, 78 98 qstep = self.qstep ) 79 99
Note: See TracChangeset
for help on using the changeset viewer.