source: sasview/guiframe/dataFitting.py @ cbf22e5

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 cbf22e5 was f444b20, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on guiframe loading

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