Skip to content

Commit

Permalink
Assign ww3 data to wave realm in access-om3 builder (#162)
Browse files Browse the repository at this point in the history
* assign ww3 data to wave realm in access-om3 builder

* add specific tests for builder parsers
  • Loading branch information
dougiesquire authored Mar 28, 2024
1 parent e2f3cc7 commit 57c2b95
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/access_nri_intake/source/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,8 @@ def __init__(self, path):
@staticmethod
def parser(file):
try:
match_groups = re.match(
r".*/([^/]*)/([^/]*)/output\d+/([^/]*)/.*\.nc", file
).groups()
# configuration = match_groups[0]
# exp_id = match_groups[1]
realm = match_groups[2]
match_groups = re.match(r".*/output\d+/([^/]*)/.*\.nc", file).groups()
realm = match_groups[0]

if realm == "ice":
realm = "seaIce"
Expand Down Expand Up @@ -323,8 +319,10 @@ def parser(file):
variable_units_list,
) = parse_access_ncfile(file)

if ("mom6" in filename) or ("ww3" in filename):
if "mom6" in filename:
realm = "ocean"
elif "ww3" in filename:
realm = "wave"
elif "cice" in filename:
realm = "seaIce"
else:
Expand Down
77 changes: 77 additions & 0 deletions tests/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,83 @@ def test_builder_build(
assert len(cat) == num_datasets


@pytest.mark.parametrize(
"filename, builder, realm, member, file_id",
[
(
"access-om2/output000/ocean/ocean.nc",
"AccessOm2Builder",
"ocean",
None,
"ocean",
),
(
"access-om2/output000/ice/OUTPUT/iceh.1900-01.nc",
"AccessOm2Builder",
"seaIce",
None,
"iceh_XXXX_XX",
),
(
"access-cm2/by578/history/atm/netCDF/by578a.pd201501_dai.nc",
"AccessCm2Builder",
"atmos",
"by578",
"a_pdXXXXXX_dai",
),
(
"access-cm2/by578a/history/atm/netCDF/by578aa.pd201501_dai.nc",
"AccessCm2Builder",
"atmos",
"by578a",
"a_pdXXXXXX_dai",
),
(
"access-cm2/by578/history/ice/iceh_d.2015-01.nc",
"AccessCm2Builder",
"seaIce",
"by578",
"iceh_d_XXXX_XX",
),
(
"access-cm2/by578/history/ocn/ocean_daily.nc-20150630",
"AccessCm2Builder",
"ocean",
"by578",
"ocean_daily",
),
(
"access-om3/output000/GMOM_JRA_WD.mom6.h.sfc_1900_01_02.nc",
"AccessOm3Builder",
"ocean",
None,
"GMOM_JRA_WD_mom6_h_sfc_XXXX_XX_XX",
),
(
"access-om3/output000/GMOM_JRA_WD.cice.h.1900-01-01.nc",
"AccessOm3Builder",
"seaIce",
None,
"GMOM_JRA_WD_cice_h_XXXX_XX_XX",
),
(
"access-om3/output000/GMOM_JRA_WD.ww3.hi.1900-01-02-00000.nc",
"AccessOm3Builder",
"wave",
None,
"GMOM_JRA_WD_ww3_hi_XXXX_XX_XX_XXXXX",
),
],
)
def test_builder_parser(test_data, filename, builder, realm, member, file_id):
Builder = getattr(builders, builder)
info = Builder.parser(str(test_data / filename))
assert info["realm"] == realm
if member:
assert info["member"] == member
assert info["file_id"] == file_id


def test_builder_columns_with_iterables(test_data):
builder = builders.AccessOm2Builder(str(test_data / "access-om2"))
assert not builder.columns_with_iterables
Expand Down

0 comments on commit 57c2b95

Please sign in to comment.