[2]:
import argopy
from argopy import DataFetcher as ArgoDataFetcher
/home/docs/checkouts/readthedocs.org/user_builds/argopy/checkouts/v0.1.4/argopy/plotters.py:33: UserWarning: argopy requires cartopy installed for full map plotting functionality
  warnings.warn("argopy requires cartopy installed for full map plotting functionality")

Performance

Caching data

If you want to avoid retrieving the same data several times during a working session, or if you fetched a large amount of data, you may want to temporarily save data in a cache file.

You can cache fetched data with the fetchers option cache.

Argopy cached data are persistent, meaning that they are stored locally on files and will survive execution of your script with a new session. They have however an expiration time of one day, since this is the update frequency of most data sources. This will ensure you always have the last version of Argo data.

All data and meta-data (index) fetchers have a caching system.

The argopy default cache folder is under your home directory at ~./.cache/argopy. But you can specify the path you want to use in several ways:

  • with argopy global options:
argopy.set_options(cachedir='mycache_folder')
  • in a temporary context:
with argopy.set_options(cachedir='mycache_folder'):
    ds = ArgoDataFetcher(cache=True).profile(6902746, 34).to_xarray()
  • when instantiating the data fetcher:
ds = ArgoDataFetcher(cache=True, cachedir='mycache_folder').profile(6902746, 34).to_xarray()

Warning

You really need to set the cache option to True. Specifying only the cachedir won’t trigger caching !

Specifyng a cache directory at the fetcher level will ensure

Clearing the cache

Cached data have an expiration time of 1 day.

If you want to manuallt clear your cache folder, and/or make sure your data are newly fetched, you can do it at the fetcher level with the clear_cache method.

Start to fetch data and store them in cache:

fetcher = ArgoDataFetcher(cache=True, cachedir='mycache_folder').profile(6902746, 34)
fetcher.to_xarray();

Fetched data are in the local cache folder:

os.listdir('mycache_folder')

where we see one hash entries the newly fetched data and the cache registry file cache.

We can then fetch something else:

fetcher2 = ArgoDataFetcher(cache=True, cachedir='mycache_folder').profile(1901393, 1)
fetcher2.to_xarray();

All fetched data are now cached in ‘mycache_folder’:

os.listdir('mycache_folder')

Note the new hash file from the fetcher2 data.

We can safely clear the cache from the first fetcher data:

fetcher.clear_cache()
os.listdir('mycache_folder')

By using the fetcher level clear cache, you make sure that only data fetched with it are removed, while other fetched data (with other fetchers for instance) will stay in place.

If you want to clear the entire cache folder, whatever the fetcher used, do it at the package level with:

argopy.clear_cache()
os.listdir('mycache_folder')

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-13-6726e674f21f> in <module>
----> 1 os.listdir('mycache_folder')

FileNotFoundError: [Errno 2] No such file or directory: 'mycache_folder'