source: sasmodels/sasmodels/sesans.py @ 08e2af7

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 08e2af7 was 08e2af7, checked in by jhbakker, 7 years ago

Memerror fix

  • Property mode set to 100644
File size: 3.2 KB
Line 
1"""
2Conversion of scattering cross section from SANS (I(q), or rather, ds/dO) in absolute
3units (cm-1)into SESANS correlation function G using a Hankel transformation, then converting
4the SESANS correlation function into polarisation from the SESANS experiment
5
6Everything is in units of metres except specified otherwise (NOT TRUE!!!)
7Everything is in conventional units (nm for spin echo length)
8
9Wim Bouwman (w.g.bouwman@tudelft.nl), June 2013
10"""
11
12from __future__ import division
13
14import numpy as np  # type: ignore
15from numpy import pi, exp  # type: ignore
16from scipy.special import j0
17#from mpmath import j0 as j0
18       
19class SesansTransform(object):
20    #: Set of spin-echo lengths in the measured data
21    SE = None  # type: np.ndarray
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):
46        #q_min = dq = 0.1 * 2*pi / self.Rmax
47
48        q_max = self.zaccept
49        q_min = dq = q_max / 100000
50        q=np.arange(q_min, q_max, q_min)
51        self.q = q
52        self.dq = dq
53
54    def _set_hankel(self):
55        #Rmax = #value in text box somewhere in FitPage?
56        q = self.q
57        dq = self.dq
58        SElength = self.SE
59
60        H0 = dq / (2 * pi) * q
61        q=np.array(q,dtype='float32')
62        SElength=np.array(SElength,dtype='float32')
63
64        # Using numpy tile, dtype is conserved
65        repq=np.tile(q,(SElength.size,1))
66        repSE=np.tile(SElength,(q.size,1))
67        H = dq / (2 * pi) * j0(repSE*repq.T)*repq.T
68
69        # Using numpy meshgrid - meshgrid produces float64 from float32 inputs! Problem for 32-bit OS: Memerrors!
70        #H0 = dq / (2 * pi) * q
71        #repSE, repq = np.meshgrid(SElength, q)
72        #repq=np.array(repq,dtype='float32')
73        #repSE=np.array(repSE,dtype='float32')
74        #H = dq / (2 * pi) * j0(repSE*repq)*repq
75
76        self._H, self._H0 = H, H0
77
78class SESANS1D(SesansTransform):
79    def __init__(self, data, _H0, _H, q_calc):
80        # x values of the data (Sasview requires these to be named "q")
81        self.q = data.x
82        self._H0 = _H0
83        self._H = _H
84        # Pysmear does some checks on the smearer object, these checks require the "data" object...
85        self.data=data
86        # q values of the SAS model
87        self.q_calc = q_calc # These are the MODEL's q values used by the smearer (in this case: the Hankel transform)
88    def apply(self, theory):
89        return SesansTransform.apply(self,theory)
Note: See TracBrowser for help on using the repository browser.