climate-ref-pmp 0.6.5__py3-none-any.whl → 0.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,17 +2,45 @@
2
2
  Rapid evaluating CMIP data
3
3
  """
4
4
 
5
+ from __future__ import annotations
6
+
5
7
  import importlib.metadata
8
+ import os
9
+ from typing import TYPE_CHECKING
10
+
11
+ from loguru import logger
6
12
 
7
13
  from climate_ref_core.dataset_registry import DATASET_URL, dataset_registry_manager
8
14
  from climate_ref_core.providers import CondaDiagnosticProvider
9
15
  from climate_ref_pmp.diagnostics import ENSO, AnnualCycle, ExtratropicalModesOfVariability
10
16
 
17
+ if TYPE_CHECKING:
18
+ from climate_ref.config import Config
19
+
11
20
  __version__ = importlib.metadata.version("climate-ref-pmp")
12
21
 
22
+
13
23
  # Create the PMP diagnostics provider
14
24
  # PMP uses a conda environment to run the diagnostics
15
- provider = CondaDiagnosticProvider("PMP", __version__)
25
+ class PMPDiagnosticProvider(CondaDiagnosticProvider):
26
+ """
27
+ Provider for PMP diagnostics.
28
+ """
29
+
30
+ def configure(self, config: Config) -> None:
31
+ """Configure the provider."""
32
+ super().configure(config)
33
+ self.env_vars["PCMDI_CONDA_EXE"] = str(self.get_conda_exe())
34
+ # This is a workaround for a fatal error in internal_Finalize of MPICH
35
+ # when running in a conda environment on MacOS.
36
+ # It is not clear if this is a bug in MPICH or a problem with the conda environment.
37
+ if "FI_PROVIDER" not in os.environ: # pragma: no branch
38
+ logger.debug("Setting env variable 'FI_PROVIDER=tcp'")
39
+ self.env_vars["FI_PROVIDER"] = "tcp"
40
+
41
+
42
+ provider = PMPDiagnosticProvider("PMP", __version__)
43
+
16
44
 
17
45
  # Annual cycle diagnostics and metrics
18
46
  provider.register(AnnualCycle())
@@ -1,3 +1,4 @@
1
+ import json
1
2
  from collections.abc import Iterable
2
3
  from pathlib import Path
3
4
  from typing import Any, Union
@@ -215,8 +216,6 @@ def clean_up_json(json_file: Union[str, Path]) -> None:
215
216
  json_file : str or Path
216
217
  Path to the JSON file to clean up.
217
218
  """
218
- import json
219
-
220
219
  with open(str(json_file)) as f:
221
220
  data = json.load(f)
222
221
 
@@ -159,13 +159,6 @@ def build_pmp_command(
159
159
  # Note this uses the driver script from the REF env *not* the PMP conda env
160
160
  _parameter_file = _get_resource("climate_ref_pmp.params", parameter_file, use_resources=True)
161
161
 
162
- # This is a workaround for a fatal error in internal_Finalize of MPICH
163
- # when running in a conda environment on MacOS.
164
- # It is not clear if this is a bug in MPICH or a problem with the conda environment.
165
- if "FI_PROVIDER" not in os.environ: # pragma: no branch
166
- logger.debug("Setting env variable 'FI_PROVIDER=tcp'")
167
- os.environ["FI_PROVIDER"] = "tcp"
168
-
169
162
  # Run the driver script inside the PMP conda environment
170
163
  cmd = [
171
164
  driver_file,