2.16.3.4. pycsamt.geology.rock_providers#
Pluggable rock-property sources for RockDatabase.
No public, machine-readable service currently maps a rock or lithology
name directly to a resistivity range (see pycsamt.geology.rock_library
for why the built-in table is a literature compilation rather than a live
fetch). This module instead gives
from_url() and
from_provider() a small,
source-agnostic contract, so a project- or organisation-controlled
endpoint – an internal REST API, a JSON file on a shared drive or object
store, or a public service, should one appear – can be plugged in without
touching pycsamt.geology.lithology.
Every provider implements RockPropertyProvider: a zero-argument
fetch() returning (entries, metadata), a list of
RockEntry plus a small provenance
dictionary recording where they came from. RemoteRockPropertyProvider
caches successful fetches under ~/.pycsamt/rock_db (override with the
PYCSAMT_ROCKDB_CACHE environment variable or the cache_dir
argument, matching the convention already used by
pycsamt.ai._zoo’s model cache) and, on any failure – network error,
timeout, or a response that does not match the expected schema – falls
back first to a stale cache entry and then to
LocalRockPropertyProvider, rather than raising, unless
fallback=False.
Classes
|
Provider wrapping the bundled table or a local CSV file. |
|
Fetch rock entries as JSON from url, with caching and fallback. |
|
Minimal contract every rock-property source must satisfy. |
Exceptions
|
Raised by a provider when a fetch fails and |
- class pycsamt.geology.rock_providers.RockPropertyProvider(*args, **kwargs)[source]
Bases:
ProtocolMinimal contract every rock-property source must satisfy.
- class pycsamt.geology.rock_providers.LocalRockPropertyProvider(csv_path=None)[source]
Bases:
objectProvider wrapping the bundled table or a local CSV file.
This is what
RemoteRockPropertyProviderfalls back to, and is also usable directly wherever aRockPropertyProvideris expected but no remote source is involved.- Parameters:
csv_path (path-like, optional) – When given, entries come from
from_csv(). When omitted, entries come fromdefault().
- class pycsamt.geology.rock_providers.RemoteRockPropertyProvider(url, *, cache_dir=None, ttl_seconds=86400.0, timeout=10.0, force=False, fallback=True)[source]
Bases:
objectFetch rock entries as JSON from url, with caching and fallback.
- Parameters:
url (str) – Any URL
urllib.request.urlopen()can open (http(s)://,file://, …), serving a JSON array of objects with at leastname,rho_min,rho_max.cache_dir (path-like, optional) – Override the local cache location. Defaults to
$PYCSAMT_ROCKDB_CACHEor~/.pycsamt/rock_db.ttl_seconds (float) – Reuse a cached response younger than this many seconds instead of re-fetching.
timeout (float) – Network timeout in seconds for the fetch itself.
force (bool) – Re-fetch even if a fresh cache entry exists.
fallback (bool) – On failure, fall back to a stale cache entry (if any) and then to
LocalRockPropertyProvider, instead of raisingRockProviderFetchError.
- exception pycsamt.geology.rock_providers.RockProviderFetchError[source]
Bases:
RuntimeErrorRaised by a provider when a fetch fails and
fallback=False.Examples
>>> isinstance(RockProviderFetchError("network down"), RuntimeError) True