seagrid.download.cache#
Local cache files that survive interrupted downloads.
Every download in seagrid is written to <target>.partial and moved into
place only when it is complete (partial(), finish()). A file or
Zarr store that exists under its final name is therefore either complete or
was written by something else, and is_complete() checks the second
case: a Zarr store with metadata but no data chunks, or a netCDF file that
cannot be opened.
Adapted from tracmass.seagrid.zarr_cache (tracmass_jax).
Functions
|
Return True if path is cached and should not be downloaded again. |
|
Remove the partial download of path, if there is one. |
|
Move a completed download from |
|
Return True if a Zarr store holds data chunks. |
|
Return True if path is a usable cached file or store. |
|
Return where a download of path is written until it is complete. |
- seagrid.download.cache.cached(path, data_var=None, *, force=False, label='seagrid')[source]#
Return True if path is cached and should not be downloaded again.
- Parameters:
path (
stroros.PathLike) – The cached file or store.data_var (
str, optional) – Variable that must be present.force (
bool, optional) – If True, never cached (download again). Default False.label (
str, optional) – Name used in the warning.
- Returns:
- Warns:
UserWarning – If path exists but is incomplete; it will be downloaded again.
- Return type:
- seagrid.download.cache.discard(path)[source]#
Remove the partial download of path, if there is one.
- Parameters:
path (
stroros.PathLike) – Final file or Zarr store (not the.partialname).- Return type:
None
- seagrid.download.cache.finish(path)[source]#
Move a completed download from
partial()into place at path.An existing file or store at path is replaced.
- Parameters:
path (
stroros.PathLike) – Final file or Zarr store.- Returns:
pathlib.Path– path.- Raises:
FileNotFoundError – If there is no partial download of path.
- Return type:
- seagrid.download.cache.has_zarr_data(path, name=None)[source]#
Return True if a Zarr store holds data chunks.
- Parameters:
path (
stroros.PathLike) – The store.name (
str, optional) – Variable to check. Default: any variable.
- Returns:
bool– False if the store or variable is missing or holds only metadata.- Return type:
- seagrid.download.cache.is_complete(path, data_var=None)[source]#
Return True if path is a usable cached file or store.
A Zarr store (a directory) must hold data chunks, for data_var if given.
A netCDF/HDF file must open with
xarrayand contain data_var if given.Any other file must be non-empty.
- Parameters:
path (
stroros.PathLike) – The cached file or store.data_var (
str, optional) – Variable that must be present.
- Returns:
- Return type:
- seagrid.download.cache.partial(path)[source]#
Return where a download of path is written until it is complete.
- Parameters:
path (
stroros.PathLike) – Final file or Zarr store.- Returns:
pathlib.Path– path with.partialappended to its name.- Return type:
Examples
>>> partial("/data/x.nc").name 'x.nc.partial'