-
Notifications
You must be signed in to change notification settings - Fork 2
/
combine_h5_2d.py
58 lines (47 loc) · 1.6 KB
/
combine_h5_2d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sys
sys.path.append('/Users/franktsung/Documents/codes/python-tsung/')
sys.path.append('/Volumes/Lacie-5TB/codes/pyVisOS/')
from h5_utilities import *
import matplotlib.pyplot as plt
import glob
import numpy
argc=len(sys.argv)
if(argc < 3):
print('Usage: python 1d_combine.py DIRNAME OUTNAME')
sys.exit()
dirname=sys.argv[1]
outfilename = sys.argv[2]
filelist=sorted(glob.glob(dirname+'/*.h5'))
total_time=len(filelist)
h5_filename=filelist[1]
h5_data=read_hdf(h5_filename)
array_dims=h5_data.shape
nx=array_dims[0]
ny=array_dims[1]
time_step=h5_data.run_attributes['TIME'][0]
h5_output=hdf_data()
h5_output.shape=[total_time,ny]
# print 'nx='+repr(nx)
# print 'ny='+repr(ny)
# print 'time_step='+repr(time_step)
# print 'total_time='+repr(total_time)
h5_output.data=numpy.zeros((total_time,ny))
h5_output.axes=[data_basic_axis(0,h5_data.axes[0].axis_min,h5_data.axes[0].axis_max,ny),
data_basic_axis(1,0.0,(time_step*total_time-1),total_time)]
h5_output.run_attributes['TIME']=0.0
# h5_output.run_attributes['UNITS']=h5_data.run_attributes['UNITS']
h5_output.axes[0].attributes['LONG_NAME']=h5_data.axes[0].attributes['LONG_NAME']
h5_output.axes[0].attributes['UNITS']=h5_data.axes[0].attributes['UNITS']
h5_output.axes[1].attributes['LONG_NAME']='TIME'
h5_output.axes[1].attributes['UNITS']='1/\omega_p'
file_number=0
for h5_filename in filelist:
print( h5_filename)
h5_data=read_hdf(h5_filename)
temp=numpy.sum(numpy.abs(h5_data.data),axis=0)/nx
h5_output.data[file_number,1:ny]=temp[1:ny]
file_number+=1
# print 'before write'
# print outfilename
write_hdf(h5_output,outfilename)
# print 'after write'