Changeset 5925e90 in sasmodels


Ignore:
Timestamp:
Jan 30, 2016 11:01:46 PM (9 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:
5c962df
Parents:
eafc9fa
Message:

fix mistranslated log normal distribution; update docs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/resolution.py

    r823e620 r5925e90  
    470470 
    471471def eval_form(q, form, pars): 
     472    """ 
     473    Return the SAS model evaluated at *q*. 
     474 
     475    *form* is the SAS model returned from :fun:`core.load_model`. 
     476 
     477    *pars* are the parameter values to use when evaluating. 
     478    """ 
    472479    from sasmodels import core 
    473480    kernel = core.make_kernel(form, [q]) 
     
    478485 
    479486def gaussian(q, q0, dq): 
     487    """ 
     488    Return the Gaussian resolution function. 
     489 
     490    *q0* is the center, *dq* is the width and *q* are the points to evaluate. 
     491    """ 
    480492    from numpy import exp, pi 
    481493    return exp(-0.5*((q-q0)/dq)**2)/(sqrt(2*pi)*dq) 
     
    559571 
    560572class ResolutionTest(unittest.TestCase): 
     573    """ 
     574    Test the resolution calculations. 
     575    """ 
    561576 
    562577    def setUp(self): 
     
    668683 
    669684class IgorComparisonTest(unittest.TestCase): 
     685    """ 
     686    Test resolution calculations against those returned by Igor. 
     687    """ 
    670688 
    671689    def setUp(self): 
     
    675693        self.model = core.load_model(sphere, dtype='double') 
    676694 
    677     def Iq_sphere(self, pars, resolution): 
     695    def _eval_sphere(self, pars, resolution): 
    678696        from sasmodels import core 
    679697        kernel = core.make_kernel(self.model, [resolution.q_calc]) 
     
    683701        return result 
    684702 
    685     def compare(self, q, output, answer, tolerance): 
     703    def _compare(self, q, output, answer, tolerance): 
    686704        #err = (output - answer)/answer 
    687705        #idx = abs(err) >= tolerance 
     
    700718        q, width, answer, _ = data 
    701719        resolution = Perfect1D(q) 
    702         output = self.Iq_sphere(pars, resolution) 
    703         self.compare(q, output, answer, 1e-6) 
     720        output = self._eval_sphere(pars, resolution) 
     721        self._compare(q, output, answer, 1e-6) 
    704722 
    705723    def test_pinhole(self): 
     
    713731        q, q_width, answer = data 
    714732        resolution = Pinhole1D(q, q_width) 
    715         output = self.Iq_sphere(pars, resolution) 
     733        output = self._eval_sphere(pars, resolution) 
    716734        # TODO: relative error should be lower 
    717         self.compare(q, output, answer, 3e-4) 
     735        self._compare(q, output, answer, 3e-4) 
    718736 
    719737    def test_pinhole_romberg(self): 
     
    736754        q_calc, tol = None, 0.01 
    737755        resolution = Pinhole1D(q, q_width, q_calc=q_calc) 
    738         output = self.Iq_sphere(pars, resolution) 
     756        output = self._eval_sphere(pars, resolution) 
    739757        if 0: # debug plot 
    740758            import matplotlib.pyplot as plt 
    741759            resolution = Perfect1D(q) 
    742             source = self.Iq_sphere(pars, resolution) 
     760            source = self._eval_sphere(pars, resolution) 
    743761            plt.loglog(q, source, '.') 
    744762            plt.loglog(q, answer, '-', hold=True) 
    745763            plt.loglog(q, output, '-', hold=True) 
    746764            plt.show() 
    747         self.compare(q, output, answer, tol) 
     765        self._compare(q, output, answer, tol) 
    748766 
    749767    def test_slit(self): 
     
    757775        q, delta_qv, _, answer = data 
    758776        resolution = Slit1D(q, width=delta_qv, height=0) 
    759         output = self.Iq_sphere(pars, resolution) 
     777        output = self._eval_sphere(pars, resolution) 
    760778        # TODO: eliminate Igor test since it is too inaccurate to be useful. 
    761779        # This means we can eliminate the test data as well, and instead 
    762780        # use a generated q vector. 
    763         self.compare(q, output, answer, 0.5) 
     781        self._compare(q, output, answer, 0.5) 
    764782 
    765783    def test_slit_romberg(self): 
     
    777795                               delta_qv[0], 0.) 
    778796        resolution = Slit1D(q, width=delta_qv, height=0, q_calc=q_calc) 
    779         output = self.Iq_sphere(pars, resolution) 
     797        output = self._eval_sphere(pars, resolution) 
    780798        # TODO: relative error should be lower 
    781         self.compare(q, output, answer, 0.025) 
     799        self._compare(q, output, answer, 0.025) 
    782800 
    783801    def test_ellipsoid(self): 
     
    799817        # TODO: 10% is too much error; use better algorithm 
    800818        #print(np.max(abs(answer-output)/answer)) 
    801         self.compare(q, output, answer, 0.1) 
     819        self._compare(q, output, answer, 0.1) 
    802820 
    803821    #TODO: can sas q spacing be too sparse for the resolution calculation? 
     
    813831        q, q_width, answer = data[:, ::20] # Take every nth point 
    814832        resolution = Pinhole1D(q, q_width) 
    815         output = self.Iq_sphere(pars, resolution) 
    816         self.compare(q, output, answer, 1e-6) 
     833        output = self._eval_sphere(pars, resolution) 
     834        self._compare(q, output, answer, 1e-6) 
    817835 
    818836 
     
    10671085 
    10681086def demo_pinhole_1d(): 
     1087    """ 
     1088    Show example of pinhole smearing. 
     1089    """ 
    10691090    q = np.logspace(-4, np.log10(0.2), 400) 
    10701091    q_width = 0.1*q 
     
    10731094 
    10741095def demo_slit_1d(): 
     1096    """ 
     1097    Show example of slit smearing. 
     1098    """ 
    10751099    q = np.logspace(-4, np.log10(0.2), 100) 
    10761100    w = h = 0. 
     
    10831107 
    10841108def demo(): 
     1109    """ 
     1110    Run the resolution demos. 
     1111    """ 
    10851112    import matplotlib.pyplot as plt 
    10861113    plt.subplot(121) 
Note: See TracChangeset for help on using the changeset viewer.