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_overrides |
dict[str, str]
|
Environment variables overriding the process environment for commands run 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
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 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 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 | |
conda_exe_path
property
#
Where the conda executable lives, whether or not it has been installed yet.
Use this when only the location is needed.
get_conda_exe installs the executable, which requires network access.
env_path
property
#
A unique path for storing the conda environment.
prefix
property
writable
#
Path where conda environments are stored.
configure(config)
#
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
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 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
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 |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
provider_by_slug(slug)
cached
#
Look up a registered provider by its slug
Entry points can be enumerated without importing them, so only the provider that matches is ever loaded. The loaded provider is the module-level singleton, so it carries whatever configuration the current process has already applied to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Slug of the provider, for example |
required |
Raises:
| Type | Description |
|---|---|
InvalidProviderException
|
If no registered provider has the given slug. |
Returns:
| Type | Description |
|---|---|
DiagnosticProvider
|
DiagnosticProvider instance |
Source code in packages/climate-ref-core/src/climate_ref_core/providers.py
resolve_diagnostic(full_slug)
#
Look up a diagnostic from its full slug
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
full_slug
|
str
|
Slug of the form |
required |
Raises:
| Type | Description |
|---|---|
InvalidProviderException
|
If the slug is malformed or names a provider that is not installed. |
KeyError
|
If the provider does not supply a diagnostic with that slug. |
Returns:
| Type | Description |
|---|---|
Diagnostic
|
The diagnostic registered with the named provider. |