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.
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
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
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.
ignore_datasets_file = field(factory=_get_default_ignore_datasets_file)
class-attribute
instance-attribute
#
Path to the file containing the ignore datasets
This file is a YAML file that contains a list of facets to ignore per diagnostic.
The format is:
If this is not specified, a default ignore datasets file will be used. The default file is downloaded from the Climate-REF GitHub repository if it does not exist or is older than 6 hours.
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.
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.
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.
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
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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 | |
dimensions_cv = env_field(name='DIMENSIONS_CV_PATH', converter=Path)
class-attribute
instance-attribute
#
Path to a file containing the controlled vocabulary for the dimensions in a CMEC diagnostics bundle
This defaults to the controlled vocabulary for the CMIP7 Assessment Fast Track diagnostics,
which is included in the climate_ref_core package.
This controlled vocabulary is used to validate the dimensions in the diagnostics bundle. If custom diagnostics are implemented, this file may need to be extended to include any new dimensions.
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.
default_providers()
#
Default diagnostic provider
Used if no diagnostic providers are specified in the configuration
Returns:
| Type | Description |
|---|---|
list[DiagnosticProviderConfig]
|
List of default diagnostic providers |