Cache#

The DiskCacheStore and GCPCacheStore module enables connections to backend storage sources for caching large files.

By default, pycontrails uses the DiskCacheStore which stores files in the user cache directory or the current hard drive.

[1]:
from pycontrails import DiskCacheStore, GCPCacheStore

Disk Cache#

Store and retrieve files from the local hard drive.

[2]:
disk = DiskCacheStore()
[3]:
disk.path("test/cache/path.nc")
[4]:
disk.exists("test/cache/path.nc")
[4]:
False
[5]:
disk.cache_dir
[6]:
disk.size
[6]:
21090.761006

GCP Cache#

Requires [gcp] optional dependencies:

$ pip install pycontrails[gcp]

Store and retrieve files from Google Cloud Storage.

[7]:
gcp = GCPCacheStore(bucket="contrails-301217-unit-test", cache_dir="test/objects")
[8]:
gcp.bucket
[8]:
'contrails-301217-unit-test'
[9]:
gcp.path("path.nc")
[9]:
'test/objects/path.nc'
[10]:
gcp.gs_path("met/ecmwf/some-path.nc")
[10]:
'gs://contrails-301217-unit-test/test/objects/met/ecmwf/some-path.nc'
[11]:
gcp.exists("some-path.nc")
[11]:
False

Put objects#

By default, GCP cache is read only. Pass read_only=False to constructor to allow writing

[12]:
gcp = GCPCacheStore(bucket="contrails-301217-unit-test", cache_dir="test/objects", read_only=False)
[13]:
gcp.put("cache.ipynb", "cache.ipynb")
[13]:
'cache.ipynb'
[14]:
gcp.get("cache.ipynb")