Changeset 9f7fbd9 in sasview


Ignore:
Timestamp:
Mar 24, 2015 3:28:54 PM (10 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
66f21cd
Parents:
0efb04d
Message:

rewrite slit smearing for usans

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/sas/fit/AbstractFitEngine.py

    r386ffe1 r9f7fbd9  
    161161        # TODO: Should provide an option for users to set it like percent, 
    162162        # constant, or dy data 
    163         if dy == None or dy == [] or dy.all() == 0: 
     163        if dy is None or dy == [] or dy.all() == 0: 
    164164            self.dy = numpy.ones(len(y)) 
    165165        else: 
     
    260260        """ 
    261261        return [] 
    262      
    263      
     262 
     263 
    264264class FitData2D(Data2D): 
    265265    """ 
  • src/sas/fit/BumpsFitting.py

    r386ffe1 r9f7fbd9  
    107107        self.model = model.model 
    108108        self.data = data 
     109        if self.data.smearer is not None: 
     110            self.data.smearer.model = self.model 
    109111        self._define_pars() 
    110112        self._init_pars(kw) 
     
    174176    def _recalculate(self): 
    175177        if self._dirty: 
    176             self._residuals, self._theory = self.data.residuals(self.model.evalDistribution) 
     178            self._residuals, self._theory \ 
     179                = self.data.residuals(self.model.evalDistribution) 
    177180            self._dirty = False 
    178181 
  • src/sas/models/qsmearing.py

    rfd5ac0d r9f7fbd9  
    8181    # If we found slit smearing data, return a slit smearer 
    8282    if _found_slit == True: 
    83         return SlitSmearer(data1D, model) 
     83        return PySlitSmearer(data1D, model) 
    8484    return None 
    8585             
     
    583583    return nbins_low, nbins_high, \ 
    584584             new_width[data_x_ext > 0], data_x_ext[data_x_ext > 0] 
     585 
     586 
     587 
     588from .resolution import Slit1D 
     589class PySlitSmearer(object): 
     590    def __init__(self, data1D, model = None): 
     591        self.model = model 
     592 
     593        q = data1D.x 
     594        width = data1D.dxw if data1D.dxw is not None else 0 
     595        height = data1D.dxl if data1D.dxl is not None else 0 
     596        # TODO: width and height seem to be reversed 
     597        self.resolution = Slit1D(q, height, width) 
     598 
     599    def __call__(self, iq_in, first_bin=0, last_bin=None): 
     600        if last_bin is None or last_bin >= len(iq_in): 
     601            last_bin = len(iq_in) - 1 
     602        q_calc = self.resolution.q_calc 
     603        iq_calc = numpy.empty_like(q_calc) 
     604        iq_calc[:first_bin] = 0 
     605        iq_calc[first_bin:last_bin+1] = iq_in 
     606        if last_bin < len(q_calc)-1: 
     607            iq_calc[last_bin:] = self.model.evalDistribution(q_calc[last_bin:]) 
     608        iq_out = self.resolution.apply(iq_calc) 
     609        return iq_out[first_bin:last_bin+1] 
     610 
     611    def get_bin_range(self, q_min=None, q_max=None): 
     612        """ 
     613 
     614        :param q_min: minimum q-value to smear 
     615        :param q_max: maximum q-value to smear 
     616 
     617        """ 
     618        # assume the data values are sorted 
     619        first = numpy.searchsorted(self.resolution.q, q_min) 
     620        # assume that the resolution is much larger than the q range 
     621        last = len(self.resolution.q)-1 
     622        return first, last 
  • test/pr_inversion/test/test_output.txt

    r8a428fc r9f7fbd9  
    33#alpha=0.0007 
    44#chi2=836.797 
    5 #elapsed=0.00199986 
     5#elapsed=0.000377893 
    66#qmin=None 
    77#qmax=None 
  • test/sasfit/test/utest_fit_smeared.py

    refa5e44 r9f7fbd9  
    165165    def test_slit(self): 
    166166        smear = smear_selection(self.data_slit) 
    167         self.assertEqual(smear.__class__.__name__, 'SlitSmearer') 
     167        #self.assertEqual(smear.__class__.__name__, 'SlitSmearer') 
     168        self.assertEqual(smear.__class__.__name__, 'PySlitSmearer') 
    168169 
    169170        fitter = Fit('bumps') 
     
    181182         
    182183        result1, = fitter.fit() 
    183          
     184 
    184185        #print "v",result1.pvec 
    185186        #print "dv",result1.stderr 
    186187        #print "chisq(v)",result1.fitness 
    187          
    188         self.assertTrue( math.fabs(result1.pvec[0]-2340) < 20 ) 
    189         self.assertTrue( math.fabs(result1.pvec[1]-0.010) < 0.002 ) 
     188 
     189        numpy.testing.assert_allclose(result1.pvec, [2323.466,0.22137], rtol=0.001) 
    190190 
    191191if __name__ == '__main__': 
Note: See TracChangeset for help on using the changeset viewer.