Skip to content

Commit

Permalink
Merge pull request #47 from TomNicholas/rename_open_dataset_via_kerchunk
Browse files Browse the repository at this point in the history
Rename open_dataset_via_kerchunk to open_virtual_dataset
  • Loading branch information
TomNicholas committed Mar 25, 2024
2 parents 4375ccb + 4b137fe commit 13f40fc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/api.md
Expand Up @@ -16,6 +16,6 @@
## Xarray

```{eval-rst}
.. autoclass:: virtualizarr.xarray.open_dataset_via_kerchunk
.. autoclass:: virtualizarr.xarray.open_virtual_dataset
:members:
```
2 changes: 1 addition & 1 deletion virtualizarr/__init__.py
@@ -1,3 +1,3 @@
from .manifests import ManifestArray # type: ignore # noqa
from .xarray import VirtualiZarrDatasetAccessor # type: ignore # noqa
from .xarray import open_dataset_via_kerchunk # noqa: F401
from .xarray import open_virtual_dataset # noqa: F401
8 changes: 4 additions & 4 deletions virtualizarr/kerchunk.py
Expand Up @@ -37,23 +37,23 @@ def read_kerchunk_references_from_file(
if filetype is None:
filetype = _automatically_determine_filetype(filepath)

if filetype == "netCDF3":
if filetype.lower() == "netcdf3":
from kerchunk.netCDF3 import SingleHdf5ToZarr

refs = SingleHdf5ToZarr.NetCDF3ToZarr(filepath).translate()
elif filetype == "netCDF4":
elif filetype.lower() == "netcdf4":
from kerchunk.hdf import SingleHdf5ToZarr

refs = SingleHdf5ToZarr(filepath).translate()
elif filetype == "grib":
# TODO Grib files should be handled as a DataTree object
# see https://github.com/TomNicholas/VirtualiZarr/issues/11
raise NotImplementedError(f"Unsupported file type: {filetype}")
elif filetype == "tiff":
elif filetype.lower() == "tiff":
from kerchunk.tiff import tiff_to_zarr

refs = tiff_to_zarr(filepath)
elif filetype == "fits":
elif filetype.lower() == "fits":
from kerchunk.fits import process_file

refs = process_file(filepath)
Expand Down
5 changes: 3 additions & 2 deletions virtualizarr/xarray.py
Expand Up @@ -16,14 +16,14 @@ class ManifestBackendArray(ManifestArray, BackendArray):
...


def open_dataset_via_kerchunk(
def open_virtual_dataset(
filepath: str,
filetype: str,
drop_variables: Optional[List[str]] = None,
virtual_array_class=ManifestArray,
) -> xr.Dataset:
"""
Use kerchunk to open a single legacy file as an xarray Dataset wrapping virtualized zarr arrays.
Open a file or store as an xarray Dataset wrapping virtualized zarr arrays.
It's important that we avoid creating any IndexVariables, as our virtualized zarr array objects don't actually contain a collection that can be turned into a pandas.Index.
Expand All @@ -33,6 +33,7 @@ def open_dataset_via_kerchunk(
File path to open as a set of virtualized zarr arrays.
filetype : str, default None
Type of file to be opened. Used to determine which kerchunk file format backend to use.
Can be one of {'netCDF3', 'netCDF4'}.
If not provided will attempt to automatically infer the correct filetype from the the filepath's extension.
drop_variables: list[str], default is None
Variables in the file to drop before returning.
Expand Down

0 comments on commit 13f40fc

Please sign in to comment.