Skip to content

Commit 57c2b95

Browse files
authored
Assign ww3 data to wave realm in access-om3 builder (#162)
* assign ww3 data to wave realm in access-om3 builder * add specific tests for builder parsers
1 parent e2f3cc7 commit 57c2b95

File tree

2 files changed

+82
-7
lines changed

2 files changed

+82
-7
lines changed

src/access_nri_intake/source/builders.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,8 @@ def __init__(self, path):
221221
@staticmethod
222222
def parser(file):
223223
try:
224-
match_groups = re.match(
225-
r".*/([^/]*)/([^/]*)/output\d+/([^/]*)/.*\.nc", file
226-
).groups()
227-
# configuration = match_groups[0]
228-
# exp_id = match_groups[1]
229-
realm = match_groups[2]
224+
match_groups = re.match(r".*/output\d+/([^/]*)/.*\.nc", file).groups()
225+
realm = match_groups[0]
230226

231227
if realm == "ice":
232228
realm = "seaIce"
@@ -323,8 +319,10 @@ def parser(file):
323319
variable_units_list,
324320
) = parse_access_ncfile(file)
325321

326-
if ("mom6" in filename) or ("ww3" in filename):
322+
if "mom6" in filename:
327323
realm = "ocean"
324+
elif "ww3" in filename:
325+
realm = "wave"
328326
elif "cice" in filename:
329327
realm = "seaIce"
330328
else:

tests/test_builders.py

+77
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,83 @@ def test_builder_build(
6262
assert len(cat) == num_datasets
6363

6464

65+
@pytest.mark.parametrize(
66+
"filename, builder, realm, member, file_id",
67+
[
68+
(
69+
"access-om2/output000/ocean/ocean.nc",
70+
"AccessOm2Builder",
71+
"ocean",
72+
None,
73+
"ocean",
74+
),
75+
(
76+
"access-om2/output000/ice/OUTPUT/iceh.1900-01.nc",
77+
"AccessOm2Builder",
78+
"seaIce",
79+
None,
80+
"iceh_XXXX_XX",
81+
),
82+
(
83+
"access-cm2/by578/history/atm/netCDF/by578a.pd201501_dai.nc",
84+
"AccessCm2Builder",
85+
"atmos",
86+
"by578",
87+
"a_pdXXXXXX_dai",
88+
),
89+
(
90+
"access-cm2/by578a/history/atm/netCDF/by578aa.pd201501_dai.nc",
91+
"AccessCm2Builder",
92+
"atmos",
93+
"by578a",
94+
"a_pdXXXXXX_dai",
95+
),
96+
(
97+
"access-cm2/by578/history/ice/iceh_d.2015-01.nc",
98+
"AccessCm2Builder",
99+
"seaIce",
100+
"by578",
101+
"iceh_d_XXXX_XX",
102+
),
103+
(
104+
"access-cm2/by578/history/ocn/ocean_daily.nc-20150630",
105+
"AccessCm2Builder",
106+
"ocean",
107+
"by578",
108+
"ocean_daily",
109+
),
110+
(
111+
"access-om3/output000/GMOM_JRA_WD.mom6.h.sfc_1900_01_02.nc",
112+
"AccessOm3Builder",
113+
"ocean",
114+
None,
115+
"GMOM_JRA_WD_mom6_h_sfc_XXXX_XX_XX",
116+
),
117+
(
118+
"access-om3/output000/GMOM_JRA_WD.cice.h.1900-01-01.nc",
119+
"AccessOm3Builder",
120+
"seaIce",
121+
None,
122+
"GMOM_JRA_WD_cice_h_XXXX_XX_XX",
123+
),
124+
(
125+
"access-om3/output000/GMOM_JRA_WD.ww3.hi.1900-01-02-00000.nc",
126+
"AccessOm3Builder",
127+
"wave",
128+
None,
129+
"GMOM_JRA_WD_ww3_hi_XXXX_XX_XX_XXXXX",
130+
),
131+
],
132+
)
133+
def test_builder_parser(test_data, filename, builder, realm, member, file_id):
134+
Builder = getattr(builders, builder)
135+
info = Builder.parser(str(test_data / filename))
136+
assert info["realm"] == realm
137+
if member:
138+
assert info["member"] == member
139+
assert info["file_id"] == file_id
140+
141+
65142
def test_builder_columns_with_iterables(test_data):
66143
builder = builders.AccessOm2Builder(str(test_data / "access-om2"))
67144
assert not builder.columns_with_iterables

0 commit comments

Comments
 (0)