forked from TomaszGolan/hdf5_manipulator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract_big.py
executable file
·55 lines (41 loc) · 1.14 KB
/
extract_big.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
#!/usr/bin/env python
"""
Create hdf5 file with a subset of datasets from original (big) hdf5 file
"""
import os
import sys
import h5py
import numpy as np
from parser import get_args_extract as parser
import msg
import check
def copy(source, output, keys):
"""Copy requested datasets.
Keyword arguments:
source -- input file
output -- output file
keys -- keys to be copied
"""
for k in keys:
if k not in source:
msg.warning("%s requested, but not found." % k)
continue
else:
msg.info("Copying %s" % k)
source.copy(k, output)
if __name__ == '__main__':
msg.box("HDF5 MANIPULATOR: EXTRACT")
args = parser()
f = h5py.File(args.input, 'r')
o = h5py.File(args.output, 'w')
print "The following datasets were found in %s:\n" % args.input
msg.list_dataset(f)
copy(f, o, [k.strip() for k in args.keys.split(',')])
if len(o):
print "\nThe following dataset were saved in %s:\n" % args.output
msg.list_dataset(o)
else:
msg.warning("No datasets were copied.")
f.close()
o.close()
msg.info("Done")