Advertisement
Guest User

Paw Animation

a guest
Feb 16th, 2011
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue Feb 15 14:34:46 2011
  4.  
  5. @author: Ivo
  6. """
  7.  
  8. '''
  9. Created on 15 feb 2011
  10.  
  11. @author: Ivo
  12. '''
  13.  
  14. import sys, time, os, gc
  15. import matplotlib
  16. matplotlib.use('WXAgg')
  17. from matplotlib import rcParams
  18. import numpy as np
  19. import matplotlib.cm as cm
  20. import matplotlib.pyplot as plt
  21. from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
  22. from matplotlib.figure import Figure
  23. from wx import *
  24. import h5py
  25. sys.path.append("C:\\IvoPython\\PyDev\\")
  26. import data
  27.  
  28.  
  29. class DataCollect(object):
  30.     """ This class receives a frame from the measurement and then passes it on
  31.    """
  32.     def __init__(self, array3d, init = 0):
  33.         self.init = init
  34.         self.array3d = array3d
  35.         self.maxsize = np.shape(self.array3d)[2]
  36.         self.curFrame = self.init
  37.        
  38.     def next(self):
  39.         if self.curFrame < self.maxsize:
  40.             slice = self.curFrame
  41.         elif self.curFrame == self.maxsize:
  42.             exit(0)
  43.         self.data = self.array3d[:,:,slice]
  44.         self.curFrame += 1
  45.         return self.data
  46.  
  47. TIMER_ID = NewId()
  48.  
  49. class PlotFigure(Frame):
  50.     """ This class draws a window and updates it with data from DataCollect
  51.    """
  52.     def __init__(self):
  53.         Frame.__init__(self, None, -1, "Test embedded wxFigure")
  54.         self.fig = Figure((3,3), 75) #Varying the size of Figure has a big influence on the speed
  55.         self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
  56.         EVT_TIMER(self, TIMER_ID, self.onTimer)
  57.  
  58.     def init_plot_data(self):
  59.         self.datagen = DataCollect(array3d)
  60.         self.axes = self.fig.add_subplot(111)
  61.         self.axes.imshow(self.datagen.next().T)
  62.  
  63.     def onTimer(self, evt):
  64.         self.data = self.datagen.next()
  65.         self.axes.imshow(self.datagen.next().T)
  66.         self.canvas.draw()
  67.  
  68. if __name__ == '__main__':
  69.     # Code required to load a measurement
  70.     basedir = os.path.dirname('C:\\IvoPython\\paw-analysis\\')
  71.     datafile = h5py.File(basedir+'\\data.hdf5', 'r')
  72.     dog = 'Bell Oscar'
  73.     for measurement in data.dogs['/' +  dog]:    
  74.         if  'sel_1' in measurement.name:
  75.             array3d = measurement.data
  76.     # Code for creating a Window
  77.     app = PySimpleApp()
  78.     frame = PlotFigure()
  79.     frame.init_plot_data()
  80.     t = Timer(frame, TIMER_ID)
  81.     t.Start(1)
  82.     frame.Show()
  83.     app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement