diff --git a/src/access_nri_intake/source/builders.py b/src/access_nri_intake/source/builders.py index 4b485af1..bd46232a 100644 --- a/src/access_nri_intake/source/builders.py +++ b/src/access_nri_intake/source/builders.py @@ -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" @@ -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: diff --git a/tests/test_builders.py b/tests/test_builders.py index e180919f..878dd119 100644 --- a/tests/test_builders.py +++ b/tests/test_builders.py @@ -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