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

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 c5e0d84 was b3e8629, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Initial changes to make SasView? run with python3

  • Property mode set to 100755
File size: 8.9 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 math
7from .BaseInteractor import BaseInteractor
8
9class SectorInteractor(BaseInteractor):
10    """
11    Select an annulus through a 2D plot
12    """
13    def __init__(self, base, axes, color='black', zorder=3):
14        """
15        """
16        BaseInteractor.__init__(self, base, axes, color=color)
17        self.markers = []
18        self.axes = axes
19        self.qmax = self.base.data2D.xmax
20        self.connect = self.base.connect
21
22        # # Number of points on the plot
23        self.nbins = 20
24        theta1 = 2 * math.pi / 3
25        theta2 = -2 * math.pi / 3
26
27        # Inner circle
28        from .Arc import ArcInteractor
29        self.inner_circle = ArcInteractor(self, self.base.subplot,
30                                          zorder=zorder,
31                                          r=self.qmax / 2.0,
32                                          theta1=theta1,
33                                          theta2=theta2)
34        self.inner_circle.qmax = self.qmax
35        self.outer_circle = ArcInteractor(self, self.base.subplot,
36                                          zorder=zorder + 1,
37                                          r=self.qmax / 1.8,
38                                          theta1=theta1,
39                                          theta2=theta2)
40        self.outer_circle.qmax = self.qmax * 1.2
41        # self.outer_circle.set_cursor(self.base.qmax/1.8, 0)
42        from Edge import RadiusInteractor
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        # print "phimin, phimax, rmin ,rmax",math.degrees(phimin),
135        # math.degrees(phimax), rmin ,rmax
136        # from sas.sascalc.dataloader.manipulations import SectorQ
137
138        sect = new_sector(r_min=rmin, r_max=rmax,
139                          phi_min=phimin, phi_max=phimax)
140        sector = sect(self.base.data2D)
141
142        from sas.sasgui.guiframe.dataFitting import Data1D
143        if hasattr(sector, "dxl"):
144            dxl = sector.dxl
145        else:
146            dxl = None
147        if hasattr(sector, "dxw"):
148            dxw = sector.dxw
149        else:
150            dxw = None
151        new_plot = Data1D(x=sector.x, y=sector.y, dy=sector.dy,
152                          dxl=dxl, dxw=dxw)
153        new_plot.name = str(new_sector.__name__) + \
154                        "(" + self.base.data2D.name + ")"
155        new_plot.source = self.base.data2D.source
156        new_plot.interactive = True
157        # print "loader output.detector",output.source
158        new_plot.detector = self.base.data2D.detector
159        # If the data file does not tell us what the axes are, just assume...
160        new_plot.xaxis("\\rm{Q}", 'rad')
161        new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}")
162        new_plot.group_id = str(new_sector.__name__) + self.base.data2D.name
163
164    def validate(self, param_name, param_value):
165        """
166        Test the proposed new value "value" for row "row" of parameters
167        """
168        # Here, always return true
169        return True
170
171    def moveend(self, ev):
172        #TODO: why is this empty?
173        pass
174
175    def restore(self):
176        """
177        Restore the roughness for this layer.
178        """
179        self.inner_circle.restore()
180        self.outer_circle.restore()
181        self.right_edge.restore()
182        self.left_edge.restore()
183
184    def move(self, x, y, ev):
185        """
186        Process move to a new position, making sure that the move is allowed.
187        """
188        pass
189
190    def set_cursor(self, x, y):
191        """
192        """
193        pass
194
195    def get_params(self):
196        """
197        """
198        params = {}
199        params["r_min"] = self.inner_circle.get_radius()
200        params["r_max"] = self.outer_circle.get_radius()
201        params["phi_min"] = self.right_edge.get_angle()
202        params["phi_max"] = self.left_edge.get_angle()
203        params["nbins"] = self.nbins
204        return params
205
206    def set_params(self, params):
207        """
208        """
209        # print "setparams on main slicer ",params
210        inner = params["r_min"]
211        outer = params["r_max"]
212        phi_min = params["phi_min"]
213        phi_max = params["phi_max"]
214        self.nbins = int(params["nbins"])
215
216        self.inner_circle.set_cursor(inner, phi_min, phi_max, self.nbins)
217        self.outer_circle.set_cursor(outer, phi_min, phi_max, self.nbins)
218        self.right_edge.set_cursor(inner, outer, phi_min)
219        self.left_edge.set_cursor(inner, outer, phi_max)
220        self._post_data()
221
222    def freeze_axes(self):
223        """
224        """
225        self.base.freeze_axes()
226
227    def thaw_axes(self):
228        """
229        """
230        self.base.thaw_axes()
231
232    def draw(self):
233        """
234        """
235        self.base.draw()
236
237class SectorInteractorQ(SectorInteractor):
238    """
239    """
240    def __init__(self, base, axes, color='black', zorder=3):
241        """
242        """
243        SectorInteractor.__init__(self, base, axes, color=color)
244        self.base = base
245        self._post_data()
246
247    def _post_data(self):
248        """
249        """
250        from sas.sascalc.dataloader.manipulations import SectorQ
251        self.post_data(SectorQ)
252
253
254class SectorInteractorPhi(SectorInteractor):
255    """
256    """
257    def __init__(self, base, axes, color='black', zorder=3):
258        """
259        """
260        SectorInteractor.__init__(self, base, axes, color=color)
261        self.base = base
262        self._post_data()
263
264    def _post_data(self):
265        """
266        """
267        from sas.sascalc.dataloader.manipulations import SectorPhi
268        self.post_data(SectorPhi)
269
Note: See TracBrowser for help on using the repository browser.