-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from daviddritschel/write-h5py
Convert script to hdf5 file
- Loading branch information
Showing
6 changed files
with
71 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
|
||
import h5py | ||
import numpy as np | ||
import os | ||
from ps_config import nx, ny, ellx, ymin, ymax | ||
|
||
print("Parameters from parameters.f90:") | ||
print("nx = ", nx) | ||
print("ny = ", ny) | ||
print("ellx = ", ellx) | ||
print("ymin = ", ymin) | ||
print("ymax = ", ymax) | ||
|
||
#----------------------------------------------------------------- | ||
# Open ene.asc file in one directory to get time between frames: | ||
in_file=open('evolution/ecomp.asc','r') | ||
time, ekin, epot, etot = np.loadtxt(in_file,dtype=float,unpack=True) | ||
in_file.close() | ||
nt = len(time) | ||
|
||
dset = { | ||
'bb': 'buoyancy', | ||
'zz': 'vorticity' | ||
} | ||
|
||
N = nx * (ny + 1) | ||
|
||
h5file = h5py.File('ps_fields.hdf5', 'w') | ||
|
||
h5file.attrs['nsteps'] = nt | ||
|
||
box = h5file.create_group('box') | ||
box.attrs['extent'] = (ellx, ymax - ymin) | ||
box.attrs['origin'] = (-ellx * 0.5, ymin) | ||
box.attrs['ncells'] = (np.int32(nx), np.int32(ny)) | ||
|
||
for frame in range(nt): | ||
group = h5file.create_group('step#' + str(frame).zfill(10)) | ||
|
||
for field in ['bb', 'zz']: | ||
fname = os.path.join('evolution', field + '.r4') | ||
|
||
in_file = open(fname,'r') | ||
raw_array = np.fromfile(in_file,dtype=np.float32) | ||
in_file.close() | ||
|
||
Z = np.empty([nx, ny+1]) | ||
Z = raw_array[frame*(N+1)+1:(frame+1)*(N+1)].reshape(nx, ny+1) | ||
|
||
group[dset[field]] = np.float64(Z.copy()) | ||
|
||
h5file.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters