Vocabularies¶
Controlled vocabularies for envlib metadata fields.
Each vocabulary is a bundled JSON file in this package directory. A user-level
overlay directory (~/.envlib/vocabularies/) takes precedence per-file when
present — :func:refresh writes there, never into the installed package.
Vocabulary semantics:
- Upstream-sourced lists (
variablemembership,standard_name) are refreshable from their APIs via :func:refresh. - The envlib-curated
(variable, feature) -> CF standard_namemapping insidevariable.jsonis hand-maintained and NEVER regenerated by refresh — refresh only reports new/removed upstream terms for manual curation. - envlib-defined vocabularies (
feature,method,processing_level,aggregation_statistic,frequency_interval,license) have no upstream source; refresh does not touch them.
list(field)
¶
Return the valid canonical values for a vocabulary field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
One of the envlib vocabulary fields (e.g. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of canonical values. For |
list[str]
|
codes only — input aliases ( |
Source code in envlib/vocabularies/__init__.py
canonical(field, value)
¶
Resolve user input to the canonical vocabulary value.
Matching is case-insensitive after whitespace stripping; frequency_interval
additionally resolves the closed input-alias table ('24h' -> 'day',
'60min' -> '1h'). Raises ValueError when the value is not in the
vocabulary.
Source code in envlib/vocabularies/__init__.py
is_valid(field, value)
¶
Whether value is acceptable input for the vocabulary field (aliases included).
get_cf_standard_names(variable, feature)
¶
CF standard_name candidates envlib considers for a (variable, feature) pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
envlib variable (CV member; raises |
required |
feature
|
str
|
envlib feature (CV member; raises |
required |
Returns:
| Type | Description |
|---|---|
list[str] | None
|
Ordered candidate list — the FIRST entry is the curated default that |
list[str] | None
|
envlib auto-populates at validate/register time; an empty list means |
list[str] | None
|
"curated: no applicable standard name" (common for freshwater |
list[str] | None
|
water-quality variables); |
list[str] | None
|
(envlib warns but does not block). |
Source code in envlib/vocabularies/__init__.py
frequency_entry(code)
¶
Return the frequency_interval table entry for a canonical or alias code.
The entry dict has keys name (canonical code), kind ('fixed' |
'calendar'), seconds (int, or None for calendar codes), aliases.
Source code in envlib/vocabularies/__init__.py
refresh(field=None, _target_dir=None)
¶
Refresh upstream-sourced vocabularies from their APIs.
Fetches the ODM2 variablename list and/or the current CF standard-name table
and writes updated vocabulary files to the user overlay directory
(~/.envlib/vocabularies/) — never into the installed package. For
variable, only ODM2-sourced membership is updated (additively — upstream
removals are reported, never deleted); curated cf mappings and envlib
extensions are never touched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str | None
|
|
None
|
_target_dir
|
str | Path | None
|
Internal/dev hook — write somewhere other than the user overlay dir (used to generate the bundled files). |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Report dict keyed by refreshed field (counts, added/removed terms, |
dict
|
snake-case collisions, extension conflicts). |