Changes in / [fa70e04:3a45c2c] in sasmodels
- Files:
-
- 10 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/direct_model.py
rd1ff3a5 rd1ff3a5 202 202 203 203 if self.data_type == 'sesans': 204 q = sesans.make_q(data.sample.zacceptance, data.Rmax) 205 index = slice(None, None) 206 res = None 207 if data.y is not None: 208 Iq, dIq = data.y, data.dy 204 from sas.sascalc.data_util.nxsunit import Converter 205 qmax, qunits = data.sample.zacceptance 206 SElength = Converter(data._xunit)(data.x, "A") 207 zaccept = Converter(qunits)(qmax, "1/A"), 208 Rmax = 10000000 209 index = slice(None, None) # equivalent to index [:] 210 Iq = data.y[index] 211 dIq = data.dy[index] 212 oriented = getattr(data, 'oriented', False) 213 if oriented: 214 res = sesans.OrientedSesansTransform(data.x[index], SElength, zaccept, Rmax) 215 # Oriented sesans transform produces q_calc = [qx, qy] 216 q_vectors = res.q_calc 209 217 else: 210 Iq, dIq = None, None 211 #self._theory = np.zeros_like(q) 212 q_vectors = [q] 213 q_mono = sesans.make_all_q(data) 218 res = sesans.SesansTransform(data.x[index], SElength, zaccept, Rmax) 219 # Unoriented sesans transform produces q_calc = q 220 q_vectors = [res.q_calc] 214 221 elif self.data_type == 'Iqxy': 215 222 #if not model.info.parameters.has_2d: … … 230 237 #self._theory = np.zeros_like(self.Iq) 231 238 q_vectors = res.q_calc 232 q_mono = []233 239 elif self.data_type == 'Iq': 234 240 index = (data.x >= data.qmin) & (data.x <= data.qmax) … … 255 261 #self._theory = np.zeros_like(self.Iq) 256 262 q_vectors = [res.q_calc] 257 q_mono = []258 263 elif self.data_type == 'Iq-oriented': 259 264 index = (data.x >= data.qmin) & (data.x <= data.qmax) … … 272 277 qy_width=data.dxl[index]) 273 278 q_vectors = res.q_calc 274 q_mono = []275 279 else: 276 280 raise ValueError("Unknown data type") # never gets here … … 279 283 # so we can save/restore state 280 284 self._kernel_inputs = q_vectors 281 self._kernel_mono_inputs = q_mono282 285 self._kernel = None 283 286 self.Iq, self.dIq, self.index = Iq, dIq, index … … 317 320 if self._kernel is None: 318 321 self._kernel = self._model.make_kernel(self._kernel_inputs) 319 self._kernel_mono = (320 self._model.make_kernel(self._kernel_mono_inputs)321 if self._kernel_mono_inputs else None)322 322 323 323 Iq_calc = call_kernel(self._kernel, pars, cutoff=cutoff) … … 326 326 # TODO: extend plotting of calculate Iq to other measurement types 327 327 # TODO: refactor so we don't store the result in the model 328 self.Iq_calc = Iq_calc 329 if self.data_type == 'sesans': 330 Iq_mono = (call_kernel(self._kernel_mono, pars, mono=True) 331 if self._kernel_mono_inputs else None) 332 result = sesans.transform(self._data, 333 self._kernel_inputs[0], Iq_calc, 334 self._kernel_mono_inputs, Iq_mono) 335 else: 336 result = self.resolution.apply(Iq_calc) 337 if hasattr(self.resolution, 'nx'): 338 self.Iq_calc = ( 339 self.resolution.qx_calc, self.resolution.qy_calc, 340 np.reshape(Iq_calc, (self.resolution.ny, self.resolution.nx)) 341 ) 328 self.Iq_calc = None 329 result = self.resolution.apply(Iq_calc) 330 if hasattr(self.resolution, 'nx'): 331 self.Iq_calc = ( 332 self.resolution.qx_calc, self.resolution.qy_calc, 333 np.reshape(Iq_calc, (self.resolution.ny, self.resolution.nx)) 334 ) 342 335 return result 343 336 -
sasmodels/sesans.py
r9f91afe r2cdc35b 20 20 Spin-Echo SANS transform calculator. Similar to a resolution function, 21 21 the SesansTransform object takes I(q) for the set of *q_calc* values and 22 produces a transformed dataset 22 produces a transformed dataset. 23 23 24 24 *SElength* (A) is the set of spin-echo lengths in the measured data. … … 48 48 49 49 def apply(self, Iq): 50 # tye: (np.ndarray) -> np.ndarray51 50 G0 = np.dot(self._H0, Iq) 52 51 G = np.dot(self._H.T, Iq) … … 78 77 self.q_calc = q 79 78 self._H, self._H0 = H, H0 79 80 class OrientedSesansTransform(object): 81 """ 82 Oriented Spin-Echo SANS transform calculator. Similar to a resolution 83 function, the OrientedSesansTransform object takes I(q) for the set 84 of *q_calc* values and produces a transformed dataset. 85 86 *SElength* (A) is the set of spin-echo lengths in the measured data. 87 88 *zaccept* (1/A) is the maximum acceptance of scattering vector in the spin 89 echo encoding dimension (for ToF: Q of min(R) and max(lam)). 90 91 *Rmax* (A) is the maximum size sensitivity; larger radius requires more 92 computation time. 93 """ 94 #: SElength from the data in the original data units; not used by transform 95 #: but the GUI uses it, so make sure that it is present. 96 q = None # type: np.ndarray 97 98 #: q values to calculate when computing transform 99 q_calc = None # type: np.ndarray 100 101 # transform arrays 102 _cosmat = None # type: np.ndarray 103 _cos0 = None # type: np.ndarray 104 _Iq_shape = None # type: Tuple[int, int] 105 106 def __init__(self, z, SElength, zaccept, Rmax): 107 # type: (np.ndarray, float, float) -> None 108 #import logging; logging.info("creating SESANS transform") 109 self.q = z 110 self._set_cosmat(SElength, zaccept, Rmax) 111 112 def apply(self, Iq): 113 dq = self.q_calc[0][0] 114 Iq = np.reshape(Iq, self._Iq_shape) 115 G0 = self._cos0 * np.sum(Iq) * dq 116 G = np.sum(np.dot(Iq, self._cosmat), axis=0) * dq 117 P = G - G0 118 return P 119 120 def _set_cosmat(self, SElength, zaccept, Rmax): 121 # type: (np.ndarray, float, float) -> None 122 # Force float32 arrays, otherwise run into memory problems on some machines 123 SElength = np.asarray(SElength, dtype='float32') 124 125 # Rmax = #value in text box somewhere in FitPage? 126 q_max = 2 * pi / (SElength[1] - SElength[0]) 127 q_min = 0.1 * 2 * pi / (np.size(SElength) * SElength[-1]) 128 q_min *= 100 129 130 q = np.arange(q_min, q_max, q_min, dtype='float32') 131 dq = q_min 132 133 cos0 = np.float32(dq / (2 * pi)) 134 cosmat = np.float32(dq / (2 * pi)) * np.cos(q[:, None] * SElength[None, :]) 135 136 qx, qy = np.meshgrid(q, q) 137 self._Iq_shape = qx.shape 138 self.q_calc = qx.flatten(), qy.flatten() 139 self._cosmat, self._cos0 = cosmat, cos0
Note: See TracChangeset
for help on using the changeset viewer.