-
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.
BUG: Fixing storage incompatibilities. (#30)
- Loading branch information
Showing
5 changed files
with
95 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,64 @@ | ||
import argparse | ||
|
||
import h5py | ||
|
||
from sdafile.utils import write_header | ||
|
||
|
||
def make_test_data(filename): | ||
|
||
with h5py.File(filename, 'w') as f: | ||
|
||
# Header | ||
write_header(f.attrs) | ||
|
||
# curly | ||
g = f.create_group('curly') | ||
g.attrs['RecordType'] = 'numeric' | ||
g.attrs['Empty'] = 'no' | ||
g.attrs['Deflate'] = 0 | ||
g.attrs['Description'] = '3x4 array (double)' | ||
|
||
ds = g.create_dataset( | ||
'curly', | ||
shape=(3, 4), | ||
maxshape=(None, None), | ||
dtype='<f8', | ||
chunks=(3, 4), | ||
compression=0, # gzip | ||
fillvalue=0.0, | ||
) | ||
ds.attrs['RecordType'] = 'numeric' | ||
ds.attrs['Empty'] = 'no' | ||
|
||
# curly 2 | ||
g = f.create_group('curly 2') | ||
g.attrs['RecordType'] = 'numeric' | ||
g.attrs['Empty'] = 'no' | ||
g.attrs['Deflate'] = 0 | ||
g.attrs['Description'] = 'Single version of curly' | ||
|
||
ds = g.create_dataset( | ||
'curly 2', | ||
shape=(3, 4), | ||
maxshape=(None, None), | ||
dtype='<f4', | ||
chunks=(3, 4), | ||
compression=0, | ||
fillvalue=0.0, | ||
) | ||
ds.attrs['RecordType'] = 'numeric' | ||
ds.attrs['Empty'] = 'no' | ||
|
||
# larry | ||
g = f.create_group('larry') | ||
g.attrs['RecordType'] = 'character' | ||
g.attrs['Empty'] = 'yes' | ||
g.attrs['Deflate'] = 0 | ||
g.attrs['Description'] = 'An empty character array' | ||
|
||
ds = g.create_dataset( | ||
'larry', | ||
shape=(1, 1), | ||
maxshape=(None, None), | ||
dtype='<u1', | ||
chunks=(1, 1), | ||
compression=0, | ||
fillvalue=0, | ||
) | ||
ds.attrs['RecordType'] = 'character' | ||
ds.attrs['Empty'] = 'yes' | ||
|
||
# moe | ||
g = f.create_group('moe') | ||
g.attrs['RecordType'] = 'logical' | ||
g.attrs['Empty'] = 'no' | ||
g.attrs['Deflate'] = 0 | ||
g.attrs['Description'] = 'A 1x1 logical array' | ||
|
||
ds = g.create_dataset( | ||
'moe', | ||
shape=(1, 1), | ||
maxshape=(None, None), | ||
dtype='<u1', | ||
chunks=(1, 1), | ||
compression=0, | ||
fillvalue=0, | ||
) | ||
ds.attrs['RecordType'] = 'logical' | ||
ds.attrs['Empty'] = 'no' | ||
|
||
# my function | ||
g = f.create_group('my function') | ||
g.attrs['RecordType'] = 'function' | ||
g.attrs['Empty'] = 'no' | ||
g.attrs['Deflate'] = 0 | ||
g.attrs['Description'] = 'Sine function' | ||
|
||
ds = g.create_dataset( | ||
'my function', | ||
shape=(1, 10280), | ||
maxshape=(1, 10280), | ||
dtype='<u1', | ||
chunks=None, | ||
fillvalue=0, | ||
) | ||
ds.attrs['RecordType'] = 'function' | ||
ds.attrs['Command'] = 'sin' | ||
ds.attrs['Empty'] = 'no' | ||
import numpy as np | ||
from scipy import sparse | ||
|
||
from sdafile import SDAFile | ||
|
||
|
||
EXAMPLE_A1 = np.zeros(5, dtype=np.float64) | ||
|
||
EXAMPLE_A2 = np.empty((4, 3), dtype=np.complex128) | ||
EXAMPLE_A2.real = 0 | ||
EXAMPLE_A2.imag = 1 | ||
|
||
EXAMPLE_A3 = sparse.eye(5).tocoo() | ||
|
||
EXAMPLE_A4 = np.nan | ||
|
||
|
||
def make_example_data(filename): | ||
|
||
sda_file = SDAFile(filename, 'w') | ||
|
||
sda_file.insert("example A1", EXAMPLE_A1, "5x1 zeros") | ||
|
||
sda_file.insert("example A2", EXAMPLE_A2, "4x3 imaginary numbers") | ||
|
||
sda_file.insert("example A3", EXAMPLE_A3, "5x5 sparse matrix") | ||
|
||
sda_file.insert("example A4", np.nan, "Empty array") | ||
|
||
sda_file.insert("example B", True, "Logical scalar") | ||
|
||
sda_file.insert("example C", "Here is some text", "Some text") | ||
|
||
desc = "Cell array combining examples A1 and A2" | ||
sda_file.insert("example E", [EXAMPLE_A1, EXAMPLE_A2], desc) | ||
|
||
desc = "Structure combining examples A1 and A2" | ||
a1a2 = {"A1": EXAMPLE_A1, "A2": EXAMPLE_A2} | ||
sda_file.insert("example F", a1a2, desc) | ||
|
||
desc = "Structure array combining examples A1 and A2 (repeated)" | ||
cell = np.array([a1a2, a1a2], dtype=object).reshape(2, 1) | ||
sda_file.insert("example G", cell, desc) | ||
|
||
desc = "Cell array of structures combining examples A1-A4" | ||
a3a4 = {"A3": EXAMPLE_A3, "A4": EXAMPLE_A4} | ||
cell = np.array([a1a2, a3a4], dtype=object).reshape(2, 1) | ||
sda_file.insert("example H", cell, desc) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('filename', help="The name of the file to create") | ||
parser.add_argument( | ||
"filename", | ||
help="The name of the file to create", | ||
nargs="?", | ||
default="SDAreference_py.sda", | ||
) | ||
|
||
args = parser.parse_args() | ||
make_test_data(args.filename) | ||
make_example_data(args.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
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