Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow LindiH5pyFile.from_hdf5_file to accept remote URL for local file #66

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lindi/LindiH5ZarrStore/LindiH5ZarrStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,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,
rly marked this conversation as resolved.
Show resolved Hide resolved
"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.
rly marked this conversation as resolved.
Show resolved Hide resolved
"""
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