forked from ufs-community/uwtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdeps.py
130 lines (111 loc) · 3.64 KB
/
cdeps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
"""
A driver for the CDEPS data models.
"""
from pathlib import Path
from iotaa import asset, task, tasks
from uwtools.api.template import _render
from uwtools.config.formats.nml import NMLConfig
from uwtools.drivers.driver import AssetsCycleBased
from uwtools.strings import STR
from uwtools.utils.tasks import file
class CDEPS(AssetsCycleBased):
"""
A driver for the CDEPS data models.
"""
# Workflow tasks
@tasks
def atm(self):
"""
Create data atmosphere configuration with all required content.
"""
yield self._taskname("data atmosphere configuration")
yield [
self.atm_nml(),
self.atm_stream(),
]
@task
def atm_nml(self):
"""
Create data atmosphere Fortran namelist file (datm_in).
"""
fn = "datm_in"
yield self._taskname(f"namelist file {fn}")
path = self._rundir / fn
yield asset(path, path.is_file)
yield None
path.parent.mkdir(parents=True, exist_ok=True)
self._model_namelist_file("atm_in", path)
@task
def atm_stream(self):
"""
Create data atmosphere stream config file (datm.streams).
"""
fn = "datm.streams"
yield self._taskname(f"stream file {fn}")
path = self._rundir / fn
yield asset(path, path.is_file)
template_file = self._driver_config["atm_streams"]["template_file"]
yield file(path=Path(template_file))
self._model_stream_file("atm_streams", path, template_file)
@tasks
def ocn(self):
"""
Create data ocean configuration with all required content.
"""
yield self._taskname("data atmosphere configuration")
yield [
self.ocn_nml(),
self.ocn_stream(),
]
@task
def ocn_nml(self):
"""
Create data ocean Fortran namelist file (docn_in).
"""
fn = "docn_in"
yield self._taskname(f"namelist file {fn}")
path = self._rundir / fn
yield asset(path, path.is_file)
yield None
path.parent.mkdir(parents=True, exist_ok=True)
self._model_namelist_file("ocn_in", path)
@task
def ocn_stream(self):
"""
Create data ocean stream config file (docn.streams).
"""
fn = "docn.streams"
yield self._taskname(f"stream file {fn}")
path = self._rundir / fn
yield asset(path, path.is_file)
template_file = self._driver_config["ocn_streams"]["template_file"]
yield file(path=Path(template_file))
self._model_stream_file("ocn_streams", path, template_file)
# Private helper methods
@property
def _driver_name(self) -> str:
"""
Returns the name of this driver.
"""
return STR.cdeps
def _model_namelist_file(self, group: str, path: Path) -> None:
"""
Create an atmosphere or ocean namelist file.
:param group: "atm_in" or "ocn_in".
:param path: Path to write namelist to.
"""
self._create_user_updated_config(
config_class=NMLConfig, config_values=self._driver_config[group], path=path
)
def _model_stream_file(self, group: str, path: Path, template_file: str) -> None:
"""
Create an atmosphere or ocean stream file, based on a template.
:param group: "atm_in" or "ocn_in".
:param path: Path to write namelist to.
:param template_file: Path to the template file to render.
"""
_render(
input_file=Path(template_file),
output_file=path,
values_src=self._driver_config[group],
)