source: sasview/sansguiframe/src/sans/guiframe/local_perspectives/plotting/AzimutSlicer.py @ eace08e

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 eace08e was eace08e, checked in by Jae Cho <jhjcho@…>, 12 years ago

fixing pylint warnings

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