Changeset ca2bdae in sasview


Ignore:
Timestamp:
Sep 13, 2011 5:17:52 PM (13 years ago)
Author:
Jae Cho <jhjcho@…>
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:
fba201a0
Parents:
05325ec4
Message:

fixed minor inconsistency problem with residuals and chi2 between compute and fit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fittingview/src/sans/perspectives/fitting/fitting.py

    rcfcb7197 rca2bdae  
    14981498        instead of calling expansive CalcChisqr in guithread 
    14991499        """ 
    1500         data = deepcopy(data) 
     1500        data_copy = deepcopy(data) 
    15011501         
    15021502        # default chisqr 
     
    15041504        #to compute chisq make sure data has valid data 
    15051505        # return None if data == None 
    1506         if not check_data_validity(data): 
     1506        if not check_data_validity(data_copy): 
    15071507            return chisqr 
    15081508         
    15091509        # Get data: data I, theory I, and data dI in order 
    1510         if data.__class__.__name__ == "Data2D": 
     1510        if data_copy.__class__.__name__ == "Data2D": 
    15111511            if index == None:  
    1512                 index = numpy.ones(len(data.data),ntype=bool) 
     1512                index = numpy.ones(len(data_copy.data),ntype=bool) 
    15131513            if self.weight != None: 
    1514                 data.err_data = self.weight 
     1514                data_copy.err_data = self.weight 
    15151515            # get rid of zero error points 
    1516             index = index & (data.err_data != 0)   
    1517             index = index & (numpy.isfinite(data.data))  
    1518             fn = data.data[index]  
    1519             theory_data = self.page_finder[page_id].get_theory_data(fid=data.id) 
     1516            index = index & (data_copy.err_data != 0)   
     1517            index = index & (numpy.isfinite(data_copy.data))  
     1518            fn = data_copy.data[index]  
     1519            theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 
    15201520            gn = theory_data.data[index] 
    1521             en = data.err_data[index] 
     1521            en = data_copy.err_data[index] 
    15221522        else: 
    15231523            # 1 d theory from model_thread is only in the range of index 
    15241524            if index == None:  
    1525                 index = numpy.ones(len(data.y), ntype=bool) 
     1525                index = numpy.ones(len(data_copy.y), ntype=bool) 
    15261526            if self.weight != None: 
    1527                 data.dy = self.weight 
    1528             if data.dy == None or data.dy == []: 
    1529                 dy = numpy.ones(len(data.y)) 
     1527                data_copy.dy = self.weight 
     1528            if data_copy.dy == None or data_copy.dy == []: 
     1529                dy = numpy.ones(len(data_copy.y)) 
    15301530            else: 
    15311531                ## Set consitently w/AbstractFitengine: 
    15321532                # But this should be corrected later. 
    1533                 dy = deepcopy(data.dy) 
     1533                dy = deepcopy(data_copy.dy) 
    15341534                dy[dy==0] = 1   
    1535             fn = data.y[index]  
    1536             theory_data = self.page_finder[page_id].get_theory_data(fid=data.id) 
     1535            fn = data_copy.y[index]  
     1536            theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 
    15371537            gn = theory_data.y 
    15381538            en = dy[index] 
     
    15421542        # get chisqr only w/finite 
    15431543        chisqr = numpy.average(residuals * residuals) 
    1544         self._plot_residuals(page_id, data, index) 
    1545         #reset weight 
    1546         self.weight = None 
     1544        self._plot_residuals(page_id, data_copy, index) 
     1545         
    15471546        return chisqr 
    15481547     
     
    15551554        : Note: this is different from the residuals in cal_chisqr() 
    15561555        """ 
     1556        data_copy = deepcopy(data) 
    15571557        # Get data: data I, theory I, and data dI in order 
    1558         if data.__class__.__name__ == "Data2D": 
     1558        if data_copy.__class__.__name__ == "Data2D": 
    15591559            # build residuals 
    15601560            residuals = Data2D() 
    15611561            #residuals.copy_from_datainfo(data) 
    15621562            # Not for trunk the line below, instead use the line above 
    1563             data.clone_without_data(len(data.data), residuals) 
     1563            data_copy.clone_without_data(len(data_copy.data), residuals) 
    15641564            residuals.data = None 
    1565             fn = data.data#[index]  
    1566             theory_data = self.page_finder[page_id].get_theory_data(fid=data.id) 
     1565            fn = data_copy.data#[index]  
     1566            theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 
    15671567            gn = theory_data.data#[index] 
    1568             en = data.err_data#[index] 
     1568            en = self.weight#data_copy.err_data#[index] 
    15691569            residuals.data = (fn - gn) / en  
    1570             residuals.qx_data = data.qx_data#[index] 
    1571             residuals.qy_data = data.qy_data #[index] 
    1572             residuals.q_data = data.q_data#[index] 
     1570            residuals.qx_data = data_copy.qx_data#[index] 
     1571            residuals.qy_data = data_copy.qy_data #[index] 
     1572            residuals.q_data = data_copy.q_data#[index] 
    15731573            residuals.err_data = numpy.ones(len(residuals.data))#[index] 
    15741574            residuals.xmin = min(residuals.qx_data) 
     
    15761576            residuals.ymin = min(residuals.qy_data) 
    15771577            residuals.ymax = max(residuals.qy_data) 
    1578             residuals.q_data = data.q_data#[index] 
    1579             residuals.mask = data.mask 
     1578            residuals.q_data = data_copy.q_data#[index] 
     1579            residuals.mask = data_copy.mask 
    15801580            residuals.scale = 'linear' 
    15811581            # check the lengths 
     
    15841584        else: 
    15851585            # 1 d theory from model_thread is only in the range of index 
    1586             if data.dy == None or data.dy == []: 
    1587                 dy = numpy.ones(len(data.y)) 
     1586            if data_copy.dy == None or data_copy.dy == []: 
     1587                dy = numpy.ones(len(data_copy.y)) 
    15881588            else: 
    15891589                ## Set consitently w/AbstractFitengine:  
    15901590                ## But this should be corrected later. 
    1591                 dy = deepcopy(data.dy) 
     1591                dy = self.weight#deepcopy(data_copy.dy) 
    15921592                dy[dy==0] = 1   
    1593             fn = data.y[index]  
    1594             theory_data = self.page_finder[page_id].get_theory_data(fid=data.id) 
     1593            fn = data_copy.y[index]  
     1594            theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 
    15951595            gn = theory_data.y 
    15961596            en = dy[index] 
     
    15981598            residuals = Data1D() 
    15991599            residuals.y = (fn - gn) / en 
    1600             residuals.x = data.x[index] 
     1600            residuals.x = data_copy.x[index] 
    16011601            residuals.dy = numpy.ones(len(residuals.y)) 
    16021602            residuals.dx = None 
     
    16201620         
    16211621        # plot data 
    1622         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title))    
    1623          
     1622        wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title))  
     1623        #reset weight   
     1624        self.weight = None 
    16241625#def profile(fn, *args, **kw): 
    16251626#    import cProfile, pstats, os 
Note: See TracChangeset for help on using the changeset viewer.