Skip to content

Commit

Permalink
add test_parse_access_ncfile
Browse files Browse the repository at this point in the history
  • Loading branch information
dougiesquire committed Jun 28, 2023
1 parent 2e556d9 commit 3f74664
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/access_nri_intake/source/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ def parse_access_ncfile(file):
if "long_name" in attrs:
variable_list.append(var)
variable_long_name_list.append(attrs["long_name"])
if "standard_name" in attrs:
variable_standard_name_list.append(attrs["standard_name"])
if "cell_methods" in attrs:
variable_cell_methods_list.append(attrs["cell_methods"])
if "standard_name" in attrs:
variable_standard_name_list.append(attrs["standard_name"])
if "cell_methods" in attrs:
variable_cell_methods_list.append(attrs["cell_methods"])

start_date, end_date, frequency = get_timeinfo(ds)

Expand Down
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 ACCESS-NRI and contributors. See the top-level COPYRIGHT file for details.
# SPDX-License-Identifier: Apache-2.0

import os
from pathlib import Path

from pytest import fixture

here = os.path.abspath(os.path.dirname(__file__))


@fixture(scope="session")
def test_data():
return Path(os.path.join(here, "data"))
Binary file not shown.
Binary file not shown.
214 changes: 213 additions & 1 deletion tests/test_source_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from access_nri_intake.source.utils import parse_access_filename
from access_nri_intake.source.utils import parse_access_filename, parse_access_ncfile


@pytest.mark.parametrize(
Expand Down Expand Up @@ -69,3 +69,215 @@
)
def test_parse_access_filename(filename, expected):
assert parse_access_filename(filename) == expected


@pytest.mark.parametrize(
"filename, expected",
[
(
"access-om2/output000/ocean/ocean.nc",
(
"ocean.nc",
"ocean",
None,
"1yr",
"1900-01-01, 00:00:00",
"1910-01-01, 00:00:00",
["temp", "time_bounds"],
["Conservative temperature", "time axis boundaries"],
["sea_water_conservative_temperature"],
["time: mean"],
),
),
(
"access-om2/output000/ocean/ocean_month.nc",
(
"ocean_month.nc",
"ocean_month",
None,
"1mon",
"1900-01-01, 00:00:00",
"1910-01-01, 00:00:00",
["mld", "time_bounds"],
[
"mixed layer depth determined by density criteria",
"time axis boundaries",
],
["ocean_mixed_layer_thickness_defined_by_sigma_t"],
["time: mean"],
),
),
(
"access-om2/output000/ocean/ocean_month_inst_nobounds.nc",
(
"ocean_month_inst_nobounds.nc",
"ocean_month_inst_nobounds",
None,
"1mon",
"1900-01-16, 12:00:00",
"1900-01-16, 12:00:00",
["mld"],
["mixed layer depth determined by density criteria"],
["ocean_mixed_layer_thickness_defined_by_sigma_t"],
["time: mean"],
),
),
(
"access-om2/output000/ice/OUTPUT/iceh.1900-01.nc",
(
"iceh.1900-01.nc",
"iceh_XXXX_XX",
"1900-01",
"1mon",
"1900-01-01, 00:00:00",
"1900-02-01, 00:00:00",
["TLAT", "TLON", "aice_m", "tarea", "time_bounds"],
[
"T grid center latitude",
"T grid center longitude",
"ice area (aggregate)",
"area of T grid cells",
"boundaries for time-averaging interval",
],
[],
["time: mean"],
),
),
(
"access-cm2/mem1/history/atm/netCDF/by578a.pd201501_dai.nc",
(
"by578a.pd201501_dai.nc",
"by578a_pdXXXXXX_dai",
"201501",
"1day",
"2015-01-01, 00:00:00",
"2015-02-01, 00:00:00",
["fld_s03i236"],
["TEMPERATURE AT 1.5M"],
["air_temperature"],
["time: mean"],
),
),
(
"access-cm2/mem1/history/ice/iceh_d.2015-01.nc",
(
"iceh_d.2015-01.nc",
"iceh_d_XXXX_XX",
"2015-01",
"1day",
"2015-01-01, 00:00:00",
"2015-02-01, 00:00:00",
["TLAT", "TLON", "aice", "tarea", "time_bounds"],
[
"T grid center latitude",
"T grid center longitude",
"ice area (aggregate)",
"area of T grid cells",
"boundaries for time-averaging interval",
],
[],
["time: mean"],
),
),
(
"access-cm2/mem1/history/ocn/ocean_daily.nc-20150630",
(
"ocean_daily.nc-20150630",
"ocean_daily",
None,
"1day",
"2015-01-01, 00:00:00",
"2015-07-01, 00:00:00",
["sst", "time_bounds"],
["Potential temperature", "time axis boundaries"],
["sea_surface_temperature"],
["time: mean"],
),
),
(
"access-cm2/mem1/history/ocn/ocean_scalar.nc-20150630",
(
"ocean_scalar.nc-20150630",
"ocean_scalar",
None,
"1mon",
"2015-01-01, 00:00:00",
"2015-07-01, 00:00:00",
["temp_global_ave", "time_bounds"],
["Global mean temp in liquid seawater", "time axis boundaries"],
["sea_water_potential_temperature"],
["time: mean"],
),
),
(
"access-esm1-5/history/atm/netCDF/HI-C-05-r1.pa-185001_mon.nc",
(
"HI-C-05-r1.pa-185001_mon.nc",
"HI_C_05_r1_pa_XXXXXX_mon",
"185001",
"1mon",
"1850-01-01, 00:00:00",
"1850-02-01, 00:00:00",
["fld_s03i236"],
["TEMPERATURE AT 1.5M"],
["air_temperature"],
["time: mean"],
),
),
(
"access-esm1-5/history/ice/iceh.1850-01.nc",
(
"iceh.1850-01.nc",
"iceh_XXXX_XX",
"1850-01",
"1mon",
"1850-01-01, 00:00:00",
"1850-02-01, 00:00:00",
["TLAT", "TLON", "aice", "tarea", "time_bounds"],
[
"T grid center latitude",
"T grid center longitude",
"ice area (aggregate)",
"area of T grid cells",
"boundaries for time-averaging interval",
],
[],
["time: mean"],
),
),
(
"access-esm1-5/history/ocn/ocean_bgc_ann.nc-18501231",
(
"ocean_bgc_ann.nc-18501231",
"ocean_bgc_ann",
None,
"1yr",
"1849-12-30, 00:00:00",
"1850-12-30, 00:00:00",
["fgco2_raw", "time_bounds"],
["Flux into ocean - DIC, inc. anth.", "time axis boundaries"],
[],
["time: mean"],
),
),
(
"access-esm1-5/history/ocn/ocean_bgc.nc-18501231",
(
"ocean_bgc.nc-18501231",
"ocean_bgc",
None,
"1mon",
"1849-12-30, 00:00:00",
"1850-12-30, 00:00:00",
["o2", "time_bounds"],
["o2", "time axis boundaries"],
[],
["time: mean"],
),
),
],
)
def test_parse_access_ncfile(test_data, filename, expected):
file = test_data / filename

assert parse_access_ncfile(file) == expected

0 comments on commit 3f74664

Please sign in to comment.