def display(self, map, det=None, xrmfile=None, xoff=0, yoff=0, with_savepos=True, **kws): self.xoff = xoff self.yoff = yoff self.det = det self.xrmfile = xrmfile self.map = map self.title = '' if 'title' in kws: self.title = kws['title'] if 'contrast_level' not in kws: kws['contrast_level'] = 0.5 ImageFrame.display(self, map, **kws) # self.set_contrast_levels() if self.save_callback is not None and hasattr(self, 'pos_name'): self.pos_name.Enable(with_savepos) sd = kws.get('subtitles', None) if sd is not None: for i, name in enumerate(('red', 'green', 'blue')): sub = sd.get(name, None) if sub is not None: self.cmap_panels[i].title.SetLabel(sub)
def display(self, map, det=None, xrmfile=None, xoff=0, yoff=0, **kws): self.xoff = xoff self.yoff = yoff self.det = det self.xrmfile = xrmfile self.map = map self.title = '' if 'title' in kws: self.title = kws['title'] ImageFrame.display(self, map, **kws) if 'x' in kws: self.panel.xdata = kws['x'] if 'y' in kws: self.panel.ydata = kws['y'] if self.panel.conf.auto_contrast: self.set_contrast_levels() if self.wxmplot_version > 0.921: sd = kws.get('subtitles', {}) if sd is None: return t_red = sd.get('red', None) t_green = sd.get('green', None) t_blue = sd.get('blue', None) if t_red is not None: self.cmap_panels[0].title.SetLabel(t_red) if t_green is not None: self.cmap_panels[1].title.SetLabel(t_green) if t_blue is not None: self.cmap_panels[2].title.SetLabel(t_blue)
def display(self, map, det=None, xrmfile=None, xoff=0, yoff=0, with_savepos=True, **kws): self.xoff = xoff self.yoff = yoff self.det = det self.xrmfile = xrmfile self.map = map self.title = '' if 'title' in kws: self.title = kws['title'] ImageFrame.display(self, map, **kws) if 'x' in kws: self.panel.xdata = kws['x'] if 'y' in kws: self.panel.ydata = kws['y'] self.set_contrast_levels() if self.save_callback is not None and hasattr(self, 'pos_name'): self.pos_name.Enable(with_savepos) sd = kws.get('subtitles', None) if sd is not None: for i, name in enumerate(('red', 'green', 'blue')): sub = sd.get(name, None) if sub is not None: self.cmap_panels[i].title.SetLabel(sub)
def display(self, map, det=None, xrmfile=None, xoff=0, yoff=0, **kws): self.xoff = xoff self.yoff = yoff self.det = det self.xrmfile = xrmfile self.map = map self.title = '' if 'title' in kws: self.title = kws['title'] ImageFrame.display(self, map, **kws) if 'x' in kws: self.panel.xdata = kws['x'] if 'y' in kws: self.panel.ydata = kws['y'] if self.panel.conf.auto_contrast: self.set_contrast_levels()
def display(self, map, xrmfile=None, ai=None, mask=None, **kws): self.xrmfile = xrmfile self.map = map self.title = '' if 'title' in kws: self.title = kws['title'] ImageFrame.display(self, map, **kws) if self.panel.conf.auto_contrast: self.set_contrast_levels() self.ai = ai self.mask = mask if np.shape(self.mask) == np.shape(map): self.masked_map = map * (np.ones(np.shape(self.mask))-mask.value) self.panel.xdata = np.arange(map.shape[0]) self.panel.ydata = np.arange(map.shape[0])
def display_map(self, map, title='', info='', x=None, y=None, det=None, with_config=True): """display a map in an available image display""" displayed = False while not displayed: try: imd = self.im_displays.pop() imd.display(map, title=title, x=x, y=y) displayed = True except IndexError: on_lasso = Closure(self.lassoHandler, det=det) imd = ImageFrame(output_title=title, lasso_callback=on_lasso, config_on_frame=with_config) imd.display(map, title=title, x=x, y=y) displayed = True except PyDeadObjectError: displayed = False self.im_displays.append(imd) imd.SetStatusText(info, 1) imd.Show() imd.Raise()
def onLoadMask(self, evt=None): wildcards = 'pyFAI mask (*.edf)|*.edf|All files (*.*)|*.*' dlg = wx.FileDialog(self, message='Choose XRD mask file', defaultDir=os.getcwd(), wildcard=wildcards, style=wx.FD_OPEN) edffile, read = None, False if dlg.ShowModal() == wx.ID_OK: read = True edffile = dlg.GetPath().replace('\\', '/') dlg.Destroy() if read: print('Reading mask file: %s' % edffile) try: import fabio self.mask = fabio.open(edffile).data self.masked_map = self.map * (np.ones(np.shape(self.mask))-self.mask) self.MskCkBx.SetValue(True) ImageFrame.display(self, self.masked_map) except: print('File must be .edf format; user must have fabio installed.')
def onApplyMask(self, event): ''' Applies mask to 2DXRD map mkak 2016.09.29 ''' if event.GetEventObject().GetValue(): if self.masked_map is None: print('Mask file not defined.') question = 'No mask found in map file. Would you like to load a new file now?' caption = 'Load mask file?' dlg = wx.MessageDialog(self, question, caption, wx.YES_NO | wx.ICON_QUESTION) print 'answer:', dlg.ShowModal() # == wx.ID_YES read = dlg.ShowModal() dlg.Destroy() if read == wx.ID_YES: self.onLoadMask() self.MskCkBx.SetValue(False) else: ImageFrame.display(self, self.masked_map) else: ImageFrame.display(self, self.map)
def onApplyMask(self, event): ''' Applies mask to 2DXRD map mkak 2016.09.29 ''' if event.GetEventObject().GetValue(): if self.masked_map is None: print('Mask file not defined.') question = 'No mask found in map file. Would you like to load a new file now?' caption = 'Load mask file?' dlg = wx.MessageDialog(self, question, caption, wx.YES_NO | wx.ICON_QUESTION) print( 'answer:', dlg.ShowModal()) # == wx.ID_YES read = dlg.ShowModal() dlg.Destroy() if read == wx.ID_YES: self.onLoadMask() self.MskCkBx.SetValue(False) else: ImageFrame.display(self, self.masked_map) else: ImageFrame.display(self, self.map)
import sys if not hasattr(sys, 'frozen'): import wxversion wxversion.ensureMinimal('2.8') import wx from tifffile import imread from wxmplot import ImageFrame img = imread("ceo2.tiff") app = wx.App() frame = ImageFrame() frame.display(img) frame.Show() app.MainLoop()
# # read Pilatus image into numpy array import sys if not hasattr(sys, 'frozen'): import wxversion wxversion.ensureMinimal('2.8') import wx from tifffile import imread from wxmplot import ImageFrame dat = imread('Pilatus.tiff') app = wx.App() frame = ImageFrame() frame.display(dat) frame.Show() app.MainLoop()
def gauss2d(x, y, x0, y0, sx, sy): return outer( exp( -(((y-y0)/float(sy))**2)/2), exp( -(((x-x0)/float(sx))**2)/2) ) if __name__ == '__main__': app = wx.App() frame = ImageFrame(mode='rgb') ny, nx = 350, 400 x = arange(nx) y = arange(ny) ox = x / 100.0 oy = -1 + y / 200.0 red = 2. * random.random(size=nx*ny).reshape(ny, nx) red = red + 0.25 + (6.0*gauss2d(x, y, 90, 76, 5, 6) + 3.0*gauss2d(x, y, 160, 190, 70, 33) + 2.0*gauss2d(x, y, 180, 100, 12, 6)) green = 0.3 * random.random(size=nx*ny).reshape(ny, nx) green = green + 0.11 + (1.0*gauss2d(x, y, 175, 98, 3, 7) + 1.2*gauss2d(x, y, 270, 230, 78, 63)) blue = 0.6 * random.random(size=nx*ny).reshape(ny, nx) blue = blue + (2.9*gauss2d(x, y, 240, 265, 78, 23) + 3.5*gauss2d(x, y, 181, 93, 34, 11) + 7.0*gauss2d(x, y, 220, 310, 40, 133)) dat = array([red, green, blue]).swapaxes(2, 0) frame.display(dat, x=ox, y=oy, subtitles={'red':'Red Image', 'green': 'Green Blob', 'blue': 'other'}) frame.Show() app.MainLoop()
import sys if not hasattr(sys, 'frozen'): import wxversion wxversion.ensureMinimal('2.8') import wx import numpy import Image from wxmplot import ImageFrame img = Image.open("ceo2.tiff") h, v = img.size app = wx.App() frame = ImageFrame() frame.display(numpy.array(img.getdata()).reshape(h, v)[::-1]) frame.Show() app.MainLoop()
import sys import wx import numpy as np from wxmplot import ImageFrame y, x = np.mgrid[-5:5:101j, -4:6:101j] dat = np.sin(x*x/3.0 + y*y)/(1 + (x+y)*(x+y)) x0 = x[0,:] y0 = y[:,0] app = wx.App() frame = ImageFrame(mode='intensity') frame.display(dat, x=x0, y=y0) frame.Show() app.MainLoop()
import sys import wx from tifffile import imread from wxmplot import ImageFrame img = imread('Pilatus.tiff') app = wx.App() frame = ImageFrame() frame.display(img) frame.Show() app.MainLoop()
import sys import wx from numpy import exp, random, arange, outer from wxmplot import ImageFrame def gauss2d(x, y, x0, y0, sx, sy): return outer(exp(-(((y - y0) / float(sy))**2) / 2), exp(-(((x - x0) / float(sx))**2) / 2)) if __name__ == '__main__': app = wx.App() frame = ImageFrame() ny, nx = 350, 400 x = arange(nx) y = arange(ny) ox = x / 100.0 oy = -1 + y / 200.0 dat = 0.3 * random.random(size=nx * ny).reshape(ny, nx) dat = dat + (16.0 * gauss2d(x, y, 190, 96, 15, 26) + 27.0 * gauss2d(x, y, 140, 210, 51, 42)) frame.display(dat, x=ox, y=oy, style='contour', contour_labels=True) frame.Show() app.MainLoop()
import sys if not hasattr(sys, "frozen"): import wxversion wxversion.ensureMinimal("2.8") import wx from numpy import exp, random, arange, outer from wxmplot import ImageFrame def gauss2d(x, y, x0, y0, sx, sy): return outer(exp(-(((y - y0) / float(sy)) ** 2) / 2), exp(-(((x - x0) / float(sx)) ** 2) / 2)) if __name__ == "__main__": app = wx.App() frame = ImageFrame() ny, nx = 350, 400 x = arange(nx) y = arange(ny) ox = x / 100.0 oy = -1 + y / 200.0 dat = 0.3 * random.random(size=nx * ny).reshape(ny, nx) dat = dat + (16.0 * gauss2d(x, y, 190, 96, 15, 26) + 27.0 * gauss2d(x, y, 140, 210, 51, 42)) frame.display(dat, x=ox, y=oy, style="contour", contour_labels=True) frame.Show() app.MainLoop()
import wx from numpy import exp, random, arange, outer from wxmplot import ImageFrame def gauss2d(x, y, x0, y0, sx, sy): return outer(exp(-(((y-y0)/float(sy))**2)/2), exp(-(((x-x0)/float(sx))**2)/2)) if __name__ == '__main__': app = wx.PySimpleApp() frame = ImageFrame(config_on_frame=True) ny, nx = 350, 400 x = arange(nx) y = arange(ny) ox = x / 62. oy = -2 + y / 97.0 dat = 0.2 + (0.3*random.random(size=nx*ny).reshape(ny, nx) + 6.0*gauss2d(x, y, 90, 76, 5, 6) + 1.0*gauss2d(x, y, 180, 100, 7, 3) + 1.0*gauss2d(x, y, 175, 98, 3, 7) + 0.5*gauss2d(x, y, 181, 93, 4, 11) + 1.8*gauss2d(x, y, 270, 230, 78, 63) + 0.9*gauss2d(x, y, 240, 265, 8, 3) + 7.0*gauss2d(x, y, 40, 310, 2, 3) ) frame.display(dat, x=ox, y=oy) frame.Show() app.MainLoop()
import sys import wx from tifffile import imread from wxmplot import ImageFrame img = imread('ceo2.tiff') app = wx.App() frame = ImageFrame() frame.display(img, contrast_level=0.1, colormap='plasma') frame.Show() app.MainLoop()
# # read Pilatus image into numpy array import sys import wx from tifffile import imread from wxmplot import ImageFrame dat = imread('Pilatus.tiff') app = wx.App() frame = ImageFrame() frame.display(dat) frame.Show() app.MainLoop()
return outer( exp( -(((y-y0)/float(sy))**2)/2), exp( -(((x-x0)/float(sx))**2)/2) ) if __name__ == '__main__': app = wx.App() frame = ImageFrame(mode='rgb') ny, nx = 350, 400 x = arange(nx) y = arange(ny) ox = x / 100.0 oy = -1 + y / 200.0 red = 0.02 * random.random(size=nx*ny).reshape(ny, nx) red = red + (6.0*gauss2d(x, y, 90, 76, 5, 6) + 3.0*gauss2d(x, y, 165, 190, 70, 33) + 2.0*gauss2d(x, y, 180, 100, 12, 6)) green = 0.3 * random.random(size=nx*ny).reshape(ny, nx) green = green + (5.0*gauss2d(x, y, 173, 98, 4, 9) + 3.2*gauss2d(x, y, 270, 230, 78, 63)) blue = 0.1 * random.random(size=nx*ny).reshape(ny, nx) blue = blue + (2.9*gauss2d(x, y, 240, 265, 78, 23) + 3.5*gauss2d(x, y, 185, 95, 22, 11) + 7.0*gauss2d(x, y, 220, 310, 40, 133)) dat = array([red, green, blue]).swapaxes(2, 0) frame.display(dat, x=ox, y=oy, subtitles={'red':'Red Image', 'green': 'Green Blob', 'blue': 'other'}) frame.Show() app.MainLoop()
import sys import wx import numpy as np from wxmplot import ImageFrame y, x = np.mgrid[-5:5:101j, -4:6:101j] dat = np.sin(x * x / 3.0 + y * y) / (1 + (x + y) * (x + y)) x0 = x[0, :] y0 = y[:, 0] app = wx.App() frame = ImageFrame(mode='intensity') frame.display(dat, x=x0, y=y0) frame.Show() app.MainLoop()
import sys import wx from numpy import exp, random, arange, outer from wxmplot import ImageFrame def gauss2d(x, y, x0, y0, sx, sy): return outer(exp(-(((y-y0)/float(sy))**2)/2), exp(-(((x-x0)/float(sx))**2)/2)) ny, nx = 350, 400 x = arange(nx) y = arange(ny) ox = x / 62. oy = -2 + y / 97.0 dat = 0.2 + (0.3*random.random(size=nx*ny).reshape(ny, nx) + 6.0*gauss2d(x, y, 90, 76, 5, 6) + 1.0*gauss2d(x, y, 180, 100, 7, 3) + 1.0*gauss2d(x, y, 175, 98, 3, 7) + 0.5*gauss2d(x, y, 181, 93, 4, 11) + 1.8*gauss2d(x, y, 270, 230, 78, 63) + 0.9*gauss2d(x, y, 240, 265, 8, 3) + 7.0*gauss2d(x, y, 40, 310, 2, 3) ) app = wx.App() frame = ImageFrame(mode='intensity') frame.display(dat, x=ox, y=oy) frame.Show() app.MainLoop()
import sys import wx from tifffile import imread from wxmplot import ImageFrame img = imread('ceo2.tiff') app = wx.App() frame = ImageFrame() frame.display(img, auto_contrast=True, colormap='plasma') frame.Show() app.MainLoop()