Skip to content

Commit

Permalink
Update kerchunker.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaze committed Oct 24, 2024
1 parent 22411b9 commit fb5e550
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions argopy/stores/kerchunker.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ class ArgoKerchunker:
Note that the `kerchunk <https://fsspec.github.io/kerchunk/>`_ library is required if you need to extract
zarr data from netcdf file(s), a.k.a. :meth:`argopy.stores.ArgoKerchunker.translate`.
Examples
--------
.. code-block:: python
:caption: API examples
:caption: Examples
>>> ncfile = "s3://argo-gdac-sandbox/pub/dac/coriolis/6903090/6903090_prof.nc"
Expand Down Expand Up @@ -94,7 +92,7 @@ def __init__(
Options passed to fsspec when opening netcdf file
This argument is passed to :class:`kerchunk.netCDF3.NetCDF3ToZarr` or :class:`kerchunk.hdf.SingleHdf5ToZarr`
during translation, and in `backend_kwargs` of :class:`xarray.open_dataset`.
during translation, and in `backend_kwargs` of :class:`xr.open_dataset`.
"""
# Instance file system to load/save kerchunk json files
Expand Down Expand Up @@ -173,12 +171,22 @@ def _tojson(self, ncfile: Union[str, Path]):

return ncfile, kerchunk_jsfile, kerchunk_data

def translate(self, ncfiles: List):
def translate(self, ncfiles: Union[str, Path, List]):
"""Compute kerchunk data for one or a list of netcdf files
Kerchunk data are saved with the instance file store
Once translated, netcdf file reference data are internally registered in ``kerchunk_references``
Once translated, netcdf file reference data are internally registered in the :attr:`ArgoKerchunker.kerchunk_references` attribute
If more than 1 netcdf file is provided, the translation is executed in parallel:
- if `Dask <https://www.dask.org>`_ is available we use :meth:`dask.delayed`/:meth:`dask.compute`,
- otherwise we use a :class:`concurrent.futures.ThreadPoolExecutor`.
See Also
--------
:meth:`ArgoKerchunker.to_kerchunk`
"""
if not HAS_KERCHUNK:
raise ModuleNotFoundError("This method requires the 'kerchunk' library")
Expand Down Expand Up @@ -216,6 +224,10 @@ def to_kerchunk(self, ncfile: Union[str, Path], overwrite: bool = False):
"""Return json kerchunk data for a given netcdf file
Load data from instance file store, translate if necessary
See Also
--------
:meth:`ArgoKerchunker.translate`
"""
if overwrite:
self.translate(ncfile)
Expand Down

0 comments on commit fb5e550

Please sign in to comment.