source: sasview/guiframe/dataFitting.py @ 3e41f43

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 3e41f43 was 32c0841, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on pylint

  • Property mode set to 100644
File size: 8.1 KB
Line 
1"""
2Adapters for fitting module
3"""
4import copy
5import numpy
6import math
7from data_util.uncertainty import Uncertainty
8from danse.common.plottools.plottables import Data1D as PlotData1D
9from danse.common.plottools.plottables import Data2D as PlotData2D
10from danse.common.plottools.plottables import Theory1D as PlotTheory1D
11
12from DataLoader.data_info import Data1D as LoadData1D
13from DataLoader.data_info import Data2D as LoadData2D
14
15class Data1D(PlotData1D, LoadData1D):
16    """
17    """
18    def __init__(self, x=None, y=None, dx=None, dy=None):
19        """
20        """
21        if x is None:
22            x = []
23        if y is None:
24            y = []
25        PlotData1D.__init__(self, x, y, dx, dy)
26        LoadData1D.__init__(self, x, y, dx, dy)
27        self.id = None
28        self.group_id = None
29        self.is_data = True
30   
31    def copy_from_datainfo(self, data1d):
32        """
33        copy values of Data1D of type DataLaoder.Data_info
34        """
35        self.= copy.deepcopy(data1d.x)
36        self.= copy.deepcopy(data1d.y)
37        self.dy = copy.deepcopy(data1d.dy)
38       
39        if hasattr(data1d, "dx"):
40            self.dx = copy.deepcopy(data1d.dx)   
41        if hasattr(data1d, "dxl"):
42            self.dxl = copy.deepcopy(data1d.dxl)
43        if hasattr(data1d, "dxw"):
44            self.dxw = copy.deepcopy(data1d.dxw)
45   
46        self.xaxis(data1d._xaxis, data1d._xunit)
47        self.yaxis(data1d._yaxis, data1d._yunit)
48       
49    def __str__(self):
50        """
51        print data
52        """
53        _str = "%s\n" % LoadData1D.__str__(self)
54     
55        return _str
56   
57    def _perform_operation(self, other, operation):
58        """
59        """
60        # First, check the data compatibility
61        dy, dy_other = self._validity_check(other)
62        result = Data1D(x=[], y=[], dx=None, dy=None)
63        result.clone_without_data(clone=self)
64        result.copy_from_datainfo(data1d=self)
65        for i in range(len(self.x)):
66            result.x[i] = self.x[i]
67            if self.dx is not None and len(self.x) == len(self.dx):
68                result.dx[i] = self.dx[i]
69           
70            a = Uncertainty(self.y[i], dy[i]**2)
71            if isinstance(other, Data1D):
72                b = Uncertainty(other.y[i], dy_other[i]**2)
73            else:
74                b = other
75           
76            output = operation(a, b)
77            result.y[i] = output.x
78            if result.dy is None: result.dy = numpy.zeros(len(self.x))
79            result.dy[i] = math.sqrt(math.fabs(output.variance))
80        return result
81   
82class Theory1D(PlotTheory1D, LoadData1D):
83    """
84    """
85    def __init__(self, x=None, y=None, dy=None):
86        """
87        """
88        if x is None:
89            x = []
90        if y is None:
91            y = []
92        PlotTheory1D.__init__(self, x, y, dy)
93        LoadData1D.__init__(self, x, y, dy)
94        self.id = None
95        self.group_id = None
96        self.is_data = True
97   
98    def copy_from_datainfo(self, data1d):
99        """
100        copy values of Data1D of type DataLaoder.Data_info
101        """
102        self.= copy.deepcopy(data1d.x)
103        self.= copy.deepcopy(data1d.y)
104        self.dy = copy.deepcopy(data1d.dy)
105        if hasattr(data1d, "dx"):
106            self.dx = copy.deepcopy(data1d.dx) 
107        if hasattr(data1d, "dxl"):
108            self.dxl = copy.deepcopy(data1d.dxl)
109        if hasattr(data1d, "dxw"):
110            self.dxw = copy.deepcopy(data1d.dxw)   
111        self.xaxis(data1d._xaxis, data1d._xunit)
112        self.yaxis(data1d._yaxis, data1d._yunit)
113       
114    def __str__(self):
115        """
116        print data
117        """
118        _str = "%s\n" % LoadData1D.__str__(self)
119     
120        return _str
121   
122    def _perform_operation(self, other, operation):
123        """
124        """
125        # First, check the data compatibility
126        dy, dy_other = self._validity_check(other)
127        result = Theory1D(x=[], y=[], dy=None)
128        result.clone_without_data(clone=self)
129        result.copy_from_datainfo(data1d=self)
130        for i in range(len(self.x)):
131            result.x[i] = self.x[i]
132           
133            a = Uncertainty(self.y[i], dy[i]**2)
134            if isinstance(other, Data1D):
135                b = Uncertainty(other.y[i], dy_other[i]**2)
136            else:
137                b = other
138            output = operation(a, b)
139            result.y[i] = output.x
140            if result.dy is None:
141                result.dy = numpy.zeros(len(self.x))
142            result.dy[i] = math.sqrt(math.fabs(output.variance))
143        return result
144   
145     
146class Data2D(PlotData2D, LoadData2D):
147    """
148    """
149    def __init__(self, image=None, err_image=None,
150                 xmin=None, xmax=None, ymin=None, ymax=None,
151                 zmin=None, zmax=None, qx_data=None, qy_data=None,
152                 q_data=None, mask=None, dqx_data=None, dqy_data=None):
153        """
154        """
155        PlotData2D.__init__(self, image=image, err_image=err_image,
156                            xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
157                            zmin=zmin, zmax=zmax, qx_data=qx_data, 
158                            qy_data=qy_data)
159       
160        LoadData2D.__init__(self, data=image, err_data=err_image,
161                            qx_data=qx_data, qy_data=qy_data,
162                            dqx_data=dqx_data, dqy_data=dqy_data,
163                            q_data=q_data, mask=mask)
164       
165    def copy_from_datainfo(self, data2d):
166        """
167        copy value of Data2D of type DataLoader.data_info
168        """
169        self.data = copy.deepcopy(data2d.data)
170        self.qx_data = copy.deepcopy(data2d.qx_data)
171        self.qy_data = copy.deepcopy(data2d.qy_data)
172        self.q_data = copy.deepcopy(data2d.q_data)
173        self.mask = copy.deepcopy(data2d.mask)
174        self.err_data = copy.deepcopy(data2d.err_data)
175        self.x_bins = copy.deepcopy(data2d.x_bins)
176        self.y_bins = copy.deepcopy(data2d.y_bins)
177        if data2d.dqx_data is not None:
178            self.dqx_data = copy.deepcopy(data2d.dqx_data)
179        if data2d.dqy_data is not None:
180            self.dqy_data = copy.deepcopy(data2d.dqy_data)
181        self.xmin = data2d.xmin
182        self.xmax = data2d.xmax
183        self.ymin = data2d.ymin
184        self.ymax = data2d.ymax
185        if hasattr(data2d, "zmin"):
186            self.zmin = data2d.zmin
187        if hasattr(data2d, "zmax"):
188            self.zmax = data2d.zmax
189        self.xaxis(data2d._xaxis, data2d._xunit)
190        self.yaxis(data2d._yaxis, data2d._yunit)
191       
192    def __str__(self):
193        """
194        print data
195        """
196        _str = "%s\n" % LoadData2D.__str__(self)
197        return _str
198   
199    def _perform_operation(self, other, operation):
200        """
201        Perform 2D operations between data sets
202       
203        :param other: other data set
204        :param operation: function defining the operation
205       
206        """
207        # First, check the data compatibility
208        dy, dy_other = self._validity_check(other)
209   
210        result = Data2D(image=None, qx_data=None, qy_data=None,
211                         err_image=None, xmin=None, xmax=None,
212                         ymin=None, ymax=None, zmin=None, zmax=None)
213       
214        result.clone_without_data(clone=self)
215        result.copy_from_datainfo(data2d=self)
216       
217        for i in range(numpy.size(self.data, 0)):
218            for j in range(numpy.size(self.data, 1)):
219                result.data[i][j] = self.data[i][j]
220                if self.err_data is not None and \
221                        numpy.size(self.data) == numpy.size(self.err_data):
222                    result.err_data[i][j] = self.err_data[i][j]
223               
224                a = Uncertainty(self.data[i][j], dy[i][j]**2)
225                if isinstance(other, Data2D):
226                    b = Uncertainty(other.data[i][j], dy_other[i][j]**2)
227                else:
228                    b = other
229                output = operation(a, b)
230                result.data[i][j] = output.x
231                result.err_data[i][j] = math.sqrt(math.fabs(output.variance))
232        return result
233       
Note: See TracBrowser for help on using the repository browser.