source: sasview/guiframe/local_perspectives/plotting/SectorSlicer.py @ b98db8c

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

comment added

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