-
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
9 changed files
with
227 additions
and
64 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
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,27 @@ | ||
import tempfile | ||
import numpy as np | ||
import h5py | ||
import lindi | ||
|
||
|
||
def test_external_array_link(): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
filename = f"{tmpdir}/test.h5" | ||
X = np.random.randn(50, 12) | ||
with h5py.File(filename, "w") as f: | ||
f.create_dataset("dataset1", data=X, chunks=(10, 6)) | ||
with lindi.LindiH5ZarrStore.from_file( | ||
filename, | ||
url=filename, | ||
opts=lindi.LindiH5ZarrStoreOpts( | ||
num_dataset_chunks_threshold=4 | ||
) | ||
) as store: | ||
rfs = store.to_reference_file_system() | ||
client = lindi.LindiH5pyFile.from_reference_file_system(rfs) | ||
X2 = client["dataset1"][:] # type: ignore | ||
assert np.array_equal(X, X2) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_external_array_link() |
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,45 @@ | ||
import json | ||
import pytest | ||
import lindi | ||
|
||
|
||
@pytest.mark.network | ||
def test_remote_data_1(): | ||
import pynwb | ||
|
||
# Define the URL for a remote NWB file | ||
h5_url = "https://api.dandiarchive.org/api/assets/11f512ba-5bcf-4230-a8cb-dc8d36db38cb/download/" | ||
|
||
# Create a read-only Zarr store as a wrapper for the h5 file | ||
store = lindi.LindiH5ZarrStore.from_file(h5_url) | ||
|
||
# Generate a reference file system | ||
rfs = store.to_reference_file_system() | ||
|
||
# Save it to a file for later use | ||
with open("example.zarr.json", "w") as f: | ||
json.dump(rfs, f, indent=2) | ||
|
||
# Create an h5py-like client from the reference file system | ||
client = lindi.LindiH5pyFile.from_reference_file_system(rfs) | ||
|
||
# Open using pynwb | ||
with pynwb.NWBHDF5IO(file=client, mode="r") as io: | ||
nwbfile = io.read() | ||
print(nwbfile) | ||
|
||
|
||
@pytest.mark.network | ||
def test_remote_data_2(): | ||
import pynwb | ||
|
||
# Define the URL for a remote .zarr.json file | ||
url = 'https://kerchunk.neurosift.org/dandi/dandisets/000939/assets/11f512ba-5bcf-4230-a8cb-dc8d36db38cb/zarr.json' | ||
|
||
# Load the h5py-like client from the reference file system | ||
client = lindi.LindiH5pyFile.from_reference_file_system(url) | ||
|
||
# Open using pynwb | ||
with pynwb.NWBHDF5IO(file=client, mode="r") as io: | ||
nwbfile = io.read() | ||
print(nwbfile) |
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,58 @@ | ||
import h5py | ||
import tempfile | ||
import lindi | ||
|
||
|
||
def test_store(): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
filename = f"{tmpdir}/test.h5" | ||
with h5py.File(filename, "w") as f: | ||
f.create_dataset("dataset1", data=[1, 2, 3]) | ||
group1 = f.create_group("group1") | ||
group1.create_group("group2") | ||
group1.create_dataset("dataset2", data=[4, 5, 6]) | ||
with lindi.LindiH5ZarrStore.from_file(filename, url=filename) as store: | ||
store.to_file(f"{tmpdir}/test.zarr.json") # for coverage | ||
a = store.listdir('') | ||
assert _lists_are_equal(a, ['dataset1', 'group1'], ordered=False) | ||
b = store.listdir('group1') | ||
assert _lists_are_equal(b, ['group2', 'dataset2'], ordered=False) | ||
c = store.listdir('group1/group2') | ||
assert _lists_are_equal(c, [], ordered=False) | ||
assert '.zattrs' in store | ||
assert '.zgroup' in store | ||
assert 'dataset1' not in store | ||
assert 'dataset1/.zattrs' in store | ||
assert 'dataset1/.zarray' in store | ||
assert 'dataset1/.zgroup' not in store | ||
assert 'dataset1/0' in store | ||
assert 'group1' not in store | ||
assert 'group1/.zattrs' in store | ||
assert 'group1/.zgroup' in store | ||
assert 'group1/.zarray' not in store | ||
assert 'group1/group2' not in store | ||
assert 'group1/group2/.zattrs' in store | ||
assert 'group1/group2/.zgroup' in store | ||
assert 'group1/group2/.zarray' not in store | ||
assert 'group1/dataset2' not in store | ||
assert 'group1/dataset2/.zattrs' in store | ||
assert 'group1/dataset2/.zarray' in store | ||
assert 'group1/dataset2/.zgroup' not in store | ||
assert 'group1/dataset2/0' in store | ||
client = lindi.LindiH5pyFile.from_zarr_store(store) | ||
X = client["dataset1"][:] # type: ignore | ||
assert _lists_are_equal(X, [1, 2, 3], ordered=True) | ||
Y = client["group1/dataset2"][:] # type: ignore | ||
assert _lists_are_equal(Y, [4, 5, 6], ordered=True) | ||
|
||
|
||
def _lists_are_equal(a, b, ordered: bool): | ||
if ordered: | ||
if len(a) != len(b): | ||
return False | ||
for i in range(len(a)): | ||
if a[i] != b[i]: | ||
return False | ||
return True | ||
else: | ||
return set(a) == set(b) |