From 957fcd9a20bd0d2f5bee35cb4a662c2be1206dd9 Mon Sep 17 00:00:00 2001 From: fraserwg <fraser.goldsworth@st-annes.ox.ac.uk> Date: Thu, 9 Feb 2023 10:20:02 +0100 Subject: [PATCH] added tests for vector calculus functions --- pyicon/pyicon_calc_xr.py | 16 +++++----------- pyicon/tests/test_pyicon_calc_xr.py | 9 +++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pyicon/pyicon_calc_xr.py b/pyicon/pyicon_calc_xr.py index afd12af..26bb740 100644 --- a/pyicon/pyicon_calc_xr.py +++ b/pyicon/pyicon_calc_xr.py @@ -471,28 +471,22 @@ def xr_calc_curl(ds_IcD, vector, rot_coeff=None): Dataarray containing vector variable on cell edges. rot_coeff : xr.DataArray or None - Array with dims ("vertex", "ne") + Array containing dims ("vertex", "ne") Returns ------- curl_vec : xr.DataArray - vertical component of the curl of the vector + vertical component of the curl of the vector defined on vertex points Notes ----- - We calculate the curl through the use of Stokes' theorem (technically - Green's theorem as we're working with 2D velocity!), however, only the - vertical component is calculated. A similar procedure can be used to - calculate the horizontal components of the curl (oriented along cell edges - and defined at intermediate Z levels.) This will be implemented in a future - release. + We calculate the curl through the use of Stokes'/Green's theorem + Green's theorem as we're working with 2D velocity!), A similar procedure can be used to calculate the horizontal components of the curl (oriented + along cell edges and defined at intermediate Z levels.) This will be implemented in a future release. If you're using this function on large datasets, performance gains may be made if you play around with the dimension order. - When applying to a gradient we get identically zero. Should add this as a - test to the testing suite - """ assert "edge" in vector.dims diff --git a/pyicon/tests/test_pyicon_calc_xr.py b/pyicon/tests/test_pyicon_calc_xr.py index c8eb7be..0121600 100644 --- a/pyicon/tests/test_pyicon_calc_xr.py +++ b/pyicon/tests/test_pyicon_calc_xr.py @@ -86,3 +86,12 @@ def test_xr_crop_tgrid(tgrid, request): assert cropped_tgrid["ireg_v"].sum() == 135385 assert cropped_tgrid["ireg_v"].prod() == -1427286351937536000 + + +def test_nabla_funcs(processed_tgrid): + # Want to check curl of a gradient + gradient = pyic.xr_calc_grad(processed_tgrid, processed_tgrid["clon"]) + curl_of_grad = pyic.xr_calc_curl(processed_tgrid, gradient) + assert np.allclose(curl_of_grad, 0) + + # Should include other tests in the future if any refactoring is done -- GitLab