# Copyright 2023 ACCESS-NRI and contributors. See the top-level COPYRIGHT file for details.
# SPDX-License-Identifier: Apache-2.0

from pathlib import Path
from unittest import mock

import intake
import pandas as pd
import pytest
import xarray as xr
from ecgtools.builder import INVALID_ASSET, TRACEBACK
from intake_esm.source import _get_xarray_open_kwargs, _open_dataset
from intake_esm.utils import OPTIONS

from access_nri_intake.source import CORE_COLUMNS, builders
from access_nri_intake.source.utils import _AccessNCFileInfo


@pytest.mark.parametrize(
    "basedirs, builder, kwargs, num_assets, num_valid_assets, num_datasets",
    [
        (["access-om2"], "AccessOm2Builder", {}, 12, 12, 6),
        (
            ["access-cm2/by578", "access-cm2/by578a"],
            "AccessCm2Builder",
            {"ensemble": True},
            18,
            14,
            7,
        ),
        (["access-esm1-5"], "AccessEsm15Builder", {"ensemble": False}, 11, 11, 11),
        (["access-om3"], "AccessOm3Builder", {}, 12, 12, 6),
        (["mom6"], "Mom6Builder", {}, 27, 27, 15),
    ],
)
def test_builder_build(
    tmp_path,
    test_data,
    basedirs,
    builder,
    kwargs,
    num_assets,
    num_valid_assets,
    num_datasets,
):
    """
    Test the various steps of the build process
    """
    Builder = getattr(builders, builder)
    path = [str(test_data / Path(basedir)) for basedir in basedirs]
    builder = Builder(path, **kwargs)

    builder.get_assets()
    assert isinstance(builder.assets, list)
    assert len(builder.assets) == num_assets

    builder.build()
    assert isinstance(builder.df, pd.DataFrame)
    assert len(builder.df) == num_valid_assets
    assert all([col in builder.df.columns for col in CORE_COLUMNS])

    builder.save(name="test", description="test datastore", directory=str(tmp_path))

    cat = intake.open_esm_datastore(
        str(tmp_path / "test.json"),
        columns_with_iterables=builder.columns_with_iterables,
    )
    assert len(cat.df) == num_valid_assets
    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",
        ),
        # MOM6
        (
            "mom6/output000/19000101.ice_daily.nc",
            "Mom6Builder",
            "seaIce",
            None,
            "XXXXXXXX_ice_daily",
        ),
        (
            "mom6/output001/19010101.ice_month.nc",
            "Mom6Builder",
            "seaIce",
            None,
            "XXXXXXXX_ice_month",
        ),
        (
            "mom6/output001/19010101.ocean_annual_rho2.nc",
            "Mom6Builder",
            "ocean",
            None,
            "XXXXXXXX_ocean_annual_rho2",
        ),
        (
            "mom6/output000/19000101.ocean_annual_z.nc",
            "Mom6Builder",
            "ocean",
            None,
            "XXXXXXXX_ocean_annual_z",
        ),
        (
            "mom6/output000/19000101.ocean_daily.nc",
            "Mom6Builder",
            "ocean",
            None,
            "XXXXXXXX_ocean_daily",
        ),
        (
            "mom6/output001/19010101.ocean_month_rho2.nc",
            "Mom6Builder",
            "ocean",
            None,
            "XXXXXXXX_ocean_month_rho2",
        ),
        (
            "mom6/output000/19000101.ocean_month_z.nc",
            "Mom6Builder",
            "ocean",
            None,
            "XXXXXXXX_ocean_month_z",
        ),
        (
            "mom6/output001/19010101.ocean_month.nc",
            "Mom6Builder",
            "ocean",
            None,
            "XXXXXXXX_ocean_month",
        ),
        (
            "mom6/output000/19000101.ocean_scalar_annual.nc",
            "Mom6Builder",
            "ocean",
            None,
            "XXXXXXXX_ocean_scalar_annual",
        ),
        (
            "mom6/output001/19010101.ocean_scalar_month.nc",
            "Mom6Builder",
            "ocean",
            None,
            "XXXXXXXX_ocean_scalar_month",
        ),
        (
            "mom6/output000/19000101.ocean_static.nc",
            "Mom6Builder",
            "ocean",
            None,
            "XXXXXXXX_ocean_static",
        ),
    ],
)
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


@mock.patch("access_nri_intake.source.utils._AccessNCFileInfo.to_dict")
@pytest.mark.parametrize(
    "filename",
    [
        "mom6/output000/19000101.ice_daily.nc",
        "mom6/output001/19010101.ice_month.nc",
        "mom6/output001/19010101.ocean_annual_rho2.nc",
        "mom6/output000/19000101.ocean_annual_z.nc",
        "mom6/output000/19000101.ocean_daily.nc",
        "mom6/output001/19010101.ocean_month_rho2.nc",
        "mom6/output000/19000101.ocean_month_z.nc",
        "mom6/output001/19010101.ocean_month.nc",
        "mom6/output000/19000101.ocean_scalar_annual.nc",
        "mom6/output001/19010101.ocean_scalar_month.nc",
        "mom6/output000/19000101.ocean_static.nc",
    ],
)
def test_Mom6Builder_parser_bad_realm(to_dict_mock, test_data, filename):
    to_dict_mock.return_value = {
        "filename": filename.replace("ice", "badrealm").replace("ocean", "badrealm")
    }
    info = builders.Mom6Builder.parser(str(test_data / filename))
    assert INVALID_ASSET in info.keys()
    assert TRACEBACK in info.keys()
    assert "ParserError" in info[TRACEBACK]


@pytest.mark.parametrize(
    "filename",
    ["rubbish_name.nc"],
)
@pytest.mark.parametrize(
    "builder",
    [
        "AccessOm2Builder",
        "AccessOm3Builder",
        "Mom6Builder",
        "AccessEsm15Builder",
        "AccessCm2Builder",
    ],
)
def test_builder_parser_exception(test_data, filename, builder):
    Builder = getattr(builders, builder)
    info = Builder.parser(str(test_data / filename))
    assert INVALID_ASSET in info.keys()
    assert info[INVALID_ASSET] == str(test_data / filename)
    assert TRACEBACK in info.keys()


def test_builder_columns_with_iterables(test_data):
    builder = builders.AccessOm2Builder(str(test_data / "access-om2"))
    assert not builder.columns_with_iterables
    builder.build()
    assert sorted(list(builder.columns_with_iterables)) == sorted(
        [
            col
            for col, val in builder.df.map(type).isin([list, tuple, set]).any().items()
            if val
        ]
    )


