Skip to content

Commit 165df01

Browse files
committed
Test HDF5 virtual dataset.
1 parent b712c44 commit 165df01

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

tiled/_tests/test_directory_walker.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import random
44
from pathlib import Path
55

6+
import h5py
67
import numpy
78
import pytest
89
import tifffile
910
import yaml
1011

12+
from ..adapters.hdf5 import HDF5Adapter
1113
from ..adapters.tiff import TiffAdapter
1214
from ..catalog import in_memory
1315
from ..catalog.register import (
@@ -237,3 +239,57 @@ def read_tiff_with_yaml_metadata(
237239
client = from_context(context)
238240
assert numpy.array_equal(data, client["image"][:])
239241
assert client["image"].metadata["test_key"] == 3.0
242+
243+
244+
@pytest.mark.asyncio
245+
async def test_hdf5_virtual_datasets(tmpdir):
246+
layout = h5py.VirtualLayout(shape=(4, 100), dtype="i4")
247+
248+
data_filepaths = []
249+
for n in range(1, 5):
250+
filepath = Path(tmpdir, f"{n}.h5")
251+
data_filepaths.append(filepath)
252+
vsource = h5py.VirtualSource(filepath, "data", shape=(100,))
253+
layout[n - 1] = vsource
254+
255+
# Add virtual dataset to output file
256+
filepath = Path(tmpdir, "VDS.h5")
257+
with h5py.File(filepath, "w", libver="latest") as file:
258+
file.create_virtual_dataset("data", layout, fillvalue=-5)
259+
260+
assets = [
261+
Asset(
262+
data_uri=str(ensure_uri(str(fp))),
263+
is_directory=False,
264+
parameter=None, # an indirect dependency
265+
)
266+
for fp in data_filepaths
267+
]
268+
assets.append(
269+
Asset(
270+
data_uri=str(ensure_uri(str(filepath))),
271+
is_directory=False,
272+
parameter="filepath",
273+
)
274+
)
275+
catalog = in_memory(writable_storage=tmpdir)
276+
with Context.from_app(build_app(catalog)) as context:
277+
adapter = HDF5Adapter.from_filepath(filepath)
278+
await create_node_safe(
279+
catalog,
280+
key="VDS",
281+
structure_family=adapter.structure_family,
282+
metadata=dict(adapter.metadata()),
283+
specs=adapter.specs,
284+
data_sources=[
285+
DataSource(
286+
mimetype="application/x-hdf5",
287+
structure=None,
288+
parameters={},
289+
management=Management.external,
290+
assets=assets,
291+
)
292+
],
293+
)
294+
client = from_context(context)
295+
client["VDS"]["data"][:]

tiled/catalog/adapter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ async def get_adapter(self):
379379
)
380380
parameters = collections.defaultdict(list)
381381
for asset in data_source.assets:
382+
if asset.parameter is None:
383+
continue
382384
data_uri = httpx.URL(asset.data_uri)
383385
if data_uri.scheme != "file":
384386
raise NotImplementedError(

0 commit comments

Comments
 (0)