source: sasview/src/sas/qtgui/Plotting/Slicers/AzimutSlicer.py @ b1a7a81

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since b1a7a81 was e20870bc, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Masking dialog for fitting

  • Property mode set to 100644
File size: 8.8 KB
Line 
1# TODO: the line slicer should listen to all 2DREFRESH events, get the data and slice it
2#       before pushing a new 1D data update.
3#
4# TODO: NEED MAJOR REFACTOR
5#
6import numpy as np
7from sas.qtgui.Plotting.Slicers.Arc import ArcInteractor
8from sas.qtgui.Plotting.Slicers.RadiusInteractor import RadiusInteractor
9from sas.qtgui.Plotting.Slicers.BaseInteractor import BaseInteractor
10
11class SectorInteractor(BaseInteractor):
12    """
13    Select an annulus through a 2D plot
14    """
15    def __init__(self, base, axes, color='black', zorder=3):
16        """
17        """
18        BaseInteractor.__init__(self, base, axes, color=color)
19        self.markers = []
20        self.axes = axes
21        self.qmax = self.base.data2D.xmax
22        self.connect = self.base.connect
23
24        # # Number of points on the plot
25        self.nbins = 20
26        theta1 = 2 * np.pi / 3
27        theta2 = -2 * np.pi / 3
28
29        # Inner circle
30        self.inner_circle = ArcInteractor(self, self.base.subplot,
31                                          zorder=zorder,
32                                          r=self.qmax / 2.0,
33                                          theta1=theta1,
34                                          theta2=theta2)
35        self.inner_circle.qmax = self.qmax
36        self.outer_circle = ArcInteractor(self, self.base.subplot,
37                                          zorder=zorder + 1,
38                                          r=self.qmax / 1.8,
39                                          theta1=theta1,
40                                          theta2=theta2)
41        self.outer_circle.qmax = self.qmax * 1.2
42        # self.outer_circle.set_cursor(self.base.qmax/1.8, 0)
43        self.right_edge = RadiusInteractor(self, self.base.subplot,
44                                           zorder=zorder + 1,
45                                           arc1=self.inner_circle,
46                                           arc2=self.outer_circle,
47                                           theta=theta1)
48        self.left_edge = RadiusInteractor(self, self.base.subplot,
49                                          zorder=zorder + 1,
50                                          arc1=self.inner_circle,
51                                          arc2=self.outer_circle,
52                                          theta=theta2)
53        self.update()
54        self._post_data()
55
56    def set_layer(self, n):
57        """
58        """
59        self.layernum = n
60        self.update()
61
62    def clear(self):
63        """
64        """
65        self.clear_markers()
66        self.outer_circle.clear()
67        self.inner_circle.clear()
68        self.right_edge.clear()
69        self.left_edge.clear()
70
71    def update(self):
72        """
73        Respond to changes in the model by recalculating the profiles and
74        resetting the widgets.
75        """
76        # Update locations
77        if self.inner_circle.has_move:
78            # print "inner circle has moved"
79            self.inner_circle.update()
80            r1 = self.inner_circle.get_radius()
81            r2 = self.outer_circle.get_radius()
82            self.right_edge.update(r1, r2)
83            self.left_edge.update(r1, r2)
84        if self.outer_circle.has_move:
85            # print "outer circle has moved"
86            self.outer_circle.update()
87            r1 = self.inner_circle.get_radius()
88            r2 = self.outer_circle.get_radius()
89            self.left_edge.update(r1, r2)
90            self.right_edge.update(r1, r2)
91        if self.right_edge.has_move:
92            # print "right edge has moved"
93            self.right_edge.update()
94            self.inner_circle.update(theta1=self.right_edge.get_angle(),
95                                     theta2=None)
96            self.outer_circle.update(theta1=self.right_edge.get_angle(),
97                                     theta2=None)
98        if  self.left_edge.has_move:
99            # print "left Edge has moved"
100            self.left_edge.update()
101            self.inner_circle.update(theta1=None,
102                                     theta2=self.left_edge.get_angle())
103            self.outer_circle.update(theta1=None,
104                                     theta2=self.left_edge.get_angle())
105
106    def save(self, ev):
107        """
108        Remember the roughness for this layer and the next so that we
109        can restore on Esc.
110        """
111        self.base.freeze_axes()
112        self.inner_circle.save(ev)
113        self.outer_circle.save(ev)
114        self.right_edge.save(ev)
115        self.left_edge.save(ev)
116
117    def _post_data(self):
118        pass
119
120    def post_data(self, new_sector):
121        """ post data averaging in Q"""
122        if self.inner_circle.get_radius() < self.outer_circle.get_radius():
123            rmin = self.inner_circle.get_radius()
124            rmax = self.outer_circle.get_radius()
125        else:
126            rmin = self.outer_circle.get_radius()
127            rmax = self.inner_circle.get_radius()
128        if self.right_edge.get_angle() < self.left_edge.get_angle():
129            phimin = self.right_edge.get_angle()
130            phimax = self.left_edge.get_angle()
131        else:
132            phimin = self.left_edge.get_angle()
133            phimax = self.right_edge.get_angle()
134
135        sect = new_sector(r_min=rmin, r_max=rmax,
136                          phi_min=phimin, phi_max=phimax)
137        sector = sect(self.base.data2D)
138
139        from sas.sasgui.guiframe.dataFitting import Data1D
140        if hasattr(sector, "dxl"):
141            dxl = sector.dxl
142        else:
143            dxl = None
144        if hasattr(sector, "dxw"):
145            dxw = sector.dxw
146        else:
147            dxw = None
148        new_plot = Data1D(x=sector.x, y=sector.y, dy=sector.dy,
149                          dxl=dxl, dxw=dxw)
150        new_plot.name = str(new_sector.__name__) + \
151                        "(" + self.base.data2D.name + ")"
152        new_plot.source = self.base.data2D.source
153        new_plot.interactive = True
154        # print "loader output.detector",output.source
155        new_plot.detector = self.base.data2D.detector
156        # If the data file does not tell us what the axes are, just assume...
157        new_plot.xaxis("\\rm{Q}", 'rad')
158        new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}")
159        new_plot.group_id = str(new_sector.__name__) + self.base.data2D.name
160
161    def validate(self, param_name, param_value):
162        """
163        Test the proposed new value "value" for row "row" of parameters
164        """
165        # Here, always return true
166        return True
167
168    def moveend(self, ev):
169        #TODO: why is this empty?
170        pass
171
172    def restore(self):
173        """
174        Restore the roughness for this layer.
175        """
176        self.inner_circle.restore()
177        self.outer_circle.restore()
178        self.right_edge.restore()
179        self.left_edge.restore()
180
181    def move(self, x, y, ev):
182        """
183        Process move to a new position, making sure that the move is allowed.
184        """
185        pass
186
187    def set_cursor(self, x, y):
188        """
189        """
190        pass
191
192    def get_params(self):
193        """
194        """
195        params = {}
196        params["r_min"] = self.inner_circle.get_radius()
197        params["r_max"] = self.outer_circle.get_radius()
198        params["phi_min"] = self.right_edge.get_angle()
199        params["phi_max"] = self.left_edge.get_angle()
200        params["nbins"] = self.nbins
201        return params
202
203    def set_params(self, params):
204        """
205        """
206        # print "setparams on main slicer ",params
207        inner = params["r_min"]
208        outer = params["r_max"]
209        phi_min = params["phi_min"]
210        phi_max = params["phi_max"]
211        self.nbins = int(params["nbins"])
212
213        self.inner_circle.set_cursor(inner, phi_min, phi_max, self.nbins)
214        self.outer_circle.set_cursor(outer, phi_min, phi_max, self.nbins)
215        self.right_edge.set_cursor(inner, outer, phi_min)
216        self.left_edge.set_cursor(inner, outer, phi_max)
217        self._post_data()
218
219    def freeze_axes(self):
220        """
221        """
222        self.base.freeze_axes()
223
224    def thaw_axes(self):
225        """
226        """
227        self.base.thaw_axes()
228
229    def draw(self):
230        """
231        """
232        self.base.draw()
233
234class SectorInteractorQ(SectorInteractor):
235    """
236    """
237    def __init__(self, base, axes, color='black', zorder=3):
238        """
239        """
240        SectorInteractor.__init__(self, base, axes, color=color)
241        self.base = base
242        self._post_data()
243
244    def _post_data(self):
245        """
246        """
247        from sas.sascalc.dataloader.manipulations import SectorQ
248        self.post_data(SectorQ)
249
250
251class SectorInteractorPhi(SectorInteractor):
252    """
253    """
254    def __init__(self, base, axes, color='black', zorder=3):
255        """
256        """
257        SectorInteractor.__init__(self, base, axes, color=color)
258        self.base = base
259        self._post_data()
260
261    def _post_data(self):
262        """
263        """
264        from sas.sascalc.dataloader.manipulations import SectorPhi
265        self.post_data(SectorPhi)
266
Note: See TracBrowser for help on using the repository browser.