Changeset ea75043 in sasmodels for sasmodels/resolution2d.py


Ignore:
Timestamp:
Mar 29, 2016 6:22:13 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
d6f5da6
Parents:
1d61d07
Message:

add support for oriented usans using direct 2d resolution integral

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/resolution2d.py

    r823e620 rea75043  
    1010from numpy import pi, cos, sin, sqrt 
    1111 
     12from . import resolution 
    1213from .resolution import Resolution 
    1314 
     
    2021NR = {'xhigh':10, 'high':5, 'med':5, 'low':3} 
    2122NPHI = {'xhigh':20, 'high':12, 'med':6, 'low':4} 
     23 
     24## Defaults 
     25N_SLIT_PERP = {'xhigh':2000, 'high':1000, 'med':500, 'low':250} 
     26N_SLIT_PERP_DOC = ", ".join("%s=%d"%(name,value) for value,name in 
     27                            sorted((v,k) for k,v in N_SLIT_PERP.items())) 
    2228 
    2329class Pinhole2D(Resolution): 
     
    167173        else: 
    168174            return theory 
     175 
     176 
     177class Slit2D(Resolution): 
     178    """ 
     179    Slit aperture with resolution function on an oriented sample. 
     180 
     181    *q* points at which the data is measured. 
     182 
     183    *qx_width* slit width in qx 
     184 
     185    *qy_width* slit height in qy; current implementation requires a fixed 
     186    qy_width for all q points. 
     187 
     188    *q_calc* is the list of q points to calculate, or None if this 
     189    should be estimated from the *q* and *qx_width*. 
     190 
     191    *accuracy* determines the number of *qy* points to compute for each *q*. 
     192    The values are stored in sasmodels.resolution2d.N_SLIT_PERP.  The default 
     193    values are: %s 
     194    """ 
     195    __doc__ = __doc__%N_SLIT_PERP_DOC 
     196    def __init__(self, q, qx_width, qy_width=0., q_calc=None, accuracy='low'): 
     197        # Remember what q and width was used even though we won't need them 
     198        # after the weight matrix is constructed 
     199        self.q, self.qx_width, self.qy_width = q, qx_width, qy_width 
     200 
     201        # Allow independent resolution on each qx point even though it is not 
     202        # needed in practice.  Set qy_width to the maximum qy width. 
     203        if np.isscalar(qx_width): 
     204            qx_width = np.ones(len(q))*qx_width 
     205        else: 
     206            qx_width = np.asarray(qx_width) 
     207        if not np.isscalar(qy_width): 
     208            qy_width = np.max(qy_width) 
     209 
     210        # Build grid of qx, qy points 
     211        if q_calc is not None: 
     212            qx_calc = np.sort(q_calc) 
     213        else: 
     214            qx_calc = resolution.pinhole_extend_q(q, qx_width, nsigma=3) 
     215        qy_calc = np.linspace(-qy_width, qy_width, N_SLIT_PERP[accuracy]*10) 
     216        self.q_calc = [v.flatten() for v in np.meshgrid(qx_calc, qy_calc)] 
     217        self.qx_calc, self.qy_calc = qx_calc, qy_calc 
     218        self.nx, self.ny = len(qx_calc), len(qy_calc) 
     219        self.dy = 2*qy_width/self.ny 
     220 
     221        # Build weight matrix for resolution integration 
     222        if np.any(qx_width > 0): 
     223            self.weights = resolution.pinhole_resolution(qx_calc, q, 
     224                    np.maximum(qx_width, resolution.MINIMUM_RESOLUTION)) 
     225        elif len(qx_calc)==len(q) and np.all(qx_calc == q): 
     226            self.weights = None 
     227        else: 
     228            raise ValueError("Slit2D fails with q_calc != q") 
     229 
     230    def apply(self, theory): 
     231        Iq = np.sum(theory.reshape(self.ny, self.nx), axis=0)*self.dy 
     232        if self.weights is not None: 
     233            Iq = resolution.apply_resolution_matrix(self.weights, Iq) 
     234        return Iq 
     235 
Note: See TracChangeset for help on using the changeset viewer.