source: sasmodels/sasmodels/sesans.py @ 94d13f1

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 94d13f1 was 94d13f1, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

simplify interface to sesans transform

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[c97724e]1"""
[d459d4e]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
[c97724e]5
[d459d4e]6Everything is in units of metres except specified otherwise (NOT TRUE!!!)
7Everything is in conventional units (nm for spin echo length)
[c97724e]8
9Wim Bouwman (w.g.bouwman@tudelft.nl), June 2013
10"""
11
12from __future__ import division
13
[7ae2b7f]14import numpy as np  # type: ignore
15from numpy import pi, exp  # type: ignore
[54f1d96]16from scipy.special import j0
[94d13f1]17
[54f1d96]18class SesansTransform(object):
[94d13f1]19    """
20    Spin-Echo SANS transform calculator.  Similar to a resolution function,
21    the SesansTransform object takes I(q) for the set of *q_calc* values and
22    produces a transformed dataset
23
24    *SElength* (A) is the set of spin-echo lengths in the measured data.
25
26    *zaccept* (1/A) is the maximum acceptance of scattering vector in the spin
27    echo encoding dimension (for ToF: Q of min(R) and max(lam)).
28
29    *Rmax* (A) is the maximum size sensitivity; larger radius requires more
30    computation time.
31    """
32    #: SElength from the data in the original data units; not used by transform
33    #: but the GUI uses it, so make sure that it is present.
[54f1d96]34    q = None  # type: np.ndarray
35
[94d13f1]36    #: q values to calculate when computing transform
37    q_calc = None  # type: np.ndarray
38
[54f1d96]39    # transform arrays
[94d13f1]40    _H = None  # type: np.ndarray
41    _H0 = None # type: np.ndarray
[54f1d96]42
[94d13f1]43    def __init__(self, z, SElength, zaccept, Rmax):
44        # type: (np.ndarray, float, float) -> None
45        #import logging; logging.info("creating SESANS transform")
46        self.q = z
47        self._set_hankel(SElength, zaccept, Rmax)
[54f1d96]48
49    def apply(self, Iq):
[94d13f1]50        # tye: (np.ndarray) -> np.ndarray
51        G0 = np.dot(self._H0, Iq)
52        G = np.dot(self._H.T, Iq)
[54f1d96]53        P = G - G0
54        return P
55
[94d13f1]56    def _set_hankel(self, SElength, zaccept, Rmax):
57        # type: (np.ndarray, float, float) -> None
58        # Force float32 arrays, otherwise run into memory problems on some machines
59        SElength = np.asarray(SElength, dtype='float32')
[54f1d96]60
[94d13f1]61        #Rmax = #value in text box somewhere in FitPage?
62        q_max = 2*pi / (SElength[1] - SElength[0])
63        q_min = 0.1 * 2*pi / (np.size(SElength) * SElength[-1])
64        q = np.arange(q_min, q_max, q_min, dtype='float32')
65        dq = q_min
[54f1d96]66
[94d13f1]67        H0 = np.float32(dq/(2*pi)) * q
[54f1d96]68
[94d13f1]69        repq = np.tile(q, (SElength.size, 1)).T
70        repSE = np.tile(SElength, (q.size, 1))
71        H = np.float32(dq/(2*pi)) * j0(repSE*repq) * repq
72
73        self.q_calc = q
74        self._H, self._H0 = H, H0
Note: See TracBrowser for help on using the repository browser.