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

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 f39511b was 2d107b8, checked in by Gervaise Alina <gervyh@…>, 16 years ago

small changes circular averaging

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