Changeset 90e5ca1 in sasview for Invariant


Ignore:
Timestamp:
Mar 17, 2010 7:01:04 PM (14 years ago)
Author:
Gervaise Alina <gervyh@…>
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:
9ce7641c
Parents:
43e685d
Message:

modify invariant to get the fitted power
add another unittest that fail in both gui and computation

Location:
Invariant
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Invariant/invariant.py

    rc75a8ed r90e5ca1  
    362362        self._low_extrapolation_function = Guinier() 
    363363        self._low_extrapolation_power = None 
     364        self._low_extrapolation_power_fitted = None 
    364365    
    365366        self._high_extrapolation_npts = 4 
    366367        self._high_extrapolation_function = PowerLaw() 
    367368        self._high_extrapolation_power = None 
     369        self._high_extrapolation_power_fitted = None 
    368370         
    369371        # Extrapolation range 
     
    391393        return  new_data 
    392394      
    393     def _fit(self, model, qmin=Q_MINIMUM, qmax=Q_MAXIMUM, power=None): 
     395    def _fit(self, model, qmin=Q_MINIMUM, qmax=Q_MAXIMUM, power=None, range=None): 
    394396        """ 
    395397            fit data with function using  
     
    408410        extrapolator = Extrapolator(data=self._data, model=model) 
    409411        p, dp = extrapolator.fit(power=power, qmin=qmin, qmax=qmax)  
     412        if range is not None and range == 'low': 
     413            self._low_extrapolation_power_fitted = -1*p[0] 
     414        if range is not None and range == 'high': 
     415            self._high_extrapolation_power_fitted = -1*p[0] 
    410416         
    411417        return model.extract_model_parameters(constant=p[1], slope=p[0], dconstant=dp[1], dslope=dp[0]) 
     
    511517        return result_data 
    512518     
     519    def get_extrapolation_power(self, range='high'): 
     520        """ 
     521            return the fitted power for power law function at a givenr ange 
     522        """ 
     523        if range == 'low': 
     524            return self._low_extrapolation_power_fitted 
     525        return self._high_extrapolation_power_fitted 
     526     
    513527    def get_qstar_low(self): 
    514528        """ 
     
    529543                         qmin=qmin, 
    530544                         qmax=qmax, 
    531                          power=self._low_extrapolation_power) 
     545                         power=self._low_extrapolation_power, 
     546                         range='low') 
    532547         
    533548        # Distribution starting point 
     
    566581                         qmin=qmin, 
    567582                         qmax=qmax, 
    568                          power=self._high_extrapolation_power) 
     583                         power=self._high_extrapolation_power, 
     584                         range='high') 
    569585         
    570586        #create new Data1D to compute the invariant 
     
    653669            self._high_extrapolation_npts  = npts 
    654670            self._high_extrapolation_power = power 
     671            self._high_extrapolation_power_fitted = power 
    655672        else: 
    656673            if function == 'power_law': 
     
    660677            self._low_extrapolation_npts  = npts 
    661678            self._low_extrapolation_power = power 
     679            self._low_extrapolation_power_fitted = power 
    662680         
    663681    def get_qstar(self, extrapolation=None): 
  • Invariant/test/utest_use_cases.py

    rbdd162f r90e5ca1  
    237237        self.assertAlmostEquals(s , 941.7452, 3) 
    238238       
    239    
     239    def test_use_case_6(self): 
     240        """ 
     241            Invariant with high-Q extrapolation 
     242        """ 
     243        # Create invariant object. Background and scale left as defaults. 
     244        inv = invariant.InvariantCalculator(data=self.data) 
     245         
     246        # Set the extrapolation parameters for the high-Q range 
     247        inv.set_extrapolation(range='low', npts=10, function='power_law', power=4) 
     248         
     249        # The version of the call without error 
     250        # The function parameter defaults to None, then is picked to be 'power_law' for extrapolation='high' 
     251        qstar = inv.get_qstar(extrapolation='low') 
     252         
     253        # The version of the call with error 
     254        qstar, qstar_err = inv.get_qstar_with_error(extrapolation='low') 
     255 
     256        # Get the volume fraction and surface 
     257        v, dv = inv.get_volume_fraction_with_error(contrast=2.6e-6) 
     258        s, ds = inv.get_surface_with_error(contrast=2.6e-6, porod_const=2) 
     259         
     260        # Test results 
     261        self.assertAlmostEquals(qstar, 7.49e-5,2) 
     262        self.assertAlmostEquals(v, 0.005952674, 3) 
     263        self.assertAlmostEquals(s , 941.7452, 3) 
     264         
    240265class TestInvPinholeSmear(unittest.TestCase): 
    241266    """ 
Note: See TracChangeset for help on using the changeset viewer.