Changeset 4d270706 in sasview for Invariant


Ignore:
Timestamp:
Jan 6, 2010 8:26:11 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:
4cbaf35
Parents:
196608d
Message:

change on method name and fit

Location:
Invariant
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Invariant/invariant.py

    r25a92d1 r4d270706  
    77import numpy 
    88 
    9 from DataLoader.data_info import Data1D as LoaderData1D 
     9from sans.guiframe.dataFitting import Data1D as LoaderData1D 
    1010from DataLoader.qsmearing import smear_selection 
    1111 
     
    114114                                & (self.data.x <= self._qmax_unsmeared) 
    115115   
    116     def fit(self, power =None): 
     116    def fit(self, power=None): 
    117117        """ 
    118118           Fit data for y = ax + b  return a and b 
     
    129129            print "The dy data for Invariant calculation should be prepared before get to FitFunctor.fit()..." 
    130130            sigma = one[self.idx_unsmeared ] 
    131         sigma2 = sigma*sigma 
     131        sigma2 = sigma * sigma 
    132132 
    133133        # Compute theory data f(x) 
     
    145145            A = numpy.vstack([ self.data.x[self.idx]/sigma, 
    146146                               numpy.ones(len(self.data.x[self.idx]))/sigma]).T 
    147      
     147            
    148148            a, b = numpy.linalg.lstsq(A, fx)[0] 
    149149            return a, b 
     
    231231                    for power_law will be the power value 
    232232        """ 
    233         fit_x = numpy.array([math.log(x) for x in self._data.x]) 
    234         if function.__name__ == "guinier":         
     233        #fit_x = numpy.array([math.log(x) for x in self._data.x]) 
     234        if function.__name__ == "guinier":    
     235            fit_x = numpy.array([x * x for x in self._data.x])      
    235236            qmin = qmin**2 
    236237            qmax = qmax**2 
     
    240241 
    241242        elif function.__name__ == "power_law": 
     243            fit_x = numpy.array([math.log(x) for x in self._data.x]) 
    242244            qmin = math.log(qmin) 
    243245            qmax = math.log(qmax) 
     
    495497                return math.sqrt(sum) 
    496498    
    497     def _get_qstar_low(self): 
     499    def get_qstar_low(self): 
    498500        """ 
    499501            Compute the invariant for extrapolated data at low q range. 
     
    505507            @return q_star: the invariant for data extrapolated at low q. 
    506508        """ 
    507         data = self._get_extra_data_low() 
     509        data = self.get_extra_data_low() 
    508510        return self._get_qstar(data=data) 
    509511         
    510     def _get_qstar_high(self): 
     512    def get_qstar_high(self): 
    511513        """ 
    512514            Compute the invariant for extrapolated data at high q range. 
     
    518520            @return q_star: the invariant for data extrapolated at high q. 
    519521        """ 
    520         data = self._get_extra_data_high() 
     522        data = self.get_extra_data_high() 
    521523        return self._get_qstar(data=data) 
    522524         
    523     def _get_extra_data_low(self): 
     525    def get_extra_data_low(self): 
    524526        """ 
    525527            This method creates a new data set from the invariant calculator. 
     
    546548        qmin = self._data.x[0] 
    547549        qmax = self._data.x[self._low_extrapolation_npts - 1] 
    548          
    549550        try: 
    550551            # fit the data with a model to get the appropriate parameters 
     
    554555                              power=self._low_extrapolation_power) 
    555556        except: 
     557            #raise 
    556558            return None 
    557559         
     
    583585        return data_min 
    584586           
    585     def _get_extra_data_high(self): 
     587    def get_extra_data_high(self): 
    586588        """ 
    587589            This method creates a new data from the invariant calculator. 
     
    677679                    return qstar_0     
    678680                if extrapolation==low: 
    679                     return qstar_0 + self._get_qstar_low() 
     681                    return qstar_0 + self.get_qstar_low() 
    680682                elif extrapolation==high: 
    681                     return qstar_0 + self._get_qstar_high() 
     683                    return qstar_0 + self.get_qstar_high() 
    682684                elif extrapolation==both: 
    683                     return qstar_0 + self._get_qstar_low() + self._get_qstar_high() 
     685                    return qstar_0 + self.get_qstar_low() + self.get_qstar_high() 
    684686            
    685687            @param extrapolation: string to apply optional extrapolation     
     
    689691            checking that the scale and the background are properly apply to the data 
    690692             
    691             @warning: if error occur self._get_qstar_low() or self._get_qstar_low() 
     693            @warning: if error occur self.get_qstar_low() or self.get_qstar_low() 
    692694            their returned value will be ignored 
    693695        """ 
     
    700702        extrapolation = extrapolation.lower()     
    701703        if extrapolation == "low": 
    702             self._qstar = qstar_0 + self._get_qstar_low() 
     704            self._qstar = qstar_0 + self.get_qstar_low() 
    703705            return self._qstar 
    704706        elif extrapolation == "high": 
    705             self._qstar = qstar_0 + self._get_qstar_high() 
     707            self._qstar = qstar_0 + self.get_qstar_high() 
    706708            return self._qstar 
    707709        elif extrapolation == "both": 
    708             self._qstar = qstar_0 + self._get_qstar_low() + self._get_qstar_high() 
     710            self._qstar = qstar_0 + self.get_qstar_low() + self.get_qstar_high() 
    709711            return self._qstar 
    710712        
     
    723725            @return: specific surface  
    724726        """ 
     727        if contrast is None or porod_const is None: 
     728            return  
    725729        #Check whether we have Q star 
    726730        if self._qstar is None: 
     
    754758            @note: volume fraction must have no unit 
    755759        """ 
     760        if contrast is None: 
     761            return  
    756762        if contrast < 0: 
    757763            raise ValueError, "contrast must be greater than zero"   
     
    812818            @return: V, dV = self.get_volume_fraction_with_error(contrast), dV 
    813819        """ 
     820        if contrast is None: 
     821            return  
    814822        self._qstar, self._qstar_err = self.get_qstar_with_error() 
    815823         
     
    845853            @return S, dS: the surface, with its uncertainty 
    846854        """ 
     855        if contrast is None or porod_const is None: 
     856            return  
    847857        v, dv = self.get_volume_fraction_with_error(contrast) 
    848858        self._qstar, self._qstar_err = self.get_qstar_with_error() 
  • Invariant/test/utest_use_cases.py

    r6e74ee4 r4d270706  
    11""" 
    22   Implementation of the use-case from a usage perspective.  
    3    TODO: check the return values to perform actual unit testing. 
     3   
    44""" 
    55import unittest 
     
    88from sans.invariant import invariant 
    99_ERR_SURFACE = 0.3 
     10 
    1011class Data1D: 
    1112    print "I am not of type Dataloader.Data1D" 
Note: See TracChangeset for help on using the changeset viewer.