Changeset 4026380 in sasview for DataLoader/invariant.py
- Timestamp:
- Nov 14, 2009 10:33:21 AM (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:
- fd6b789
- Parents:
- c13b8cc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/invariant.py
r01fb70b r4026380 14 14 @note: The data boundaries are assumed as infinite range. 15 15 """ 16 def __init__(self, data ,contrast=None, pConst=None):16 def __init__(self, data): 17 17 """ 18 18 Initialize variables … … 21 21 @param pConst: Porod Constant of type float 22 22 """ 23 self.q_star = self.getQstar(data= data) 24 self.volume = self._getVolFrac(contrast= contrast) 25 self.surface= self._getSurface(pConst= pConst) 23 ## Invariant 24 self.q_star = self._get_q_star(data= data) 26 25 27 def __call__(self, contrast, pConst): 28 """ 29 @precondition: self.q_star has already been computed 30 """ 31 self.volume = self._getVolFrac(contrast= contrast) 32 self.surface = self._getSurface(pConst= pConst) 33 34 return self 35 36 def getQstar(self, data): 26 def _get_q_star(self, data): 37 27 """ 38 28 @param data: data of type Data1D … … 42 32 #Process only data that inherited from DataLoader.Data_info.Data1D 43 33 raise ValueError,"Data must be of type DataLoader.Data1D" 44 if data.dxl == None: 45 return self._getQStarUnsmear(data= data) 34 35 # Check whether we have slit smearing information 36 if data.is_slit_smeared(): 37 return self._get_qstar_unsmeared(data= data) 46 38 else: 47 return self._get QStarSmear(data= data)39 return self._get_qstar_smeared(data= data) 48 40 49 41 50 42 51 def _get QStarUnsmear(self, data):43 def _get_qstar_unsmeared(self, data): 52 44 """ 53 45 @param data: data of type Data1D … … 86 78 87 79 88 def _get QStarSmear(self, data):80 def _get_qstar_smeared(self, data): 89 81 """ 90 82 @param data: data of type Data1D 91 Compute invariant with s mearing info83 Compute invariant with slit smearing info 92 84 q_star= x0*dxl *y0 *dx0 + x1*dxl *y1 *dx1 + ..+ xn*dxl *yn *dxn 93 85 where n= infinity … … 125 117 return sum 126 118 127 def _getVolFrac(self,contrast):119 def get_volume_fraction(self, contrast): 128 120 """ 129 121 Compute volume fraction is given by: … … 137 129 q_star unit 1/A^(3)*1/cm 138 130 139 the result returned will be 0<= volume <= 1 or None131 the result returned will be 0<= volume <= 1 140 132 141 133 @param contrast: contrast value provides by the user of type float 142 @return None : if the invariant Calculator does not a computed 143 q_star already stored 134 @return: volume fraction 144 135 @note: volume fraction must have no unit 145 136 """ 146 if contrast ==None:147 #No contrast value is provided for calculation then no calculation148 return149 137 if contrast < 0: 150 138 raise ValueError, "contrast must be greater than zero" 151 139 152 140 if self.q_star ==None: 153 r eturn141 raise RuntimeError, "Q_star is not defined" 154 142 155 143 if self.q_star < 0: 156 raise ValueError, "invariant must be greater than zero "144 raise ValueError, "invariant must be greater than zero. Q_star=%g" % self.q_star 157 145 158 146 #compute intermediate constant … … 161 149 discrim= 1 - 4*k 162 150 if discrim < 0: 163 r eturn151 raise RuntimeError, "could not compute the volume fraction: negative discriminant" 164 152 elif discrim ==0: 165 153 volume = 1/2 … … 169 157 volume1 = 0.5 *(1 - math.sqrt(discrim)) 170 158 volume2 = 0.5 *(1 + math.sqrt(discrim)) 171 print "volume1",volume1172 print "volume2",volume2173 159 174 160 if 0<= volume1 and volume1 <= 1: … … 176 162 elif 0<= volume2 and volume2<= 1: 177 163 return volume2 178 r eturn164 raise RuntimeError, "could not compute the volume fraction: inconsistent results" 179 165 180 def _getSurface(self, pConst, volume=None):166 def get_surface(self, contrast, porod_const): 181 167 """ 182 168 Compute the surface given by: 183 169 surface = (2*pi *volume(1- volume)*pConst)/ q_star 184 @param volume : volume previously calculated 185 @return None: if volume used for computation equal None 170 171 @param contrast: contrast value provides by the user of type float 172 @param porod_const: Porod constant 173 @return: specific surface 186 174 """ 187 #check if the user provides a value for volume 188 if volume != None: 189 self.volume = float(volume) 175 # Compute the volume 176 volume = self.get_volume_fraction(contrast) 190 177 191 #return None if volume or q_star is not computed 192 if self.q_star ==None or self.volume == None: 193 return 178 # Check whether we have Q star 179 if self.q_star ==None: 180 raise RuntimeError, "Q_star is not defined" 181 194 182 if self.q_star ==0: 195 raise ZeroDivisionError, "invariant must be greater than zero"183 raise ValueError, "invariant must be greater than zero. Q_star=%g" % self.q_star 196 184 197 return 2*math.pi* self.volume*(1- self.volume)*float(pConst)/self.q_star185 return 2*math.pi*volume*(1-volume)*float(porod_const)/self.q_star 198 186 199 187
Note: See TracChangeset
for help on using the changeset viewer.