Changeset 26b848d in sasmodels


Ignore:
Timestamp:
Nov 20, 2016 5:39:44 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:
777d369
Parents:
589b740
Message:

SESANS optimizations

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/resolution.py

    r589b740 r26b848d  
    1111 
    1212from sasmodels import sesans 
     13from sasmodels.sesans import SesansTransform as SesansTransform 
    1314 
    1415__all__ = ["Resolution", "Perfect1D", "Pinhole1D", "Slit1D", 
     
    5758        return theory 
    5859 
    59  
    60 class SESANS1D(Resolution): 
    61     def __init__(self, data, H0, H, q_calc): 
    62         self.q = data.x 
    63         self.H0 = H0 
    64         self.H = H 
    65         self.data=data 
    66         self.q_calc = q_calc 
    67     def apply(self, theory): 
    68         return sesans.SesansTransform.apply(theory) 
    69         #return sesans.hankeltrafo(self.H0, self.H, theory) 
    70  
    71 """ 
    72     def __init__(self, data, q_calc): 
    73         self.q = data.x 
    74         self.data = data 
    75         self.q_calc = q_calc 
    76  
    77     def apply(self, theory): 
    78         return sesans.transform(self.data, self.q_calc, theory, None, None) 
    79 """ 
    8060class Pinhole1D(Resolution): 
    8161    r""" 
  • sasmodels/sesans.py

    r589b740 r26b848d  
    1414import numpy as np  # type: ignore 
    1515from numpy import pi, exp  # type: ignore 
    16 #from scipy.special import jv as besselj 
    1716from scipy.special import j0 
    1817#from mpmath import j0 as j0 
    19 #from mpmath import besselj 
    20 #from mpmath import mpf 
    21 from src.sas.sascalc.data_util.nxsunit import Converter 
    22 #from sas.sasgui.perspectives.fitting.fitpage import FitPage 
    23 #import direct_model.DataMixin as model 
    2418         
    25 def make_q(q_max, Rmax): 
    26     r""" 
    27     Return a $q$ vector suitable for SESANS covering from $2\pi/ (10 R_{\max})$ 
    28     to $q_max$. This is the integration range of the Hankel transform; bigger range and  
    29     more points makes a better numerical integration. 
    30     Smaller q_min will increase reliable spin echo length range.  
    31     Rmax is the "radius" of the largest expected object and can be set elsewhere. 
    32     q_max is determined by the acceptance angle of the SESANS instrument. 
    33     """ 
    34     from sas.sascalc.data_util.nxsunit import Converter 
    35  
    36     q_min = dq = 0.1 * 2*pi / Rmax 
    37     return np.arange(q_min, 
    38                      Converter(q_max[1])(q_max[0], 
    39                                          units="1/A"), 
    40                      dq) 
    41  
    42 def Hankelconstructor(data): 
    43     Rmax = 1000000 
    44     #Rmax = #value in text box? 
    45     q_calc = make_q(data.sample.zacceptance, Rmax) 
    46     SElength = Converter(data._xunit)(data.x, "A") 
    47     dq = q_calc[1] - q_calc[0] 
    48     H0 = dq / (2 * pi) * q_calc 
    49     repSE, repq = np.meshgrid(SElength,q_calc) 
    50     repq=np.array(repq,dtype='f') 
    51     repSE=np.array(repSE,dtype='f') 
    52     H = dq / (2 * pi) * j0(repSE*repq)*repq 
    53     return H0, H, q_calc 
    54  
    55 def hankeltrafo(H0, H, Iq_calc): 
    56     G0 = np.dot(H0, Iq_calc) 
    57     G = np.dot(H.T, Iq_calc) 
    58     P = G - G0 
    59     return P  # This is the logarithmic Polarization, not the linear one as found in Andersson2008! 
    60  
    61  
    6219class SesansTransform(object): 
    6320    #: Set of spin-echo lengths in the measured data 
    64     SElength = None  # type: np.ndarray 
     21    SE = None  # type: np.ndarray 
    6522    #: Maximum acceptance of scattering vector in the spin echo encoding dimension (for ToF: Q of min(R) and max(lam)) 
    6623    zaccept = None # type: float 
     
    8946        q_min = dq = 0.1 * 2*pi / self.Rmax 
    9047        q_max = self.zaccept 
    91         q=np.arange(q_min,q_max) 
     48        q=np.arange(q_min, q_max, q_min) 
    9249        self.q = q 
    9350        self.dq = dq 
     
    10057 
    10158        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') 
     59        repSE, repq = np.meshgrid(SElength, q) 
     60        repq=np.array(repq,dtype='float32') 
     61        repSE=np.array(repSE,dtype='float32') 
    10562        H = dq / (2 * pi) * j0(repSE*repq)*repq 
    10663 
    10764        self._H, self._H0 = H, H0 
    10865 
     66class SESANS1D(SesansTransform): 
     67    def __init__(self, data, _H0, _H, q_calc): 
     68        # x values of the data (Sasview requires these to be named "q") 
     69        self.q = data.x 
     70        self._H0 = _H0 
     71        self._H = _H 
     72        # Pysmear does some checks on the smearer object, these checks require the "data" object... 
     73        self.data=data 
     74        # q values of the SAS model 
     75        self.q_calc = q_calc # These are the MODEL's q values used by the smearer (in this case: the Hankel transform) 
     76    def apply(self, theory): 
     77        return SesansTransform.apply(self,theory) 
Note: See TracChangeset for help on using the changeset viewer.