Changeset 589b740 in sasmodels for sasmodels/sesans.py


Ignore:
Timestamp:
Nov 20, 2016 3:43:52 AM (7 years ago)
Author:
jhbakker
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
26b848d
Parents:
46d9f48
Message:

test branch for SEsans class in sesans.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/sesans.py

    r46d9f48 r589b740  
    1414import numpy as np  # type: ignore 
    1515from numpy import pi, exp  # type: ignore 
    16 from scipy.special import jv as besselj 
     16#from scipy.special import jv as besselj 
    1717from scipy.special import j0 
    18 #from mpmath import j0 
    19 from mpmath import besselj 
    20 from mpmath import mpf 
     18#from mpmath import j0 as j0 
     19#from mpmath import besselj 
     20#from mpmath import mpf 
    2121from src.sas.sascalc.data_util.nxsunit import Converter 
    2222#from sas.sasgui.perspectives.fitting.fitpage import FitPage 
     
    4242def Hankelconstructor(data): 
    4343    Rmax = 1000000 
     44    #Rmax = #value in text box? 
    4445    q_calc = make_q(data.sample.zacceptance, Rmax) 
    4546    SElength = Converter(data._xunit)(data.x, "A") 
     
    4748    H0 = dq / (2 * pi) * q_calc 
    4849    repSE, repq = np.meshgrid(SElength,q_calc) 
     50    repq=np.array(repq,dtype='f') 
     51    repSE=np.array(repSE,dtype='f') 
    4952    H = dq / (2 * pi) * j0(repSE*repq)*repq 
    5053    return H0, H, q_calc 
     
    5558    P = G - G0 
    5659    return P  # This is the logarithmic Polarization, not the linear one as found in Andersson2008! 
     60 
     61 
     62class SesansTransform(object): 
     63    #: Set of spin-echo lengths in the measured data 
     64    SElength = None  # type: np.ndarray 
     65    #: Maximum acceptance of scattering vector in the spin echo encoding dimension (for ToF: Q of min(R) and max(lam)) 
     66    zaccept = None # type: float 
     67    #: Maximum size sensitivity; larger radius requires more computation 
     68    Rmax = None  # type: float 
     69    #: q values to calculate when computing transform 
     70    q = None  # type: np.ndarray 
     71 
     72    # transform arrays 
     73    _H = None  # type: np.ndarray 
     74    _H0 = None # type: np.ndarray 
     75 
     76    def set_transform(self, SE, zaccept, Rmax): 
     77        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: 
     78            self.SE, self.zaccept, self.Rmax = SE, zaccept, Rmax 
     79            self._set_q() 
     80            self._set_hankel() 
     81 
     82    def apply(self, Iq): 
     83        G0 = np.dot(self._H0, Iq) 
     84        G = np.dot(self._H.T, Iq) 
     85        P = G - G0 
     86        return P 
     87 
     88    def _set_q(self): 
     89        q_min = dq = 0.1 * 2*pi / self.Rmax 
     90        q_max = self.zaccept 
     91        q=np.arange(q_min,q_max) 
     92        self.q = q 
     93        self.dq = dq 
     94 
     95    def _set_hankel(self): 
     96        #Rmax = #value in text box somewhere in FitPage? 
     97        q = self.q 
     98        dq = self.dq 
     99        SElength = self.SE 
     100 
     101        H0 = dq / (2 * pi) * q 
     102        repSE, repq = np.meshgrid(SElength,q) 
     103        repq=np.array(repq,dtype='f') 
     104        repSE=np.array(repSE,dtype='f') 
     105        H = dq / (2 * pi) * j0(repSE*repq)*repq 
     106 
     107        self._H, self._H0 = H, H0 
     108 
Note: See TracChangeset for help on using the changeset viewer.