Configuration#
earthlens writes two different kinds of file, and they go to two different places.
| What lands there | Set it with | Environment variable | Default | |
|---|---|---|---|---|
| Output | the products you asked for | set_output_dir() |
EARTHLENS_DATA_DIR |
~/.earthlens/data |
| Cache | regenerable intermediates | set_cache_dir() |
EARTHLENS_CACHE |
the per-platform user cache directory |
Keeping them apart matters: a cleanup script that deletes anything called a cache must not take your requested products with it.
Pointing earthlens at one location#
from earthlens.core import EarthLens, set_output_dir, set_cache_dir
set_output_dir("/data/earthlens") # or: export EARTHLENS_DATA_DIR=/data/earthlens
set_cache_dir("/data/earthlens-cache") # or: export EARTHLENS_CACHE=/data/earthlens-cache
EarthLens(data_source="chc", variables=["precipitation"],
start="2009-01-01", end="2009-01-02").download()
# writes under /data/earthlens/chc
Resolution order for each directory, highest priority first:
- the
set_*_dir()override; - the environment variable;
- the built-in default.
Both are process-wide with no locking. Set them once at process start, before constructing any backend: a backend captures its output directory at construction, so changing the setting mid-run splits output across two locations rather than raising.
Where a download goes#
path= on a backend (or on the EarthLens facade) always wins:
| You pass | It writes to |
|---|---|
path="out" |
./out — a relative path is anchored to the working directory |
path="/data/run" |
/data/run |
path="" |
the current working directory |
| nothing at all | the configured output directory |
The facade adds a per-source subdirectory when path is omitted, so EarthLens(data_source="chc", …).download()
writes under <output_dir()>/chc/.
This changed
Before this was introduced, omitting path= wrote to the current working directory, and the facade wrote to
./earthlens-data/<source>/. If you have a script that globbed ./earthlens-data/** afterwards, it now finds
nothing. To keep the old behaviour, pass path="" for the working directory, or set
EARTHLENS_DATA_DIR=. — and your existing files are still wherever they were written, nothing was moved for
you.
Where cached intermediates go#
Backends that download an archive, extract or index on the way to their output cache it under the shared cache directory, each in its own subdirectory:
| Backend | Cache subdirectory |
|---|---|
| aqueduct, catrare, flopros, glaciers, solar_wind_atlas | aqueduct/, catrare/, … |
| cmip6 | cmip6/ |
| caravan | caravan/ |
| nwp | nwp/idx/ |
| osm | osm_pbf/ |
Backends that expose a cache_dir= argument still let you override it for one request.
This changed too
These nine backends previously cached in three different places: some under your output path=
(<path>/_aqueduct_cache/ and friends), some under ~/.earthlens/cache/, and some under the platform user
cache. They now all follow cache_dir().
Nothing is migrated for you, so anything cached by an earlier version is simply left behind. It is all regenerable — delete the old directories whenever convenient:
~/.earthlens/cache/(the old osm and cmip6 caches)- the old platform cache, which on Windows had a doubled path segment
(
…\AppData\Local\earthlens\earthlens\Cache, now…\AppData\Local\earthlens\Cache) - any
_aqueduct_cache/,_catrare_cache/,_flopros_cache/,_glaciers_cache/or_cache/gsa/folder sitting inside a previous output directory
The caravan cache in particular can be tens of GB, so it is worth checking.
API#
Process-wide directories for earthlens output and cached intermediates.
earthlens writes two different kinds of file, and they belong in two different places:
- Output — the products a caller asked for. A backend given an explicit
path=writes there; otherwise the location is resolved byoutput_dir(), so a whole project can be pointed at one location (a NAS mount, say) without threadingpath=through every call. - Cache — raw intermediates a backend downloads on the way to that output:
archives it unzips,
.osm.pbfextracts, GRIB index sidecars, catalog CSVs. These are regenerable, so they are kept out of the output tree and resolved bycache_dir(). Backends that expose acache_dir=argument still let a caller override it per request.
Keeping them apart matters: a cleanup script that deletes anything called a cache must not take requested products with it.
Both settings are process-wide module state with no locking. Set them once at process start, before any backend is constructed: a backend captures its output directory at construction, so changing a setting mid-run splits output across two locations rather than raising.
Resolution order for each, highest priority first:
| output | cache | |
|---|---|---|
| 1 | set_output_dir(...) |
set_cache_dir(...) |
| 2 | EARTHLENS_DATA_DIR |
EARTHLENS_CACHE |
| 3 | ~/.earthlens/data |
the per-platform user cache directory |
Example
set_output_dir(path)
#
Set the process-wide directory downloads are written to.
Takes precedence over the EARTHLENS_DATA_DIR environment variable. Only
None clears a previous override; every other value is treated as a
directory, so "" means the current working directory rather than a reset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str] | None
|
The directory to use, or |
required |
Examples:
- Point every backend at one directory, then clear the override:
- The override wins over whatever the environment says:
See Also
output_dir: Reads back the directory this function sets. set_cache_dir: The equivalent for regenerable intermediates.
Source code in libs/core/src/earthlens/config.py
output_dir()
#
Resolve the directory earthlens downloads are written to.
Resolution order: the set_output_dir() override, then the
EARTHLENS_DATA_DIR environment variable, then ~/.earthlens/data.
Returns:
| Type | Description |
|---|---|
Path
|
The resolved absolute directory. It is not created here; backends |
Path
|
create it lazily on the first download that writes to it. |
Examples:
- Read back the directory the next download will write to:
- Resolving the directory never creates it on disk:
See Also
set_output_dir: Sets the override this function reads first.
earthlens.base.AbstractDataSource: Falls back to this directory when it
is constructed without an explicit path.
Source code in libs/core/src/earthlens/config.py
set_cache_dir(path)
#
Set the process-wide directory regenerable intermediates are cached in.
Takes precedence over the EARTHLENS_CACHE environment variable. Only
None clears a previous override; every other value is treated as a
directory, so "" means the current working directory rather than a reset.
This is the root each backend hangs its own subdirectory off — the archives,
extracts and index sidecars it downloads on the way to producing output. It
is not where requested products land; that is output_dir().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str] | None
|
The directory to use, or |
required |
Examples:
- Point every backend's intermediates at one directory:
- Backends hang their own subdirectory off it:
See Also
cache_dir: Reads back the directory this function sets. set_output_dir: The equivalent for requested products.
Source code in libs/core/src/earthlens/config.py
cache_dir()
#
Resolve the directory regenerable intermediates are cached in.
Resolution order: the set_cache_dir() override, then the
EARTHLENS_CACHE environment variable, then the per-platform user cache
directory (platformdirs.user_cache_dir), which is the correct spelling on
Windows as well as Linux and macOS.
Backends append their own name, so two backends never share a cache tree.
Returns:
| Type | Description |
|---|---|
Path
|
The resolved absolute directory. It is not created here; each backend |
Path
|
creates its own subdirectory on first use. |
Examples:
- Read back the cache root a backend will hang its subdirectory off:
- Resolving the directory never creates it on disk:
See Also
set_cache_dir: Sets the override this function reads first. output_dir: Where requested products land, as opposed to intermediates.
Source code in libs/core/src/earthlens/config.py
resolve_output_path(path)
#
Resolve a backend's path= argument to an absolute output directory.
The single place the path= contract is implemented, so every backend
resolves it identically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str] | None
|
The backend's |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The absolute output directory. It is not created here. |
Examples:
- An omitted path follows the configured output directory:
- An explicit value wins, and is made absolute:
See Also
output_dir: The fallback used when path is None.