Skip to content

Commit 665d77b

Browse files
committed
Refactor downloader constants
1 parent bf53e46 commit 665d77b

8 files changed

Lines changed: 997 additions & 948 deletions

File tree

climateset/download/constants/cmip6.py

Lines changed: 25 additions & 925 deletions
Large diffs are not rendered by default.
Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1+
# pylint: disable=C0103
2+
from dataclasses import dataclass
3+
from typing import Final
4+
5+
from climateset.utils import get_yaml_config
6+
17
# TODO remove raw variables from here
8+
9+
10+
@dataclass(frozen=True)
211
class Cmip6plusConstants:
312
"""
13+
Dataclass to represent CMIP6PLUS constants that are used by the download module.
14+
415
Attributes:
5-
NODE_LINK (str): Where the data can be accessed
6-
MODEL_SOURCES (List<str>): Identifiers for supported climate models
7-
VAR_SOURCE_LOOKUP (Dict<str, List<str>>): model and raw variables
8-
SUPPORTED_EXPERIMENTS (list<str>): experiments of climate models (runs) that are supported
16+
NODE_LINK : Where the data can be accessed
17+
MODEL_SOURCES : Identifiers for supported climate models
18+
VAR_SOURCE_LOOKUP : model and raw variables
19+
SUPPORTED_EXPERIMENTS : experiments of climate models (runs) that are supported
920
"""
1021

11-
NODE_LINK = "http://esgf-data2.llnl.gov"
22+
NODE_LINK: Final[str]
23+
MODEL_SOURCES: Final[tuple[str, ...]]
24+
VAR_SOURCE_LOOKUP: Final[tuple[str, ...]]
25+
SUPPORTED_EXPERIMENTS: Final[tuple[str, ...]]
1226

13-
MODEL_SOURCES = [
14-
"HasGEM3-GC31-LL",
15-
]
1627

17-
VAR_SOURCE_LOOKUP = [
18-
"areacella",
19-
"mrsofc",
20-
]
28+
_data = get_yaml_config("downloader/constants/cmip6plus.yaml")
2129

22-
SUPPORTED_EXPERIMENTS = [
23-
"hist-lu",
24-
"hist-piAer",
25-
"hist-piVolc",
26-
]
30+
CMIP6PLUS_CONSTANTS = Cmip6plusConstants(
31+
NODE_LINK=_data["node_link"],
32+
MODEL_SOURCES=tuple(_data["model_sources"]),
33+
SUPPORTED_EXPERIMENTS=tuple(_data["supported_experiments"]),
34+
VAR_SOURCE_LOOKUP=tuple(_data["var_source_lookup"]),
35+
)

climateset/download/constants/esgf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .cmip6 import Cmip6Constants
2-
from .cmip6plus import Cmip6plusConstants
1+
from .cmip6 import CMIP6_CONSTANTS
2+
from .cmip6plus import CMIP6PLUS_CONSTANTS
33
from .input4mips import INPUT4MIPS_CONSTANTS
44

55
CMIP6 = "CMIP6"
@@ -11,8 +11,8 @@
1111
# constant classes for esgf projects implemented here
1212
# add your own esgf project for downloading to download/constants/ and add the constant class to the dict and lists here
1313
ESGF_PROJECTS_CONSTANTS = {
14-
CMIP6: Cmip6Constants,
15-
CMIP6PLUS: Cmip6plusConstants,
14+
CMIP6: CMIP6_CONSTANTS,
15+
CMIP6PLUS: CMIP6PLUS_CONSTANTS,
1616
INPUT4MIPS: INPUT4MIPS_CONSTANTS,
1717
}
1818

climateset/download/constants/input4mips.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010

1111
@dataclass(frozen=True)
1212
class Input4MIPSConstants:
13+
"""
14+
Data class to represent Input4MIPS constants that are used by the download module.
15+
16+
Attributes:
17+
NODE_LINK : Node link is used to run an ESGF search
18+
EMISSION_ENDINGS : File endings for emission variables
19+
META_ENDINGS_PRC : File endings for PRC meta variables
20+
META_ENDINGS_SHARE : File endings for SHARE meta variables
21+
VAR_SOURCE_LOOKUP : Model and raw variables
22+
"""
23+
1324
NODE_LINK: Final[str]
1425
EMISSIONS_ENDINGS: Final[tuple[str, ...]]
1526
META_ENDINGS_PRC: Final[tuple[str, ...]]

0 commit comments

Comments
 (0)