[2d107b8] | 1 | |
---|
| 2 | |
---|
[4ac8556] | 3 | import wx |
---|
[32c0841] | 4 | #import copy |
---|
| 5 | #from copy import deepcopy |
---|
[4ac8556] | 6 | import math |
---|
| 7 | import numpy |
---|
[55a0dc1] | 8 | from sans.guiframe.events import NewPlotEvent |
---|
| 9 | from sans.guiframe.events import StatusEvent |
---|
| 10 | from sans.guiframe.events import SlicerParameterEvent |
---|
| 11 | from sans.guiframe.events import EVT_SLICER_PARS |
---|
[4ac8556] | 12 | from BaseInteractor import _BaseInteractor |
---|
| 13 | from sans.guiframe.dataFitting import Data1D |
---|
[32c0841] | 14 | #import SlicerParameters |
---|
[2d107b8] | 15 | |
---|
[0f6d05f8] | 16 | |
---|
[38224f10] | 17 | class BoxInteractor(_BaseInteractor): |
---|
[2d107b8] | 18 | """ |
---|
[83f4445] | 19 | BoxInteractor define a rectangle that return data1D average of Data2D |
---|
| 20 | in a rectangle area defined by -x, x ,y, -y |
---|
[2d107b8] | 21 | """ |
---|
[32c0841] | 22 | def __init__(self, base, axes, color='black', zorder=3): |
---|
[2d107b8] | 23 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
[6c0568b] | 24 | ## Class initialization |
---|
[2d107b8] | 25 | self.markers = [] |
---|
| 26 | self.axes = axes |
---|
[6c0568b] | 27 | ##connecting artist |
---|
[2d107b8] | 28 | self.connect = self.base.connect |
---|
[6c0568b] | 29 | ## determine x y values |
---|
[32c0841] | 30 | self.x = 0.5 * min(math.fabs(self.base.data2D.xmax), |
---|
| 31 | math.fabs(self.base.data2D.xmin)) |
---|
| 32 | self.y = 0.5 * min(math.fabs(self.base.data2D.xmax), |
---|
| 33 | math.fabs(self.base.data2D.xmin)) |
---|
[6c0568b] | 34 | ## when reach qmax reset the graph |
---|
[32c0841] | 35 | self.qmax = max(self.base.data2D.xmax, self.base.data2D.xmin, |
---|
| 36 | self.base.data2D.ymax, self.base.data2D.ymin) |
---|
[2d107b8] | 37 | ## Number of points on the plot |
---|
[ffd23b5] | 38 | self.nbins = 30 |
---|
[32c0841] | 39 | ## If True, I(|Q|) will be return, otherwise, |
---|
| 40 | #negative q-values are allowed |
---|
[a4d4b35] | 41 | self.fold = True |
---|
[6c0568b] | 42 | ## reference of the current Slab averaging |
---|
[32c0841] | 43 | self.averager = None |
---|
[6c0568b] | 44 | ## Create vertical and horizaontal lines for the rectangle |
---|
[32c0841] | 45 | self.vertical_lines = VerticalLines(self, |
---|
| 46 | self.base.subplot, |
---|
| 47 | color='blue', |
---|
| 48 | zorder=zorder, |
---|
| 49 | y=self.y , |
---|
| 50 | x=self.x) |
---|
[18eba35] | 51 | self.vertical_lines.qmax = self.qmax |
---|
| 52 | |
---|
[32c0841] | 53 | self.horizontal_lines = HorizontalLines(self, |
---|
| 54 | self.base.subplot, |
---|
| 55 | color='green', |
---|
| 56 | zorder=zorder, |
---|
| 57 | x=self.x, |
---|
| 58 | y=self.y) |
---|
| 59 | self.horizontal_lines.qmax = self.qmax |
---|
[6c0568b] | 60 | ## draw the rectangle and plost the data 1D resulting |
---|
| 61 | ## of averaging data2D |
---|
[38224f10] | 62 | self.update() |
---|
[0f6d05f8] | 63 | self._post_data() |
---|
[6c0568b] | 64 | ## Bind to slice parameter events |
---|
[18eba35] | 65 | self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) |
---|
[2d107b8] | 66 | |
---|
| 67 | def _onEVT_SLICER_PARS(self, event): |
---|
[6c0568b] | 68 | """ |
---|
[83f4445] | 69 | receive an event containing parameters values to reset the slicer |
---|
| 70 | |
---|
| 71 | :param event: event of type SlicerParameterEvent with params as |
---|
[6c0568b] | 72 | attribute |
---|
| 73 | """ |
---|
[32c0841] | 74 | wx.PostEvent(self.base.parent, |
---|
| 75 | StatusEvent(status="BoxSlicer._onEVT_SLICER_PARS")) |
---|
[2d107b8] | 76 | event.Skip() |
---|
| 77 | if event.type == self.__class__.__name__: |
---|
[0f6d05f8] | 78 | self.set_params(event.params) |
---|
[2d107b8] | 79 | self.base.update() |
---|
[32c0841] | 80 | |
---|
[2d107b8] | 81 | def update_and_post(self): |
---|
[6c0568b] | 82 | """ |
---|
[83f4445] | 83 | Update the slicer and plot the resulting data |
---|
[6c0568b] | 84 | """ |
---|
[2d107b8] | 85 | self.update() |
---|
| 86 | self._post_data() |
---|
[83f4445] | 87 | |
---|
[2d107b8] | 88 | def set_layer(self, n): |
---|
[6c0568b] | 89 | """ |
---|
[83f4445] | 90 | Allow adding plot to the same panel |
---|
| 91 | |
---|
| 92 | :param n: the number of layer |
---|
| 93 | |
---|
[6c0568b] | 94 | """ |
---|
[2d107b8] | 95 | self.layernum = n |
---|
| 96 | self.update() |
---|
| 97 | |
---|
| 98 | def clear(self): |
---|
[6c0568b] | 99 | """ |
---|
[83f4445] | 100 | Clear the slicer and all connected events related to this slicer |
---|
[6c0568b] | 101 | """ |
---|
[32c0841] | 102 | self.averager = None |
---|
[2d107b8] | 103 | self.clear_markers() |
---|
[18eba35] | 104 | self.horizontal_lines.clear() |
---|
| 105 | self.vertical_lines.clear() |
---|
| 106 | self.base.connect.clearall() |
---|
| 107 | self.base.Unbind(EVT_SLICER_PARS) |
---|
[2d107b8] | 108 | |
---|
| 109 | def update(self): |
---|
| 110 | """ |
---|
| 111 | Respond to changes in the model by recalculating the profiles and |
---|
| 112 | resetting the widgets. |
---|
| 113 | """ |
---|
[6c0568b] | 114 | ##Update the slicer if an horizontal line is dragged |
---|
[18eba35] | 115 | if self.horizontal_lines.has_move: |
---|
| 116 | self.horizontal_lines.update() |
---|
| 117 | self.vertical_lines.update(y=self.horizontal_lines.y) |
---|
[6c0568b] | 118 | ##Update the slicer if a vertical line is dragged |
---|
[18eba35] | 119 | if self.vertical_lines.has_move: |
---|
| 120 | self.vertical_lines.update() |
---|
| 121 | self.horizontal_lines.update(x=self.vertical_lines.x) |
---|
[83f4445] | 122 | |
---|
[2d107b8] | 123 | def save(self, ev): |
---|
| 124 | """ |
---|
| 125 | Remember the roughness for this layer and the next so that we |
---|
| 126 | can restore on Esc. |
---|
| 127 | """ |
---|
| 128 | self.base.freeze_axes() |
---|
[18eba35] | 129 | self.vertical_lines.save(ev) |
---|
| 130 | self.horizontal_lines.save(ev) |
---|
| 131 | |
---|
[ffd23b5] | 132 | def _post_data(self): |
---|
| 133 | pass |
---|
| 134 | |
---|
[32c0841] | 135 | def post_data(self, new_slab=None, nbins=None, direction=None): |
---|
[6c0568b] | 136 | """ |
---|
[83f4445] | 137 | post data averaging in Qx or Qy given new_slab type |
---|
| 138 | |
---|
| 139 | :param new_slab: slicer that determine with direction to average |
---|
| 140 | :param nbins: the number of points plotted when averaging |
---|
| 141 | :param direction: the direction of averaging |
---|
| 142 | |
---|
[6c0568b] | 143 | """ |
---|
[32c0841] | 144 | x_min = -1 * math.fabs(self.vertical_lines.x) |
---|
| 145 | x_max = math.fabs(self.vertical_lines.x) |
---|
| 146 | y_min = -1 * math.fabs(self.horizontal_lines.y) |
---|
| 147 | y_max = math.fabs(self.horizontal_lines.y) |
---|
[ffd23b5] | 148 | |
---|
[32c0841] | 149 | if nbins != None: |
---|
| 150 | self.nbins = nbins |
---|
| 151 | if self.averager == None: |
---|
| 152 | if new_slab == None: |
---|
| 153 | msg = "post data:cannot average , averager is empty" |
---|
| 154 | raise ValueError, msg |
---|
| 155 | self.averager = new_slab |
---|
[a4d4b35] | 156 | if direction == "X": |
---|
[32c0841] | 157 | if self.fold: |
---|
| 158 | x_low = 0 |
---|
| 159 | else: |
---|
| 160 | x_low = math.fabs(x_min) |
---|
| 161 | bin_width = (x_max + x_low)/self.nbins |
---|
[a4d4b35] | 162 | else: |
---|
[32c0841] | 163 | if self.fold: |
---|
| 164 | y_low = 0 |
---|
| 165 | else: |
---|
| 166 | y_low = math.fabs(y_min) |
---|
| 167 | bin_width = (y_max + y_low)/self.nbins |
---|
[6c0568b] | 168 | ## Average data2D given Qx or Qy |
---|
[32c0841] | 169 | box = self.averager(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, |
---|
[ffd23b5] | 170 | bin_width=bin_width) |
---|
[a4d4b35] | 171 | box.fold = self.fold |
---|
[ffd23b5] | 172 | boxavg = box(self.base.data2D) |
---|
[6c0568b] | 173 | #3 Create Data1D to plot |
---|
[32c0841] | 174 | if hasattr(boxavg, "dxl"): |
---|
| 175 | dxl = boxavg.dxl |
---|
[ffd23b5] | 176 | else: |
---|
[32c0841] | 177 | dxl = None |
---|
| 178 | if hasattr(boxavg, "dxw"): |
---|
| 179 | dxw = boxavg.dxw |
---|
[ffd23b5] | 180 | else: |
---|
[32c0841] | 181 | dxw = None |
---|
| 182 | new_plot = Data1D(x=boxavg.x, y=boxavg.y, dy=boxavg.dy) |
---|
[4ac8556] | 183 | new_plot.dxl = dxl |
---|
| 184 | new_plot.dxw = dxw |
---|
[32c0841] | 185 | new_plot.name = str(self.averager.__name__) + \ |
---|
| 186 | "(" + self.base.data2D.name + ")" |
---|
| 187 | new_plot.source = self.base.data2D.source |
---|
[ffd23b5] | 188 | new_plot.interactive = True |
---|
[32c0841] | 189 | new_plot.detector = self.base.data2D.detector |
---|
[ffd23b5] | 190 | # If the data file does not tell us what the axes are, just assume... |
---|
[ddf6df3] | 191 | new_plot.xaxis("\\rm{Q}", '\\AA^{-1}') |
---|
[ffd23b5] | 192 | new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") |
---|
[32c0841] | 193 | new_plot.group_id = str(self.averager.__name__) + self.base.data2D.name |
---|
[ffd23b5] | 194 | new_plot.id = str(self.averager.__name__) |
---|
[70cf5d3] | 195 | #new_plot.is_data= True |
---|
[ffd23b5] | 196 | wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, |
---|
[32c0841] | 197 | title=str(self.averager.__name__))) |
---|
[83f4445] | 198 | |
---|
[2d107b8] | 199 | def moveend(self, ev): |
---|
[6c0568b] | 200 | """ |
---|
[83f4445] | 201 | Called after a dragging event. |
---|
| 202 | Post the slicer new parameters and creates a new Data1D |
---|
| 203 | corresponding to the new average |
---|
[6c0568b] | 204 | """ |
---|
[2d107b8] | 205 | self.base.thaw_axes() |
---|
| 206 | # Post paramters |
---|
[0d9dae8] | 207 | event = SlicerParameterEvent() |
---|
[2d107b8] | 208 | event.type = self.__class__.__name__ |
---|
[0f6d05f8] | 209 | event.params = self.get_params() |
---|
[2d107b8] | 210 | wx.PostEvent(self.base.parent, event) |
---|
[6c0568b] | 211 | # create the new data1D |
---|
[2d107b8] | 212 | self._post_data() |
---|
| 213 | |
---|
| 214 | def restore(self): |
---|
| 215 | """ |
---|
| 216 | Restore the roughness for this layer. |
---|
| 217 | """ |
---|
[18eba35] | 218 | self.horizontal_lines.restore() |
---|
| 219 | self.vertical_lines.restore() |
---|
| 220 | |
---|
[2d107b8] | 221 | def move(self, x, y, ev): |
---|
| 222 | """ |
---|
| 223 | Process move to a new position, making sure that the move is allowed. |
---|
| 224 | """ |
---|
| 225 | pass |
---|
| 226 | |
---|
| 227 | def set_cursor(self, x, y): |
---|
| 228 | pass |
---|
| 229 | |
---|
| 230 | def get_params(self): |
---|
[6c0568b] | 231 | """ |
---|
[83f4445] | 232 | Store a copy of values of parameters of the slicer into a dictionary. |
---|
| 233 | |
---|
| 234 | :return params: the dictionary created |
---|
| 235 | |
---|
[6c0568b] | 236 | """ |
---|
[2d107b8] | 237 | params = {} |
---|
[32c0841] | 238 | params["x_max"] = math.fabs(self.vertical_lines.x) |
---|
| 239 | params["y_max"] = math.fabs(self.horizontal_lines.y) |
---|
| 240 | params["nbins"] = self.nbins |
---|
[2d107b8] | 241 | return params |
---|
| 242 | |
---|
| 243 | def set_params(self, params): |
---|
[6c0568b] | 244 | """ |
---|
[83f4445] | 245 | Receive a dictionary and reset the slicer with values contained |
---|
| 246 | in the values of the dictionary. |
---|
| 247 | |
---|
| 248 | :param params: a dictionary containing name of slicer parameters and |
---|
[6c0568b] | 249 | values the user assigned to the slicer. |
---|
| 250 | """ |
---|
[0f6d05f8] | 251 | self.x = float(math.fabs(params["x_max"])) |
---|
| 252 | self.y = float(math.fabs(params["y_max"] )) |
---|
[32c0841] | 253 | self.nbins = params["nbins"] |
---|
[18eba35] | 254 | |
---|
[32c0841] | 255 | self.horizontal_lines.update(x=self.x, y=self.y) |
---|
| 256 | self.vertical_lines.update(x=self.x, y=self.y) |
---|
| 257 | self.post_data(nbins=None) |
---|
[18eba35] | 258 | |
---|
[2d107b8] | 259 | def freeze_axes(self): |
---|
[83f4445] | 260 | """ |
---|
| 261 | """ |
---|
[2d107b8] | 262 | self.base.freeze_axes() |
---|
| 263 | |
---|
| 264 | def thaw_axes(self): |
---|
[83f4445] | 265 | """ |
---|
| 266 | """ |
---|
[2d107b8] | 267 | self.base.thaw_axes() |
---|
| 268 | |
---|
| 269 | def draw(self): |
---|
[83f4445] | 270 | """ |
---|
| 271 | """ |
---|
[2d107b8] | 272 | self.base.draw() |
---|
| 273 | |
---|
[6c0568b] | 274 | |
---|
[18eba35] | 275 | class HorizontalLines(_BaseInteractor): |
---|
[2d107b8] | 276 | """ |
---|
[d955bf19] | 277 | Draw 2 Horizontal lines centered on (0,0) that can move |
---|
| 278 | on the x- direction and in opposite direction |
---|
[2d107b8] | 279 | """ |
---|
[32c0841] | 280 | def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5): |
---|
| 281 | """ |
---|
| 282 | """ |
---|
[2d107b8] | 283 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
[6c0568b] | 284 | ##Class initialization |
---|
[2d107b8] | 285 | self.markers = [] |
---|
| 286 | self.axes = axes |
---|
[6c0568b] | 287 | ## Saving the end points of two lines |
---|
[32c0841] | 288 | self.x = x |
---|
| 289 | self.save_x = x |
---|
[3554b99a] | 290 | |
---|
[32c0841] | 291 | self.y = y |
---|
| 292 | self.save_y = y |
---|
[6c0568b] | 293 | ## Creating a marker |
---|
[18eba35] | 294 | try: |
---|
| 295 | # Inner circle marker |
---|
[32c0841] | 296 | self.inner_marker = self.axes.plot([0], [self.y], linestyle='', |
---|
[18eba35] | 297 | marker='s', markersize=10, |
---|
| 298 | color=self.color, alpha=0.6, |
---|
| 299 | pickradius=5, label="pick", |
---|
[32c0841] | 300 | # Prefer this to other lines |
---|
| 301 | zorder=zorder, |
---|
[18eba35] | 302 | visible=True)[0] |
---|
| 303 | except: |
---|
[32c0841] | 304 | self.inner_marker = self.axes.plot([0], [self.y], linestyle='', |
---|
[18eba35] | 305 | marker='s', markersize=10, |
---|
| 306 | color=self.color, alpha=0.6, |
---|
[32c0841] | 307 | label="pick", visible=True)[0] |
---|
| 308 | message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION " |
---|
| 309 | message += "OF MATPLOTLIB\n Get the SVN version that" |
---|
| 310 | message += " is at least as recent as June 1, 2007" |
---|
| 311 | owner = self.base.base.parent |
---|
| 312 | wx.PostEvent(owner, |
---|
| 313 | StatusEvent(status="AnnulusSlicer: %s" % message)) |
---|
[6c0568b] | 314 | ## Define 2 horizontal lines |
---|
[32c0841] | 315 | self.top_line = self.axes.plot([self.x, -self.x], [self.y, self.y], |
---|
[18eba35] | 316 | linestyle='-', marker='', |
---|
[32c0841] | 317 | color=self.color, visible=True)[0] |
---|
| 318 | self.bottom_line = self.axes.plot([self.x, -self.x], [-self.y, -self.y], |
---|
[2d107b8] | 319 | linestyle='-', marker='', |
---|
[32c0841] | 320 | color=self.color, visible=True)[0] |
---|
[6c0568b] | 321 | ## Flag to check the motion of the lines |
---|
[32c0841] | 322 | self.has_move = False |
---|
[6c0568b] | 323 | ## Connecting markers to mouse events and draw |
---|
[18eba35] | 324 | self.connect_markers([self.top_line, self.inner_marker]) |
---|
[3554b99a] | 325 | self.update() |
---|
[2d107b8] | 326 | |
---|
| 327 | def set_layer(self, n): |
---|
[6c0568b] | 328 | """ |
---|
[83f4445] | 329 | Allow adding plot to the same panel |
---|
| 330 | |
---|
| 331 | :param n: the number of layer |
---|
| 332 | |
---|
[6c0568b] | 333 | """ |
---|
[2d107b8] | 334 | self.layernum = n |
---|
| 335 | self.update() |
---|
| 336 | |
---|
| 337 | def clear(self): |
---|
[6c0568b] | 338 | """ |
---|
[83f4445] | 339 | Clear this slicer and its markers |
---|
[6c0568b] | 340 | """ |
---|
[2d107b8] | 341 | self.clear_markers() |
---|
| 342 | try: |
---|
[18eba35] | 343 | self.inner_marker.remove() |
---|
| 344 | self.top_line.remove() |
---|
| 345 | self.bottom_line.remove() |
---|
[2d107b8] | 346 | except: |
---|
| 347 | # Old version of matplotlib |
---|
| 348 | for item in range(len(self.axes.lines)): |
---|
| 349 | del self.axes.lines[0] |
---|
[030873e] | 350 | |
---|
[32c0841] | 351 | def update(self, x=None, y=None): |
---|
[2d107b8] | 352 | """ |
---|
[83f4445] | 353 | Draw the new roughness on the graph. |
---|
| 354 | |
---|
| 355 | :param x: x-coordinates to reset current class x |
---|
| 356 | :param y: y-coordinates to reset current class y |
---|
| 357 | |
---|
[2d107b8] | 358 | """ |
---|
[6c0568b] | 359 | ## Reset x, y- coordinates if send as parameters |
---|
[32c0841] | 360 | if x != None: |
---|
| 361 | self.x = numpy.sign(self.x) * math.fabs(x) |
---|
| 362 | if y != None: |
---|
| 363 | self.y = numpy.sign(self.y) * math.fabs(y) |
---|
[6c0568b] | 364 | ## Draw lines and markers |
---|
[32c0841] | 365 | self.inner_marker.set(xdata=[0], ydata=[self.y]) |
---|
| 366 | self.top_line.set(xdata=[self.x, -self.x], ydata=[self.y, self.y]) |
---|
| 367 | self.bottom_line.set(xdata=[self.x,-self.x], ydata=[-self.y, -self.y]) |
---|
[2d107b8] | 368 | |
---|
| 369 | def save(self, ev): |
---|
| 370 | """ |
---|
| 371 | Remember the roughness for this layer and the next so that we |
---|
| 372 | can restore on Esc. |
---|
| 373 | """ |
---|
[32c0841] | 374 | self.save_x = self.x |
---|
| 375 | self.save_y = self.y |
---|
[2d107b8] | 376 | self.base.freeze_axes() |
---|
| 377 | |
---|
| 378 | def moveend(self, ev): |
---|
[6c0568b] | 379 | """ |
---|
[83f4445] | 380 | Called after a dragging this edge and set self.has_move to False |
---|
| 381 | to specify the end of dragging motion |
---|
[6c0568b] | 382 | """ |
---|
[32c0841] | 383 | self.has_move = False |
---|
[2d107b8] | 384 | self.base.moveend(ev) |
---|
[83f4445] | 385 | |
---|
[2d107b8] | 386 | def restore(self): |
---|
| 387 | """ |
---|
| 388 | Restore the roughness for this layer. |
---|
| 389 | """ |
---|
[18eba35] | 390 | self.x = self.save_x |
---|
| 391 | self.y = self.save_y |
---|
[0f6d05f8] | 392 | |
---|
[2d107b8] | 393 | def move(self, x, y, ev): |
---|
| 394 | """ |
---|
| 395 | Process move to a new position, making sure that the move is allowed. |
---|
| 396 | """ |
---|
[32c0841] | 397 | self.y = y |
---|
| 398 | self.has_move = True |
---|
[2d107b8] | 399 | self.base.base.update() |
---|
| 400 | |
---|
[18eba35] | 401 | |
---|
| 402 | class VerticalLines(_BaseInteractor): |
---|
[2d107b8] | 403 | """ |
---|
[83f4445] | 404 | Select an annulus through a 2D plot |
---|
[2d107b8] | 405 | """ |
---|
[32c0841] | 406 | def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5): |
---|
| 407 | """ |
---|
| 408 | """ |
---|
[2d107b8] | 409 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
| 410 | self.markers = [] |
---|
| 411 | self.axes = axes |
---|
[32c0841] | 412 | self.x = math.fabs(x) |
---|
| 413 | self.save_x = self.x |
---|
| 414 | self.y = math.fabs(y) |
---|
| 415 | self.save_y = y |
---|
[18eba35] | 416 | try: |
---|
| 417 | # Inner circle marker |
---|
[32c0841] | 418 | self.inner_marker = self.axes.plot([self.x], [0], linestyle='', |
---|
[18eba35] | 419 | marker='s', markersize=10, |
---|
| 420 | color=self.color, alpha=0.6, |
---|
| 421 | pickradius=5, label="pick", |
---|
[32c0841] | 422 | # Prefer this to other lines |
---|
| 423 | zorder=zorder, visible=True)[0] |
---|
[18eba35] | 424 | except: |
---|
[32c0841] | 425 | self.inner_marker = self.axes.plot([self.x], [0], linestyle='', |
---|
[18eba35] | 426 | marker='s', markersize=10, |
---|
| 427 | color=self.color, alpha=0.6, |
---|
[32c0841] | 428 | label="pick", visible=True)[0] |
---|
| 429 | message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" |
---|
| 430 | message += " OF MATPLOTLIB\n Get the SVN version that is" |
---|
| 431 | message += " at least as recent as June 1, 2007" |
---|
[18eba35] | 432 | |
---|
[32c0841] | 433 | self.right_line = self.axes.plot([self.x, self.x], |
---|
| 434 | [self.y , -self.y], |
---|
[18eba35] | 435 | linestyle='-', marker='', |
---|
[32c0841] | 436 | color=self.color, visible=True)[0] |
---|
| 437 | self.left_line = self.axes.plot([-self.x, -self.x], |
---|
| 438 | [self.y, -self.y], |
---|
[2d107b8] | 439 | linestyle='-', marker='', |
---|
[32c0841] | 440 | color=self.color, visible=True)[0] |
---|
| 441 | self.has_move = False |
---|
[18eba35] | 442 | self.connect_markers([self.right_line, self.inner_marker]) |
---|
[2d107b8] | 443 | self.update() |
---|
| 444 | |
---|
| 445 | def set_layer(self, n): |
---|
[6c0568b] | 446 | """ |
---|
[83f4445] | 447 | Allow adding plot to the same panel |
---|
| 448 | |
---|
| 449 | :param n: the number of layer |
---|
| 450 | |
---|
[6c0568b] | 451 | """ |
---|
[2d107b8] | 452 | self.layernum = n |
---|
| 453 | self.update() |
---|
| 454 | |
---|
| 455 | def clear(self): |
---|
[6c0568b] | 456 | """ |
---|
[83f4445] | 457 | Clear this slicer and its markers |
---|
[6c0568b] | 458 | """ |
---|
[2d107b8] | 459 | self.clear_markers() |
---|
| 460 | try: |
---|
[18eba35] | 461 | self.inner_marker.remove() |
---|
| 462 | self.left_line.remove() |
---|
| 463 | self.right_line.remove() |
---|
[2d107b8] | 464 | except: |
---|
| 465 | # Old version of matplotlib |
---|
| 466 | for item in range(len(self.axes.lines)): |
---|
| 467 | del self.axes.lines[0] |
---|
[18eba35] | 468 | |
---|
[32c0841] | 469 | def update(self, x=None, y=None): |
---|
[2d107b8] | 470 | """ |
---|
[83f4445] | 471 | Draw the new roughness on the graph. |
---|
| 472 | |
---|
| 473 | :param x: x-coordinates to reset current class x |
---|
| 474 | :param y: y-coordinates to reset current class y |
---|
| 475 | |
---|
[2d107b8] | 476 | """ |
---|
[6c0568b] | 477 | ## reset x, y -coordinates if given as parameters |
---|
[32c0841] | 478 | if x != None: |
---|
| 479 | self.x = numpy.sign(self.x) * math.fabs(x) |
---|
| 480 | if y != None: |
---|
| 481 | self.y = numpy.sign(self.y) * math.fabs(y) |
---|
[6c0568b] | 482 | ## draw lines and markers |
---|
[32c0841] | 483 | self.inner_marker.set(xdata=[self.x], ydata=[0]) |
---|
| 484 | self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y]) |
---|
| 485 | self.right_line.set(xdata=[self.x, self.x], ydata=[self.y, -self.y]) |
---|
[0f6d05f8] | 486 | |
---|
[2d107b8] | 487 | def save(self, ev): |
---|
| 488 | """ |
---|
| 489 | Remember the roughness for this layer and the next so that we |
---|
| 490 | can restore on Esc. |
---|
| 491 | """ |
---|
[83f4445] | 492 | self.save_x = self.x |
---|
| 493 | self.save_y = self.y |
---|
[2d107b8] | 494 | self.base.freeze_axes() |
---|
[83f4445] | 495 | |
---|
[2d107b8] | 496 | def moveend(self, ev): |
---|
[6c0568b] | 497 | """ |
---|
[83f4445] | 498 | Called after a dragging this edge and set self.has_move to False |
---|
| 499 | to specify the end of dragging motion |
---|
[6c0568b] | 500 | """ |
---|
[32c0841] | 501 | self.has_move = False |
---|
[2d107b8] | 502 | self.base.moveend(ev) |
---|
[83f4445] | 503 | |
---|
[2d107b8] | 504 | def restore(self): |
---|
| 505 | """ |
---|
| 506 | Restore the roughness for this layer. |
---|
| 507 | """ |
---|
[18eba35] | 508 | self.x = self.save_x |
---|
| 509 | self.y = self.save_y |
---|
[3554b99a] | 510 | |
---|
[2d107b8] | 511 | def move(self, x, y, ev): |
---|
| 512 | """ |
---|
| 513 | Process move to a new position, making sure that the move is allowed. |
---|
| 514 | """ |
---|
[32c0841] | 515 | self.has_move = True |
---|
| 516 | self.x = x |
---|
[8ff3ec1] | 517 | self.base.base.update() |
---|
| 518 | |
---|
[18eba35] | 519 | |
---|
[ffd23b5] | 520 | class BoxInteractorX(BoxInteractor): |
---|
[eba08f1a] | 521 | """ |
---|
[83f4445] | 522 | Average in Qx direction |
---|
[eba08f1a] | 523 | """ |
---|
[32c0841] | 524 | def __init__(self, base, axes, color='black', zorder=3): |
---|
[ffd23b5] | 525 | BoxInteractor.__init__(self, base, axes, color=color) |
---|
[32c0841] | 526 | self.base = base |
---|
[ffd23b5] | 527 | self._post_data() |
---|
[6c0568b] | 528 | |
---|
[ffd23b5] | 529 | def _post_data(self): |
---|
[6c0568b] | 530 | """ |
---|
[83f4445] | 531 | Post data creating by averaging in Qx direction |
---|
[6c0568b] | 532 | """ |
---|
[ffd23b5] | 533 | from DataLoader.manipulations import SlabX |
---|
[32c0841] | 534 | self.post_data(SlabX, direction="X") |
---|
[ffd23b5] | 535 | |
---|
| 536 | |
---|
| 537 | class BoxInteractorY(BoxInteractor): |
---|
[eba08f1a] | 538 | """ |
---|
[83f4445] | 539 | Average in Qy direction |
---|
[eba08f1a] | 540 | """ |
---|
[32c0841] | 541 | def __init__(self, base, axes, color='black', zorder=3): |
---|
[ffd23b5] | 542 | BoxInteractor.__init__(self, base, axes, color=color) |
---|
[32c0841] | 543 | self.base = base |
---|
[ffd23b5] | 544 | self._post_data() |
---|
[6c0568b] | 545 | |
---|
[ffd23b5] | 546 | def _post_data(self): |
---|
[6c0568b] | 547 | """ |
---|
[83f4445] | 548 | Post data creating by averaging in Qy direction |
---|
[6c0568b] | 549 | """ |
---|
[ffd23b5] | 550 | from DataLoader.manipulations import SlabY |
---|
[32c0841] | 551 | self.post_data(SlabY, direction="Y") |
---|
[ffd23b5] | 552 | |
---|
[2d107b8] | 553 | |
---|