Changeset 5925e90 in sasmodels
- Timestamp:
- Jan 30, 2016 11:01:46 PM (9 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/resolution.py
r823e620 r5925e90 470 470 471 471 def 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 """ 472 479 from sasmodels import core 473 480 kernel = core.make_kernel(form, [q]) … … 478 485 479 486 def 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 """ 480 492 from numpy import exp, pi 481 493 return exp(-0.5*((q-q0)/dq)**2)/(sqrt(2*pi)*dq) … … 559 571 560 572 class ResolutionTest(unittest.TestCase): 573 """ 574 Test the resolution calculations. 575 """ 561 576 562 577 def setUp(self): … … 668 683 669 684 class IgorComparisonTest(unittest.TestCase): 685 """ 686 Test resolution calculations against those returned by Igor. 687 """ 670 688 671 689 def setUp(self): … … 675 693 self.model = core.load_model(sphere, dtype='double') 676 694 677 def Iq_sphere(self, pars, resolution):695 def _eval_sphere(self, pars, resolution): 678 696 from sasmodels import core 679 697 kernel = core.make_kernel(self.model, [resolution.q_calc]) … … 683 701 return result 684 702 685 def compare(self, q, output, answer, tolerance):703 def _compare(self, q, output, answer, tolerance): 686 704 #err = (output - answer)/answer 687 705 #idx = abs(err) >= tolerance … … 700 718 q, width, answer, _ = data 701 719 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) 704 722 705 723 def test_pinhole(self): … … 713 731 q, q_width, answer = data 714 732 resolution = Pinhole1D(q, q_width) 715 output = self. Iq_sphere(pars, resolution)733 output = self._eval_sphere(pars, resolution) 716 734 # TODO: relative error should be lower 717 self. compare(q, output, answer, 3e-4)735 self._compare(q, output, answer, 3e-4) 718 736 719 737 def test_pinhole_romberg(self): … … 736 754 q_calc, tol = None, 0.01 737 755 resolution = Pinhole1D(q, q_width, q_calc=q_calc) 738 output = self. Iq_sphere(pars, resolution)756 output = self._eval_sphere(pars, resolution) 739 757 if 0: # debug plot 740 758 import matplotlib.pyplot as plt 741 759 resolution = Perfect1D(q) 742 source = self. Iq_sphere(pars, resolution)760 source = self._eval_sphere(pars, resolution) 743 761 plt.loglog(q, source, '.') 744 762 plt.loglog(q, answer, '-', hold=True) 745 763 plt.loglog(q, output, '-', hold=True) 746 764 plt.show() 747 self. compare(q, output, answer, tol)765 self._compare(q, output, answer, tol) 748 766 749 767 def test_slit(self): … … 757 775 q, delta_qv, _, answer = data 758 776 resolution = Slit1D(q, width=delta_qv, height=0) 759 output = self. Iq_sphere(pars, resolution)777 output = self._eval_sphere(pars, resolution) 760 778 # TODO: eliminate Igor test since it is too inaccurate to be useful. 761 779 # This means we can eliminate the test data as well, and instead 762 780 # use a generated q vector. 763 self. compare(q, output, answer, 0.5)781 self._compare(q, output, answer, 0.5) 764 782 765 783 def test_slit_romberg(self): … … 777 795 delta_qv[0], 0.) 778 796 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) 780 798 # TODO: relative error should be lower 781 self. compare(q, output, answer, 0.025)799 self._compare(q, output, answer, 0.025) 782 800 783 801 def test_ellipsoid(self): … … 799 817 # TODO: 10% is too much error; use better algorithm 800 818 #print(np.max(abs(answer-output)/answer)) 801 self. compare(q, output, answer, 0.1)819 self._compare(q, output, answer, 0.1) 802 820 803 821 #TODO: can sas q spacing be too sparse for the resolution calculation? … … 813 831 q, q_width, answer = data[:, ::20] # Take every nth point 814 832 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) 817 835 818 836 … … 1067 1085 1068 1086 def demo_pinhole_1d(): 1087 """ 1088 Show example of pinhole smearing. 1089 """ 1069 1090 q = np.logspace(-4, np.log10(0.2), 400) 1070 1091 q_width = 0.1*q … … 1073 1094 1074 1095 def demo_slit_1d(): 1096 """ 1097 Show example of slit smearing. 1098 """ 1075 1099 q = np.logspace(-4, np.log10(0.2), 100) 1076 1100 w = h = 0. … … 1083 1107 1084 1108 def demo(): 1109 """ 1110 Run the resolution demos. 1111 """ 1085 1112 import matplotlib.pyplot as plt 1086 1113 plt.subplot(121)
Note: See TracChangeset
for help on using the changeset viewer.