-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
157 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
warnings.filterwarnings("ignore") | ||
|
||
|
||
__version__ = '0.5.1' | ||
__version__ = '0.6.0' | ||
|
||
|
||
def abspath(path): | ||
|
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,47 @@ | ||
'''G5repack | ||
Read and write a HDF5 file, to write it more efficiently by removing features like | ||
extendible datasets. | ||
Usage: | ||
G5repack [options] <source>... | ||
Arguments: | ||
<source> HDF5-file. | ||
Options: | ||
-h, --help Show help. | ||
--version Show version. | ||
(c - MIT) T.W.J. de Geus | tom@geus.me | www.geus.me | github.com/tdegeus/GooseHDF5 | ||
''' | ||
|
||
from .. import getpaths | ||
from .. import __version__ | ||
import docopt | ||
import h5py | ||
import os | ||
import tempfile | ||
import warnings | ||
warnings.filterwarnings("ignore") | ||
|
||
def check_isfile(fname): | ||
if not os.path.isfile(fname): | ||
raise IOError('"{0:s}" does not exist'.format(fname)) | ||
|
||
def main(): | ||
|
||
args = docopt.docopt(__doc__, version=__version__) | ||
tempname = next(tempfile._get_candidate_names()) | ||
|
||
for filename in args['<source>']: | ||
|
||
print(filename) | ||
|
||
check_isfile(filename) | ||
|
||
with h5py.File(filename, 'r') as source: | ||
with h5py.File(tempname, 'w') as tmp: | ||
for path in getpaths(source): | ||
tmp[path] = source[path][...] | ||
|
||
os.replace(tempname, filename) |
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,24 @@ | ||
import subprocess | ||
import os | ||
import h5py | ||
import numpy as np | ||
|
||
def run(cmd): | ||
out = list(filter(None, subprocess.check_output(cmd, shell=True).decode('utf-8').split('\n'))) | ||
return out | ||
|
||
a = np.random.random(5) | ||
|
||
with h5py.File('a.hdf5', 'w') as source: | ||
source['/a'] = a | ||
|
||
output = run('G5repack a.hdf5') | ||
|
||
with h5py.File('a.hdf5', 'r') as source: | ||
b = source['/a'][...] | ||
|
||
os.remove('a.hdf5') | ||
|
||
if not np.all(a == b): | ||
raise IOError('Test failed') | ||
|