Changeset b5de88e in sasview for src/sas/guiframe/local_perspectives/plotting/boxMask.py
- Timestamp:
- Mar 5, 2015 2:49:03 PM (9 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 7d56795
- Parents:
- 824e488
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/local_perspectives/plotting/boxMask.py
r79492222 rb5de88e 1 2 3 4 1 import math 5 #import wx6 #from copy import deepcopy7 2 from BaseInteractor import _BaseInteractor 8 3 from boxSum import PointInteractor 9 4 from boxSum import VerticalDoubleLine 10 5 from boxSum import HorizontalDoubleLine 11 #from sas.guiframe.events import SlicerParamUpdateEvent12 6 13 7 … … 15 9 """ 16 10 BoxMask Class: determine 2 rectangular area to find the pixel of 17 a Data inside of box. 18 11 a Data inside of box. 12 19 13 Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine. 20 14 21 15 :param zorder: Artists with lower zorder values are drawn first. 22 16 :param x_min: the minimum value of the x coordinate … … 26 20 27 21 """ 28 def __init__(self, base, axes, color='black', zorder=3, side=None, 29 22 def __init__(self, base, axes, color='black', zorder=3, side=None, 23 x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025): 30 24 """ 31 25 """ 32 26 _BaseInteractor.__init__(self, base, axes, color=color) 33 # # class initialization34 # # list of Boxmask markers27 # # class initialization 28 # # list of Boxmask markers 35 29 self.markers = [] 36 30 self.axes = axes 37 31 self.mask = None 38 32 self.is_inside = side 39 # # connect the artist for the motion33 # # connect the artist for the motion 40 34 self.connect = self.base.connect 41 # # when qmax is reached the selected line is reset42 # the its previous value35 # # when qmax is reached the selected line is reset 36 # the its previous value 43 37 self.qmax = min(self.base.data.xmax, self.base.data.xmin) 44 # # Define the box limits38 # # Define the box limits 45 39 self.xmin = -1 * 0.5 * min(math.fabs(self.base.data.xmax), 46 math.fabs(self.base.data.xmin))40 math.fabs(self.base.data.xmin)) 47 41 self.ymin = -1 * 0.5 * min(math.fabs(self.base.data.xmax), 48 42 math.fabs(self.base.data.xmin)) 49 43 self.xmax = 0.5 * min(math.fabs(self.base.data.xmax), 50 44 math.fabs(self.base.data.xmin)) 51 self.ymax = 52 53 # # center of the box45 self.ymax = 0.5 * min(math.fabs(self.base.data.xmax), 46 math.fabs(self.base.data.xmin)) 47 # # center of the box 54 48 self.center_x = 0.0002 55 49 self.center_y = 0.0003 56 # # Number of points on the plot50 # # Number of points on the plot 57 51 self.nbins = 20 58 # # Define initial result the summation52 # # Define initial result the summation 59 53 self.count = 0 60 54 self.error = 0 61 55 self.data = self.base.data 62 # # Flag to determine if the current figure has moved63 # # set to False == no motion , set to True== motion56 # # Flag to determine if the current figure has moved 57 # # set to False == no motion , set to True== motion 64 58 self.has_move = False 65 # # Create Box edges59 # # Create Box edges 66 60 self.horizontal_lines = HorizontalDoubleLine(self, 67 61 self.base.subplot, 68 62 color='blue', 69 70 71 72 73 63 zorder=zorder, 64 y=self.ymax, 65 x=self.xmax, 66 center_x=self.center_x, 67 center_y=self.center_y) 74 68 self.horizontal_lines.qmax = self.qmax 75 69 76 70 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)71 self.base.subplot, 72 color='grey', 73 zorder=zorder, 74 y=self.ymax, 75 x=self.xmax, 76 center_x=self.center_x, 77 center_y=self.center_y) 84 78 self.vertical_lines.qmax = self.qmax 85 79 86 80 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)91 # # Save the name of the slicer panel associate with this slicer92 self.panel_name = "" 93 # # Update and post slicer parameters81 self.base.subplot, color='grey', 82 zorder=zorder, 83 center_x=self.center_x, 84 center_y=self.center_y) 85 # # Save the name of the slicer panel associate with this slicer 86 self.panel_name = "" 87 # # Update and post slicer parameters 94 88 self.update() 95 89 self._post_data() 96 90 97 91 def clear(self): 98 92 """ … … 104 98 self.center.clear() 105 99 self.base.connect.clearall() 106 #self.base.Unbind(EVT_SLICER_PARS) 107 100 108 101 def update(self): 109 102 """ … … 111 104 resetting the widgets. 112 105 """ 113 # check if the center point has moved and update the figure accordingly 106 # check if the center point has moved and update the figure accordingly 114 107 if self.center.has_move: 115 108 self.center.update() 116 109 self.horizontal_lines.update(center=self.center) 117 110 self.vertical_lines.update(center=self.center) 118 # # check if the horizontal lines have moved and update119 # the figure accordingly 111 # # check if the horizontal lines have moved and update 112 # the figure accordingly 120 113 if self.horizontal_lines.has_move: 121 114 self.horizontal_lines.update() … … 123 116 y2=self.horizontal_lines.y2, 124 117 height=self.horizontal_lines.half_height) 125 # # check if the vertical lines have moved and update126 # the figure accordingly 118 # # check if the vertical lines have moved and update 119 # the figure accordingly 127 120 if self.vertical_lines.has_move: 128 121 self.vertical_lines.update() … … 130 123 x2=self.vertical_lines.x2, 131 124 width=self.vertical_lines.half_width) 132 # if self.is_inside != None:125 # if self.is_inside != None: 133 126 out = self._post_data() 134 127 return out 135 128 136 129 def save(self, ev): 137 130 """ … … 143 136 self.vertical_lines.save(ev) 144 137 self.center.save(ev) 145 138 146 139 def _post_data(self): 147 140 """ … … 150 143 """ 151 144 from sas.dataloader.manipulations import Boxcut 152 # # Data 2D for which the pixel will be summed145 # # Data 2D for which the pixel will be summed 153 146 data = self.base.data 154 147 mask = data.mask 155 # # the region of the summation156 x_min = self.horizontal_lines.x2 157 x_max = self.horizontal_lines.x1 148 # # the region of the summation 149 x_min = self.horizontal_lines.x2 150 x_max = self.horizontal_lines.x1 158 151 y_min = self.vertical_lines.y2 159 152 y_max = self.vertical_lines.y1 … … 164 157 else: 165 158 out = (mask(data)) 166 # self.base.data.mask=out159 # self.base.data.mask=out 167 160 self.mask = mask 168 return out 169 161 return out 162 170 163 def moveend(self, ev): 171 164 """ 172 165 After a dragging motion this function is called to compute 173 the error and the sum of pixel of a given data 2D 166 the error and the sum of pixel of a given data 2D 174 167 """ 175 168 self.base.thaw_axes() 176 # # post169 # # post 177 170 self._post_data() 178 171 179 172 def restore(self): 180 173 """ … … 184 177 self.vertical_lines.restore() 185 178 self.center.restore() 186 179 187 180 def move(self, x, y, ev): 188 181 """ … … 190 183 """ 191 184 pass 192 185 193 186 def set_cursor(self, x, y): 194 187 pass 195 188 196 189 def get_params(self): 197 190 """ 198 191 Store a copy of values of parameters of the slicer into a dictionary. 199 192 200 193 :return params: the dictionary created 201 194 202 195 """ 203 196 params = {} 204 197 params["Width"] = math.fabs(self.vertical_lines.half_width) * 2 205 params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 198 params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 206 199 params["center_x"] = self.center.x 207 200 params["center_y"] = self.center.y 208 201 return params 209 202 210 203 def get_mask(self): 211 204 """ … … 214 207 mask = self.mask 215 208 return mask 216 209 217 210 def set_params(self, params): 218 211 """ 219 Receive a dictionary and reset the slicer with values contained 212 Receive a dictionary and reset the slicer with values contained 220 213 in the values of the dictionary. 221 222 :param params: a dictionary containing name of slicer parameters and 214 215 :param params: a dictionary containing name of slicer parameters and 223 216 values the user assigned to the slicer. 224 217 """ 225 x_max = math.fabs(params["Width"] )/2226 y_max = math.fabs(params["Height"]) /2227 228 self.center_x = params["center_x"] 218 x_max = math.fabs(params["Width"]) / 2 219 y_max = math.fabs(params["Height"]) / 2 220 221 self.center_x = params["center_x"] 229 222 self.center_y = params["center_y"] 230 # update the slicer given values of params223 # update the slicer given values of params 231 224 self.center.update(center_x=self.center_x, center_y=self.center_y) 232 self.horizontal_lines.update(center=self.center, 233 width=x_max, 234 height=y_max) 235 self.vertical_lines.update(center=self.center, 236 width=x_max, 237 height=y_max) 238 #compute the new error and sum given values of params 225 self.horizontal_lines.update(center=self.center, width=x_max, height=y_max) 226 self.vertical_lines.update(center=self.center, width=x_max, height=y_max) 227 # compute the new error and sum given values of params 239 228 self._post_data() 240 229 241 230 def freeze_axes(self): 242 231 self.base.freeze_axes() 243 232 244 233 def thaw_axes(self): 245 234 self.base.thaw_axes() … … 248 237 self.base.update() 249 238 250 class inner_BoxMask(BoxMask): 251 def __call__(self): 252 self.base.data.mask = (self._post_data()==False) 253 254 239 class inner_BoxMask(BoxMask): 240 def __call__(self): 241 self.base.data.mask = (self._post_data() == False)
Note: See TracChangeset
for help on using the changeset viewer.