-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat_slice.py
More file actions
149 lines (132 loc) · 5.08 KB
/
Copy pathcat_slice.py
File metadata and controls
149 lines (132 loc) · 5.08 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Example file for concatenating on-axis slice data
# created when the -DSLICES flag is turned on
import h5py
import numpy as np
ns = 0
ne = 300
step = 1 # n_hydro
n_procs = 2 # number of processors that did the cholla calculation
dnamein = '../../../../../ix/eschneider/hjl28/data/tests/cloud_tracking/hdf5_large_ct/raw/'
dnameout = '../../../../../ix/eschneider/hjl28/data/tests/cloud_tracking/hdf5_large_ct/'
DE = True # set to True if Dual Energy flag was used
SCALAR = False # set to True if Scalar was used
# loop over the output times
for n in range(ns, ne, step):
# open the output file for writing
fileout = h5py.File(dnameout+str(n)+'/'+str(n)+'_slice.h5', 'w')
print(n)
# loop over files for a given output time
for i in range(0, n_procs):
# open the input file for reading
filein = h5py.File(dnamein+str(n)+'/'+str(n)+'_slice.h5.'+str(i), 'r')
# read in the header data from the input file
head = filein.attrs
# if it's the first input file, write the header attributes
# and create the datasets in the output file
if (i == 0):
gamma = head['gamma']
t = head['t']
dt = head['dt']
dx = head['dx']
n_step = head['n_step']
nx = head['dims'][0]
ny = head['dims'][1]
nz = head['dims'][2]
length_unit = head["length_unit"]
mass_unit = head["mass_unit"]
time_unit = head["time_unit"]
density_unit = head["density_unit"]
velocity_unit = head["velocity_unit"]
energy_unit = head["energy_unit"]
fileout.attrs['gamma'] = gamma
fileout.attrs['t'] = t
fileout.attrs['dt'] = dt
fileout.attrs['dx'] = dx
fileout.attrs['n_step'] = n_step
fileout.attrs['dims'] = [nx, ny, nz]
fileout.attrs['length_unit'] = length_unit
fileout.attrs['time_unit'] = time_unit
fileout.attrs['mass_unit'] = mass_unit
fileout.attrs['density_unit'] = density_unit
fileout.attrs['velocity_unit'] = velocity_unit
fileout.attrs['energy_unit'] = energy_unit
d_xy = np.zeros((nx,ny))
d_xz = np.zeros((nx,nz))
d_yz = np.zeros((ny,nz))
mx_xy = np.zeros((nx,ny))
mx_xz = np.zeros((nx,nz))
mx_yz = np.zeros((ny,nz))
my_xy = np.zeros((nx,ny))
my_xz = np.zeros((nx,nz))
my_yz = np.zeros((ny,nz))
mz_xy = np.zeros((nx,ny))
mz_xz = np.zeros((nx,nz))
mz_yz = np.zeros((ny,nz))
E_xy = np.zeros((nx,ny))
E_xz = np.zeros((nx,nz))
E_yz = np.zeros((ny,nz))
if DE:
GE_xy = np.zeros((nx,ny))
GE_xz = np.zeros((nx,nz))
GE_yz = np.zeros((ny,nz))
if SCALAR:
scalar_xy = np.zeros((nx,ny))
scalar_xz = np.zeros((nx,nz))
scalar_yz = np.zeros((ny,nz))
# write data from individual processor file to
# correct location in concatenated file
nxl = head['dims_local'][0]
nyl = head['dims_local'][1]
nzl = head['dims_local'][2]
xs = head['offset'][0]
ys = head['offset'][1]
zs = head['offset'][2]
d_xy[xs:xs+nxl,ys:ys+nyl] += filein['d_xy']
d_xz[xs:xs+nxl,zs:zs+nzl] += filein['d_xz']
d_yz[ys:ys+nyl,zs:zs+nzl] += filein['d_yz']
mx_xy[xs:xs+nxl,ys:ys+nyl] += filein['mx_xy']
mx_xz[xs:xs+nxl,zs:zs+nzl] += filein['mx_xz']
mx_yz[ys:ys+nyl,zs:zs+nzl] += filein['mx_yz']
my_xy[xs:xs+nxl,ys:ys+nyl] += filein['my_xy']
my_xz[xs:xs+nxl,zs:zs+nzl] += filein['my_xz']
my_yz[ys:ys+nyl,zs:zs+nzl] += filein['my_yz']
mz_xy[xs:xs+nxl,ys:ys+nyl] += filein['mz_xy']
mz_xz[xs:xs+nxl,zs:zs+nzl] += filein['mz_xz']
mz_yz[ys:ys+nyl,zs:zs+nzl] += filein['mz_yz']
E_xy[xs:xs+nxl,ys:ys+nyl] += filein['E_xy']
E_xz[xs:xs+nxl,zs:zs+nzl] += filein['E_xz']
E_yz[ys:ys+nyl,zs:zs+nzl] += filein['E_yz']
if DE:
GE_xy[xs:xs+nxl,ys:ys+nyl] += filein['GE_xy']
GE_xz[xs:xs+nxl,zs:zs+nzl] += filein['GE_xz']
GE_yz[ys:ys+nyl,zs:zs+nzl] += filein['GE_yz']
if SCALAR:
scalar_xy[xs:xs+nxl,ys:ys+nyl] += filein['scalar_xy']
scalar_xz[xs:xs+nxl,zs:zs+nzl] += filein['scalar_xz']
scalar_yz[ys:ys+nyl,zs:zs+nzl] += filein['scalar_yz']
filein.close()
# wrte out the new datasets
fileout.create_dataset('d_xy', data=d_xy)
fileout.create_dataset('d_xz', data=d_xz)
fileout.create_dataset('d_yz', data=d_yz)
fileout.create_dataset('mx_xy', data=mx_xy)
fileout.create_dataset('mx_xz', data=mx_xz)
fileout.create_dataset('mx_yz', data=mx_yz)
fileout.create_dataset('my_xy', data=my_xy)
fileout.create_dataset('my_xz', data=my_xz)
fileout.create_dataset('my_yz', data=my_yz)
fileout.create_dataset('mz_xy', data=mz_xy)
fileout.create_dataset('mz_xz', data=mz_xz)
fileout.create_dataset('mz_yz', data=mz_yz)
fileout.create_dataset('E_xy', data=E_xy)
fileout.create_dataset('E_xz', data=E_xz)
fileout.create_dataset('E_yz', data=E_yz)
if DE:
fileout.create_dataset('GE_xy', data=GE_xy)
fileout.create_dataset('GE_xz', data=GE_xz)
fileout.create_dataset('GE_yz', data=GE_yz)
if SCALAR:
fileout.create_dataset('scalar_xy', data=scalar_xy)
fileout.create_dataset('scalar_xz', data=scalar_xz)
fileout.create_dataset('scalar_yz', data=scalar_yz)
fileout.close()