climate_ref.config
#
Configuration management
The REF uses a tiered configuration model, where configuration is sourced from a hierarchy of different places.
Each configuration value has a default which is used if not other configuration is available.
Then configuration is loaded from a .toml file which overrides any default values.
Finally, some configuration can be overridden at runtime using environment variables,
which always take precedence over any other configuration values.
BUNDLED_IGNORE_DATASETS = PackagedResource('climate_ref', DEFAULT_IGNORE_DATASETS_FILENAME)
module-attribute
#
The grey list shipped inside the climate_ref package.
This is the copy that was current when the installed version was released. It is always readable, so a solve never depends on the network or on a writable cache.
env_prefix = 'REF'
module-attribute
#
Prefix for the environment variables used by the REF
Config
#
Configuration that is used by the REF
Source code in packages/climate-ref/src/climate_ref/config.py
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
cmip6_parser = env_field('CMIP6_PARSER', default='complete')
class-attribute
instance-attribute
#
Parser to use for CMIP6 datasets
This can be either drs or complete.
drs: Use the DRS parser, which parses the dataset based on the DRS naming conventions.complete: Use the complete parser, which parses the dataset based on all available metadata.
cmip7_parser = env_field('CMIP7_PARSER', default='complete')
class-attribute
instance-attribute
#
Parser to use for CMIP7 datasets
This can be either drs or complete.
drs: Use the DRS parser, which parses the dataset based on the DRS naming conventions.complete: Use the complete parser, which parses the dataset based on all available metadata.
ignore_datasets_file = env_field('IGNORE_DATASETS_FILE', converter=_optional_path, default=None)
class-attribute
instance-attribute
#
Path to a file containing the grey list
This file is a YAML file that contains a list of facets to ignore per diagnostic.
The format is:
Leave this unset to use the grey list shipped inside the climate_ref package,
refreshed from ignore_datasets_url when that is possible.
Setting it pins the grey list to a file you manage, and disables fetching.
ignore_datasets_resource
property
#
The grey list to apply when solving
Resolves to ignore_datasets_file if it is set,
then to a copy refreshed from ignore_datasets_url,
and finally to the copy shipped inside climate_ref.
A cache that has not been refreshed for DEFAULT_IGNORE_DATASETS_MAX_STALE is skipped.
Without that bound,
a copy left behind by an older release would shadow the newer packaged copy
indefinitely on a host that can never reach the network.
Returns:
| Type | Description |
|---|---|
LayeredResource
|
The resolved grey list resource. |
ignore_datasets_url = env_field('IGNORE_DATASETS_URL', default=DEFAULT_IGNORE_DATASETS_URL)
class-attribute
instance-attribute
#
URL to refresh the grey list from at solve time.
The download happens during solving only, at most once every 6 hours, and never during configuration loading. A failed download is not an error, since the copy shipped in the package is used instead.
Set to an empty string (e.g. REF_IGNORE_DATASETS_URL=) to skip the attempt entirely,
which avoids the request timeout on a host with no route to the internet.
log_format = env_field('LOG_FORMAT', default=DEFAULT_LOG_FORMAT)
class-attribute
instance-attribute
#
Format of the log messages that are displayed by the REF via the CLI
Examples of the formatting options are available in the
loguru documentation.
{extra[execution_prefix]} names the execution a record was logged during, if any.
log_json = env_field('LOG_JSON', default=False, converter=_bool)
class-attribute
instance-attribute
#
Write console log messages as JSON, one object per line
Use this when logs are collected by an aggregator such as Loki,
so a multi-line traceback stays a single entry and context such as the execution can be filtered on.
log_format still sets the text field of each record.
log_level = field(default='INFO')
class-attribute
instance-attribute
#
Log level of messages that are displayed by the REF via the CLI
This value is overridden if a value is specified via the CLI.
n_jobs = env_field('N_JOBS', default=1, converter=int)
class-attribute
instance-attribute
#
Number of worker processes used to parse dataset files
1 parses serially,
-1 uses all available CPUs,
and any other positive value is used as-is.
Parsing opens netCDF files, so it is bound by (highly parallel) filesystem latency rather than by CPU.
This applies both to ref datasets ingest (where --n-jobs overrides it)
and to the finalisation of datasets that the solver performs
when they were ingested with the drs parser.
collect_validation_errors(config_file)
classmethod
#
Collect strict validation errors for a configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
Path
|
Path to the configuration file to validate. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of validation errors. An empty list means the file is valid. |
Source code in packages/climate-ref/src/climate_ref/config.py
default()
classmethod
#
Load the default configuration
This will load the configuration from the default configuration location,
which is typically the user's configuration directory.
This location can be overridden by setting the REF_CONFIGURATION environment variable.
Returns:
| Type | Description |
|---|---|
Config
|
The default configuration |
Source code in packages/climate-ref/src/climate_ref/config.py
dump(defaults=True)
#
Dump the configuration to a TOML document
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
defaults
|
bool
|
If True, include default values in the output |
True
|
Returns:
| Type | Description |
|---|---|
TOMLDocument
|
The configuration as a TOML document |
Source code in packages/climate-ref/src/climate_ref/config.py
dumps(defaults=True)
#
load(config_file, allow_missing=True)
classmethod
#
Load the configuration from a file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
Path
|
Path to the configuration file. This should be a TOML file. |
required |
Returns:
| Type | Description |
|---|---|
Config
|
The configuration loaded from the file |
Source code in packages/climate-ref/src/climate_ref/config.py
refresh()
#
Refresh the configuration values
This returns a new instance of the configuration based on the same configuration file and any current environment variables.
Source code in packages/climate-ref/src/climate_ref/config.py
save(config_file=None)
#
Save the configuration as a TOML file
The configuration will be saved to the specified file. If no file is specified, the configuration will be saved to the file that was used to load the configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
Path | None
|
The file to save the configuration to |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no configuration file is specified and the configuration was not loaded from a file |
Source code in packages/climate-ref/src/climate_ref/config.py
DbConfig
#
Database configuration
We support SQLite and PostgreSQL databases.
The default is to use SQLite, which is a file-based database that is stored in the
REF_CONFIGURATION directory.
This is a good option for testing and development, but not recommended for production use.
For production use, we recommend using PostgreSQL.
Source code in packages/climate-ref/src/climate_ref/config.py
database_url = env_field(name='DATABASE_URL')
class-attribute
instance-attribute
#
Database URL that describes the connection to the database.
Defaults to sqlite:///{config.paths.db}/climate_ref.db.
This configuration value will be overridden by the REF_DATABASE_URL environment variable.
Schemas
The following schemas are supported:
max_backups = env_field(name='MAX_BACKUPS', default=5)
class-attribute
instance-attribute
#
Maximum number of database backups to keep.
When running migrations for on-disk SQLite databases, a backup of the database is created. This setting controls how many of these backups are retained. The oldest backups are automatically removed when this limit is exceeded.
DiagnosticProviderConfig
#
Defining the diagnostic providers used by the REF.
Each diagnostic provider is a package that contains the logic for running a specific set of diagnostics. This configuration determines which diagnostic providers are loaded and used when solving.
Multiple diagnostic providers can be specified as shown in the example below.
[[diagnostic_providers]]
provider = "climate_ref_esmvaltool:provider"
[diagnostic_providers.config]
[[diagnostic_providers]]
provider = "climate_ref_ilamb:provider"
[diagnostic_providers.config]
[[diagnostic_providers]]
provider = "climate_ref_pmp:provider"
[diagnostic_providers.config]
Source code in packages/climate-ref/src/climate_ref/config.py
config = field(factory=dict)
class-attribute
instance-attribute
#
Additional configuration for the diagnostic provider.
See the documentation for the diagnostic package for the available configuration options.
provider
instance-attribute
#
Package that contains the diagnostic provider
This should be the fully qualified name of the diagnostic provider.
ExecutorConfig
#
Configuration to define the executor to use for running diagnostics
Source code in packages/climate-ref/src/climate_ref/config.py
config = field(factory=dict)
class-attribute
instance-attribute
#
Additional configuration for the executor.
See the documentation for the executor for the available configuration options. These options will be passed to the executor class when it is created.
executor = env_field(name='EXECUTOR', default='climate_ref.executor.LocalExecutor')
class-attribute
instance-attribute
#
Executor class to use for running diagnostics
This should be the fully qualified name of the executor class
(e.g. climate_ref.executor.LocalExecutor).
The default is to use the local executor which runs the executions locally, in-parallel
using a process pool.
This class will be used for all executions of diagnostics.
measure_resources = env_field(name='EXECUTOR_MEASURE_RESOURCES', default=True, converter=_bool)
class-attribute
instance-attribute
#
Whether to record what each execution costs in wall time, CPU time and peak memory.
The measurement is what ref executions resources aggregates,
so turning it off leaves that command without new samples.
Set it to false where the sampling thread is unwelcome,
for example in a memory-constrained container or a profiling run.
build(config, database)
#
Create an instance of the executor
Returns:
| Type | Description |
|---|---|
Executor
|
An executor that can be used to run diagnostics |
Source code in packages/climate-ref/src/climate_ref/config.py
NativeStoreConfig
#
Configuration for the content-addressed native-bundle object store.
The native store holds the curated native outputs (NetCDF, PNG, ...) produced by each
test case, keyed by their sha256 digest.
Read operations (has, fetch) are always anonymous and credential-free.
Write operations are gated to the mint verb only.
Source code in packages/climate-ref/src/climate_ref/config.py
bucket = env_field(name='NATIVE_STORE_BUCKET', default='ref-baselines-public')
class-attribute
instance-attribute
#
Name of the writable (Cloudflare R2) bucket.
Non-secret routing config, consumed only by the mint verb.
Set REF_NATIVE_STORE_BUCKET to override.
Write credentials are not stored here: the access-key id and secret-access-key are
read from REF_NATIVE_STORE_ACCESS_KEY_ID / REF_NATIVE_STORE_SECRET_ACCESS_KEY
(falling back to boto3's default credential chain) at upload time only, so secrets never
land in a serialised config.
cache_dir = env_field(name='NATIVE_STORE_CACHE_DIR', converter=Path)
class-attribute
instance-attribute
#
Local pooch cache directory for downloaded native blobs.
Defaults via :func:~climate_ref_core.dataset_registry.resolve_cache_dir,
so the REF_DATASET_CACHE_DIR environment variable applies here too.
s3_endpoint_url = env_field(name='NATIVE_STORE_S3_ENDPOINT_URL', default='https://2aa5172b2bba093c516027d6fa13cdc8.r2.cloudflarestorage.com')
class-attribute
instance-attribute
#
S3 API endpoint for the writable (Cloudflare R2) backend, without the bucket.
Non-secret routing config, consumed only by the mint verb. Defaults to the
production Climate-REF R2 account endpoint (default jurisdiction — note there is no
.eu in the host). Anonymous read (fetch / has) uses :attr:url instead and
never touches this.
Set REF_NATIVE_STORE_S3_ENDPOINT_URL to override (e.g. a staging account).
url = env_field(name='NATIVE_STORE_URL', default='https://baselines.climate-ref.org')
class-attribute
instance-attribute
#
Base URL of the native-bundle object store.
Blobs are served at {url}/{digest}.
Defaults to the production Climate-REF baselines endpoint.
Set REF_NATIVE_STORE_URL to a local file:///path/to/dir (or a plain filesystem path)
for offline development and testing.
PathConfig
#
Common paths used by the REF application
Warning
These paths must be common across all systems that the REF is being run. Generally, this means that they should be mounted in the same location on all systems.
If any of these paths are specified as relative paths, they will be resolved to absolute paths. These absolute paths will be used for all operations in the REF.
Source code in packages/climate-ref/src/climate_ref/config.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
dimensions_cv = env_field(name='DIMENSIONS_CV_PATH', converter=_optional_path, default=None)
class-attribute
instance-attribute
#
Path to a file containing the controlled vocabulary for the dimensions in a CMEC diagnostics bundle
Leave this unset to use the controlled vocabulary for the CMIP7 Assessment Fast Track
diagnostics, which is shipped inside the climate_ref_core package.
That copy is read straight out of the installed package,
so it needs no network access and no writable filesystem.
This controlled vocabulary is used to validate the dimensions in the diagnostics bundle. If custom diagnostics are implemented, point this at a copy that has been extended with any new dimensions.
dimensions_cv_resource
property
#
The controlled vocabulary to validate diagnostic bundles against
Resolves to dimensions_cv if it is set, and to the copy shipped
inside climate_ref_core otherwise.
Returns:
| Type | Description |
|---|---|
LayeredResource
|
The resolved controlled vocabulary resource. |
log = env_field(name='LOG_ROOT', converter=ensure_absolute_path)
class-attribute
instance-attribute
#
Directory to store log files from the compute engine
This is not currently used by the REF, but is included for future use.
results = env_field(name='RESULTS_ROOT', converter=ensure_absolute_path)
class-attribute
instance-attribute
#
Path to store the executions
scratch = env_field(name='SCRATCH_ROOT', converter=ensure_absolute_path)
class-attribute
instance-attribute
#
Shared scratch space for the REF.
This directory is used to write the intermediate executions of a diagnostic execution. After the diagnostic has been run, the executions will be copied to the executions directory.
This directory must be accessible by all the diagnostic services that are used to run the diagnostics, but does not need to be mounted in the same location on all the diagnostic services.
software = env_field(name='SOFTWARE_ROOT', converter=ensure_absolute_path)
class-attribute
instance-attribute
#
Shared software space for the REF.
This directory is used to store software environments.
This directory must be accessible by all the diagnostic services that are used to run the diagnostics, and should be mounted in the same location on all the diagnostic services.
ReportStoreConfig
#
Configuration for the public store that hosts baseline diff reports.
A diff report is a small static site keyed by pull request and head sha, so this store is addressed by path rather than by digest. It is a different bucket to the native store because an R2 token cannot be scoped to a prefix, so a token that can write reports must not also be able to overwrite baseline blobs.
Write credentials are not stored here: the access-key id and secret-access-key are read from
REF_REPORT_STORE_ACCESS_KEY_ID / REF_REPORT_STORE_SECRET_ACCESS_KEY
(falling back to boto3's default credential chain) at upload time only,
so secrets never land in a serialised config.
Source code in packages/climate-ref/src/climate_ref/config.py
bucket = env_field(name='REPORT_STORE_BUCKET', default='ref-baselines-reports')
class-attribute
instance-attribute
#
Name of the writable (Cloudflare R2) reports bucket.
Non-secret routing config, consumed only when uploading a report.
Set REF_REPORT_STORE_BUCKET to override.
s3_endpoint_url = env_field(name='REPORT_STORE_S3_ENDPOINT_URL', default='https://2aa5172b2bba093c516027d6fa13cdc8.r2.cloudflarestorage.com')
class-attribute
instance-attribute
#
S3 API endpoint for the writable (Cloudflare R2) backend, without the bucket.
Non-secret routing config, consumed only when uploading a report.
Defaults to the production Climate-REF R2 account endpoint.
Set REF_REPORT_STORE_S3_ENDPOINT_URL to override (e.g. a staging account).
url = env_field(name='REPORT_STORE_URL', default='https://reports.baselines.climate-ref.org')
class-attribute
instance-attribute
#
Base URL the reports are served from.
Reports are served at {url}/{key}.
Defaults to the production Climate-REF reports endpoint.
Set REF_REPORT_STORE_URL to a local file:///path/to/dir (or a plain filesystem path)
to render and inspect an upload offline.
default_providers()
#
Return default diagnostic providers.
Used if no diagnostic providers are specified in the configuration
Returns:
| Type | Description |
|---|---|
list[DiagnosticProviderConfig]
|
List of default diagnostic providers |
Source code in packages/climate-ref/src/climate_ref/config.py
ensure_absolute_path(path)
#
refresh_ignore_datasets_file(config)
#
Refresh the cached grey list from config.ignore_datasets_url.
This is called at solve time so that configuration loading never performs network I/O.
The download happens at most once every DEFAULT_IGNORE_DATASETS_REFRESH_INTERVAL.
A fresh cached file is reused untouched.
Refreshing is best effort. An unset URL, an unreachable network, and an unwritable cache directory are all non-fatal: the solve falls back to the cached copy if there is one, and to the copy shipped in the package otherwise. This keeps read-only and air-gapped deployments working without any configuration.
Refreshing is skipped entirely when ignore_datasets_file is set,
since an explicit file is the operator's to manage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
The configuration providing |
required |