Changeset 33c8d73 in sasmodels


Ignore:
Timestamp:
Mar 13, 2015 4:54:44 PM (10 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:
7954f5c
Parents:
29aa28f
Message:

linting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/resolution.py

    r29aa28f r33c8d73  
    2828    q = None 
    2929    q_calc = None 
    30     def apply(self, Iq_calc): 
    31         """ 
    32         Smear *Iq_calc* by the resolution function, returning *Iq*. 
     30    def apply(self, theory): 
     31        """ 
     32        Smear *theory* by the resolution function, returning *Iq*. 
    3333        """ 
    3434        raise NotImplementedError("Subclass does not define the apply function") 
     
    4343        self.q_calc = self.q = q 
    4444 
    45     def apply(self, Iq_calc): 
    46         return Iq_calc 
     45    def apply(self, theory): 
     46        return theory 
    4747 
    4848class Pinhole1D(Resolution1D): 
     
    5252    *q* points at which the data is measured. 
    5353 
    54     *dq* gaussian 1-sigma resolution at each data point. 
     54    *q_width* gaussian 1-sigma resolution at each data point. 
    5555 
    5656    *q_calc* is the list of points to calculate, or None if this should 
    57     be autogenerated from the *q,dq*. 
     57    be autogenerated from the *q,q_width*. 
    5858    """ 
    5959    def __init__(self, q, q_width, q_calc=None): 
     
    7474                self.q, np.maximum(q_width, MINIMUM_RESOLUTION)) 
    7575 
    76     def apply(self, Iq_calc): 
    77         return apply_resolution_matrix(self.weight_matrix, Iq_calc) 
     76    def apply(self, theory): 
     77        return apply_resolution_matrix(self.weight_matrix, theory) 
    7878 
    7979class Slit1D(Resolution1D): 
     
    9898            slit_resolution(self.q_calc, self.q, self.qx_width, self.qy_width) 
    9999 
    100     def apply(self, Iq_calc): 
    101         return apply_resolution_matrix(self.weight_matrix, Iq_calc) 
    102  
    103  
    104 def apply_resolution_matrix(weight_matrix, Iq_calc): 
     100    def apply(self, theory): 
     101        return apply_resolution_matrix(self.weight_matrix, theory) 
     102 
     103 
     104def apply_resolution_matrix(weight_matrix, theory): 
    105105    """ 
    106106    Apply the resolution weight matrix to the computed theory function. 
    107107    """ 
    108     #print "apply shapes",Iq_calc.shape, self.weight_matrix.shape 
    109     Iq = np.dot(Iq_calc[None,:], weight_matrix) 
     108    #print "apply shapes",theory.shape, self.weight_matrix.shape 
     109    Iq = np.dot(theory[None,:], weight_matrix) 
    110110    #print "result shape",Iq.shape 
    111111    return Iq.flatten() 
     
    123123    edges = bin_edges(q_calc) 
    124124    edges[edges<0.0] = 0.0 # clip edges below zero 
    125     index = (q_width>0.0) # treat perfect resolution differently 
     125    index = (q_width > 0.0) # treat perfect resolution differently 
    126126    G = erf( (edges[:,None] - q[None,:]) / (sqrt(2.0)*q_width)[None,:] ) 
    127127    weights = G[1:] - G[:-1] 
     
    168168    # Make q_calc into a row vector, and q, qx_width, qy_width into columns 
    169169    # Make weights match [ q_calc X q ] 
    170     weights = np.zeros((len(q),len(q_calc)),'d') 
     170    weights = np.zeros((len(q),len(q_calc)), 'd') 
    171171    q_calc = q_calc[None,:] 
    172172    q, qx_width, qy_width, edges = [ 
     
    226226 
    227227    def setUp(self): 
    228         self.x = 0.001*np.arange(1,11) 
     228        self.x = 0.001*np.arange(1, 11) 
    229229        self.y = self.Iq(self.x) 
    230230 
     
    238238        """ 
    239239        resolution = Perfect1D(self.x) 
    240         Iq_calc = self.Iq(resolution.q_calc) 
    241         output = resolution.apply(Iq_calc) 
     240        theory = self.Iq(resolution.q_calc) 
     241        output = resolution.apply(theory) 
    242242        np.testing.assert_equal(output, self.y) 
    243243 
     
    247247        """ 
    248248        resolution = Slit1D(self.x, 0., 0.) 
    249         Iq_calc = self.Iq(resolution.q_calc) 
    250         output = resolution.apply(Iq_calc) 
     249        theory = self.Iq(resolution.q_calc) 
     250        output = resolution.apply(theory) 
    251251        np.testing.assert_equal(output, self.y) 
    252252 
     
    257257        """ 
    258258        resolution = Slit1D(self.x, 0., 0.005) 
    259         Iq_calc = self.Iq(resolution.q_calc) 
    260         output = resolution.apply(Iq_calc) 
    261         # The following commented line was the correct output for even bins [see smearer.cpp for details] 
    262         #answer = [ 9.666,  9.056,  8.329,  7.494,  6.642,  5.721,  4.774,  3.824,  2.871, 2.   ] 
    263         answer = [ 9.0618,  8.6401,  8.1186,  7.1391,  6.1528,  5.5555,     4.5584,  3.5606,  2.5623, 2.    ] 
     259        theory = self.Iq(resolution.q_calc) 
     260        output = resolution.apply(theory) 
     261        answer = [ 9.0618, 8.6401, 8.1186, 7.1391, 6.1528, 
     262                   5.5555, 4.5584, 3.5606, 2.5623, 2. ] 
    264263        np.testing.assert_allclose(output, answer, atol=1e-4) 
    265264 
     
    269268        """ 
    270269        resolution = Pinhole1D(self.x, 0.0*self.x) 
    271         Iq_calc = self.Iq(resolution.q_calc) 
    272         output = resolution.apply(Iq_calc) 
     270        theory = self.Iq(resolution.q_calc) 
     271        output = resolution.apply(theory) 
    273272        np.testing.assert_equal(output, self.y) 
    274273 
     
    279278        resolution = Pinhole1D(self.x, 0.001*np.ones_like(self.x), 
    280279                               q_calc=self.x) 
    281         Iq_calc = 12.0-1000.0*resolution.q_calc 
    282         output = resolution.apply(Iq_calc) 
    283         answer = [ 10.44785079,   9.84991299,  8.98101708, 
    284                   7.99906585,   6.99998311,  6.00001689, 
    285                   5.00093415,   4.01898292,   3.15008701,  2.55214921] 
     280        theory = 12.0-1000.0*resolution.q_calc 
     281        output = resolution.apply(theory) 
     282        answer = [ 10.44785079, 9.84991299, 8.98101708, 
     283                  7.99906585, 6.99998311, 6.00001689, 
     284                  5.00093415, 4.01898292, 3.15008701, 2.55214921] 
    286285        np.testing.assert_allclose(output, answer, atol=1e-8) 
    287286 
     
    395394 
    396395    def setUp(self): 
    397         # sample q, dq, I(q) calculated by NIST Igor SANS package 
     396        # sample q, q_width, I(q) calculated by NIST Igor SANS package 
    398397        self.data = np.loadtxt(SPHERE_RESOLUTION_TEST_DATA.split('\n')).T 
    399398        self.pars = dict(scale=1.0, background=0.01, radius=60.0, 
    400399                         solvent_sld=6.3, sld=1) 
    401400 
    402     def Iq(self, q, dq): 
     401    def Iq(self, q, q_width): 
    403402        from sasmodels import core 
    404403        from sasmodels.models import sphere 
    405404 
    406405        model = core.load_model(sphere) 
    407         resolution = Pinhole1D(q, dq) 
     406        resolution = Pinhole1D(q, q_width) 
    408407        kernel = core.make_kernel(model, [resolution.q_calc]) 
    409         Iq_calc = core.call_kernel(kernel, self.pars) 
    410         result = resolution.apply(Iq_calc) 
     408        theory = core.call_kernel(kernel, self.pars) 
     409        result = resolution.apply(theory) 
    411410        return result 
    412411 
     
    415414        Compare pinhole resolution smearing with NIST Igor SANS 
    416415        """ 
    417         q, dq, answer = self.data 
    418         output = self.Iq(q, dq) 
     416        q, q_width, answer = self.data 
     417        output = self.Iq(q, q_width) 
    419418        np.testing.assert_allclose(output, answer, rtol=0.006) 
    420419 
     
    425424        Compare pinhole resolution smearing with NIST Igor SANS on sparse data 
    426425        """ 
    427         q, dq, answer = self.data[:, ::20]  # Take every nth point 
    428         output = self.Iq(q, dq) 
     426        q, q_width, answer = self.data[:, ::20]  # Take every nth point 
     427        output = self.Iq(q, q_width) 
    429428        np.testing.assert_allclose(output, answer, rtol=0.006) 
    430429 
     
    459458 
    460459    kernel = core.make_kernel(model, [resolution.q_calc]) 
    461     Iq_calc = core.call_kernel(kernel, {'length':210, 'radius':500}) 
    462     Iq = resolution.apply(Iq_calc) 
     460    theory = core.call_kernel(kernel, {'length':210, 'radius':500}) 
     461    Iq = resolution.apply(theory) 
    463462 
    464463    import matplotlib.pyplot as plt 
    465     plt.loglog(resolution.q_calc, Iq_calc, label='unsmeared') 
     464    plt.loglog(resolution.q_calc, theory, label='unsmeared') 
    466465    plt.loglog(resolution.q, Iq, label='smeared', hold=True) 
    467466    plt.legend() 
     
    471470 
    472471def demo_pinhole_1d(): 
    473     q = np.logspace(-3,-1,400) 
    474     dq = 0.1*q 
    475     resolution = Pinhole1D(q, dq) 
     472    q = np.logspace(-3, -1, 400) 
     473    q_width = 0.1*q 
     474    resolution = Pinhole1D(q, q_width) 
    476475    _eval_demo_1d(resolution, title="10% dQ/Q Pinhole Resolution") 
    477476 
    478477def demo_slit_1d(): 
    479     q = np.logspace(-3,-1,400) 
     478    q = np.logspace(-3, -1, 400) 
    480479    qx_width = 0.005 
    481480    qy_width = 0.0 
Note: See TracChangeset for help on using the changeset viewer.