Changeset 901142f in sasview


Ignore:
Timestamp:
Apr 23, 2010 8:06:21 AM (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:
18d0bba
Parents:
8569cb9
Message:

make sur the datafitting data are working like data_info data

Location:
guiframe
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • guiframe/dataFitting.py

    r8e87ece r901142f  
    44import copy 
    55import numpy 
    6  
     6import math 
     7from data_util.uncertainty import Uncertainty 
    78from danse.common.plottools.plottables import Data1D as PlotData1D 
    89from danse.common.plottools.plottables import Data2D as PlotData2D 
     
    1718        PlotData1D.__init__(self, x, y, dx, dy) 
    1819        LoadData1D.__init__(self, x, y, dx, dy) 
    19         self.id= None 
    20         self.group_id =None 
     20        self.id = None 
     21        self.group_id = None 
    2122        self.is_data = True 
    2223     
     
    3637            self.dxw = copy.deepcopy(data1d.dxw) 
    3738     
    38         self.xaxis(data1d._xaxis,data1d._xunit) 
    39         self.yaxis(data1d._yaxis,data1d._yunit) 
     39        self.xaxis(data1d._xaxis, data1d._xunit) 
     40        self.yaxis(data1d._yaxis, data1d._yunit) 
    4041         
    4142    def __str__(self): 
     
    4647       
    4748        return _str  
     49     
     50    def _perform_operation(self, other, operation): 
     51        """ 
     52        """ 
     53        # First, check the data compatibility 
     54        dy, dy_other = self._validity_check(other) 
     55        result = Data1D(x=[], y=[], dx=None, dy=None) 
     56        result.clone_without_data(clone=self) 
     57        result.copy_from_datainfo(data1d=self) 
     58        for i in range(len(self.x)): 
     59            result.x[i] = self.x[i] 
     60            if self.dx is not None and len(self.x) == len(self.dx): 
     61                result.dx[i] = self.dx[i] 
     62             
     63            a = Uncertainty(self.y[i], dy[i]**2) 
     64            if isinstance(other, Data1D): 
     65                b = Uncertainty(other.y[i], dy_other[i]**2) 
     66            else: 
     67                b = other 
     68             
     69            output = operation(a, b) 
     70            result.y[i] = output.x 
     71            if result.dy is None: result.dy = numpy.zeros(len(self.x)) 
     72            result.dy[i] = math.sqrt(math.fabs(output.variance)) 
     73        return result 
     74     
    4875class Theory1D(PlotTheory1D,LoadData1D): 
    4976     
    50     def __init__(self,x=[],y=[],dy=None): 
     77    def __init__(self, x=[], y=[], dy=None): 
    5178        PlotTheory1D.__init__(self, x, y, dy) 
    5279        LoadData1D.__init__(self, x, y, dy) 
    53         self.id= None 
     80        self.id = None 
    5481        self.group_id = None 
    5582        self.is_data = True 
     
    6895        if hasattr(data1d, "dxw"): 
    6996            self.dxw = copy.deepcopy(data1d.dxw)     
    70         self.xaxis(data1d._xaxis,data1d._xunit) 
    71         self.yaxis(data1d._yaxis,data1d._yunit) 
     97        self.xaxis(data1d._xaxis, data1d._xunit) 
     98        self.yaxis(data1d._yaxis, data1d._yunit) 
    7299         
    73100    def __str__(self): 
     
    78105       
    79106        return _str  
     107     
     108    def _perform_operation(self, other, operation): 
     109        """ 
     110        """ 
     111        # First, check the data compatibility 
     112        dy, dy_other = self._validity_check(other) 
     113        result = Theory1D(x=[], y=[], dy=None) 
     114        result.clone_without_data(clone=self) 
     115        result.copy_from_datainfo(data1d=self) 
     116        for i in range(len(self.x)): 
     117            result.x[i] = self.x[i] 
     118            
     119            a = Uncertainty(self.y[i], dy[i]**2) 
     120            if isinstance(other, Data1D): 
     121                b = Uncertainty(other.y[i], dy_other[i]**2) 
     122            else: 
     123                b = other 
     124             
     125            output = operation(a, b) 
     126            result.y[i] = output.x 
     127            if result.dy is None: result.dy = numpy.zeros(len(self.x)) 
     128            result.dy[i] = math.sqrt(math.fabs(output.variance)) 
     129        return result 
     130     
    80131       
    81132class Data2D(PlotData2D,LoadData2D): 
    82     def __init__(self,image=None,err_image=None,xmin=None,xmax=None,ymin=None,ymax=None,zmin=None,zmax=None): 
    83          
    84         PlotData2D.__init__(self, image=image, err_image=err_image,xmin=xmin, xmax=xmax, 
    85                             ymin=ymin, ymax=ymax) 
    86          
    87         LoadData2D.__init__(self,data=image, err_data=err_image, qx_data=None,qy_data=None,q_data=None,mask=None) 
     133    def __init__(self, image=None, err_image=None, 
     134                 xmin=None, xmax=None, ymin=None, ymax=None, 
     135                 zmin=None, zmax=None, qx_data=None, qy_data=None, 
     136                 q_data=None, mask=None, dqx_data=None, dqy_data=None): 
     137         
     138        PlotData2D.__init__(self, image=image, err_image=err_image, 
     139                            xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, 
     140                            zmin=zmin, zmax=zmax, qx_data=qx_data,  
     141                            qy_data=qy_data) 
     142         
     143        LoadData2D.__init__(self, data=image, err_data=err_image, 
     144                            qx_data=qx_data, qy_data=qy_data, 
     145                            dqx_data=dqx_data, dqy_data=dqy_data, 
     146                            q_data=q_data, mask=mask) 
    88147         
    89148    def copy_from_datainfo(self, data2d): 
     
    92151        """ 
    93152        self.data     =  copy.deepcopy(data2d.data) 
    94         self.qx_data     =  copy.deepcopy(data2d.qx_data) 
    95         self.qy_data     =  copy.deepcopy(data2d.qy_data) 
    96         self.q_data     =  copy.deepcopy(data2d.q_data) 
     153        self.qx_data  =  copy.deepcopy(data2d.qx_data) 
     154        self.qy_data  =  copy.deepcopy(data2d.qy_data) 
     155        self.q_data    =  copy.deepcopy(data2d.q_data) 
    97156        self.mask     =  copy.deepcopy(data2d.mask) 
    98157        self.err_data =  copy.deepcopy(data2d.err_data) 
     
    104163        self.ymin       = data2d.ymin 
    105164        self.ymax       = data2d.ymax 
    106          
    107         self.xaxis(data2d._xaxis,data2d._xunit) 
    108         self.yaxis(data2d._yaxis,data2d._yunit) 
     165        self.zmin       = data2d.zmin 
     166        self.zmax       = data2d.zmax 
     167         
     168        self.xaxis(data2d._xaxis, data2d._xunit) 
     169        self.yaxis(data2d._yaxis, data2d._yunit) 
    109170         
    110171    def __str__(self): 
     
    115176       
    116177        return _str  
    117          
     178     
     179    def _perform_operation(self, other, operation): 
     180        """ 
     181            Perform 2D operations between data sets 
     182             
     183            @param other: other data set 
     184            @param operation: function defining the operation 
     185        """ 
     186        # First, check the data compatibility 
     187        dy, dy_other = self._validity_check(other) 
     188     
     189        result = Data2D(image=None, qx_data=None, qy_data=None, 
     190                         err_image=None, xmin=None, xmax=None, 
     191                         ymin=None, ymax=None, zmin=None, zmax=None) 
     192         
     193        result.clone_without_data(clone=self) 
     194        result.copy_from_datainfo(data2d=self) 
     195         
     196        for i in range(numpy.size(self.data,0)): 
     197            for j in range(numpy.size(self.data,1)): 
     198                result.data[i][j] = self.data[i][j] 
     199                if self.err_data is not None and \ 
     200                        numpy.size(self.data)==numpy.size(self.err_data): 
     201                    result.err_data[i][j] = self.err_data[i][j] 
     202                 
     203                a = Uncertainty(self.data[i][j], dy[i][j]**2) 
     204                if isinstance(other, Data2D): 
     205                    b = Uncertainty(other.data[i][j], dy_other[i][j]**2) 
     206                else: 
     207                    b = other 
     208                 
     209                output = operation(a, b) 
     210                result.data[i][j] = output.x 
     211                result.err_data[i][j] = math.sqrt(math.fabs(output.variance)) 
     212        return result 
     213         
Note: See TracChangeset for help on using the changeset viewer.