Changeset 7d56795 in sasview for src/sas/guiframe
- Timestamp:
- Mar 5, 2015 3:46:02 PM (10 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:
- 090e07e
- Parents:
- b5de88e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/local_perspectives/plotting/masking.py
rb5de88e r7d56795 30 30 from sas.guiframe.dataFitting import Data1D, Data2D 31 31 from boxMask import BoxMask 32 from sectorMask import SectorMask 33 from AnnulusSlicer import CircularMask 34 32 35 from sas.guiframe.events import SlicerEvent 33 36 from sas.guiframe.events import StatusEvent 37 from functools import partial 38 34 39 (InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() 35 40 … … 61 66 elapsed=0, 62 67 yieldtime=0.01, 63 worktime=0.01 64 ): 65 """ 66 """ 67 CalcThread.__init__(self, completefn, 68 updatefn, 69 yieldtime, 70 worktime) 68 worktime=0.01): 69 """ 70 """ 71 CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime) 71 72 self.starttime = 0 72 73 self.id = id 73 74 self.panel = panel 74 75 self.image = image 75 76 76 77 77 def compute(self): … … 158 158 sizer.Add(shape_txt, (1, 1), flag=wx.TOP | wx.LEFT | wx.BOTTOM, border=5) 159 159 self.innersector_rb = wx.RadioButton(self, -1, "Double Wings") 160 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerSectorMask,160 self.Bind(wx.EVT_RADIOBUTTON, partial(self._on_mask, slicer=SectorMask, inside=True), 161 161 id=self.innersector_rb.GetId()) 162 162 sizer.Add(self.innersector_rb, (2, 1), 163 163 flag=wx.RIGHT | wx.BOTTOM, border=5) 164 164 self.innercircle_rb = wx.RadioButton(self, -1, "Circular Disk") 165 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerRingMask,165 self.Bind(wx.EVT_RADIOBUTTON, partial(self._on_mask, slicer=CircularMask, inside=True), 166 166 id=self.innercircle_rb.GetId()) 167 167 sizer.Add(self.innercircle_rb, (3, 1), 168 flag=wx.RIGHT | wx.BOTTOM, border=5) 169 168 flag=wx.RIGHT | wx.BOTTOM, border=5) 170 169 self.innerbox_rb = wx.RadioButton(self, -1, "Rectangular Disk") 171 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerBoxMask,170 self.Bind(wx.EVT_RADIOBUTTON, partial(self._on_mask, slicer=BoxMask, inside=True), 172 171 id=self.innerbox_rb.GetId()) 173 172 sizer.Add(self.innerbox_rb, (4, 1), flag=wx.RIGHT | wx.BOTTOM, border=5) 174 175 173 self.outersector_rb = wx.RadioButton(self, -1, "Double Wing Window") 176 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterSectorMask,174 self.Bind(wx.EVT_RADIOBUTTON, partial(self._on_mask, slicer=SectorMask, inside=False), 177 175 id=self.outersector_rb.GetId()) 178 176 sizer.Add(self.outersector_rb, (5, 1), 179 177 flag=wx.RIGHT | wx.BOTTOM, border=5) 180 181 # outersector_y_txt = wx.StaticText(self, -1, 'Outer Sector')182 178 self.outercircle_rb = wx.RadioButton(self, -1, "Circular Window") 183 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterRingMask,179 self.Bind(wx.EVT_RADIOBUTTON, partial(self._on_mask, slicer=CircularMask, inside=False), 184 180 id=self.outercircle_rb.GetId()) 185 181 sizer.Add(self.outercircle_rb, (6, 1), 186 182 flag=wx.RIGHT | wx.BOTTOM, border=5) 187 # outerbox_txt = wx.StaticText(self, -1, 'Outer Box')188 183 self.outerbox_rb = wx.RadioButton(self, -1, "Rectangular Window") 189 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterBoxMask,184 self.Bind(wx.EVT_RADIOBUTTON, partial(self._on_mask, slicer=BoxMask, inside=False), 190 185 id=self.outerbox_rb.GetId()) 191 186 sizer.Add(self.outerbox_rb, (7, 1), flag=wx.RIGHT | wx.BOTTOM, border=5) … … 204 199 button_add = wx.Button(self, id_button, "Add") 205 200 button_add.SetToolTipString("Add the mask drawn.") 206 button_add.Bind(wx.EVT_BUTTON, self. onAddMask, id=button_add.GetId())201 button_add.Bind(wx.EVT_BUTTON, self._on_add_mask, id=button_add.GetId()) 207 202 sizer.Add(button_add, (13, 7)) 208 203 id_button = wx.NewId() 209 204 button_erase = wx.Button(self, id_button, "Erase") 210 205 button_erase.SetToolTipString("Erase the mask drawn.") 211 button_erase.Bind(wx.EVT_BUTTON, self. onEraseMask,206 button_erase.Bind(wx.EVT_BUTTON, self._on_erase_mask, 212 207 id=button_erase.GetId()) 213 208 sizer.Add(button_erase, (13, 8)) … … 215 210 button_reset = wx.Button(self, id_button, "Reset") 216 211 button_reset.SetToolTipString("Reset the mask.") 217 button_reset.Bind(wx.EVT_BUTTON, self. onResetMask,212 button_reset.Bind(wx.EVT_BUTTON, self._on_reset_mask, 218 213 id=button_reset.GetId()) 219 214 sizer.Add(button_reset, (13, 9), flag=wx.RIGHT | wx.BOTTOM, border=15) … … 221 216 button_reset = wx.Button(self, id_button, "Clear") 222 217 button_reset.SetToolTipString("Clear all mask.") 223 button_reset.Bind(wx.EVT_BUTTON, self. onClearMask,218 button_reset.Bind(wx.EVT_BUTTON, self._on_clear_mask, 224 219 id=button_reset.GetId()) 225 220 sizer.Add(button_reset, (13, 10), flag=wx.RIGHT | wx.BOTTOM, border=15) … … 230 225 self.Show(True) 231 226 232 def onInnerBoxMask(self, event=None): 233 """ 234 Call Draw Box Slicer and get mask inside of the box 227 def _on_mask(self, event=None, slicer=BoxMask, inside=True): 228 """ 229 Draw a slicer and use it as mask 230 :param event: wx event 231 :param slicer: Slicer class to use 232 :param inside: whether we mask what's inside or outside the slicer 235 233 """ 236 234 # get ready for next evt … … 238 236 # from boxMask import BoxMask 239 237 if event != None: 240 self. onClearSlicer(event)238 self._on_clear_slicer(event) 241 239 self.slicer_z += 1 242 self.slicer = BoxMask(self, self.subplot,243 zorder=self.slicer_z, side=True)240 self.slicer = slicer(self, self.subplot, 241 zorder=self.slicer_z, side=inside) 244 242 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 245 243 self.subplot.set_xlim(self.data.xmin, self.data.xmax) … … 247 245 self.slicer_mask = self.slicer.update() 248 246 249 def onOuterBoxMask(self, event=None): 250 """ 251 Call Draw Box Slicer and get mask outside of the box 252 """ 253 event.Skip() 254 # from boxMask import BoxMask 255 if event != None: 256 self.onClearSlicer(event) 257 self.slicer_z += 1 258 self.slicer = BoxMask(self, self.subplot, 259 zorder=self.slicer_z, side=False) 260 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 261 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 262 self.update() 263 self.slicer_mask = self.slicer.update() 264 265 def onInnerSectorMask(self, event=None): 266 """ 267 Call Draw Sector Slicer and get mask inside of the sector 268 """ 269 event.Skip() 270 from sectorMask import SectorMask 271 if event != None: 272 self.onClearSlicer(event) 273 self.slicer_z += 1 274 self.slicer = SectorMask(self, self.subplot, 275 zorder=self.slicer_z, side=True) 276 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 277 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 278 self.update() 279 self.slicer_mask = self.slicer.update() 280 281 def onOuterSectorMask(self, event=None): 282 """ 283 Call Draw Sector Slicer and get mask outside of the sector 284 """ 285 event.Skip() 286 from sectorMask import SectorMask 287 if event != None: 288 self.onClearSlicer(event) 289 self.slicer_z += 1 290 self.slicer = SectorMask(self, self.subplot, 291 zorder=self.slicer_z, side=False) 292 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 293 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 294 self.update() 295 self.slicer_mask = self.slicer.update() 296 297 def onInnerRingMask(self, event=None): 298 """ 299 Perform inner circular cut on Phi and draw circular slicer 300 """ 301 event.Skip() 302 from AnnulusSlicer import CircularMask 303 if event != None: 304 self.onClearSlicer(event) 305 self.slicer_z += 1 306 self.slicer = CircularMask(self, self.subplot, 307 zorder=self.slicer_z, side=True) 308 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 309 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 310 self.update() 311 self.slicer_mask = self.slicer.update() 312 313 def onOuterRingMask(self, event=None): 314 """ 315 Perform outer circular cut on Phi and draw circular slicer 316 """ 317 event.Skip() 318 from AnnulusSlicer import CircularMask 319 if event != None: 320 self.onClearSlicer(event) 321 self.slicer_z += 1 322 self.slicer = CircularMask(self, self.subplot, 323 zorder=self.slicer_z, side=False) 324 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 325 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 326 self.update() 327 self.slicer_mask = self.slicer.update() 328 329 def onAddMask(self, event): 247 def _on_add_mask(self, event): 330 248 """ 331 249 Add new mask to old mask … … 347 265 self._update_mask(mask) 348 266 349 def onEraseMask(self, event):267 def _on_erase_mask(self, event): 350 268 """ 351 269 Erase new mask from old mask … … 357 275 self._check_display_mask(mask, event) 358 276 359 def onResetMask(self, event):277 def _on_reset_mask(self, event): 360 278 """ 361 279 Reset mask to the original mask … … 363 281 self.slicer_z += 1 364 282 self.slicer = BoxMask(self, self.subplot, 365 283 zorder=self.slicer_z, side=True) 366 284 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 367 285 self.subplot.set_xlim(self.data.xmin, self.data.xmax) … … 371 289 self._check_display_mask(mask, event) 372 290 373 def onClearMask(self, event):291 def _on_clear_mask(self, event): 374 292 """ 375 293 Clear mask … … 377 295 self.slicer_z += 1 378 296 self.slicer = BoxMask(self, self.subplot, 379 297 zorder=self.slicer_z, side=True) 380 298 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 381 299 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 382 # mask = copy.deepcopy(self.default_mask)383 300 mask = numpy.ones(len(self.data.mask), dtype=bool) 384 301 self.data.mask = mask … … 386 303 self._check_display_mask(mask, event) 387 304 388 def onClearSlicer(self, event):305 def _on_clear_slicer(self, event): 389 306 """ 390 307 Clear the slicer on the plot … … 419 336 """ 420 337 # the case of liitle numbers of True points 421 if (len(mask[mask]) < 10 and self.data != None):338 if len(mask[mask]) < 10 and self.data != None: 422 339 self.ShowMessage() 423 340 mask = copy.deepcopy(self.mask) … … 454 371 zmin = min(self.data.data[self.data.data > 0]) 455 372 # plot 456 plot =self.plotpanel.image(data=temp_mask,457 qx_data=self.data.qx_data,458 qy_data=self.data.qy_data,459 xmin=self.data.xmin,460 xmax=self.data.xmax,461 ymin=self.data.ymin,462 ymax=self.data.ymax,463 zmin=zmin,464 zmax=zmax,465 cmap=self.cmap,466 color=0, symbol=0, label=self.data.name)373 self.plotpanel.image(data=temp_mask, 374 qx_data=self.data.qx_data, 375 qy_data=self.data.qy_data, 376 xmin=self.data.xmin, 377 xmax=self.data.xmax, 378 ymin=self.data.ymin, 379 ymax=self.data.ymax, 380 zmin=zmin, 381 zmax=zmax, 382 cmap=self.cmap, 383 color=0, symbol=0, label=self.data.name) 467 384 # axis labels 468 385 self.plotpanel.axes[0].set_xlabel('$\\rm{Q}_{x}(A^{-1})$') … … 583 500 """ 584 501 cal_plot = CalcPlot(panel=self.plotpanel, 585 586 502 image=self.newplot, 503 completefn=self.complete) 587 504 cal_plot.queue() 588 505 … … 625 542 pass 626 543 627 628 544 def _draw_model(self, event): 629 545 """ … … 655 571 pass 656 572 657 658 573 class Maskplotpanel(PlotPanel): 659 574 """ 660 575 PlotPanel for Quick plot and masking plot 661 576 """ 662 def __init__(self, parent, id=-1, dimension=2, color=None, 663 dpi=None, **kwargs): 577 def __init__(self, parent, id=-1, dimension=2, color=None, dpi=None, **kwargs): 664 578 """ 665 579 """ … … 757 671 status_type = 'stop' 758 672 759 if self.dimension == 3: 760 pass 761 else: 673 if not self.dimension == 3: 762 674 self.subplot.figure.canvas.draw_idle() 763 675 … … 798 710 Status msg 799 711 """ 800 if type == "stop":801 label = "Plotting..."802 able = True803 else:804 label = "Wait..."805 able = False806 712 if self.parent.parent.parent != None: 807 808 713 wx.PostEvent(self.parent.parent.parent, 714 StatusEvent(status=msg, type=type)) 809 715 810 716 class ViewerFrame(wx.Frame):
Note: See TracChangeset
for help on using the changeset viewer.