@pytest.mark.parametrize(
    "builder, filename, expected",
    [
        # Example ACCESS-CM2 filenames
        (
            builders.AccessCm2Builder,
            "bz687a.pm107912_mon",
            ("bz687a_pmXXXXXX_mon", "107912", (1, "mon")),
        ),
        (
            builders.AccessCm2Builder,
            "bz687a.p7107912_mon",
            ("bz687a_p7XXXXXX_mon", "107912", (1, "mon")),
        ),
        (
            builders.AccessCm2Builder,
            "bz687a.p7107912_dai",
            ("bz687a_p7XXXXXX_dai", "107912", (1, "day")),
        ),
        (
            builders.AccessCm2Builder,
            "iceh_m.2014-06",
            ("iceh_m_XXXX_XX", "2014-06", None),
        ),
        (
            builders.AccessCm2Builder,
            "iceh.1917-05-daily",
            ("iceh_XXXX_XX_daily", "1917-05", (1, "day")),
        ),
        (
            builders.AccessCm2Builder,
            "iceh_03h.2016-01-3hourly",
            ("iceh_03h_XXXX_XX_3hourly", "2016-01", None),
        ),
        (
            builders.AccessCm2Builder,
            "ocean_bgc_ann",
            ("ocean_bgc_ann", None, (1, "yr")),
        ),
        (builders.AccessCm2Builder, "ocean_daily", ("ocean_daily", None, (1, "day"))),
        # Example ACCESS-ESM1.5 filenames
        (
            builders.AccessEsm15Builder,
            "PI-GWL-B2035.pe-109904_dai",
            ("PI_GWL_B2035_pe_XXXXXX_dai", "109904", (1, "day")),
        ),
        (
            builders.AccessEsm15Builder,
            "PI-GWL-B2035.pa-109904_mon",
            ("PI_GWL_B2035_pa_XXXXXX_mon", "109904", (1, "mon")),
        ),
        (
            builders.AccessEsm15Builder,
            "PI-1pct-02.pe-011802_dai.nc_dai",
            ("PI_1pct_02_pe_XXXXXX_dai_nc_dai", "011802", (1, "day")),
        ),
        (
            builders.AccessEsm15Builder,
            "iceh.1917-05",
            ("iceh_XXXX_XX", "1917-05", None),
        ),
        # Example ACCESS-OM2 filenames
        (
            builders.AccessOm2Builder,
            "iceh.057-daily",
            ("iceh_XXX_daily", "057", (1, "day")),
        ),
        (
            builders.AccessOm2Builder,
            "iceh.1985-08-31",
            ("iceh_XXXX_XX_XX", "1985-08-31", None),
        ),
        (builders.AccessOm2Builder, "ocean", ("ocean", None, None)),
        (builders.AccessOm2Builder, "ocean_month", ("ocean_month", None, (1, "mon"))),
        (
            builders.AccessOm2Builder,
            "ocean-2d-area_t",
            ("ocean_2d_area_t", None, None),
        ),
        (
            builders.AccessOm2Builder,
            "ocean_daily_3d_pot_rho_1",
            ("ocean_daily_3d_pot_rho_1", None, (1, "day")),
        ),
        (
            builders.AccessOm2Builder,
            "ocean_daily_3d_vhrho_nt_07",
            ("ocean_daily_3d_vhrho_nt_XX", "07", (1, "day")),
        ),
        (
            builders.AccessOm2Builder,
            "ocean-3d-v-1-monthly-pow02-ym_1958_04",
            ("ocean_3d_v_1_monthly_pow02_ym_XXXX_XX", "1958_04", (1, "mon")),
        ),
        (
            builders.AccessOm2Builder,
            "ocean-2d-sfc_salt_flux_restore-1-monthly-mean-ym_1958_04",
            (
                "ocean_2d_sfc_salt_flux_restore_1_monthly_mean_ym_XXXX_XX",
                "1958_04",
                (1, "mon"),
            ),
        ),
        (
            builders.AccessOm2Builder,
            "ocean-2d-sea_level-540-seconds-snap-ym_2022_04_01",
            (
                "ocean_2d_sea_level_540_seconds_snap_ym_XXXX_XX_XX",
                "2022_04_01",
                None,
            ),
        ),
        (
            builders.AccessOm2Builder,
            "ocean-3d-salt-1-daily-mean-ym_2018_10_jmax511_sigfig4",
            (
                "ocean_3d_salt_1_daily_mean_ym_XXXX_XX_jmax511_sigfig4",
                "2018_10",
                (1, "day"),
            ),
        ),
        (
            builders.AccessOm2Builder,
            "oceanbgc-3d-caco3-1-yearly-mean-y_2015",
            ("oceanbgc_3d_caco3_1_yearly_mean_y_XXXX", "2015", (1, "yr")),
        ),
        (
            builders.AccessOm2Builder,
            "oceanbgc-2d-wdet100-1-daily-mean-y_2015",
            ("oceanbgc_2d_wdet100_1_daily_mean_y_XXXX", "2015", (1, "day")),
        ),
        (
            builders.AccessOm2Builder,
            "oceanbgc-3d-phy-1-daily-mean-3-sigfig-5-daily-ymd_2020_12_01",
            (
                "oceanbgc_3d_phy_1_daily_mean_3_sigfig_5_daily_ymd_XXXX_XX_XX",
                "2020_12_01",
                (1, "day"),
            ),
        ),
        (
            builders.AccessOm2Builder,
            "rregionPrydz_temp_xflux_adv",
            ("rregionPrydz_temp_xflux_adv", None, None),
        ),
        # Example ACCESS-OM3 filenames
        (
            builders.AccessOm3Builder,
            "access-om3.ww3.hi.1958-01-02-00000",
            (
                "access_om3_ww3_hi_XXXX_XX_XX_XXXXX",
                "1958-01-02-00000",
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.cice.h.1900-01-01",
            (
                "access_om3_cice_h_XXXX_XX_XX",
                "1900-01-01",
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.cice.h.1900-01",
            (
                "access_om3_cice_h_XXXX_XX",
                "1900-01",
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.cice.h.1900-01-daily",
            (
                "access_om3_cice_h_XXXX_XX_daily",
                "1900-01",
                (1, "day"),
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.mom6.ocean_sfc_1900_01_01",
            (
                "access_om3_mom6_ocean_sfc_XXXX_XX_XX",
                "1900_01_01",
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.mom6.sfc_1900_01",
            (
                "access_om3_mom6_sfc_XXXX_XX",
                "1900_01",
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.mom6.sfc_1900",
            (
                "access_om3_mom6_sfc_XXXX",
                "1900",
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.mom6.static",
            (
                "access_om3_mom6_static",
                None,
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.mom6.static",
            (
                "access_om3_mom6_static",
                None,
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.mom6.3d.uh.1mon.mean.1900",
            (
                "access_om3_mom6_3d_uh_1mon_mean_XXXX",
                "1900",
                (1, "mon"),
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.mom6.3d.uh.1mon.mean.1900-01-01-00000",
            (
                "access_om3_mom6_3d_uh_1mon_mean_XXXX_XX_XX_XXXXX",
                "1900-01-01-00000",
                (1, "mon"),
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.mom6.3d.uh.1mon.mean.1900-01",
            (
                "access_om3_mom6_3d_uh_1mon_mean_XXXX_XX",
                "1900-01",
                (1, "mon"),
            ),
        ),
        (
            builders.AccessOm3Builder,
            "GMOM_JRA_WD.ww3.hi.1900-01-03-00000",
            (
                "GMOM_JRA_WD_ww3_hi_XXXX_XX_XX_XXXXX",
                "1900-01-03-00000",
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "GMOM_JRA_WD.ww3.hi.1900",
            (
                "GMOM_JRA_WD_ww3_hi_XXXX",
                "1900",
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "GMOM_JRA_WD.ww3.hi.1900-01",
            (
                "GMOM_JRA_WD_ww3_hi_XXXX_XX",
                "1900-01",
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.mom6.3d.uh.1mon.mean.1900",
            (
                "access_om3_mom6_3d_uh_1mon_mean_XXXX",
                "1900",
                (1, "mon"),
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.mom6.3d.uh.1mon.mean.1900-01-01-00000",
            (
                "access_om3_mom6_3d_uh_1mon_mean_XXXX_XX_XX_XXXXX",
                "1900-01-01-00000",
                (1, "mon"),
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3.mom6.3d.uh.1mon.mean.1900-01",
            (
                "access_om3_mom6_3d_uh_1mon_mean_XXXX_XX",
                "1900-01",
                (1, "mon"),
            ),
        ),
        (
            builders.AccessOm3Builder,
            "GMOM_JRA_WD.ww3.hi.1900-01-03-00000",
            (
                "GMOM_JRA_WD_ww3_hi_XXXX_XX_XX_XXXXX",
                "1900-01-03-00000",
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "GMOM_JRA_WD.ww3.hi.1900",
            (
                "GMOM_JRA_WD_ww3_hi_XXXX",
                "1900",
                None,
            ),
        ),
        (
            builders.AccessOm3Builder,
            "GMOM_JRA_WD.ww3.hi.1900-01",
            (
                "GMOM_JRA_WD_ww3_hi_XXXX_XX",
                "1900-01",
                None,
            ),
        ),
        # MOM6
        (
            builders.Mom6Builder,
            "19000101.ice_daily",
            (
                "XXXXXXXX_ice_daily",
                "19000101",
                (1, "day"),
            ),
        ),
        (
            builders.Mom6Builder,
            "19010101.ice_month",
            (
                "XXXXXXXX_ice_month",
                "19010101",
                (1, "mon"),
            ),
        ),
        (
            builders.Mom6Builder,
            "19010101.ocean_annual_rho2",
            (
                "XXXXXXXX_ocean_annual_rho2",
                "19010101",
                (1, "yr"),
            ),
        ),
        (
            builders.Mom6Builder,
            "19000101.ocean_annual_z",
            (
                "XXXXXXXX_ocean_annual_z",
                "19000101",
                (1, "yr"),
            ),
        ),
        (
            builders.Mom6Builder,
            "19000101.ocean_annual",
            (
                "XXXXXXXX_ocean_annual",
                "19000101",
                (1, "yr"),
            ),
        ),
        (
            builders.Mom6Builder,
            "19000101.ocean_daily",
            (
                "XXXXXXXX_ocean_daily",
                "19000101",
                (1, "day"),
            ),
        ),
        (
            builders.Mom6Builder,
            "19010101.ocean_month_rho2",
            (
                "XXXXXXXX_ocean_month_rho2",
                "19010101",
                (1, "mon"),
            ),
        ),
        (
            builders.Mom6Builder,
            "19000101.ocean_month_z",
            (
                "XXXXXXXX_ocean_month_z",
                "19000101",
                (1, "mon"),
            ),
        ),
        (
            builders.Mom6Builder,
            "19000101.ocean_month",
            (
                "XXXXXXXX_ocean_month",
                "19000101",
                (1, "mon"),
            ),
        ),
        (
            builders.Mom6Builder,
            "19000101.ocean_scalar_annual",
            (
                "XXXXXXXX_ocean_scalar_annual",
                "19000101",
                (1, "yr"),
            ),
        ),
        (
            builders.Mom6Builder,
            "19010101.ocean_scalar_month",
            (
                "XXXXXXXX_ocean_scalar_month",
                "19010101",
                (1, "mon"),
            ),
        ),
        (
            builders.Mom6Builder,
            "19010101.ocean_static",
            (
                "XXXXXXXX_ocean_static",
                "19010101",
                None,
            ),
        ),
        (
            builders.Mom6Builder,
            "20000201.ocean_daily_2000_032",
            (
                "XXXXXXXX_ocean_daily_XXXX_XXX",
                "20000201",
                (1, "day"),
            ),
        ),
        (
            builders.Mom6Builder,
            "20000201.ocean_daily_rho2_2000_056",
            (
                "XXXXXXXX_ocean_daily_rho2_XXXX_XXX",
                "20000201",
                (1, "day"),
            ),
        ),
        (
            builders.Mom6Builder,
            "20000201.ocean_daily_z_2000_119",
            (
                "XXXXXXXX_ocean_daily_z_XXXX_XXX",
                "20000201",
                (1, "day"),
            ),
        ),
    ],
)
def test_parse_access_filename(builder, filename, expected):
    assert builder.parse_access_filename(filename) == expected


@pytest.mark.parametrize(
    "compare_files",
    [
        (True),
        (False),
    ],
)
@pytest.mark.parametrize(
    "builder, filename, expected",
    [
        (
            builders.AccessOm2Builder,
            "access-om2/output000/ocean/ocean_grid.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="ocean_grid.nc",
                file_id="ocean_grid",
                filename_timestamp=None,
                frequency="fx",
                start_date="none",
                end_date="none",
                variable=["geolat_t", "geolon_t", "xt_ocean", "yt_ocean"],
                variable_long_name=[
                    "tracer latitude",
                    "tracer longitude",
                    "tcell longitude",
                    "tcell latitude",
                ],
                variable_standard_name=["", "", "", ""],
                variable_cell_methods=["time: point", "time: point", "", ""],
                variable_units=["degrees_N", "degrees_E", "degrees_E", "degrees_N"],
            ),
        ),
        (
            builders.AccessOm2Builder,
            "access-om2/output000/ocean/ocean.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="ocean.nc",
                file_id="ocean",
                filename_timestamp=None,
                frequency="1yr",
                start_date="1900-01-01, 00:00:00",
                end_date="1910-01-01, 00:00:00",
                variable=[
                    "nv",
                    "st_ocean",
                    "temp",
                    "time",
                    "time_bounds",
                    "xt_ocean",
                    "yt_ocean",
                ],
                variable_long_name=[
                    "vertex number",
                    "tcell zstar depth",
                    "Conservative temperature",
                    "time",
                    "time axis boundaries",
                    "tcell longitude",
                    "tcell latitude",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "sea_water_conservative_temperature",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=["", "", "time: mean", "", "", "", ""],
                variable_units=[
                    "none",
                    "meters",
                    "K",
                    "days since 1900-01-01 00:00:00",
                    "days",
                    "degrees_E",
                    "degrees_N",
                ],
            ),
        ),
        (
            builders.AccessOm2Builder,
            "access-om2/output000/ocean/ocean_month.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="ocean_month.nc",
                file_id="ocean_month",
                filename_timestamp=None,
                frequency="1mon",
                start_date="1900-01-01, 00:00:00",
                end_date="1910-01-01, 00:00:00",
                variable=["mld", "nv", "time", "time_bounds", "xt_ocean", "yt_ocean"],
                variable_long_name=[
                    "mixed layer depth determined by density criteria",
                    "vertex number",
                    "time",
                    "time axis boundaries",
                    "tcell longitude",
                    "tcell latitude",
                ],
                variable_standard_name=[
                    "ocean_mixed_layer_thickness_defined_by_sigma_t",
                    "",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=["time: mean", "", "", "", "", ""],
                variable_units=[
                    "m",
                    "none",
                    "days since 1900-01-01 00:00:00",
                    "days",
                    "degrees_E",
                    "degrees_N",
                ],
            ),
        ),
        (
            builders.AccessOm2Builder,
            "access-om2/output000/ocean/ocean_month_inst_nobounds.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="ocean_month_inst_nobounds.nc",
                file_id="ocean_month_inst_nobounds",
                filename_timestamp=None,
                frequency="1mon",
                start_date="1900-01-01, 00:00:00",
                end_date="1900-02-01, 00:00:00",
                variable=["mld", "time", "xt_ocean", "yt_ocean"],
                variable_long_name=[
                    "mixed layer depth determined by density criteria",
                    "time",
                    "tcell longitude",
                    "tcell latitude",
                ],
                variable_standard_name=[
                    "ocean_mixed_layer_thickness_defined_by_sigma_t",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=["time: mean", "", "", ""],
                variable_units=[
                    "m",
                    "days since 1900-01-01 00:00:00",
                    "degrees_E",
                    "degrees_N",
                ],
            ),
        ),
        (
            builders.AccessOm2Builder,
            "access-om2/output000/ice/OUTPUT/iceh.1900-01.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="iceh.1900-01.nc",
                file_id="iceh_XXXX_XX",
                filename_timestamp="1900-01",
                frequency="1mon",
                start_date="1900-01-01, 00:00:00",
                end_date="1900-02-01, 00:00:00",
                variable=["TLAT", "TLON", "aice_m", "tarea", "time", "time_bounds"],
                variable_long_name=[
                    "T grid center latitude",
                    "T grid center longitude",
                    "ice area  (aggregate)",
                    "area of T grid cells",
                    "model time",
                    "boundaries for time-averaging interval",
                ],
                variable_standard_name=["", "", "", "", "", ""],
                variable_cell_methods=["", "", "time: mean", "", "", ""],
                variable_units=[
                    "degrees_north",
                    "degrees_east",
                    "1",
                    "m^2",
                    "days since 1900-01-01 00:00:00",
                    "days since 1900-01-01 00:00:00",
                ],
            ),
        ),
        (
            builders.AccessCm2Builder,
            "access-cm2/by578/history/atm/netCDF/by578a.pd201501_dai.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="by578a.pd201501_dai.nc",
                file_id="by578a_pdXXXXXX_dai",
                filename_timestamp="201501",
                frequency="1day",
                start_date="2015-01-01, 00:00:00",
                end_date="2015-02-01, 00:00:00",
                variable=["fld_s03i236"],
                variable_long_name=["TEMPERATURE AT 1.5M"],
                variable_standard_name=["air_temperature"],
                variable_cell_methods=["time: mean"],
                variable_units=["K"],
            ),
        ),
        (
            builders.AccessCm2Builder,
            "access-cm2/by578/history/ice/iceh_d.2015-01.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="iceh_d.2015-01.nc",
                file_id="iceh_d_XXXX_XX",
                filename_timestamp="2015-01",
                frequency="1day",
                start_date="2015-01-01, 00:00:00",
                end_date="2015-02-01, 00:00:00",
                variable=["TLAT", "TLON", "aice", "tarea", "time", "time_bounds"],
                variable_long_name=[
                    "T grid center latitude",
                    "T grid center longitude",
                    "ice area  (aggregate)",
                    "area of T grid cells",
                    "model time",
                    "boundaries for time-averaging interval",
                ],
                variable_standard_name=["", "", "", "", "", ""],
                variable_cell_methods=["", "", "time: mean", "", "", ""],
                variable_units=[
                    "degrees_north",
                    "degrees_east",
                    "1",
                    "m^2",
                    "days since 1850-01-01 00:00:00",
                    "days since 1850-01-01 00:00:00",
                ],
            ),
        ),
        (
            builders.AccessCm2Builder,
            "access-cm2/by578/history/ocn/ocean_daily.nc-20150630",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="ocean_daily.nc-20150630",
                file_id="ocean_daily",
                filename_timestamp=None,
                frequency="1day",
                start_date="2015-01-01, 00:00:00",
                end_date="2015-07-01, 00:00:00",
                variable=["nv", "sst", "time", "time_bounds", "xt_ocean", "yt_ocean"],
                variable_long_name=[
                    "vertex number",
                    "Potential temperature",
                    "time",
                    "time axis boundaries",
                    "tcell longitude",
                    "tcell latitude",
                ],
                variable_standard_name=["", "sea_surface_temperature", "", "", "", ""],
                variable_cell_methods=["", "time: mean", "", "", "", ""],
                variable_units=[
                    "none",
                    "K",
                    "days since 1850-01-01 00:00:00",
                    "days",
                    "degrees_E",
                    "degrees_N",
                ],
            ),
        ),
        (
            builders.AccessCm2Builder,
            "access-cm2/by578/history/ocn/ocean_scalar.nc-20150630",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="ocean_scalar.nc-20150630",
                file_id="ocean_scalar",
                filename_timestamp=None,
                frequency="1mon",
                start_date="2015-01-01, 00:00:00",
                end_date="2015-07-01, 00:00:00",
                variable=[
                    "nv",
                    "scalar_axis",
                    "temp_global_ave",
                    "time",
                    "time_bounds",
                ],
                variable_long_name=[
                    "vertex number",
                    "none",
                    "Global mean temp in liquid seawater",
                    "time",
                    "time axis boundaries",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "sea_water_potential_temperature",
                    "",
                    "",
                ],
                variable_cell_methods=["", "", "time: mean", "", ""],
                variable_units=[
                    "none",
                    "none",
                    "deg_C",
                    "days since 1850-01-01 00:00:00",
                    "days",
                ],
            ),
        ),
        (
            builders.AccessEsm15Builder,
            "access-esm1-5/history/atm/netCDF/HI-C-05-r1.pa-185001_mon.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="HI-C-05-r1.pa-185001_mon.nc",
                file_id="HI_C_05_r1_pa_XXXXXX_mon",
                filename_timestamp="185001",
                frequency="1mon",
                start_date="1850-01-01, 00:00:00",
                end_date="1850-02-01, 00:00:00",
                variable=["fld_s03i236"],
                variable_long_name=["TEMPERATURE AT 1.5M"],
                variable_standard_name=["air_temperature"],
                variable_cell_methods=["time: mean"],
                variable_units=["K"],
            ),
        ),
        (
            builders.AccessEsm15Builder,
            "access-esm1-5/history/ice/iceh.1850-01.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="iceh.1850-01.nc",
                file_id="iceh_XXXX_XX",
                filename_timestamp="1850-01",
                frequency="1mon",
                start_date="1850-01-01, 00:00:00",
                end_date="1850-02-01, 00:00:00",
                variable=["TLAT", "TLON", "aice", "tarea", "time", "time_bounds"],
                variable_long_name=[
                    "T grid center latitude",
                    "T grid center longitude",
                    "ice area  (aggregate)",
                    "area of T grid cells",
                    "model time",
                    "boundaries for time-averaging interval",
                ],
                variable_standard_name=["", "", "", "", "", ""],
                variable_cell_methods=["", "", "time: mean", "", "", ""],
                variable_units=[
                    "degrees_north",
                    "degrees_east",
                    "1",
                    "m^2",
                    "days since 0001-01-01 00:00:00",
                    "days since 0001-01-01 00:00:00",
                ],
            ),
        ),
        (
            builders.AccessEsm15Builder,
            "access-esm1-5/history/ocn/ocean_bgc_ann.nc-18501231",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="ocean_bgc_ann.nc-18501231",
                file_id="ocean_bgc_ann",
                filename_timestamp=None,
                frequency="1yr",
                start_date="1849-12-30, 00:00:00",
                end_date="1850-12-30, 00:00:00",
                variable=[
                    "fgco2_raw",
                    "nv",
                    "time",
                    "time_bounds",
                    "xt_ocean",
                    "yt_ocean",
                ],
                variable_long_name=[
                    "Flux into ocean - DIC, inc. anth.",
                    "vertex number",
                    "time",
                    "time axis boundaries",
                    "tcell longitude",
                    "tcell latitude",
                ],
                variable_standard_name=["", "", "", "", "", ""],
                variable_cell_methods=["time: mean", "", "", "", "", ""],
                variable_units=[
                    "mmol/m^2/s",
                    "none",
                    "days since 0001-01-01 00:00:00",
                    "days",
                    "degrees_E",
                    "degrees_N",
                ],
            ),
        ),
        (
            builders.AccessEsm15Builder,
            "access-esm1-5/history/ocn/ocean_bgc.nc-18501231",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="ocean_bgc.nc-18501231",
                file_id="ocean_bgc",
                filename_timestamp=None,
                frequency="1mon",
                start_date="1849-12-30, 00:00:00",
                end_date="1850-12-30, 00:00:00",
                variable=[
                    "nv",
                    "o2",
                    "st_ocean",
                    "time",
                    "time_bounds",
                    "xt_ocean",
                    "yt_ocean",
                ],
                variable_long_name=[
                    "vertex number",
                    "o2",
                    "tcell zstar depth",
                    "time",
                    "time axis boundaries",
                    "tcell longitude",
                    "tcell latitude",
                ],
                variable_standard_name=["", "", "", "", "", "", ""],
                variable_cell_methods=["", "time: mean", "", "", "", "", ""],
                variable_units=[
                    "none",
                    "mmol/m^3",
                    "meters",
                    "days since 0001-01-01 00:00:00",
                    "days",
                    "degrees_E",
                    "degrees_N",
                ],
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3/output000/GMOM_JRA_WD.mom6.h.native_1900_01.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="GMOM_JRA_WD.mom6.h.native_1900_01.nc",
                file_id="GMOM_JRA_WD_mom6_h_native_XXXX_XX",
                filename_timestamp="1900_01",
                frequency="1mon",
                start_date="1900-01-01, 00:00:00",
                end_date="1900-02-01, 00:00:00",
                variable=[
                    "average_DT",
                    "average_T1",
                    "average_T2",
                    "nv",
                    "thetao",
                    "time",
                    "time_bnds",
                    "xh",
                    "yh",
                    "zl",
                ],
                variable_long_name=[
                    "Length of average period",
                    "Start time for average period",
                    "End time for average period",
                    "vertex number",
                    "Sea Water Potential Temperature",
                    "time",
                    "time axis boundaries",
                    "h point nominal longitude",
                    "h point nominal latitude",
                    "Layer pseudo-depth, -z*",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "",
                    "",
                    "sea_water_potential_temperature",
                    "",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=[
                    "",
                    "",
                    "",
                    "",
                    "area:mean zl:mean yh:mean xh:mean time: mean",
                    "",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_units=[
                    "days",
                    "days since 0001-01-01 00:00:00",
                    "days since 0001-01-01 00:00:00",
                    "",
                    "degC",
                    "days since 0001-01-01 00:00:00",
                    "days since 0001-01-01 00:00:00",
                    "degrees_east",
                    "degrees_north",
                    "meter",
                ],
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3/output000/GMOM_JRA_WD.mom6.h.sfc_1900_01_02.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="GMOM_JRA_WD.mom6.h.sfc_1900_01_02.nc",
                file_id="GMOM_JRA_WD_mom6_h_sfc_XXXX_XX_XX",
                filename_timestamp="1900_01_02",
                frequency="1day",
                start_date="1900-01-01, 00:00:00",
                end_date="1900-01-02, 00:00:00",
                variable=[
                    "average_DT",
                    "average_T1",
                    "average_T2",
                    "nv",
                    "time",
                    "time_bnds",
                    "tos",
                    "xh",
                    "yh",
                ],
                variable_long_name=[
                    "Length of average period",
                    "Start time for average period",
                    "End time for average period",
                    "vertex number",
                    "time",
                    "time axis boundaries",
                    "Sea Surface Temperature",
                    "h point nominal longitude",
                    "h point nominal latitude",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "sea_surface_temperature",
                    "",
                    "",
                ],
                variable_cell_methods=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "area:mean yh:mean xh:mean time: mean",
                    "",
                    "",
                ],
                variable_units=[
                    "days",
                    "days since 0001-01-01 00:00:00",
                    "days since 0001-01-01 00:00:00",
                    "",
                    "days since 0001-01-01 00:00:00",
                    "days since 0001-01-01 00:00:00",
                    "degC",
                    "degrees_east",
                    "degrees_north",
                ],
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3/output000/GMOM_JRA_WD.mom6.h.static.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="GMOM_JRA_WD.mom6.h.static.nc",
                file_id="GMOM_JRA_WD_mom6_h_static",
                filename_timestamp=None,
                frequency="fx",
                start_date="none",
                end_date="none",
                variable=["geolat", "geolon", "xh", "yh"],
                variable_long_name=[
                    "Latitude of tracer (T) points",
                    "Longitude of tracer (T) points",
                    "h point nominal longitude",
                    "h point nominal latitude",
                ],
                variable_standard_name=["", "", "", ""],
                variable_cell_methods=["time: point", "time: point", "", ""],
                variable_units=[
                    "degrees_north",
                    "degrees_east",
                    "degrees_east",
                    "degrees_north",
                ],
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3/output000/GMOM_JRA_WD.mom6.h.z_1900_01.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="GMOM_JRA_WD.mom6.h.z_1900_01.nc",
                file_id="GMOM_JRA_WD_mom6_h_z_XXXX_XX",
                filename_timestamp="1900_01",
                frequency="1mon",
                start_date="1900-01-01, 00:00:00",
                end_date="1900-02-01, 00:00:00",
                variable=[
                    "average_DT",
                    "average_T1",
                    "average_T2",
                    "nv",
                    "thetao",
                    "time",
                    "time_bnds",
                    "xh",
                    "yh",
                    "z_l",
                ],
                variable_long_name=[
                    "Length of average period",
                    "Start time for average period",
                    "End time for average period",
                    "vertex number",
                    "Sea Water Potential Temperature",
                    "time",
                    "time axis boundaries",
                    "h point nominal longitude",
                    "h point nominal latitude",
                    "Depth at cell center",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "",
                    "",
                    "sea_water_potential_temperature",
                    "",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=[
                    "",
                    "",
                    "",
                    "",
                    "area:mean z_l:mean yh:mean xh:mean time: mean",
                    "",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_units=[
                    "days",
                    "days since 0001-01-01 00:00:00",
                    "days since 0001-01-01 00:00:00",
                    "",
                    "degC",
                    "days since 0001-01-01 00:00:00",
                    "days since 0001-01-01 00:00:00",
                    "degrees_east",
                    "degrees_north",
                    "meters",
                ],
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3/output000/GMOM_JRA_WD.cice.h.1900-01-01.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="GMOM_JRA_WD.cice.h.1900-01-01.nc",
                file_id="GMOM_JRA_WD_cice_h_XXXX_XX_XX",
                filename_timestamp="1900-01-01",
                frequency="1day",
                start_date="1900-01-01, 00:00:00",
                end_date="1900-01-02, 00:00:00",
                variable=["TLAT", "TLON", "aice", "tarea", "time", "time_bounds"],
                variable_long_name=[
                    "T grid center latitude",
                    "T grid center longitude",
                    "ice area  (aggregate)",
                    "area of T grid cells",
                    "time",
                    "time interval endpoints",
                ],
                variable_standard_name=["", "", "", "", "", ""],
                variable_cell_methods=["", "", "time: mean", "", "", ""],
                variable_units=[
                    "degrees_north",
                    "degrees_east",
                    "1",
                    "m^2",
                    "days since 0000-01-01 00:00:00",
                    "days since 0000-01-01 00:00:00",
                ],
            ),
        ),
        (
            builders.AccessOm3Builder,
            "access-om3/output000/GMOM_JRA_WD.ww3.hi.1900-01-02-00000.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="GMOM_JRA_WD.ww3.hi.1900-01-02-00000.nc",
                file_id="GMOM_JRA_WD_ww3_hi_XXXX_XX_XX_XXXXX",
                filename_timestamp="1900-01-02-00000",
                frequency="fx",  # WW3 provides no time bounds
                start_date="1900-01-02, 00:00:00",
                end_date="1900-01-02, 00:00:00",
                variable=["EF", "mapsta"],
                variable_long_name=["1D spectral density", "map status"],
                variable_standard_name=["", ""],
                variable_cell_methods=["", ""],
                variable_units=["m2 s", "unitless"],
            ),
        ),
        (
            builders.Mom6Builder,
            "mom6/output000/19000101.ice_daily.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="19000101.ice_daily.nc",
                file_id="XXXXXXXX_ice_daily",
                filename_timestamp="19000101",
                frequency="subhr",
                start_date="1900-01-01, 00:00:00",
                end_date="1900-01-01, 00:00:00",
                variable=[
                    "xT",
                    "xTe",
                    "yT",
                    "yTe",
                    "time",
                    "nv",
                    "siconc",
                    "sithick",
                    "average_T1",
                    "average_T2",
                    "average_DT",
                    "time_bnds",
                ],
                variable_long_name=[
                    "T point nominal longitude",
                    "T-cell edge nominal longitude",
                    "T point nominal latitude",
                    "T-cell edge nominal latitude",
                    "time",
                    "vertex number",
                    "ice concentration",
                    "ice thickness",
                    "Start time for average period",
                    "End time for average period",
                    "Length of average period",
                    "time axis boundaries",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "time: mean",
                    "time: mean",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_units=[
                    "degrees_E",
                    "degrees_E",
                    "degrees_N",
                    "degrees_N",
                    "days since 1900-01-01 00:00:00",
                    "",
                    "0-1",
                    "m-ice",
                    "days since 1900-01-01 00:00:00",
                    "days since 1900-01-01 00:00:00",
                    "days",
                    "days",
                ],
            ),
        ),
        (
            builders.Mom6Builder,
            "mom6/output000/19000101.ocean_annual_z.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="19000101.ocean_annual_z.nc",
                file_id="XXXXXXXX_ocean_annual_z",
                filename_timestamp="19000101",
                frequency="subhr",
                start_date="1900-01-01, 00:00:00",
                end_date="1900-01-01, 00:00:00",
                variable=[
                    "xh",
                    "yh",
                    "z_l",
                    "z_i",
                    "time",
                    "nv",
                    "xq",
                    "yq",
                    "volcello",
                    "thetao",
                    "thetao_xyave",
                    "so",
                    "so_xyave",
                    "agessc",
                    "uo",
                    "vo",
                    "umo",
                    "vmo",
                    "uh",
                    "vh",
                    "T_adx",
                    "T_ady",
                    "S_adx",
                    "S_ady",
                    "average_T1",
                    "average_T2",
                    "average_DT",
                    "time_bnds",
                ],
                variable_long_name=[
                    "h point nominal longitude",
                    "h point nominal latitude",
                    "Depth at cell center",
                    "Depth at interface",
                    "time",
                    "vertex number",
                    "q point nominal longitude",
                    "q point nominal latitude",
                    "Ocean grid-cell volume",
                    "Sea Water Potential Temperature",
                    "Sea Water Potential Temperature",
                    "Sea Water Salinity",
                    "Sea Water Salinity",
                    "Ideal Age Tracer",
                    "Sea Water X Velocity",
                    "Sea Water Y Velocity",
                    "Ocean Mass X Transport",
                    "Ocean Mass Y Transport",
                    "Zonal Thickness Flux",
                    "Meridional Thickness Flux",
                    "Advective (by residual mean) Zonal Flux of Heat",
                    "Advective (by residual mean) Meridional Flux of Heat",
                    "Advective (by residual mean) Zonal Flux of Salt",
                    "Advective (by residual mean) Meridional Flux of Salt",
                    "Start time for average period",
                    "End time for average period",
                    "Length of average period",
                    "time axis boundaries",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "ocean_volume",
                    "sea_water_potential_temperature",
                    "sea_water_potential_temperature",
                    "sea_water_salinity",
                    "sea_water_salinity",
                    "ideal_age_tracer",
                    "sea_water_x_velocity",
                    "sea_water_y_velocity",
                    "ocean_mass_x_transport",
                    "ocean_mass_y_transport",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "area:sum z_l:sum yh:sum xh:sum time: mean",
                    "area:mean z_l:mean yh:mean xh:mean time: mean",
                    "z_l:mean time: mean",
                    "area:mean z_l:mean yh:mean xh:mean time: mean",
                    "z_l:mean time: mean",
                    "area:mean z_l:mean yh:mean xh:mean time: mean",
                    "z_l:mean yh:mean xq:point time: mean",
                    "z_l:mean yq:point xh:mean time: mean",
                    "z_l:sum yh:sum xq:point time: mean",
                    "z_l:sum yq:point xh:sum time: mean",
                    "z_l:sum yh:sum xq:point time: mean",
                    "z_l:sum yq:point xh:sum time: mean",
                    "z_l:sum yh:sum xq:point time: mean",
                    "z_l:sum yq:point xh:sum time: mean",
                    "z_l:sum yh:sum xq:point time: mean",
                    "z_l:sum yq:point xh:sum time: mean",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_units=[
                    "degrees_east",
                    "degrees_north",
                    "meters",
                    "meters",
                    "days since 1900-01-01 00:00:00",
                    "",
                    "degrees_east",
                    "degrees_north",
                    "m3",
                    "degC",
                    "degC",
                    "psu",
                    "psu",
                    "yr",
                    "m s-1",
                    "m s-1",
                    "kg s-1",
                    "kg s-1",
                    "m3 s-1",
                    "m3 s-1",
                    "W",
                    "W",
                    "psu m3 s-1",
                    "psu m3 s-1",
                    "days since 1900-01-01 00:00:00",
                    "days since 1900-01-01 00:00:00",
                    "days",
                    "days",
                ],
            ),
        ),
        (
            builders.Mom6Builder,
            "mom6/output000/19000101.ocean_month_rho2.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="19000101.ocean_month_rho2.nc",
                file_id="XXXXXXXX_ocean_month_rho2",
                filename_timestamp="19000101",
                frequency="subhr",
                start_date="1900-01-01, 00:00:00",
                end_date="1900-01-01, 00:00:00",
                variable=[
                    "xh",
                    "yh",
                    "rho2_l",
                    "rho2_i",
                    "time",
                    "nv",
                    "yq",
                    "volcello",
                    "thkcello",
                    "vmo",
                    "average_T1",
                    "average_T2",
                    "average_DT",
                    "time_bnds",
                ],
                variable_long_name=[
                    "h point nominal longitude",
                    "h point nominal latitude",
                    "Target Potential Density at cell center",
                    "Target Potential Density at interface",
                    "time",
                    "vertex number",
                    "q point nominal latitude",
                    "Ocean grid-cell volume",
                    "Cell Thickness",
                    "Ocean Mass Y Transport",
                    "Start time for average period",
                    "End time for average period",
                    "Length of average period",
                    "time axis boundaries",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "ocean_volume",
                    "cell_thickness",
                    "ocean_mass_y_transport",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "area:sum rho2_l:sum yh:sum xh:sum time: mean",
                    "area:mean rho2_l:sum yh:mean xh:mean time: mean",
                    "rho2_l:sum yq:point xh:sum time: mean",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_units=[
                    "degrees_east",
                    "degrees_north",
                    "kg m-3",
                    "kg m-3",
                    "days since 1900-01-01 00:00:00",
                    "",
                    "degrees_north",
                    "m3",
                    "m",
                    "kg s-1",
                    "days since 1900-01-01 00:00:00",
                    "days since 1900-01-01 00:00:00",
                    "days",
                    "days",
                ],
            ),
        ),
        (
            builders.Mom6Builder,
            "mom6/output000/19000101.ocean_scalar_annual.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="19000101.ocean_scalar_annual.nc",
                file_id="XXXXXXXX_ocean_scalar_annual",
                filename_timestamp="19000101",
                frequency="subhr",
                start_date="1900-01-01, 00:00:00",
                end_date="1900-01-01, 00:00:00",
                variable=[
                    "scalar_axis",
                    "time",
                    "nv",
                    "masso",
                    "volo",
                    "thetaoga",
                    "soga",
                    "sosga",
                    "average_T1",
                    "average_T2",
                    "average_DT",
                    "time_bnds",
                ],
                variable_long_name=[
                    "none",
                    "time",
                    "vertex number",
                    "Mass of liquid ocean",
                    "Total volume of liquid ocean",
                    "Global Mean Ocean Potential Temperature",
                    "Global Mean Ocean Salinity",
                    "Sea Surface Salinity",
                    "Start time for average period",
                    "End time for average period",
                    "Length of average period",
                    "time axis boundaries",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "",
                    "sea_water_mass",
                    "sea_water_volume",
                    "sea_water_potential_temperature",
                    "sea_water_salinity",
                    "sea_surface_salinity",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=[
                    "",
                    "",
                    "",
                    "time: mean",
                    "time: mean",
                    "time: mean",
                    "time: mean",
                    "time: mean",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_units=[
                    "",
                    "days since 1900-01-01 00:00:00",
                    "",
                    "kg",
                    "m3",
                    "degC",
                    "psu",
                    "psu",
                    "days since 1900-01-01 00:00:00",
                    "days since 1900-01-01 00:00:00",
                    "days",
                    "days",
                ],
            ),
        ),
        (
            builders.Mom6Builder,
            "mom6/output000/19000101.ocean_static.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="19000101.ocean_static.nc",
                file_id="XXXXXXXX_ocean_static",
                filename_timestamp="19000101",
                frequency="fx",
                start_date="1900-01-01, 00:00:00",
                end_date="1900-01-01, 00:00:00",
                variable=[
                    "xh",
                    "yh",
                    "time",
                    "xq",
                    "yq",
                    "areacello",
                    "deptho",
                    "hfgeou",
                    "sftof",
                    "Coriolis",
                    "geolon",
                    "geolat",
                    "geolon_c",
                    "geolat_c",
                    "geolon_u",
                    "geolat_u",
                    "geolon_v",
                    "geolat_v",
                    "wet",
                    "wet_c",
                    "wet_u",
                    "wet_v",
                    "dxt",
                    "dyt",
                    "dxCu",
                    "dyCu",
                    "dxCv",
                    "dyCv",
                    "areacello_cu",
                    "areacello_cv",
                    "areacello_bu",
                ],
                variable_long_name=[
                    "h point nominal longitude",
                    "h point nominal latitude",
                    "time",
                    "q point nominal longitude",
                    "q point nominal latitude",
                    "Ocean Grid-Cell Area",
                    "Sea Floor Depth",
                    "Upward geothermal heat flux at sea floor",
                    "Sea Area Fraction",
                    "Coriolis parameter at corner (Bu) points",
                    "Longitude of tracer (T) points",
                    "Latitude of tracer (T) points",
                    "Longitude of corner (Bu) points",
                    "Latitude of corner (Bu) points",
                    "Longitude of zonal velocity (Cu) points",
                    "Latitude of zonal velocity (Cu) points",
                    "Longitude of meridional velocity (Cv) points",
                    "Latitude of meridional velocity (Cv) points",
                    "0 if land, 1 if ocean at tracer points",
                    "0 if land, 1 if ocean at corner (Bu) points",
                    "0 if land, 1 if ocean at zonal velocity (Cu) points",
                    "0 if land, 1 if ocean at meridional velocity (Cv) points",
                    "Delta(x) at thickness/tracer points (meter)",
                    "Delta(y) at thickness/tracer points (meter)",
                    "Delta(x) at u points (meter)",
                    "Delta(y) at u points (meter)",
                    "Delta(x) at v points (meter)",
                    "Delta(y) at v points (meter)",
                    "Ocean Grid-Cell Area",
                    "Ocean Grid-Cell Area",
                    "Ocean Grid-Cell Area",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "cell_area",
                    "sea_floor_depth_below_geoid",
                    "upward_geothermal_heat_flux_at_sea_floor",
                    "SeaAreaFraction",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "cell_area",
                    "cell_area",
                    "cell_area",
                ],
                variable_cell_methods=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "area:sum yh:sum xh:sum time: point",
                    "area:mean yh:mean xh:mean time: point",
                    "area:mean yh:mean xh:mean time: point",
                    "area:mean yh:mean xh:mean time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "time: point",
                    "area:sum yh:sum xq:sum time: point",
                    "area:sum yq:sum xh:sum time: point",
                    "area:sum yq:sum xq:sum time: point",
                ],
                variable_units=[
                    "degrees_east",
                    "degrees_north",
                    "days since 1900-01-01 00:00:00",
                    "degrees_east",
                    "degrees_north",
                    "m2",
                    "m",
                    "W m-2",
                    "%",
                    "s-1",
                    "degrees_east",
                    "degrees_north",
                    "degrees_east",
                    "degrees_north",
                    "degrees_east",
                    "degrees_north",
                    "degrees_east",
                    "degrees_north",
                    "",
                    "",
                    "",
                    "",
                    "m",
                    "m",
                    "m",
                    "m",
                    "m",
                    "m",
                    "m2",
                    "m2",
                    "m2",
                ],
            ),
        ),
        (
            builders.Mom6Builder,
            "mom6/output053/20051101.ocean_daily_2005_360.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="20051101.ocean_daily_2005_360.nc",
                file_id="XXXXXXXX_ocean_daily_XXXX_XXX",
                filename_timestamp="20051101",
                frequency="subhr",
                start_date="1991-01-01, 00:00:00",
                end_date="1991-01-01, 00:00:00",
                variable=[
                    "xh",
                    "yh",
                    "zl",
                    "time",
                    "nv",
                    "xq",
                    "yq",
                    "volcello",
                    "zos",
                    "mlotst",
                    "tauuo",
                    "tauvo",
                    "hfds",
                    "wfo",
                    "fsitherm",
                    "salt_flux",
                    "T_adx_2d",
                    "T_ady_2d",
                    "average_T1",
                    "average_T2",
                    "average_DT",
                    "time_bnds",
                ],
                variable_long_name=[
                    "h point nominal longitude",
                    "h point nominal latitude",
                    "Layer pseudo-depth, -z*",
                    "time",
                    "vertex number",
                    "q point nominal longitude",
                    "q point nominal latitude",
                    "Ocean grid-cell volume",
                    "Sea surface height above geoid",
                    "Ocean Mixed Layer Thickness Defined by Sigma T",
                    "Surface Downward X Stress",
                    "Surface Downward Y Stress",
                    "Surface ocean heat flux from SW+LW+latent+sensible+masstransfer+frazil+seaice_melt_heat",
                    "Water Flux Into Sea Water",
                    "water flux to ocean from sea ice melt(> 0) or form(< 0)",
                    "Net salt flux into ocean at surface (restoring + sea-ice)",
                    "Advective (by residual mean) Zonal Flux of Heat",
                    "Advective (by residual mean) Meridional Flux of Heat",
                    "Start time for average period",
                    "End time for average period",
                    "Length of average period",
                    "time axis boundaries",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "ocean_volume",
                    "sea_surface_height_above_geoid",
                    "ocean_mixed_layer_thickness_defined_by_sigma_t",
                    "surface_downward_x_stress",
                    "surface_downward_y_stress",
                    "surface_downward_heat_flux_in_sea_water",
                    "water_flux_into_sea_water",
                    "water_flux_into_sea_water_due_to_sea_ice_thermodynamics",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "area:sum zl:sum yh:sum xh:sum time: mean",
                    "area:mean yh:mean xh:mean time: mean",
                    "area:mean yh:mean xh:mean time: mean",
                    "yh:mean xq:point time: mean",
                    "yq:point xh:mean time: mean",
                    "area:mean yh:mean xh:mean time: mean",
                    "area:mean yh:mean xh:mean time: mean",
                    "area:mean yh:mean xh:mean time: mean",
                    "area:mean yh:mean xh:mean time: mean",
                    "zl:sum yh:sum xq:point time: mean",
                    "zl:sum yq:point xh:sum time: mean",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_units=[
                    "degrees_east",
                    "degrees_north",
                    "meter",
                    "days since 1991-01-01 00:00:00",
                    "",
                    "degrees_east",
                    "degrees_north",
                    "m3",
                    "m",
                    "m",
                    "N m-2",
                    "N m-2",
                    "W m-2",
                    "kg m-2 s-1",
                    "kg m-2 s-1",
                    "kg m-2 s-1",
                    "W",
                    "W",
                    "days since 1991-01-01 00:00:00",
                    "days since 1991-01-01 00:00:00",
                    "days",
                    "days",
                ],
            ),
        ),
        (
            builders.Mom6Builder,
            "mom6/output053/20051101.ocean_daily_rho2_2005_360.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="20051101.ocean_daily_rho2_2005_360.nc",
                file_id="XXXXXXXX_ocean_daily_rho2_XXXX_XXX",
                filename_timestamp="20051101",
                frequency="subhr",
                start_date="1991-01-01, 00:00:00",
                end_date="1991-01-01, 00:00:00",
                variable=[
                    "xh",
                    "yh",
                    "rho2_l",
                    "rho2_i",
                    "time",
                    "nv",
                    "xq",
                    "yq",
                    "volcello",
                    "umo",
                    "vmo",
                    "average_T1",
                    "average_T2",
                    "average_DT",
                    "time_bnds",
                ],
                variable_long_name=[
                    "h point nominal longitude",
                    "h point nominal latitude",
                    "Target Potential Density at cell center",
                    "Target Potential Density at interface",
                    "time",
                    "vertex number",
                    "q point nominal longitude",
                    "q point nominal latitude",
                    "Ocean grid-cell volume",
                    "Ocean Mass X Transport",
                    "Ocean Mass Y Transport",
                    "Start time for average period",
                    "End time for average period",
                    "Length of average period",
                    "time axis boundaries",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "ocean_volume",
                    "ocean_mass_x_transport",
                    "ocean_mass_y_transport",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "area:sum rho2_l:sum yh:sum xh:sum time: mean",
                    "rho2_l:sum yh:sum xq:point time: mean",
                    "rho2_l:sum yq:point xh:sum time: mean",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_units=[
                    "degrees_east",
                    "degrees_north",
                    "kg m-3",
                    "kg m-3",
                    "days since 1991-01-01 00:00:00",
                    "",
                    "degrees_east",
                    "degrees_north",
                    "m3",
                    "kg s-1",
                    "kg s-1",
                    "days since 1991-01-01 00:00:00",
                    "days since 1991-01-01 00:00:00",
                    "days",
                    "days",
                ],
            ),
        ),
        (
            builders.Mom6Builder,
            "mom6/output053/20051101.ocean_daily_z_2005_360.nc",
            _AccessNCFileInfo(
                path=None,  # type: ignore
                filename="20051101.ocean_daily_z_2005_360.nc",
                file_id="XXXXXXXX_ocean_daily_z_XXXX_XXX",
                filename_timestamp="20051101",
                frequency="subhr",
                start_date="1991-01-01, 00:00:00",
                end_date="1991-01-01, 00:00:00",
                variable=[
                    "xh",
                    "yh",
                    "z_l",
                    "z_i",
                    "time",
                    "nv",
                    "xq",
                    "z_l_sub01",
                    "yq",
                    "volcello",
                    "uo",
                    "vo",
                    "thetao",
                    "so",
                    "average_T1",
                    "average_T2",
                    "average_DT",
                    "time_bnds",
                ],
                variable_long_name=[
                    "h point nominal longitude",
                    "h point nominal latitude",
                    "Depth at cell center",
                    "Depth at interface",
                    "time",
                    "vertex number",
                    "q point nominal longitude",
                    "Depth at cell center",
                    "q point nominal latitude",
                    "Ocean grid-cell volume",
                    "Sea Water X Velocity",
                    "Sea Water Y Velocity",
                    "Sea Water Potential Temperature",
                    "Sea Water Salinity",
                    "Start time for average period",
                    "End time for average period",
                    "Length of average period",
                    "time axis boundaries",
                ],
                variable_standard_name=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "ocean_volume",
                    "sea_water_x_velocity",
                    "sea_water_y_velocity",
                    "sea_water_potential_temperature",
                    "sea_water_salinity",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_cell_methods=[
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "area:sum z_l:sum yh:sum xh:sum time: mean",
                    "z_l:mean yh:mean xq:point time: mean",
                    "z_l:mean yq:point xh:mean time: mean",
                    "area:mean z_l:mean yh:mean xh:mean time: mean",
                    "area:mean z_l:mean yh:mean xh:mean time: mean",
                    "",
                    "",
                    "",
                    "",
                ],
                variable_units=[
                    "degrees_east",
                    "degrees_north",
                    "meters",
                    "meters",
                    "days since 1991-01-01 00:00:00",
                    "",
                    "degrees_east",
                    "meters",
                    "degrees_north",
                    "m3",
                    "m s-1",
                    "m s-1",
                    "degC",
                    "psu",
                    "days since 1991-01-01 00:00:00",
                    "days since 1991-01-01 00:00:00",
                    "days",
                    "days",
                ],
            ),
        ),
    ],
)
def test_parse_access_ncfile(test_data, builder, filename, expected, compare_files):
    """
    Tests for correctness of parser. Note that if we are using intake-esm without
    coordinate discovery enabled, the `conftest.py` fixture will dynamically set
    the `xfails=True` on parametrisations of these tests where we compare files.
    This is currently default behaviour as the latest release of intake-esm does
    not support coordinate discovery. However, it is on main.
    """
    file = str(test_data / Path(filename))

    # Set the path to the test data directory
    expected.path = file

    assert builder.parse_access_ncfile(file) == expected

    if not compare_files:
        return None

    """
    In the rest of this test, we refer to the dataset loaded using intake-esm
    as ie_ds and the dataset loaded directly with xarray as xr_ds.

    We also need to perform some additional logic that intake-esm does to avoid
    xr.testing.assert_equal from failing due to preprocessing differences.
    """
    xarray_open_kwargs = _get_xarray_open_kwargs("netcdf")

    ie_ds = _open_dataset(
        urlpath=expected.path,
        varname=expected.variable,
        xarray_open_kwargs=xarray_open_kwargs,
        requested_variables=expected.variable,
    ).compute()
    ie_ds.set_coords(set(ie_ds.variables) - set(ie_ds.attrs[OPTIONS["vars_key"]]))

    xr_ds = xr.open_dataset(file, **xarray_open_kwargs)

    scalar_variables = [v for v in xr_ds.data_vars if len(xr_ds[v].dims) == 0]
    xr_ds = xr_ds.set_coords(scalar_variables)

    xr_ds = xr_ds[expected.variable]

    xr.testing.assert_equal(ie_ds, xr_ds)
