def __init__(self, parent=None, size=(650, 650), mode='intensity', lasso_callback=None, move_callback=None, save_callback=None, show_xsections=False, cursor_labels=None, with_savepos=True,output_title='Image', **kws): self.det = None self.xrmfile = None self.map = None self.move_callback = move_callback self.save_callback = save_callback self.with_savepos = with_savepos ImageFrame.__init__(self, parent=parent, size=size, lasso_callback=lasso_callback, cursor_labels=cursor_labels, mode=mode, output_title=output_title, **kws) w0, h0 = self.GetSize() w1, h1 = self.GetBestSize() self.SetSize((max(w0, w1)+5, max(h0, h1)+5)) self.SetMinSize((500, 500)) self.prof_plotter = None self.zoom_ini = None self.lastpoint = [None, None] self.rbbox = None
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 __init__(self, parent=None, size=None, mode='intensity', lasso_callback=None, move_callback=None, save_callback=None, show_xsections=False, cursor_labels=None, output_title='Image', **kws): # instdb=None, inst_name=None, self.det = None self.xrmfile = None self.map = None self.move_callback = move_callback self.save_callback = save_callback ImageFrame.__init__(self, parent=parent, size=size, lasso_callback=lasso_callback, cursor_labels=cursor_labels, mode=mode, output_title=output_title, **kws) self.panel.add_cursor_mode('prof', motion = self.prof_motion, leftdown = self.prof_leftdown, leftup = self.prof_leftup) self.panel.report_leftdown = self.report_leftdown self.panel.report_motion = self.report_motion self.prof_plotter = None self.zoom_ini = None self.lastpoint = [None, None] self.this_point = None self.rbbox = None
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, 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 __init__(self, _larch=None, parent=None, size=None, mode='intensity', move_callback=None, save_callback=None, show_xsections=False, cursor_labels=None, output_title='Image', **kws): self.xrmfile = None self.map = None self.move_callback = move_callback self.save_callback = save_callback self.larch = _larch if self.larch is None: self.init_larch() ImageFrame.__init__(self, parent=parent, size=size, cursor_labels=cursor_labels, mode=mode, output_title=output_title, **kws) self.panel.cursor_mode = 'zoom' self.panel.xaxis = 'q' self.panel.report_leftdown = self.report_leftdown self.panel.report_motion = self.report_motion self.prof_plotter = None self.zoom_ini = None self.lastpoint = [None, None] self.this_point = None self.rbbox = None
def __init__(self, wxparent=None, window=1, _larch=None, **kws): ImageFrame.__init__(self, parent=wxparent, exit_callback=self.onExit, **kws) self.Show() self.Raise() self.cursor_pos = [] self.panel.cursor_callback = self.onCursor self.window = int(window) self.symname = '%s.img%i' % (MODNAME, self.window) self._larch = _larch symtable = ensuremod(self._larch) if symtable is not None: symtable.set_symbol(self.symname, self) if self.window not in IMG_DISPLAYS: IMG_DISPLAYS[self.window] = self
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 __init__(self, wxparent=None, window=1, _larch=None, size=None, **kws): ImageFrame.__init__(self, parent=None, size=size, exit_callback=self.onExit, **kws) self.Show() self.Raise() self.cursor_pos = [] self.panel.cursor_callback = self.onCursor self.panel.contour_callback = self.onContour self.window = int(window) self.symname = '%s.img%i' % (MODNAME, self.window) self._larch = _larch symtable = ensuremod(self._larch, MODNAME) if symtable is not None: symtable.set_symbol(self.symname, self) if self.window not in IMG_DISPLAYS: IMG_DISPLAYS[self.window] = self
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 ShowImageFrame(self): if self.imageframe is None: self.imageframe = ImageFrame(self) try: self.imageframe.Show() except PyDeadObjectError: self.imageframe = Imageframe(self) self.imageframe.Show() self.imageframe.display(self.arrays[0]) self.imageframe.Raise()
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 __init__(self, parent=None, size=(650, 650), mode='intensity', lasso_callback=None, move_callback=None, save_callback=None, show_xsections=False, cursor_labels=None, with_savepos=True,output_title='Image', **kws): # instdb=None, inst_name=None, self.det = None self.xrmfile = None self.map = None self.move_callback = move_callback self.save_callback = save_callback self.with_savepos = with_savepos ImageFrame.__init__(self, parent=parent, size=size, lasso_callback=lasso_callback, cursor_labels=cursor_labels, mode=mode, output_title=output_title, **kws) self.panel.add_cursor_mode('prof', motion = self.prof_motion, leftdown = self.prof_leftdown, leftup = self.prof_leftup) self.panel.report_leftdown = self.report_leftdown self.panel.report_motion = self.report_motion w0, h0 = self.GetSize() w1, h1 = self.GetBestSize() self.SetSize((max(w0, w1)+5, max(h0, h1)+5)) self.SetMinSize((500, 500)) self.prof_plotter = None self.zoom_ini = None self.lastpoint = [None, None] self.this_point = None self.rbbox = None
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)
""" example showing display of R, G, B maps """ import wx from numpy import exp, random, arange, outer, array 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(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))
# # 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()
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 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 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()
self.dataTest, linewidth=1, color=(0, 0, 1), )[0] def create_figure(self): self.init_plot() self.canvas = FigCanvas(self.panel, -1, self.fig) def draw_plot(self): xmax = len(self.dataTest) if len(self.dataTest) > 50 else 50 #ymax = round(max(self.dataTest), 0) + 1 ymax = 100 self.axes.set_xbound(0, xmax) self.axes.set_ybound(0, ymax) self.plot_data.set_xdata(np.arange(len(self.dataTest))) self.plot_data.set_ydata(np.array(self.dataTest)) self.canvas.draw() app = wx.App(False) frame = MainWindow(None, "Sample editor") frame = ImageFrame(mode='intensity') COMPort = [d.device for d in serial.tools.list_ports.comports()] 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()
def plot_variable(self, var_name, var, dataset): """ Use `wxmplot` to plot the selected variables. Args: var_name: Name of the variable var: Netcdf4 `Variable`. dataset: Netcdf4 `Dataset`. """ # Remove fake dimensions. shape, dimensions = [], [] for num, name in zip(var.shape, var.dimensions): if num > 1: shape.append(num) dimensions.append(name) # Get data to plot. data = np.reshape(var[:], shape) opts = self.GetPlotOptions() cplx_mode = opts.cplx_mode if cplx_mode != "None": if shape[-1] != 2: err_msg = "cplx_mode: %s. Expecting 2 as last dimensions but got %d" % ( cplx_mode, shape[-1]) raise ValueError(err_msg) # Convert to complex then change shape and dimensions data = data[..., 0] + 1j * data[..., 1] shape = shape[:-1] dimensions = dimensions[:-1] if cplx_mode == "Abs": data = np.abs(data) elif cplx_mode == "Real": data = data.real elif cplx_mode == "Imag": data = data.imag else: raise ValueError("Wrong value for cplx_mode %s" % cplx_mode) # Plotting a scalar? if not shape: return ndim = len(shape) if ndim == 1: # Vector dim_name = dimensions[0] xx = range(len(dataset.dimensions[dim_name])) from wxmplot import PlotFrame frame = PlotFrame(parent=self) if opts.plot_mode == "line": frame.plot(xx, data) else: frame.scatterplot(xx, data) frame.set_xlabel(dim_name) frame.set_ylabel(var_name) frame.Show() elif ndim == 2: # Two dimensional array. dim_namex, dim_namey = dimensions xx, yy = range(len(dataset.dimensions[dim_namex])), range( len(dataset.dimensions[dim_namey])) mode = opts.image_mode if False: # 3d plot import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = Axes3D(fig) X, Y = np.meshgrid(xx, yy, sparse=False, indexing='ij') print(X.shape, Y.shape, data.shape) ax.plot_surface(X, Y, data) # rstride=8, cstride=8, alpha=0.3) plt.show() from wxmplot import ImageFrame frame = ImageFrame(parent=self) frame.display(data, title=var_name, style=mode, x=xx, y=yy, xlabel=dim_namex, ylabel=dim_namey) frame.Show() else: raise NotImplementedError()
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 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 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()
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 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()
# # 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()
""" example showing display of R, G, B maps """ import wx from numpy import exp, random, arange, outer, array 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(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) +
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()