climate_ref_core.providers
#
Interface for declaring a diagnostic provider.
This defines how diagnostic packages interoperate with the REF framework. Each diagnostic package may contain multiple diagnostics.
Each diagnostic package must implement the DiagnosticProvider interface.
MICROMAMBA_EXE_URL = 'https://github.com/mamba-org/micromamba-releases/releases/latest/download/micromamba-{platform}-{arch}'
module-attribute
#
The URL to download the micromamba executable from.
MICROMAMBA_MAX_AGE = datetime.timedelta(days=7)
module-attribute
#
Do not update if the micromamba executable is younger than this age.
CommandLineDiagnosticProvider
#
Bases: DiagnosticProvider
A provider for diagnostics that can be run from the command line.
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
CondaDiagnosticProvider
#
Bases: CommandLineDiagnosticProvider
A provider for diagnostics that can be run from the command line in a conda environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the provider. |
required |
version
|
str
|
The version of the provider. |
required |
slug
|
str | None
|
A slugified version of the name. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
env_vars |
dict[str, str]
|
Environment variables to set when running commands in the conda environment. |
pip_packages |
list[str]
|
Pip packages to install (as URLs) with |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
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 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | |
env_path
property
#
A unique path for storing the conda environment.
prefix
property
writable
#
Path where conda environments are stored.
configure(config)
#
Configure the provider.
create_env()
#
Create a conda environment.
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
get_conda_exe(update=False)
#
Get the path to a conda executable.
get_environment_file()
#
Return a context manager that provides the environment file as a Path.
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
run(cmd)
#
Run a command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
Iterable[str]
|
The command to run. |
required |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If the command fails |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
setup_environment(config)
#
validate_setup(config)
#
Validate conda environment exists.
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
DiagnosticProvider
#
The interface for registering and running diagnostics.
Each package that provides diagnostics must implement this interface.
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
configure(config)
#
Configure the provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
A configuration. |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
diagnostics()
#
Iterate over the available diagnostics for the provider.
Returns:
| Type | Description |
|---|---|
list[Diagnostic]
|
Iterator over the currently registered diagnostics. |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
fetch_data(config)
#
Fetch all data required for offline execution.
This includes reference datasets, climatology files, map files, recipes, or any other data the provider needs.
Default implementation does nothing. Override in subclasses that require data fetching. Providers are responsible for determining what data they need and how to fetch it.
Data should be downloaded to the pooch cache (via fetch_all_files
with output_dir=None). Diagnostics can then access data via
registry.abspath.
This method MUST be idempotent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
The application configuration |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
get(slug)
#
Get a diagnostic by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Name of the diagnostic (case-sensitive). |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the diagnostic with the given name is not found. |
Returns:
| Type | Description |
|---|---|
Diagnostic
|
The requested diagnostic. |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
get_data_path()
#
Get the path where this provider's data is cached.
Returns:
| Type | Description |
|---|---|
Path | None
|
The data cache path, or None if the provider doesn't use cached data. |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
ingest_data(config, db)
#
Ingest fetched data into the database.
This is called after fetch_data to register any provider-specific datasets in the database. For example, PMP climatology data needs to be ingested so it can be used by diagnostics.
Default implementation does nothing. Override in subclasses that have data to ingest.
This method MUST be idempotent.
Note: This method is only called when a database instance is provided to setup(). The database and ingestion utilities are part of the climate-ref package, not climate-ref-core. Provider implementations should handle ImportError gracefully if they need to import from climate-ref, allowing the provider to work standalone without the full climate-ref package installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
The application configuration |
required |
db
|
Any
|
The database instance (from climate-ref package) |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
register(diagnostic)
#
Register a diagnostic with the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostic
|
Diagnostic
|
The diagnostic to register. |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
setup(config, *, db=None, skip_env=False, skip_data=False)
#
Perform all setup required before offline execution.
This calls setup_environment, fetch_data, and ingest_data in the correct order. Override individual hooks for fine-grained control.
This method MUST be idempotent - safe to call multiple times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
The application configuration |
required |
db
|
Any
|
Optional database instance for data ingestion. If None, ingestion is skipped. This allows providers to be set up without the full climate-ref package (e.g., for environment setup or data fetching only). |
None
|
skip_env
|
bool
|
If True, skip environment setup (e.g., conda) |
False
|
skip_data
|
bool
|
If True, skip data fetching and ingestion |
False
|
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
setup_environment(config)
#
Set up the execution environment (e.g., conda environment).
Default implementation does nothing. Override in subclasses that require environment setup.
This method MUST be idempotent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
The application configuration |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
validate_setup(config)
#
Validate that the provider is ready for offline execution.
Returns True if setup is complete and valid, False otherwise. Default implementation returns True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
The application configuration |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if setup is valid and complete |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
import_provider(fqn)
#
Import a provider by name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fqn
|
str
|
Full package and attribute name of the provider to import For example: If only a package name is provided, the default attribute name is |
required |
Raises:
| Type | Description |
|---|---|
InvalidProviderException
|
If the provider cannot be imported If the provider isn't a valid |
Returns:
| Type | Description |
|---|---|
DiagnosticProvider
|
DiagnosticProvider instance |