source: sasview/guiframe/local_perspectives/plotting/sectorMask.py @ 992199e

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 992199e was 32c0841, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on pylint

  • Property mode set to 100644
File size: 7.9 KB
RevLine 
[c5874f2]1
2import math
3import wx
[32c0841]4#from copy import deepcopy
[c5874f2]5from BaseInteractor import _BaseInteractor
[32c0841]6from SectorSlicer import SideInteractor
7from SectorSlicer import LineInteractor
[c5874f2]8from sans.guicomm.events import SlicerParameterEvent
9
10class SectorMask(_BaseInteractor):
11    """
[d955bf19]12    Draw a sector slicer.Allow to find the data 2D inside of the sector lines
[c5874f2]13    """
[32c0841]14    def __init__(self, base, axes, color='gray', zorder=3, side=False):
15        """
16        """
[c5874f2]17        _BaseInteractor.__init__(self, base, axes, color=color)
18        ## Class initialization
19        self.markers = []
20        self.axes = axes   
21        self.is_inside = side
22        ## connect the plot to event
23        self.connect = self.base.connect
24       
25        ## compute qmax limit to reset the graph     
[32c0841]26        x = math.pow(max(self.base.data.xmax, 
27                         math.fabs(self.base.data.xmin)), 2)
28        y = math.pow(max(self.base.data.ymax, 
29                         math.fabs(self.base.data.ymin)), 2)
30        self.qmax = math.sqrt(x + y)
[c5874f2]31        ## Number of points on the plot
32        self.nbins = 20
33        ## Angle of the middle line
[32c0841]34        self.theta2 = math.pi/3
[c5874f2]35        ## Absolute value of the Angle between the middle line and any side line
[32c0841]36        self.phi = math.pi/12
[c5874f2]37       
38        ## Middle line
[32c0841]39        self.main_line = LineInteractor(self, self.base.subplot, color='blue',
40                                zorder=zorder, r=self.qmax, theta=self.theta2)
[c5874f2]41        self.main_line.qmax = self.qmax
42        ## Right Side line
[32c0841]43        self.right_line = SideInteractor(self, self.base.subplot, color='gray',
44                            zorder=zorder, r=self.qmax, phi= -1*self.phi,
45                                                            theta2=self.theta2)
[c5874f2]46        self.right_line.qmax = self.qmax
47        ## Left Side line
[32c0841]48        self.left_line = SideInteractor(self, self.base.subplot, color='gray', 
49                                    zorder=zorder, r=self.qmax, phi= self.phi,
50                                                        theta2=self.theta2)
[c5874f2]51        self.left_line.qmax = self.qmax
52        ## draw the sector               
53        self.update()
54        self._post_data()
55       
56    def clear(self):
57        """
[d955bf19]58        Clear the slicer and all connected events related to this slicer
[c5874f2]59        """
60        self.clear_markers()
61        self.main_line.clear()
62        self.left_line.clear()
63        self.right_line.clear()
64        self.base.connect.clearall()
65        #self.base.Unbind(EVT_SLICER_PARS)
66       
67    def update(self):
68        """
[d955bf19]69        Respond to changes in the model by recalculating the profiles and
70        resetting the widgets.
[c5874f2]71        """
72        # Update locations 
[32c0841]73        ## Check if the middle line was dragged and
74        #update the picture accordingly     
[c5874f2]75        if self.main_line.has_move:
76            self.main_line.update()
[32c0841]77            self.right_line.update(delta=-self.left_line.phi/2,
78                                    mline=self.main_line.theta)
79            self.left_line.update(delta=self.left_line.phi/2,
80                                   mline=self.main_line.theta)
[c5874f2]81        ## Check if the left side has moved and update the slicer accordingly 
82        if self.left_line.has_move:
83            self.main_line.update()
[32c0841]84            self.left_line.update(phi=None, delta=None, mline=self.main_line ,
[c5874f2]85                                  side=True, left=True )
[32c0841]86            self.right_line.update(phi=self.left_line.phi, delta=None,
87                                     mline=self.main_line, side=True,
88                                     left=False, right=True)
89        ## Check if the right side line has moved and
90        #update the slicer accordingly
[c5874f2]91        if self.right_line.has_move:
92            self.main_line.update()
[32c0841]93            self.right_line.update(phi=None, delta=None, mline=self.main_line,
94                                   side=True, left=False, right=True)
95            self.left_line.update(phi=self.right_line.phi, delta=None,
96                                    mline=self.main_line, side=True, left=False)
[c5874f2]97        #if self.is_inside != None:
98        out = self._post_data()
99        return out
100
101    def save(self, ev):
102        """
103        Remember the roughness for this layer and the next so that we
104        can restore on Esc.
105        """
106        self.base.freeze_axes()
107        self.main_line.save(ev)
108        self.right_line.save(ev)
109        self.left_line.save(ev)
110
111    def _post_data(self):
112        """
[d955bf19]113        compute sector averaging of data into data1D
[c5874f2]114        """
115        ## get the data to average
116        data = self.base.data
117        # If we have no data, just return
118        if data == None:
119            return
120
121        mask = data.mask
122        ## Averaging
123        from DataLoader.manipulations import Sectorcut
124        radius = self.qmax
125        phimin =  -self.left_line.phi + self.main_line.theta
126        phimax = self.left_line.phi + self.main_line.theta
127         
[32c0841]128        mask = Sectorcut(phi_min=phimin, phi_max=phimax)
[c5874f2]129        if self.is_inside:
[32c0841]130            out = (mask(data) == False)
[c5874f2]131        else:
132            out = (mask(data))
133        #self.base.data.mask=out
134        return out       
135
136    def moveend(self, ev):
137        """
[d955bf19]138        Called a dragging motion ends.Get slicer event
[c5874f2]139        """
140        self.base.thaw_axes()
141        ## Post parameters
142        event = SlicerParameterEvent()
143        event.type = self.__class__.__name__
144        event.params = self.get_params()
145        ## Send slicer paramers to plotter2D
146        wx.PostEvent(self.base, event)
147        self._post_data()
148           
149    def restore(self):
150        """
151        Restore the roughness for this layer.
152        """
153        self.main_line.restore()
154        self.left_line.restore()
155        self.right_line.restore()
156
157    def move(self, x, y, ev):
158        """
159        Process move to a new position, making sure that the move is allowed.
160        """
161        pass
162       
163    def set_cursor(self, x, y):
164        pass
165       
166    def get_params(self):
167        """
[d955bf19]168        Store a copy of values of parameters of the slicer into a dictionary.
169       
170        :return params: the dictionary created
171       
[c5874f2]172        """
173        params = {}
174        ## Always make sure that the left and the right line are at phi
175        ## angle of the middle line
176        if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi):
[32c0841]177            msg = "Phi left and phi right are "
178            msg += "different %f, %f" % (self.left_line.phi, 
179                                         self.right_line.phi)
180            raise ValueError, msg
[c5874f2]181        params["Phi"] = self.main_line.theta
182        params["Delta_Phi"] = math.fabs(self.left_line.phi)
183        return params
184   
185    def set_params(self, params):
186        """
[d955bf19]187        Receive a dictionary and reset the slicer with values contained
188        in the values of the dictionary.
189       
190        :param params: a dictionary containing name of slicer parameters and
[c5874f2]191            values the user assigned to the slicer.
192        """
193        main = params["Phi"] 
[32c0841]194        phi = math.fabs(params["Delta_Phi"])
[c5874f2]195       
[32c0841]196        self.main_line.theta = main
[c5874f2]197        ## Reset the slicer parameters
198        self.main_line.update()
[32c0841]199        self.right_line.update(phi=phi, delta=None, mline=self.main_line,
200                               side=True, right=True)
201        self.left_line.update(phi=phi, delta=None,
202                              mline=self.main_line, side=True)
[c5874f2]203        ## post the new corresponding data
204        self._post_data()
205       
206    def freeze_axes(self):
[d955bf19]207        """
208        """
[c5874f2]209        self.base.freeze_axes()
210       
211    def thaw_axes(self):
[d955bf19]212        """
213        """
[c5874f2]214        self.base.thaw_axes()
215
216    def draw(self):
[d955bf19]217        """
218        """
[c5874f2]219        self.base.update()
220       
Note: See TracBrowser for help on using the repository browser.