Skip to content

Commit

Permalink
Merge branch 'main' into chunk_iter
Browse files Browse the repository at this point in the history
  • Loading branch information
rly authored May 15, 2024
2 parents 2897504 + b7b66f2 commit 08eace7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lindi/LindiH5ZarrStore/LindiH5ZarrStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def _get_external_array_link(self, parent_key: str, h5_item: h5py.Dataset):
if self._url is not None:
self._external_array_links[parent_key] = {
"link_type": "hdf5_dataset",
"url": self._url, # url is not going to be null based on the check in __init__
"url": self._url,
"name": parent_key,
}
else:
Expand Down
3 changes: 2 additions & 1 deletion lindi/LindiH5ZarrStore/LindiH5ZarrStoreOpts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class LindiH5ZarrStoreOpts:
num_dataset_chunks_threshold (Union[int, None]): For each dataset in the
HDF5 file, if the number of chunks is greater than this threshold, then
the dataset will be represented as an external array link. If None, then
the threshold is not used. Default is 1000.
no datasets will be represented as external array links (equivalent to a
threshold of 0). Default is 1000.
"""
num_dataset_chunks_threshold: Union[int, None] = 1000
18 changes: 16 additions & 2 deletions lindi/LindiH5pyFile/LindiH5pyFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ def from_lindi_file(url_or_path: str, *, mode: LindiFileMode = "r", staging_area
return LindiH5pyFile.from_reference_file_system(url_or_path, mode=mode, staging_area=staging_area, local_cache=local_cache, local_file_path=local_file_path)

@staticmethod
def from_hdf5_file(url_or_path: str, *, mode: LindiFileMode = "r", local_cache: Union[LocalCache, None] = None, zarr_store_opts: Union[LindiH5ZarrStoreOpts, None] = None):
def from_hdf5_file(
url_or_path: str,
*,
mode: LindiFileMode = "r",
local_cache: Union[LocalCache, None] = None,
zarr_store_opts: Union[LindiH5ZarrStoreOpts, None] = None,
url: Union[str, None] = None
):
"""
Create a LindiH5pyFile from a URL or path to an HDF5 file.
Expand All @@ -73,11 +80,18 @@ def from_hdf5_file(url_or_path: str, *, mode: LindiFileMode = "r", local_cache:
The local cache to use for caching data chunks, by default None.
zarr_store_opts : Union[LindiH5ZarrStoreOpts, None], optional
The options to use for the zarr store, by default None.
url : str or None
If url_or_path is a local file name, then this can
optionally be set to the URL of the remote file to be used when
creating references. If None, and the url_or_path is a
local file name, then you will need to set
zarr_store_opts.num_dataset_chunks_threshold to None, and you will not be able
to use the to_reference_file_system method.
"""
from ..LindiH5ZarrStore.LindiH5ZarrStore import LindiH5ZarrStore # avoid circular import
if mode != "r":
raise Exception("Opening hdf5 file in write mode is not supported")
zarr_store = LindiH5ZarrStore.from_file(url_or_path, local_cache=local_cache, opts=zarr_store_opts, url=url_or_path)
zarr_store = LindiH5ZarrStore.from_file(url_or_path, local_cache=local_cache, opts=zarr_store_opts, url=url)
return LindiH5pyFile.from_zarr_store(
zarr_store=zarr_store,
mode=mode,
Expand Down

0 comments on commit 08eace7

Please sign in to comment.