source: sasview/sansguiframe/src/sans/guiframe/local_perspectives/plotting/boxMask.py @ b07ffca

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

fixing pylint warnings

  • Property mode set to 100644
File size: 9.5 KB
RevLine 
[c5874f2]1
2
3
4import math
[32c0841]5#import wx
6#from copy import deepcopy
[c5874f2]7from BaseInteractor import _BaseInteractor
[32c0841]8from boxSum import PointInteractor
9from boxSum import VerticalDoubleLine
10from boxSum import HorizontalDoubleLine
[55a0dc1]11#from sans.guiframe.events import SlicerParamUpdateEvent
[c5874f2]12
13
14class BoxMask(_BaseInteractor):
15    """
[83f4445]16    BoxMask Class: determine 2 rectangular area to find the pixel of
17    a Data inside of box.
18   
19    Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine.
20   
21    :param zorder:  Artists with lower zorder values are drawn first.
22    :param x_min: the minimum value of the x coordinate
23    :param x_max: the maximum value of the x coordinate
24    :param y_min: the minimum value of the y coordinate
25    :param y_max: the maximum value of the y coordinate
[c5874f2]26
27    """
[32c0841]28    def __init__(self, base, axes, color='black', zorder=3, side=None, 
[c5874f2]29                   x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025):
[32c0841]30        """
31        """
[c5874f2]32        _BaseInteractor.__init__(self, base, axes, color=color)
33        ## class initialization
34        ## list of Boxmask markers
35        self.markers = []
36        self.axes = axes
[3fc01c5]37        self.mask = None
[c5874f2]38        self.is_inside = side
39        ## connect the artist for the motion
40        self.connect = self.base.connect
[32c0841]41        ## when qmax is reached the selected line is reset
42        #the its previous value
[c5874f2]43        self.qmax = min(self.base.data.xmax, self.base.data.xmin)
44        ## Define the box limits
[32c0841]45        self.xmin = -1 * 0.5 * min(math.fabs(self.base.data.xmax),
46                                 math.fabs(self.base.data.xmin))
47        self.ymin = -1 * 0.5 * min(math.fabs(self.base.data.xmax),
48                                   math.fabs(self.base.data.xmin))
49        self.xmax = 0.5 * min(math.fabs(self.base.data.xmax),
50                              math.fabs(self.base.data.xmin))
51        self.ymax =  0.5 * min(math.fabs(self.base.data.xmax),
52                               math.fabs(self.base.data.xmin))
[c5874f2]53        ## center of the box
[32c0841]54        self.center_x = 0.0002
55        self.center_y = 0.0003
[c5874f2]56        ## Number of points on the plot
57        self.nbins = 20
58        ## Define initial result the summation
[32c0841]59        self.count = 0
60        self.error = 0
[c5874f2]61        self.data = self.base.data
62        ## Flag to determine if the current figure has moved
63        ## set to False == no motion , set to True== motion
[32c0841]64        self.has_move = False
[c5874f2]65        ## Create Box edges
[32c0841]66        self.horizontal_lines = HorizontalDoubleLine(self,
67                                                     self.base.subplot,
68                                                     color='blue',
[c5874f2]69                                                      zorder=zorder,
[32c0841]70                                                      y=self.ymax,
71                                                      x=self.xmax,
72                                                      center_x=self.center_x,
73                                                      center_y=self.center_y)
[c5874f2]74        self.horizontal_lines.qmax = self.qmax
75       
[32c0841]76        self.vertical_lines = VerticalDoubleLine(self,
77                                                self.base.subplot,
78                                                color='grey',
79                                                zorder=zorder,
80                                                y=self.ymax,
81                                                x=self.xmax,
82                                                center_x=self.center_x,
83                                                center_y=self.center_y)
[c5874f2]84        self.vertical_lines.qmax = self.qmax
85       
[32c0841]86        self.center = PointInteractor(self,
87                                      self.base.subplot,color='grey',
88                                    zorder=zorder,
89                                    center_x=self.center_x,
90                                    center_y=self.center_y)
[c5874f2]91        ## Save the name of the slicer panel associate with this slicer
[32c0841]92        self.panel_name = ""   
[c5874f2]93        ## Update and post slicer parameters 
94        self.update()
95        self._post_data()
[32c0841]96   
[c5874f2]97    def clear(self):
98        """
[83f4445]99        Clear the slicer and all connected events related to this slicer
[c5874f2]100        """
101        self.clear_markers()
102        self.horizontal_lines.clear()
103        self.vertical_lines.clear()
104        self.center.clear()
105        self.base.connect.clearall()
106        #self.base.Unbind(EVT_SLICER_PARS)
[83f4445]107   
[c5874f2]108    def update(self):
109        """
[83f4445]110        Respond to changes in the model by recalculating the profiles and
111        resetting the widgets.
[c5874f2]112        """
[32c0841]113        # check if the center point has moved and update the figure accordingly
[c5874f2]114        if self.center.has_move:
115            self.center.update()
[32c0841]116            self.horizontal_lines.update(center=self.center)
117            self.vertical_lines.update(center=self.center)
118        ## check if the horizontal lines have moved and update
119        # the figure accordingly   
[c5874f2]120        if self.horizontal_lines.has_move:
121            self.horizontal_lines.update()
122            self.vertical_lines.update(y1=self.horizontal_lines.y1,
123                                       y2=self.horizontal_lines.y2,
[32c0841]124                                       height=self.horizontal_lines.half_height)
125        ## check if the vertical lines have moved and update
126        # the figure accordingly   
[c5874f2]127        if self.vertical_lines.has_move:
128            self.vertical_lines.update()
129            self.horizontal_lines.update(x1=self.vertical_lines.x1,
130                                         x2=self.vertical_lines.x2,
131                                         width=self.vertical_lines.half_width)
132        #if self.is_inside != None:
133        out = self._post_data()
134        return out
135       
136    def save(self, ev):
137        """
138        Remember the roughness for this layer and the next so that we
139        can restore on Esc.
140        """
141        self.base.freeze_axes()
142        self.horizontal_lines.save(ev)
143        self.vertical_lines.save(ev)
144        self.center.save(ev)
145       
146    def _post_data(self):
147        """
[83f4445]148        Get the limits of the boxsum and compute the sum of the pixel
149        contained in that region and the error on that sum
[c5874f2]150        """
[db7a82e]151        from sans.dataloader.manipulations import Boxcut
[c5874f2]152        ## Data 2D for which the pixel will be summed
153        data = self.base.data
154        mask = data.mask
155        ## the region of the summation
[32c0841]156        x_min = self.horizontal_lines.x2
157        x_max = self.horizontal_lines.x1
158        y_min = self.vertical_lines.y2
159        y_max = self.vertical_lines.y1
[c5874f2]160        mask = Boxcut(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max)
161
162        if self.is_inside:
[32c0841]163            out = (mask(data) == False)
[c5874f2]164        else:
165            out = (mask(data))
166        #self.base.data.mask=out
[3fc01c5]167        self.mask = mask
[83f4445]168        return out 
169             
[c5874f2]170    def moveend(self, ev):
171        """
[83f4445]172        After a dragging motion this function is called to compute
173        the error and the sum of pixel of a given data 2D
[c5874f2]174        """
175        self.base.thaw_axes()
176        ## post
177        self._post_data()
178           
179    def restore(self):
180        """
181        Restore the roughness for this layer.
182        """
183        self.horizontal_lines.restore()
184        self.vertical_lines.restore()
185        self.center.restore()
186       
187    def move(self, x, y, ev):
188        """
189        Process move to a new position, making sure that the move is allowed.
190        """
191        pass
192   
193    def set_cursor(self, x, y):
194        pass
195       
196    def get_params(self):
197        """
[83f4445]198        Store a copy of values of parameters of the slicer into a dictionary.
199       
200        :return params: the dictionary created
201       
[c5874f2]202        """
203        params = {}
[32c0841]204        params["Width"] = math.fabs(self.vertical_lines.half_width) * 2
205        params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 
[c5874f2]206        params["center_x"] = self.center.x
[32c0841]207        params["center_y"] = self.center.y
[c5874f2]208        return params
209   
210    def get_mask(self):
211        """
[83f4445]212        return mask as a result of boxcut
[c5874f2]213        """
214        mask = self.mask
215        return mask
216   
217    def set_params(self, params):
218        """
[83f4445]219        Receive a dictionary and reset the slicer with values contained
220        in the values of the dictionary.
221       
222        :param params: a dictionary containing name of slicer parameters and
223           values the user assigned to the slicer.
[c5874f2]224        """
225        x_max = math.fabs(params["Width"] )/2
[32c0841]226        y_max = math.fabs(params["Height"])/2
[c5874f2]227       
[32c0841]228        self.center_x = params["center_x"] 
229        self.center_y = params["center_y"]
[c5874f2]230        #update the slicer given values of params
[32c0841]231        self.center.update(center_x=self.center_x, center_y=self.center_y)
232        self.horizontal_lines.update(center=self.center,
[c5874f2]233                                     width=x_max,
234                                     height=y_max)
[32c0841]235        self.vertical_lines.update(center=self.center,
[c5874f2]236                                    width=x_max,
237                                    height=y_max)
238        #compute the new error and sum given values of params
239        self._post_data()
240               
241    def freeze_axes(self):
242        self.base.freeze_axes()
243       
244    def thaw_axes(self):
245        self.base.thaw_axes()
246
247    def draw(self):
248        self.base.update()
249
250class inner_BoxMask(BoxMask):   
251    def __call__(self):     
[32c0841]252        self.base.data.mask = (self._post_data()==False)
253     
254   
Note: See TracBrowser for help on using the repository browser.