From 3f74664fc4d376fe8612c9c56ba171f556579333 Mon Sep 17 00:00:00 2001 From: dougiesquire Date: Wed, 28 Jun 2023 15:35:40 +1000 Subject: [PATCH] add test_parse_access_ncfile --- src/access_nri_intake/source/utils.py | 8 +- tests/conftest.py | 14 ++ .../ocean/ocean_month_inst_nobounds.nc | Bin 0 -> 21247 bytes .../ocean/ocean_month_inst_nobounds.nc | Bin 0 -> 21252 bytes tests/test_source_utils.py | 214 +++++++++++++++++- 5 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 tests/conftest.py create mode 100644 tests/data/access-om2/output000/ocean/ocean_month_inst_nobounds.nc create mode 100644 tests/data/access-om2/output001/ocean/ocean_month_inst_nobounds.nc diff --git a/src/access_nri_intake/source/utils.py b/src/access_nri_intake/source/utils.py index 93fd128..6aa274d 100644 --- a/src/access_nri_intake/source/utils.py +++ b/src/access_nri_intake/source/utils.py @@ -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) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..edecd3e --- /dev/null +++ b/tests/conftest.py @@ -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")) diff --git a/tests/data/access-om2/output000/ocean/ocean_month_inst_nobounds.nc b/tests/data/access-om2/output000/ocean/ocean_month_inst_nobounds.nc new file mode 100644 index 0000000000000000000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ZRU&M%!xX%10}b3uR}cxZUAm*DHjd}C^#|6 zM2yIfUk?umxKmW8aU-fuqk_iHGZ*5^-u(dO|3{ddNG8#jQQWSl z8RVbj_relPWQIgQA|Mfv2uK9p?g&)&9>|{fn~yZ_^8cl>_thT^fx)1mA^NGwOXnwc z4Ox4@RqUZJe?~vqb>P0ApFLjLo0}qskNyz;#s50r)0Mq1?5NzCczV-6!29j{fxrJ3 D<)^*y literal 0 HcmV?d00001 diff --git a/tests/data/access-om2/output001/ocean/ocean_month_inst_nobounds.nc b/tests/data/access-om2/output001/ocean/ocean_month_inst_nobounds.nc new file mode 100644 index 0000000000000000000000000000000000000000..53de0ad389c40965caf7895e9fe5086311d542f4 GIT binary patch literal 21252 zcmeHOZ)_CD6`#Aa&H21G4ke&AQQ1;ZK-kCK*)(ts3Fdqko0v24xdGIc^>VvDuX4BN z+^*@JXq3=YkwU5{fQ0%-O&T>+EmbMBQd=cTf|`D4Kt$nFrKlfDnCX=bR2mx(%!aU@6rNYdGf&xbg91``-sScFeyEj~j;fgd2#?0k>rxD_k! zl1}IwtErM85FtmU3*!)JC1ETZw~D5%mrU{rDC>Yfq$}r5-PTHF+ntEod1W=`hM-Ma z!?oNZBad+MzEmom%XJTLPatUsej<#tP_YcntxYm=>@#vNl^xy6D=PM_ffPDJJAxfW z(zr4eAk9D(W(+4R$1PWClx7zYA z#kQ-iMjOTU4YgL6^7W>neMtIRj3?t8lQI7Y>F~NtSJ&JHYcxTW8cwqi2#Jb4n;NFD zk8#o1rkm=|sKb+HMF*KU>OQmLSY=z?5RFAQsA~qwC38|QnCfPA!gVK;>(|@)a?}}* zLd7mMRW|BM3YI%DwKtkCmyihm){;x>lRMa=A%Q?IG)jV@K!C0ZcyElw@@dQuEk)8> z)D_-3SRN+J9{~={5iALjuu_^pR z2Djc$qmV*=#aHIGMUV|)lE>sumi})G_I5lveXeLa=cpGD;E?&h>LwKD<{P~yH zjvw$4U5c4O02GISL2wd?-2-CBu!Z!tk>0BzK&%7D8(KH5@SeHXj~bRtqb7PAANw+kI}{ozQ88$dKXcU0=6_{e(^sae1+`Bj60aD6K{XNM&5xm z0W6v!TK?kQ50gI3SiyD=?a2cN$rxq;Qxpr`3Ql0gCXOm<{zs81%s1RlmR))G#UDNN z*i%R&!@?j?ujsjSePZ&7h}2IL;*(XqtbJ31)XyZ}9P!Ea7blPL8NV>&l3eD806Q7| zJP??1GQx$2Vc||j?39+}+VKcu?;Ro+d1o>4SuSFQPE5}dlN##F<>*lXw;5C&{e#=n z+1%i8R?DUOhSEd4rzt%u5u_J~7J{77#?!%#NLhN)=PXLgQ!LvB&9fun1V$n^Zx)LxmRatUVJe_T(d5GoNmI7vvXhSJj$sxmrs-&D zv?HO}XEEz{Uaz>OV}VUduUf1M3I&_k1%FFcZ&}5}_p_TQzKd9uv zDc#o)Uk4D>iBAWM-;GEwJAdizhL+Z!J9gsU)bJ2pX8cSlmK?PO0F5|xW3MnY=7(6e zmoLuP;+v$A9yekPB45z+?*lJi9OfA{A!AZC3n*kP5s(N-1SA3y0f~S_Kq4R!kO)Ww zBmxqF8%Dr)%X0r#Rv(Q3ctF2-w=BZE@bdQ4TQURvTRq1G+M)9&-#FnJudZ)^?e0!@*FQyU88bh z9sH`mKT#WvcX_V~@3kM4p2C}}6EXU3p_>x6RxrzOwV}BxzUZ#zdW|}+j#|=~z7c`j z5?Y75ouULaDnZSiu<{SursHUaIgTRK_SQ7VDwM#R6LnxGN^bgIhk6!#61btITsRb< z;KU>oF(RM66&?_9r>IZkMpU0h1&y6&4#d~I`vJ=Tk1#rtPNOfQxO)?^GSA_k8u1f~ zmCzWAD+)igOi2VJ0uljOHCB NEB^^jaHm86_%9Im#BTrq literal 0 HcmV?d00001 diff --git a/tests/test_source_utils.py b/tests/test_source_utils.py index 284522c..6373898 100644 --- a/tests/test_source_utils.py +++ b/tests/test_source_utils.py @@ -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( @@ -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