emsarray.operations.cache#
Operations for making cache keys based on dataset geometry.
Some operations such as triangulate_dataset()
only depend on the dataset geometry and are expensive to compute.
For applications that need to derive data from the dataset geometry
it would be useful if the derived data could be reused between different runs of the same application
or between multiple time slices of the same geometry distributed across multiple files.
This module provides make_cache_key() to assist in this process
by deriving a cache key from the important parts of a dataset geometry.
Applications can use this cache key
as part of a filename when save derived geometry data to disk
or as a key to an in-memory cache of derived geometry.
The derived cache keys will be identical between different instances of an application, and between different files in multi-file datasets split over an unlimited dimension.
This module does not provide an actual cache implementation.
Functions#
- emsarray.operations.cache.make_cache_key(dataset, hash=None)#
Derive a cache key from the geometry of a dataset.
- Parameters:
dataset (
xarray.Dataset) – The dataset to generate a cache key from.hash (
hashlib-compatible hash instance, optional) – An instance of a hashlib hash class. Defaults tohashlib.blake2b()with a digest size of 32, which is secure enough and fast enough for most purposes.
- Returns:
cache_key (
str) – A string suitable for use as a cache key. The string will be safe for use as part of a filename if data is to be cached to disk.
Examples
import emsarray from emsarray.operations.cache import make_cache_key # Make a cache key from the dataset dataset = emsarray.tuorial.open_dataset("austen") cache_key = make_cache_key(dataset) >>> cache_key '580853c44e732878937598e86d0b26cb81e18d986072c0790a122244e9d3f480'
Notes
The cache key will depend on the Convention class, the emsarray version, and a hash of the geometry of the dataset. The specific structure of the cache key may change between emsarray and python versions, and should not be relied upon.