Changeset 162
- Timestamp:
- 05/06/08 17:19:16 (8 months ago)
- Files:
-
- branches/packaged_tools/NeuroTools/HDF5Tools/HDF5Factory/__init__.py (modified) (1 diff)
- branches/packaged_tools/NeuroTools/HDF5Tools/HDF5Factory/generator.py (modified) (1 diff)
- branches/packaged_tools/NeuroTools/HDF5Tools/HDF5Factory/highlevel.py (modified) (2 diffs)
- branches/packaged_tools/NeuroTools/HDF5Tools/HDF5Objects/__init__.py (modified) (1 diff)
- branches/packaged_tools/NeuroTools/HDF5Tools/HDF5Objects/h5movie.py (modified) (4 diffs)
- branches/packaged_tools/NeuroTools/HDF5Tools/__init__.py (modified) (1 diff)
- branches/packaged_tools/NeuroTools/HDF5Tools/h5objects_tests.py (modified) (11 diffs)
- branches/packaged_tools/NeuroTools/PythonObjects/__init__.py (modified) (1 diff)
- branches/packaged_tools/NeuroTools/__init__.py (modified) (1 diff)
- branches/packaged_tools/NeuroTools/h5howto.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/packaged_tools/NeuroTools/HDF5Tools/HDF5Factory/__init__.py
r136 r162 1 __path__.append('/home/thierry/ Django_Project/UnicDatabase_fromsvn/NeuroTools/HDF5Tools')1 __path__.append('/home/thierry/NeuroTools_Project/NeuroTools/HDF5Tools') 2 2 __all__ = ['highlevel', 'generator', 'navigator', 'structure', 'randomizer'] 3 3 branches/packaged_tools/NeuroTools/HDF5Tools/HDF5Factory/generator.py
r136 r162 231 231 return node.retrieve(url, format) 232 232 233 def createMovie(self, url, where, name, interlace = "INTERLACE_PIXEL",title = '', tags=None, createparents=False, overwrite = False) :233 def createMovie(self, url, where, name, interlace = "INTERLACE_PIXEL",title = '', frame_duration = None, tags=None, createparents=False, overwrite = False) : 234 234 235 235 if overwrite : 236 236 self._overwrite(where, name) 237 237 parentNode = self._getOrCreatePath(where, createparents) 238 return h5movie.H5Movie(parentNode, name, url=url, interlace = interlace, title = title, tags=tags, _open = True)238 return h5movie.H5Movie(parentNode, name, url=url, interlace = interlace, title = title, frame_duration=frame_duration, tags=tags, _open = True) 239 239 240 240 def createVLMovie(self, url, where, name, interlace = "INTERLACE_PIXEL",title = '', createparents=False, overwrite = False) : branches/packaged_tools/NeuroTools/HDF5Tools/HDF5Factory/highlevel.py
r136 r162 137 137 elif isinstance(obj, SpikeList) : 138 138 object = self.createSpikeList(obj, where, name, tags=tags, title=title, createparents = createparents, overwrite=overwrite) 139 # 139 #detect if it is the url of a image file or movie directory 140 140 elif isinstance(obj, str) and (len(obj.split('//')) > 1) : 141 141 if os.path.isfile(obj.split('//')[-1]) : … … 143 143 elif os.path.isdir(obj.split('//')[-1]) : 144 144 object = self.createMovie(obj, where, name, title=title, createparents = createparents, overwrite=overwrite) 145 #detect if it is a numpy array or convert a python regular array into numpy array 145 146 elif isinstance(obj, ndarray) | isinstance(obj, list) | isinstance(obj, tuple) : 146 147 if isinstance(obj, list) | isinstance(obj, tuple) : branches/packaged_tools/NeuroTools/HDF5Tools/HDF5Objects/__init__.py
r136 r162 1 __path__.append('/home/thierry/ Django_Project/UnicDatabase_fromsvn/NeuroTools/HDF5Tools')1 __path__.append('/home/thierry/NeuroTools_Project/NeuroTools/HDF5Tools') 2 2 __all__ = ['h5spiketrain', 'h5spikelist', 'h5serializer', 'h5image', 'h5movie'] branches/packaged_tools/NeuroTools/HDF5Tools/HDF5Objects/h5movie.py
r136 r162 162 162 return images 163 163 164 def append(self, images_list, interlace=None, subclass=None, components=None, tags = None, _open = False) :164 def append(self, images_list, interlace=None, subclass=None, components=None, frame_duration = None, tags = None, _open = False) : 165 165 #look if images is an url or a list of url 166 166 if isinstance(images_list, str) : … … 193 193 self._v_attrs.MOVIE_DISPLAY_ORIGIN = 'UL' 194 194 self._v_attrs.MOVIE_COLORMODEL = image.mode 195 self._v_attrs.MOVIE_FRAME_DURATION = frame_duration 195 196 if components in [2, 4] : 196 197 self._v_attrs.MOVIE_TRANSPARENCY = components - 1 … … 206 207 cnt += 1 207 208 208 def __init__(self, parentNode, name, url = None, interlace = 'INTERLACE_PIXEL', tags=None, im_per_sec = 50, title = '', _log = True, _open = False) :209 def __init__(self, parentNode, name, url = None, interlace = 'INTERLACE_PIXEL', tags=None, frame_duration = None, title = '', _log = True, _open = False) : 209 210 if _open == True : 210 211 assert interlace in ['INTERLACE_PIXEL', 'INTERLACE_PLANE'], "interlace must be 'INTERLACE_PIXEL' or 'INTERLACE_PLANE'" … … 229 230 filters=filters_default, 230 231 _log=_log) 231 self.append(images, interlace=interlace, subclass=subclass, components=components, tags=tags, _open=_open)232 self.append(images, interlace=interlace, subclass=subclass, components=components, frame_duration = frame_duration, tags=tags, _open=_open) 232 233 else : 233 234 super(H5Movie, self).__init__(parentNode = parentNode, name = name) branches/packaged_tools/NeuroTools/HDF5Tools/__init__.py
r136 r162 1 __path__.append('/home/thierry/ Django_Project/UnicDatabase_fromsvn/NeuroTools')1 __path__.append('/home/thierry/NeuroTools_Project/NeuroTools') 2 2 __all__ = ['HDF5Objects', 'HDF5Factory'] 3 3 branches/packaged_tools/NeuroTools/HDF5Tools/h5objects_tests.py
r136 r162 1 1 import sys 2 sys.path.append('/home/thierry/ Django_Project/UnicDatabase_fromsvn')2 sys.path.append('/home/thierry/NeuroTools_Project') 3 3 from NeuroTools.HDF5Tools.HDF5Factory.highlevel import openH5File, HDF5File 4 4 from NeuroTools.PIL import Image … … 7 7 import unittest 8 8 from numpy import array 9 import os 9 10 10 11 class base_object(object) : … … 160 161 """Base class for the ImagePixelPersistanceTestCase and ImagePlanePersitanceTestCase.""" 161 162 def test_image(self) : 162 node = self.h5image 163 width = self.image.size[0] 164 self.assert_(width == node.shape[self.arg['width']], 'widths are not equal') 165 height = self.image.size[1] 166 self.assert_(height == node.shape[self.arg['height']], 'heights are not equal') 167 components = node.shape[self.arg['components']] 168 data = list(self.image.getdata()) 169 node_data = node.read() 170 self.assert_(components == len(data[0]), 'components are not equal') 171 self.assert_(node._v_attrs.IMAGE_INTERLACE_MODE == self.arg['interlace'], "interlace mode must be INTERLACE_PIXEL.") 172 self.assert_(node._v_attrs.IMAGE_COLORMODEL == self.image.mode, "color models are diffrent.") 173 self.assert_(node._v_attrs.IMAGE_DISPLAY_ORIGIN == 'UL', 'display origin must be UL.') 174 self.assert_(node._v_attrs.IMAGE_MINMAXRANGE == list(self.image.getextrema()), 'extrema are diffrent.') 175 if 'IMAGE_TRANSPARENCY' in node._v_attrs._f_list() : 176 self.assert_(node._v_attrs.IMAGE_TRANSPARENCY == components - 1, 'problem with alpha layer.') 177 self.assert_(node._v_attrs.IMAGE_TRANSPARENCY in [1,3], 'alpha layer only exists when number of components is 2 or 4.') 178 if self.image.mode == 'RGB' : 179 subclass = 'IMAGE_TRUECOLOR' 180 elif self.image.mode in ['1', 'L', 'LA'] : 181 subclass = 'IMAGE_GRAYSCALE' 182 elif self.image.mode in ['RGBA', 'CMY', 'CMYK', 'YCbCr', 'YUV', 'HSV'] : 183 subclass = 'IMAGE_BITMAP' 184 assert subclass == node._v_attrs.IMAGE_SUBCLASS 185 for tag in self.tags : 186 attr = getattr(node._v_attrs, tag) 187 self.assert_(self.tags[tag] == attr) 188 for h in range(height) : 189 for w in range(width) : 190 c = 0 191 pixel = data[h*width + w] 192 for color in pixel : 193 if self.arg['order'] == 'hwc' : 194 self.assert_(node_data[h, w, c] == color, "pixel components are not equal") 195 elif self.arg['order'] == 'chw' : 196 self.assert_(node_data[c, h, w] == color, "pixel components are not equal") 197 c += 1 163 cnt = 0 164 for h5image in self.h5images : 165 im = self.images[cnt] 166 node = h5image 167 width = im.size[0] 168 self.assert_(width == node.shape[self.arg['width']], 'widths are not equal') 169 height = im.size[1] 170 self.assert_(height == node.shape[self.arg['height']], 'heights are not equal') 171 components = node.shape[self.arg['components']] 172 data = list(im.getdata()) 173 node_data = node.read() 174 self.assert_(components == len(data[0]), 'components are not equal') 175 self.assert_(node._v_attrs.IMAGE_INTERLACE_MODE == self.arg['interlace'], "interlace mode must be INTERLACE_PIXEL.") 176 self.assert_(node._v_attrs.IMAGE_COLORMODEL == im.mode, "color models are diffrent.") 177 self.assert_(node._v_attrs.IMAGE_DISPLAY_ORIGIN == 'UL', 'display origin must be UL.') 178 self.assert_(node._v_attrs.IMAGE_MINMAXRANGE == list(im.getextrema()), 'extrema are diffrent.') 179 if 'IMAGE_TRANSPARENCY' in node._v_attrs._f_list() : 180 self.assert_(node._v_attrs.IMAGE_TRANSPARENCY == components - 1, 'problem with alpha layer.') 181 self.assert_(node._v_attrs.IMAGE_TRANSPARENCY in [1,3], 'alpha layer only exists when number of components is 2 or 4.') 182 if im.mode == 'RGB' : 183 subclass = 'IMAGE_TRUECOLOR' 184 elif im.mode in ['1', 'L', 'LA'] : 185 subclass = 'IMAGE_GRAYSCALE' 186 elif im.mode in ['RGBA', 'CMY', 'CMYK', 'YCbCr', 'YUV', 'HSV'] : 187 subclass = 'IMAGE_BITMAP' 188 assert subclass == node._v_attrs.IMAGE_SUBCLASS 189 for tag in self.tags : 190 attr = getattr(node._v_attrs, tag) 191 self.assert_(self.tags[tag] == attr) 192 for h in range(height) : 193 for w in range(width) : 194 c = 0 195 pixel = data[h*width + w] 196 for color in pixel : 197 if self.arg['order'] == 'hwc' : 198 self.assert_(node_data[h, w, c] == color, "pixel components are not equal") 199 elif self.arg['order'] == 'chw' : 200 self.assert_(node_data[c, h, w] == color, "pixel components are not equal") 201 c += 1 202 cnt += 1 198 203 199 204 def tearDown(self): … … 218 223 219 224 def setUp(self): 220 self.image = Image.open('/tmp/image.jpg') 221 self.image.load() 225 path = '/home/thierry/NeuroTools_Project/NeuroTools/Tests/Images' 226 self.paths = [os.path.join(path,f) for f in os.listdir(path) if os.path.isfile(os.path.join(path,f))] 227 self.images = [Image.open(im) for im in self.paths] 222 228 self.tags = {'testcase' : 'PersistanceTestCase', 'kind' : 'image pixel test'} 223 229 self.h5file = openH5File('file:///tmp/persistance_test.h5', 'w') 224 self.h5image = self.h5file.createImage('file:///tmp/image.jpg', '/', 'Image_Pixel', title='Image Test Pixel', interlace = 'INTERLACE_PIXEL', tags = self.tags) 230 id = 0 231 self.h5images = [] 232 for im in self.paths : 233 self.h5images.append(self.h5file.createImage('file://%s'%(im), '/', im.split('/')[-1].replace('.', '_'), title='Image Test Pixel', interlace = 'INTERLACE_PIXEL', tags = self.tags)) 225 234 self.arg = {'width' : 1,'height' : 0,'components' : 2, 'order' : 'hwc', 'interlace':'INTERLACE_PIXEL'} 226 235 227 def test_image_pixel(self) :228 super(ImagePixelPersistanceTestCase, self).test_image()236 ## def test_image_pixel(self) : 237 ## super(ImagePixelPersistanceTestCase, self).test_image() 229 238 230 239 class ImagePlanePersistanceTestCase(ImagePersistanceTestCase) : … … 246 255 247 256 def setUp(self): 248 self.image = Image.open('/tmp/image.jpg') 249 self.image.load() 250 self.tags = {'testcase' : 'PersistanceTestCase', 'kind' : 'image plane test'} 257 path = '/home/thierry/NeuroTools_Project/NeuroTools/Tests/Images' 258 self.paths = [os.path.join(path,f) for f in os.listdir(path) if os.path.isfile(os.path.join(path,f))] 259 self.images = [Image.open(im) for im in self.paths] 260 self.tags = {'testcase' : 'PersistanceTestCase', 'kind' : 'image pixel test'} 251 261 self.h5file = openH5File('file:///tmp/persistance_test.h5', 'w') 252 self.h5image = self.h5file.createImage('file:///tmp/image.jpg', '/', 'Image_Plane', title='Image Test Plane', interlace = 'INTERLACE_PLANE', tags = self.tags) 253 self.arg = {'width' : 2,'height' : 1,'components' : 0,'order':'chw', 'interlace' : 'INTERLACE_PLANE'} 254 255 def test_image_plane(self) : 256 super(ImagePlanePersistanceTestCase, self).test_image() 262 id = 0 263 self.h5images = [] 264 for im in self.paths : 265 self.h5images.append(self.h5file.createImage('file://%s'%(im), '/', im.split('/')[-1].replace('.', '_'), title='Image Test Plane', interlace = 'INTERLACE_PLANE', tags = self.tags)) 266 self.arg = {'width' : 2,'height' : 1,'components' : 0, 'order' : 'chw', 'interlace':'INTERLACE_PLANE'} 267 268 ## def test_image_plane(self) : 269 ## super(ImagePlanePersistanceTestCase, self).test_image() 257 270 258 271 class MoviePersistanceTestCase(unittest.TestCase) : … … 323 336 324 337 def setUp(self): 325 self.url = 'file:/// tmp/movie'338 self.url = 'file:///home/thierry/NeuroTools_Project/NeuroTools/Tests/Movies/moving_gbar' 326 339 self.tags = {'testcase' : 'PersistanceTestCase', 'kind' : 'movie pixel test'} 327 340 self.h5file = openH5File('file:///tmp/persistance_test.h5', 'w') … … 329 342 self.arg = {'width' : 2,'height' : 1,'components' : 3,'order':'hwc', 'interlace' : 'INTERLACE_PIXEL'} 330 343 331 def test_movie_pixel(self) :332 super(MoviePixelPersistanceTestCase, self).test_movie()344 ## def test_movie_pixel(self) : 345 ## super(MoviePixelPersistanceTestCase, self).test_movie() 333 346 334 347 class MoviePlanePersistanceTestCase(MoviePersistanceTestCase) : … … 337 350 338 351 def setUp(self): 339 self.url = 'file:/// tmp/movie'352 self.url = 'file:///home/thierry/NeuroTools_Project/NeuroTools/Tests/Movies/moving_gbar' 340 353 self.tags = {'testcase' : 'PersistanceTestCase', 'kind' : 'movie plane test'} 341 354 self.h5file = openH5File('file:///tmp/persistance_test.h5', 'w') … … 343 356 self.arg = {'width' : 3,'height' : 2,'components' : 1,'order':'chw', 'interlace' : 'INTERLACE_PLANE'} 344 357 345 def test_movie_plane(self) :346 super(MoviePlanePersistanceTestCase, self).test_movie()358 ## def test_movie_plane(self) : 359 ## super(MoviePlanePersistanceTestCase, self).test_movie() 347 360 348 361 class SpikeTrainInitializationTestCase(unittest.TestCase) : … … 430 443 """Verify that a image file could be initialiazed from a hdf5 image in interlace pixel mode : 431 444 432 1 - Initialize a PIL imagefrom file433 2 - create a hdf5 file that will store the hdf5 object corresponding to the imagein interlace pixel mode434 3 - create the hdf5 image object from the PIL image435 4 - create a new image from the hdf5 object445 1 - Initialize PIL images from file 446 2 - create a hdf5 file that will store the hdf5 objects corresponding to the images in interlace pixel mode 447 3 - create the hdf5 images object from the PIL images 448 4 - create new images from the hdf5 objects 436 449 5 - compare the 2 images 437 450 … … 452 465 """Verify that a image file could be initialiazed from a hdf5 image in interlace plane mode : 453 466 454 1 - Initialize a PIL imagefrom file455 2 - create a hdf5 file that will store the hdf5 object corresponding to the imagein interlace plane mode456 3 - create the hdf5 image object from the PIL image457 4 - create a new image from the hdf5 object467 1 - Initialize PIL images from file 468 2 - create a hdf5 file that will store the hdf5 objects corresponding to the images in interlace plane mode 469 3 - create the hdf5 images object from the PIL images 470 4 - create new images from the hdf5 objects 458 471 5 - compare the 2 images 459 472 branches/packaged_tools/NeuroTools/PythonObjects/__init__.py
r136 r162 1 __path__.append('/home/thierry/ Django_Project/UnicDatabase_fromsvn/NeuroTools')1 __path__.append('/home/thierry/NeuroTools_Project/NeuroTools') 2 2 __all__ = ['spikes'] branches/packaged_tools/NeuroTools/__init__.py
r136 r162 1 __path__.append('/home/thierry/ Django_Project/UnicDatabase_fromsvn')1 __path__.append('/home/thierry/NeuroTools_Project') 2 2 __path__.append('/usr/lib/python2.5/site-packages') 3 3 __all__ = ['PIL', 'tables', 'PythonObjects', 'HDF5Tools'] branches/packaged_tools/NeuroTools/h5howto.py
r136 r162 10 10 11 11 import sys 12 sys.path.append('/home/thierry/ Django_Project/UnicDatabase_fromsvn')12 sys.path.append('/home/thierry/NeuroTools_Project') 13 13 from NeuroTools.HDF5Tools.HDF5Factory.highlevel import openH5File, HDF5File 14 14 from NeuroTools.PythonObjects.spikes import SpikeTrain, SpikeList 15 from numpy import ndarray, array16 15 17 16 if __name__ == '__main__' : 18 print "Init Objects." 19 #initialize a spiketrain 17 #create a SpikeTrain object 20 18 times = [1.1,2.4,3.5,4.6,5.9,6.6,7.2,8.1,9.4,10.5] 21 19 spiketrain = SpikeTrain(times, dt=0.1, t_start=times[0], t_stop=times[-1]) 22 tags_1 = {'comment1' : 'comment1 ...', 'comment2' : 'comment2...', 'quality' : 2} #optional 23 #initialize a spikelist 20 #create a SpikeList object 24 21 id_list = [1,2,3,4] 25 22 spikes = [(1,0.1), (1,1.2), (1,2.4), (1,3.6), (1,4.1), (1,5.7), (1,6.3), 26 (2,0.6), (2,1.3), (2,2.4), (2,3.7), (2,5.7),27 (3,1.2), (3,2.3), (3,4.1), (3,7.9), (3,9.3),28 (4,0.1), (4,2.4), (4,4.1), (4,7.2), (4,8.5), (4,9.4)]23 (2,0.6), (2,1.3), (2,2.4), (2,3.7), (2,5.7), 24 (3,1.2), (3,2.3), (3,4.1), (3,7.9), (3,9.3), 25 (4,0.1), (4,2.4), (4,4.1), (4,7.2), (4,8.5), (4,9.4)] 29 26 spikelist = SpikeList(spikes, id_list,dt=0.1, t_start=0.1, t_stop=9.4) 30 tags_2 = {'comment1' : 'comment1 ...', 'comment2' : 'comment2...', 'quality' : 4} #optional 31 # 32 lst = [[1,2,3,4,5,8,7,8,9,7,], [1,2,3], [8,5,9,6,8,7], ['a', 'b', 'c']] 33 tags_3 = {'comment1' : 'comment1 ...', 'comment2' : 'comment2...'} 34 #open a h5 file in write mode 27 #define the file tree with a dictionary 28 structure = {"FirstNode" :{'tags' : {'comment' : "this is the first node"}, 29 'FirstLeaf' : {'dataset' : "file:///tmp/neurons.jpg", 30 'tags' : {'comments' : 'this is an image'}}, 31 'SecondLeaf':{'dataset' : "file:///tmp/moving_gbar", 32 'tags' : {'comments' : 'this is a movie'}}, 33 'ThirdLeaf' : {'dataset':spiketrain, 'tags':{'comment':'this is a spiketrain'}}, 34 'ForthLeaf' : {'dataset':spikelist, 'tags':{'comment':'this is a spikelist'}} 35 }, 36 "SecondNode":{'tags': {'comment' : "this is a clone of the first node"}, 37 'FirstCloneLeaf' : {'dataset' : "file:///tmp/neurons.jpg", 38 'tags' : {'comments' : 'this is the same image'}}, 39 'SecondCloneLeaf':{'dataset' : "file:///tmp/moving_gbar", 40 'tags' : {'comments' : 'this is the same movie'}}, 41 'ThirdLeaf' : {'dataset':spiketrain, 'tags':{'comment':'this is a clone spiketrain'}}, 42 'ForthLeaf' : {'dataset':spikelist, 'tags':{'comment':'this is a clone spikelist'}} 43 }, 44 } 45 #store data 35 46 h5file = openH5File('file:///tmp/howto.h5', 'w') 36 #set a hdf5 structure 37 print "Set a h5file structure" 38 structure = {'array' : {'dataset' : [1,2,3], 'dataset' : [[1,2,3,4],[7,8,9,8,7,8]], 'attr1' :10, 'attr2' :20}, 39 'spiketrain' : {'dataset' : spiketrain, 'attr1' :10, 'attr2' :20, 'tags' : tags_1}, 40 'spikelist' : {'dataset' : spikelist, 'attr1' :10, 'attr2' :20, 'tags' : tags_2}, 41 'list' : {'dataset' : lst, 'attr1':20, 'attr2' : 30, 'tags' : tags_3}} 42 h5file.setStructure(structure, '/Group1', createparents=True, overwrite=True) 43 h5file.setStructure(structure, '/Group2', createparents=True, overwrite=True) 44 print "Structure done." 45 struct = h5file.getStructure("/", raw = False, attrset = 'user') 46 print struct 47 print "Structure done." 48 49 #put data in hdf5 file : 50 print "Add data to h5file." 51 #convert the spiketrain into a h5 object under a specified node and append some tags 52 h5spiketrain = h5file.createSpikeTrain(spiketrain, '/Group3', 'SpikeTrain', 'SpikeTrain', tags=tags_1, createparents=True) 53 #convert the spiketrain into a h5 object under a specified node and append some tags 54 h5spikelist = h5file.createSpikeList(spikelist, '/Group3', 'SpikeList', 'SpikeList', tags=tags_2, createparents=True) 55 #add an image under a specified node and add some tags 56 tags = {'comment1' : 'comment1', 'quality' : 3} 57 h5image = h5file.createImage('file:///tmp/image.jpg', '/Group3', 'Image_Pixel', title='Image Pixel', interlace = 'INTERLACE_PIXEL', tags = tags) 58 h5image = h5file.createImage('file:///tmp/image.jpg', '/Group3', 'Image_Plane', title='Image Plane', interlace = 'INTERLACE_PLANE', tags = tags) 59 #make movie from a folder that contains multiple image file under specified node and add some tags 60 tags = {'comment1' : 'comment1', 'quality' : 2} 61 h5image = h5file.createMovie('file:///tmp/movie', '/Group3', 'Movie_Pixel', title='Movie Pixel', interlace = 'INTERLACE_PIXEL', tags = tags, createparents=True) 62 h5image = h5file.createMovie('file:///tmp/movie', '/Group3', 'Movie_Plane', title='Movie Plane', interlace = 'INTERLACE_PLANE', tags = tags, createparents=True) 63 #make a known object into the h5 tree 64 ar = ndarray([3,2], dtype = 'int8') 65 ar[:] = [[4,5],[8,9],[10,11]] 66 obj = h5file.store(ar, "/Group3", "NDArray", createparents=True) 47 h5file.setStructure(structure, "/AllNodes", createparents=True) 67 48 h5file.list() 68 49 h5file.close() 69 print "Data added." 70 print "Retrieve data from h5file." 71 #retrieve data from each node 50 51 #retrieve data 72 52 h5file = openH5File('file:///tmp/howto.h5', 'r') 73 #retrieve spiketrain 74 h5file.retrieveSpikeTrain('/Group3/SpikeTrain') 75 #retrieve spikelist 76 h5file.retrieveSpikeList('/Group3/SpikeList') 77 #retrieve image 78 h5file.convertImage('file:///tmp/convertion_pixel.png', "/Group3/Image_Pixel", format = 'png') 79 image_1 = h5file.retrieveImage('file:///tmp/convertion_pixel.png', "/Group3/Image_Pixel", format = 'png') 80 h5file.convertImage('file:///tmp/convertion_plane.png', "/Group3/Image_Plane", format = 'png') 81 image_2 = h5file.retrieveImage('file:///tmp/convertion_plane.png', "/Group3/Image_Plane", format = 'png') 82 #retrieve movie 83 h5file.convertMovie('file:///tmp/convertion_pixel', "/Group3/Movie_Pixel", format = 'png') 84 movie_1 = h5file.retrieveMovie('file:///tmp/convertion_pixel', "/Group3/Movie_Pixel", format = 'png') 85 h5file.convertMovie('file:///tmp/convertion_plane', "/Group3/Movie_Plane", format = 'png') 86 movie_2 = h5file.retrieveMovie('file:///tmp/convertion_plane', "/Group3/Movie_Plane", format = 'png') 87 #retrieve NDArray 88 print h5file.root.Group3.NDArray.read() 53 structure = h5file.getStructure("/AllNodes", raw=False, attrset='user') 89 54 h5file.close() 90 print "Retrieval ended." 55 56 ## print "Init Objects." 57 ## #initialize a spiketrain 58 ## times = [1.1,2.4,3.5,4.6,5.9,6.6,7.2,8.1,9.4,10.5] 59 ## spiketrain = SpikeTrain(times, dt=0.1, t_start=times[0], t_stop=times[-1]) 60 ## tags_1 = {'comment1' : 'comment1 ...', 'comment2' : 'comment2...', 'quality' : 2} #optional 61 ## #initialize a spikelist 62 ## id_list = [1,2,3,4] 63 ## spikes = [(1,0.1), (1,1.2), (1,2.4), (1,3.6), (1,4.1), (1,5.7), (1,6.3), 64 ## (2,0.6), (2,1.3), (2,2.4), (2,3.7), (2,5.7), 65 ## (3,1.2), (3,2.3), (3,4.1), (3,7.9), (3,9.3), 66 ## (4,0.1), (4,2.4), (4,4.1), (4,7.2), (4,8.5), (4,9.4)] 67 ## spikelist = SpikeList(spikes, id_list,dt=0.1, t_start=0.1, t_stop=9.4) 68 ## tags_2 = {'comment1' : 'comment1 ...', 'comment2' : 'comment2...', 'quality' : 4} #optional 69 ## # 70 ## lst = [[1,2,3,4,5,8,7,8,9,7,], [1,2,3], [8,5,9,6,8,7], ['a', 'b', 'c']] 71 ## tags_3 = {'comment1' : 'comment1 ...', 'comment2' : 'comment2...'} 72 ## #open a h5 file in write mode 73 ## h5file = openH5File('file:///tmp/howto.h5', 'w') 74 ## #set a hdf5 structure 75 ## print "Set a h5file structure" 76 ## structure = {'array' : {'dataset' : [1,2,3], 'dataset' : [[1,2,3,4],[7,8,9,8,7,8]], 'attr1' :10, 'attr2' :20}, 77 ## 'spiketrain' : {'dataset' : spiketrain, 'attr1' :10, 'attr2' :20, 'tags' : tags_1}, 78 ## 'spikelist' : {'dataset' : spikelist, 'attr1' :10, 'attr2' :20, 'tags' : tags_2}, 79 ## 'list' : {'dataset' : lst, 'attr1':20, 'attr2' : 30, 'tags' : tags_3}} 80 ## h5file.setStructure(structure, '/Group1', createparents=True, overwrite=True) 81 ## h5file.setStructure(structure, '/Group2', createparents=True, overwrite=True) 82 ## print "Structure done." 83 ## struct = h5file.getStructure("/", raw = False, attrset = 'user') 84 ## print struct 85 ## print "Structure done." 86 ## 87 ## #put data in hdf5 file : 88 ## print "Add data to h5file." 89 ## #convert the spiketrain into a h5 object under a specified node and append some tags 90 ## h5spiketrain = h5file.createSpikeTrain(spiketrain, '/Group3', 'SpikeTrain', 'SpikeTrain', tags=tags_1, createparents=True) 91 ## #convert the spiketrain into a h5 object under a specified node and append some tags 92 ## h5spikelist = h5file.createSpikeList(spikelist, '/Group3', 'SpikeList', 'SpikeList', tags=tags_2, createparents=True) 93 ## #add an image under a specified node and add some tags 94 ## tags = {'comment1' : 'comment1', 'quality' : 3} 95 ## h5image = h5file.createImage('file:///tmp/image.jpg', '/Group3', 'Image_Pixel', title='Image Pixel', interlace = 'INTERLACE_PIXEL', tags = tags) 96 ## h5image = h5file.createImage('file:///tmp/image.jpg', '/Group3', 'Image_Plane', title='Image Plane', interlace = 'INTERLACE_PLANE', tags = tags) 97 ## #make movie from a folder that contains multiple image file under specified node and add some tags 98 ## tags = {'comment1' : 'comment1', 'quality' : 2} 99 ## h5image = h5file.createMovie('file:///tmp/movie', '/Group3', 'Movie_Pixel', title='Movie Pixel', interlace = 'INTERLACE_PIXEL', tags = tags, createparents=True) 100 ## h5image = h5file.createMovie('file:///tmp/movie', '/Group3', 'Movie_Plane', title='Movie Plane', interlace = 'INTERLACE_PLANE', tags = tags, createparents=True) 101 ## #make a known object into the h5 tree 102 ## ar = ndarray([3,2], dtype = 'int8') 103 ## ar[:] = [[4,5],[8,9],[10,11]] 104 ## obj = h5file.store(ar, "/Group3", "NDArray", createparents=True) 105 ## h5file.list() 106 ## h5file.close() 107 ## print "Data added." 108 ## print "Retrieve data from h5file." 109 ## #retrieve data from each node 110 ## h5file = openH5File('file:///tmp/howto.h5', 'r') 111 ## #retrieve spiketrain 112 ## h5file.retrieveSpikeTrain('/Group3/SpikeTrain') 113 ## #retrieve spikelist 114 ## h5file.retrieveSpikeList('/Group3/SpikeList') 115 ## #retrieve image 116 ## h5file.convertImage('file:///tmp/convertion_pixel.png', "/Group3/Image_Pixel", format = 'png') 117 ## image_1 = h5file.retrieveImage('file:///tmp/convertion_pixel.png', "/Group3/Image_Pixel", format = 'png') 118 ## h5file.convertImage('file:///tmp/convertion_plane.png', "/Group3/Image_Plane", format = 'png') 119 ## image_2 = h5file.retrieveImage('file:///tmp/convertion_plane.png', "/Group3/Image_Plane", format = 'png') 120 ## #retrieve movie 121 ## h5file.convertMovie('file:///tmp/convertion_pixel', "/Group3/Movie_Pixel", format = 'png') 122 ## movie_1 = h5file.retrieveMovie('file:///tmp/convertion_pixel', "/Group3/Movie_Pixel", format = 'png') 123 ## h5file.convertMovie('file:///tmp/convertion_plane', "/Group3/Movie_Plane", format = 'png') 124 ## movie_2 = h5file.retrieveMovie('file:///tmp/convertion_plane', "/Group3/Movie_Plane", format = 'png') 125 ## #retrieve NDArray 126 ## print h5file.root.Group3.NDArray.read() 127 ## h5file.close() 128 ## print "Retrieval ended." 91 129 92 130

