samedi 11 avril 2015

how to read multiple hdf files and close it simultaneously


Vote count:

0




how can I read multiple hdf files and store that data in files in a local variable and I need to close each file after storing the values in the local variable, how it possible? Is it can be done by append function.


Here my code because of time lag i need to close each file after getting the data approx 220 files I need to load.



from mayavi import mlab
import h5py
import numpy as np
from matplotlib import pyplot
import os
import Tkinter
mlab.figure(size = (3456,2304),bgcolor=(1,1,1))

global d,d1,d2,activation_times,save_count
save_count=0

activation_times=[]
d1=[]
d2=[]
d3=[]
myfile = h5py.File('800_800_150_gocconv50_June2014_withML.hdf5','r+')
myfile.keys()
d = myfile['/positions/granules']

global d1x,d1y,d1z,d2x,d2y,d2z


d1x = []
d1y = []
d1z = []
d2x = []
d2y = []
d2z = []

global cells
cells ={}


for i in range(0,2):
time = h5py.File('spike_time/net2_cpu%d.hdf5'%i,'r+')
#print time.keys()
#d1=time['/grc']
d1=time['/grc']
for ii,item in enumerate(d1):
#print item
cells[str(item)] = time['/grc/'+str(item)+'/spk']
#print "cells",cells[str(item)][:][:]

print "data loading done!!!",i



def activation_calls(timee):
print "timee",timee
#print float(1)/(2)
current_time = float(timee)/(40)
print "current_time=",current_time
for it,i in enumerate(d1):
#for i in range(0,300000): #number of cells

tt= i
activation_times=cells[str(tt)][:][:]
#print "activation_times",activation_times
for jj in range (len(activation_times)):

if activation_times[jj] == current_time:
d1x.append(d[i,0]*1e6)
d1y.append(d[i,1]*1e6)
d1z.append(d[i,2]*1e6)
break
else:
d2x.append(d[i,0]*1e6)
d2y.append(d[i,1]*1e6)
d2z.append(d[i,2]*1e6)

#time.close()

def rot_zoom():#rotate and zooming
for i in range(1,360):
mlab.view(azimuth=0+i, elevation=45, distance=-300+i, focalpoint=(0,0,0))
fun_save()
def zoomin():#zoom in
for i in range(1,360):
mlab.view(azimuth=0, elevation=45, distance=1500-i, focalpoint=(0,0,0))
fun_save()

def zoomout():#zoom out
for i in range(1,360):
mlab.view(azimuth=0, elevation=45, distance=300+i, focalpoint=(0,0,0))
fun_save()
def fun_save():
fname = '0%d.png'%save_count
mlab.savefig(fname)
save_count=save_count+1

#print int(float(d[1][0]*1e6))
#print x[2]*1e6

for ii in range(1,8000):
#for it,ii in enumerate(d1):
activation_calls(ii)
#mlab.view(azimuth=0+ii, elevation=45+ii, distance=200, focalpoint=(0,0,0))
#mlab.yaw(-10) #rotation
#mlab.move(forward=23+ii,right=32+ii,up=12-ii)
#mlab.view(azimuth=0+ii, elevation=-45, distance=1000, focalpoint=(0,0,0))
#mlab.move(0,0,0)
mlab.points3d(d1x, d1y, d1z, scale_factor=25, color=(1,1,0), opacity=0.3) # not spiking
mlab.points3d(d2x, d2y, d2z, scale_factor=25, color=(0,0,1), opacity=0.3) # spiking
#print mlab.view()
fun_save()


#rot_zoom()
zoomin()
#zoomout()

#fname = '0%d.png'%ii
#mlab.savefig(fname)

mlab.clf()

del d1x[:]
del d1y[:]
del d1z[:]

del d2x[:]
del d2y[:]
del d2z[:]



#framerate=200
#os.system("rm mymovie.mp4")
#os.system("ffmpeg -framerate 1/5 -start_number 916 -i 0%d.png -c:v libx264 -vf 'crop=in_w-1:in_h' -r 200 -pix_fmt yuv420p mymovie.mp4")
#os.system("ffmpeg -r -b 1800 -start_number 916 -i 0%d.png mymovie.mp4")
#os.system("ffmpeg -r "+str(fps)+" -b 1800 -start_number 916 -i 0%d.png mymovie.mp4")
#os.system("rm 0*.png")


mlab.show()
myfile.close()


asked 7 mins ago







how to read multiple hdf files and close it simultaneously

Aucun commentaire:

Enregistrer un commentaire