[c97724e] | 1 | """ |
---|
[d459d4e] | 2 | Conversion of scattering cross section from SANS (I(q), or rather, ds/dO) in absolute |
---|
| 3 | units (cm-1)into SESANS correlation function G using a Hankel transformation, then converting |
---|
| 4 | the SESANS correlation function into polarisation from the SESANS experiment |
---|
[c97724e] | 5 | |
---|
[d459d4e] | 6 | Everything is in units of metres except specified otherwise (NOT TRUE!!!) |
---|
| 7 | Everything is in conventional units (nm for spin echo length) |
---|
[c97724e] | 8 | |
---|
| 9 | Wim Bouwman (w.g.bouwman@tudelft.nl), June 2013 |
---|
| 10 | """ |
---|
| 11 | |
---|
| 12 | from __future__ import division |
---|
| 13 | |
---|
[7ae2b7f] | 14 | import numpy as np # type: ignore |
---|
| 15 | from numpy import pi, exp # type: ignore |
---|
[46d9f48] | 16 | from scipy.special import j0 |
---|
[589b740] | 17 | #from mpmath import j0 as j0 |
---|
[02e70ff] | 18 | |
---|
[589b740] | 19 | class SesansTransform(object): |
---|
| 20 | #: Set of spin-echo lengths in the measured data |
---|
[26b848d] | 21 | SE = None # type: np.ndarray |
---|
[589b740] | 22 | #: Maximum acceptance of scattering vector in the spin echo encoding dimension (for ToF: Q of min(R) and max(lam)) |
---|
| 23 | zaccept = None # type: float |
---|
| 24 | #: Maximum size sensitivity; larger radius requires more computation |
---|
| 25 | Rmax = None # type: float |
---|
| 26 | #: q values to calculate when computing transform |
---|
| 27 | q = None # type: np.ndarray |
---|
| 28 | |
---|
| 29 | # transform arrays |
---|
| 30 | _H = None # type: np.ndarray |
---|
| 31 | _H0 = None # type: np.ndarray |
---|
| 32 | |
---|
| 33 | def set_transform(self, SE, zaccept, Rmax): |
---|
| 34 | if self.SE is None or len(SE) != len(self.SE) or np.any(SE != self.SE) or zaccept != self.zaccept or Rmax != self.Rmax: |
---|
| 35 | self.SE, self.zaccept, self.Rmax = SE, zaccept, Rmax |
---|
| 36 | self._set_q() |
---|
| 37 | self._set_hankel() |
---|
| 38 | |
---|
| 39 | def apply(self, Iq): |
---|
| 40 | G0 = np.dot(self._H0, Iq) |
---|
| 41 | G = np.dot(self._H.T, Iq) |
---|
| 42 | P = G - G0 |
---|
| 43 | return P |
---|
| 44 | |
---|
| 45 | def _set_q(self): |
---|
[08e2af7] | 46 | #q_min = dq = 0.1 * 2*pi / self.Rmax |
---|
| 47 | |
---|
[15ec718] | 48 | q_max = 2*pi / (self.SE[1]-self.SE[0]) |
---|
| 49 | q_min = dq = 0.1 *2*pi / (np.size(self.SE) * self.SE[-1]) |
---|
| 50 | |
---|
| 51 | #q_min = dq = q_max / 100000 |
---|
[26b848d] | 52 | q=np.arange(q_min, q_max, q_min) |
---|
[589b740] | 53 | self.q = q |
---|
| 54 | self.dq = dq |
---|
| 55 | |
---|
| 56 | def _set_hankel(self): |
---|
| 57 | #Rmax = #value in text box somewhere in FitPage? |
---|
| 58 | q = self.q |
---|
| 59 | dq = self.dq |
---|
| 60 | SElength = self.SE |
---|
| 61 | |
---|
| 62 | H0 = dq / (2 * pi) * q |
---|
[08e2af7] | 63 | q=np.array(q,dtype='float32') |
---|
| 64 | SElength=np.array(SElength,dtype='float32') |
---|
| 65 | |
---|
| 66 | # Using numpy tile, dtype is conserved |
---|
| 67 | repq=np.tile(q,(SElength.size,1)) |
---|
| 68 | repSE=np.tile(SElength,(q.size,1)) |
---|
| 69 | H = dq / (2 * pi) * j0(repSE*repq.T)*repq.T |
---|
| 70 | |
---|
| 71 | # Using numpy meshgrid - meshgrid produces float64 from float32 inputs! Problem for 32-bit OS: Memerrors! |
---|
| 72 | #H0 = dq / (2 * pi) * q |
---|
| 73 | #repSE, repq = np.meshgrid(SElength, q) |
---|
| 74 | #repq=np.array(repq,dtype='float32') |
---|
| 75 | #repSE=np.array(repSE,dtype='float32') |
---|
| 76 | #H = dq / (2 * pi) * j0(repSE*repq)*repq |
---|
[589b740] | 77 | |
---|
| 78 | self._H, self._H0 = H, H0 |
---|
| 79 | |
---|
[26b848d] | 80 | class SESANS1D(SesansTransform): |
---|
| 81 | def __init__(self, data, _H0, _H, q_calc): |
---|
| 82 | # x values of the data (Sasview requires these to be named "q") |
---|
| 83 | self.q = data.x |
---|
| 84 | self._H0 = _H0 |
---|
| 85 | self._H = _H |
---|
| 86 | # Pysmear does some checks on the smearer object, these checks require the "data" object... |
---|
| 87 | self.data=data |
---|
| 88 | # q values of the SAS model |
---|
| 89 | self.q_calc = q_calc # These are the MODEL's q values used by the smearer (in this case: the Hankel transform) |
---|
| 90 | def apply(self, theory): |
---|
| 91 | return SesansTransform.apply(self,theory) |
---|