From 6668da8ed3c6169e864a65e1cab54930757b5a37 Mon Sep 17 00:00:00 2001 From: Nicolas Tessore Date: Sat, 25 Nov 2023 09:52:53 +0000 Subject: [PATCH 1/4] add test and coverage reports --- .github/workflows/test.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ab52df8 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: Test +on: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - run: pip install ".[test]" + - run: pytest --pyargs angst + - run: pytest --import-mode prepend --doctest-modules src/ + coverage: + name: Coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: "3.12" + - run: pip install ".[test]" pytest-cov + - run: pytest --cov=angst --cov-report=xml + - uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From e6db4a3a592b93eabd357f9c0ab6975ff41216f0 Mon Sep 17 00:00:00 2001 From: Nicolas Tessore Date: Sat, 25 Nov 2023 10:01:35 +0000 Subject: [PATCH 2/4] do not skip tests if one fails --- .github/workflows/test.yml | 1 + README.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ab52df8..af4d8df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,7 @@ jobs: strategy: matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + fail-fast: false steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 diff --git a/README.md b/README.md index 3602840..bce7643 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # **Angst** — Angular statistics +[![codecov](https://codecov.io/gh/ntessore/angst/graph/badge.svg?token=MPIHKHSRT4)](https://codecov.io/gh/ntessore/angst) + **Angst** is a _work-in-progress_ Python package for statistics on the sphere. ## Installation From e5c47e494a2d4f45a2b2f9a0f893083013ad3ec2 Mon Sep 17 00:00:00 2001 From: Nicolas Tessore Date: Sat, 25 Nov 2023 10:04:05 +0000 Subject: [PATCH 3/4] add missing annotations future --- src/angst/_core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/angst/_core.py b/src/angst/_core.py index 9f23867..46dabcc 100644 --- a/src/angst/_core.py +++ b/src/angst/_core.py @@ -5,6 +5,8 @@ """ +from __future__ import annotations + __all__ = [ "inv_triangle_number", ] From d4aa0fa04bc4337bd302407e2be4d9d32083e06e Mon Sep 17 00:00:00 2001 From: Nicolas Tessore Date: Sat, 25 Nov 2023 10:42:51 +0000 Subject: [PATCH 4/4] add missing test --- src/angst/test/test_points.py | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/angst/test/test_points.py b/src/angst/test/test_points.py index d106515..74b500e 100644 --- a/src/angst/test/test_points.py +++ b/src/angst/test/test_points.py @@ -67,3 +67,49 @@ def test_displace_abs(rng): cos_a = np.cos(th) * np.cos(th_) + np.cos(delt) * np.sin(th) * np.sin(th_) npt.assert_allclose(cos_a, np.cos(abs_alpha)) + + +def test_displacement(rng): + from textwrap import dedent + import angst + + # unit changes for displacements + deg5 = np.radians(5.0) + north = np.exp(1j * 0.0) + east = np.exp(1j * (np.pi / 2)) + south = np.exp(1j * np.pi) + west = np.exp(1j * (3 * np.pi / 2)) + + # test data: coordinates and expected displacement + data = [ + # equator + (0.0, 0.0, 0.0, 5.0, deg5 * north), + (0.0, 0.0, -5.0, 0.0, deg5 * east), + (0.0, 0.0, 0.0, -5.0, deg5 * south), + (0.0, 0.0, 5.0, 0.0, deg5 * west), + # pole + (0.0, 90.0, 180.0, 85.0, deg5 * north), + (0.0, 90.0, -90.0, 85.0, deg5 * east), + (0.0, 90.0, 0.0, 85.0, deg5 * south), + (0.0, 90.0, 90.0, 85.0, deg5 * west), + ] + + # test each displacement individually + for from_lon, from_lat, to_lon, to_lat, alpha in data: + alpha_ = angst.displacement(from_lon, from_lat, to_lon, to_lat) + assert np.allclose(alpha_, alpha), dedent( + f""" + displacement from ({from_lon}, {from_lat}) to ({to_lon}, {to_lat}) + distance: expected {np.abs(alpha)}, got {np.abs(alpha_)} + direction: expected {np.angle(alpha)}, got {np.angle(alpha_)} + """ + ) + + # test on an array + alpha = angst.displacement( + rng.uniform(-180.0, 180.0, size=(20, 1)), + rng.uniform(-90.0, 90.0, size=(20, 1)), + rng.uniform(-180.0, 180.0, size=5), + rng.uniform(-90.0, 90.0, size=5), + ) + assert alpha.shape == (20, 5)