-
Notifications
You must be signed in to change notification settings - Fork 2
/
combine_1d_list.py
85 lines (64 loc) · 1.98 KB
/
combine_1d_list.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#
# Combine 1D data into 1 HDF5 file
#
# FST, (c) 2020 Regents of The University of California
#
import sys
sys.path.append('/Users/franktsung/Documents/codes/python-tsung/')
sys.path.append('/Volumes/Lacie-5TB/codes/pyVisOS/')
import osh5io
import osh5def
import osh5vis
import osh5utils
from h5_utilities import *
import matplotlib.pyplot as plt
import sys
import getopt
import glob
import numpy as np
argc=len(sys.argv)
if(argc < 3):
print('Usage: python combine_1d.py DIRNAME OUTNAME')
sys.exit()
dirname=sys.argv[1]
outfilename = sys.argv[2]
filelist=sorted(glob.glob(dirname+'/*.h5'))
total_time=len(filelist)
my_share = total_time
i_begin=0
i_end = total_time
h5_filename=filelist[1]
h5_data=osh5io.read_h5(h5_filename)
array_dims=h5_data.shape
nx=array_dims[0]
time_step=h5_data.run_attrs['TIME'][0]
# h5_output=hdf_data()
# h5_output.shape=[total_time,ny]
print('nx='+repr(nx))
print('time_step='+repr(time_step))
print('total_time='+repr(total_time))
#
xaxis=h5_data.axes[0]
taxis=osh5def.DataAxis(0, time_step * (total_time -1), total_time,
attrs={'NAME':'t', 'LONG_NAME':'time', 'UNITS':'1 / \omega_p'})
data_attrs=h5_data.data_attrs
h5_output= np.zeros((total_time,nx))
# total = np.zeros((total_time,nx))
# h5_output.axes=[data_basic_axis(0,h5_data.axes[0].min,h5_data.axes[0].max,ny),
# data_basic_axis(1,0.0,(time_step*total_time-1),total_time)]
# run_attrs = h5_output.run_attrs
run_attrs = {'XMAX' : np.array( [ time_step * (total_time-1),xaxis.max] ) ,
'XMIN' : np.array( [0, xaxis.min, 0] ) }
file_number=0
for file_number in range(i_begin,i_end):
h5_filename=filelist[file_number]
if (file_number % 10 == 0 ):
print(h5_filename)
h5_data=osh5io.read_h5(h5_filename)
h5_output[file_number,1:nx]=h5_data.data[1:nx]
# file_number+=1
print('before write')
print(outfilename)
b=osh5def.H5Data(h5_output, timestamp='x', data_attrs=data_attrs,run_attrs=run_attrs, axes=[taxis, xaxis])
osh5io.write_h5(b,filename=outfilename)
print('after write')