From 158f853a51c0af643628aa8e0138486d12b6fe63 Mon Sep 17 00:00:00 2001 From: Tyler Sutterley Date: Mon, 9 Jun 2025 10:21:17 -0700 Subject: [PATCH] test: add check for reading lsmasks ci: verify that git lfs is used docs: add badge for conda-forge --- .github/workflows/python-publish.yml | 2 + .github/workflows/python-request.yml | 2 + README.rst | 4 ++ test/test_gia.py | 2 +- test/test_masks.py | 56 ++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 test/test_masks.py diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index aaa92f8f..1217a730 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -14,6 +14,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + lfs: true - name: Set up Python uses: actions/setup-python@v4 with: diff --git a/.github/workflows/python-request.yml b/.github/workflows/python-request.yml index 1cff97f4..0bda629f 100644 --- a/.github/workflows/python-request.yml +++ b/.github/workflows/python-request.yml @@ -23,6 +23,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + lfs: true - name: Set up mamba ${{ matrix.python-version }} uses: mamba-org/setup-micromamba@v1 with: diff --git a/README.rst b/README.rst index 517a14bc..b4c4cd41 100644 --- a/README.rst +++ b/README.rst @@ -5,6 +5,7 @@ gravity-toolkit |License| |Documentation Status| |PyPI| +|conda-forge| |commits-since| |zenodo| @@ -17,6 +18,9 @@ gravity-toolkit .. |PyPI| image:: https://img.shields.io/pypi/v/gravity-toolkit.svg :target: https://pypi.python.org/pypi/gravity-toolkit/ +.. |conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/gravity-toolkit + :target: https://anaconda.org/conda-forge/gravity-toolkit + .. |commits-since| image:: https://img.shields.io/github/commits-since/tsutterley/gravity-toolkit/latest :target: https://github.com/tsutterley/gravity-toolkit/releases/latest diff --git a/test/test_gia.py b/test/test_gia.py index 4e61c577..9abe91a5 100644 --- a/test/test_gia.py +++ b/test/test_gia.py @@ -1,7 +1,7 @@ #!/usr/bin/env python u""" test_gia.py (12/2022) -Tests the that GIA model readers are equivalent +Tests that the GIA model readers are equivalent """ import gzip import time diff --git a/test/test_masks.py b/test/test_masks.py new file mode 100644 index 00000000..70c1f923 --- /dev/null +++ b/test/test_masks.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +u""" +test_masks.py (06/2025) +Tests that the stored masks can be read +""" +import pytest +import numpy as np +import gravity_toolkit as gravtk + +# parameterize land-sea masks +_land_sea_masks = ["landsea_1d.nc", "landsea_hd.nc", "landsea_qd.nc"] +@pytest.mark.parametrize("LANDMASK", _land_sea_masks) +def test_lsmask(LANDMASK): + u""" + Test that the land mask can be read and that the + area of the ocean is close to the expected value + """ + # Land-Sea Mask with Antarctica from Rignot (2017) and Greenland from GEUS + # 0=Ocean, 1=Land, 2=Lake, 3=Small Island, 4=Ice Shelf + # Open the land-sea NetCDF file for reading + lsmask = gravtk.utilities.get_data_path(['data',LANDMASK]) + landsea = gravtk.spatial().from_netCDF4(lsmask, date=False, varname='LSMASK') + # degree spacing and grid dimensions + dlon, dlat = landsea.spacing + nlat, nlon = landsea.shape + # colatitude in radians + gridlon, gridlat = np.meshgrid(landsea.lon, landsea.lat) + th = (90.0 - gridlat)*np.pi/180.0 + # grid spacing in radians + dphi = np.pi*np.abs(dlon)/180.0 + dth = np.pi*np.abs(dlat)/180.0 + # create land function + land_function = np.zeros((nlat, nlon), dtype=np.float64) + # combine land and island levels for land function + indx,indy = np.nonzero((landsea.data >= 1) & (landsea.data <= 3)) + land_function[indx,indy] = 1.0 + # calculate the ocean function + ocean_function = 1.0 - land_function + # average Radius of the Earth [km] + rad_e = gravtk.units().rad_e/1e5 + # total area of ocean calculated by integrating the ocean function + area = np.sum(ocean_function*np.sin(th)*dphi*dth*rad_e**2) + # assert that the area is close to the expected value + assert np.isclose(area, 3.62e8, rtol=0.01) + +def test_smoothed(): + """ + Test that the smoothed land mask can be read + """ + # Read Smoothed Ocean and Land Functions + # will mask out land regions in the final current maps + LANDMASK = gravtk.utilities.get_data_path(['data','land_fcn_300km.nc']) + landsea = gravtk.spatial().from_netCDF4(LANDMASK, + date=False, varname='LSMASK') + assert landsea.shape == (180, 360) + assert landsea.spacing == (1.0, 1.0)