diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..af4d8df --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,37 @@ +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"] + fail-fast: false + 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 }} 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 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", ] 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)