Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ jobs:
env:
NUMBA_DISABLE_COVERAGE: "1"
run: |
coverage run -m pytest -v -s

coverage run -m pytest -v -s
- name: Upload coverage to Coveralls
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
run: coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/ObservationalExpansions/flex/blob/main/LICENSE)


[![Coverage Status](https://coveralls.io/repos/github/ObservationalExpansions/flex/badge.svg?branch=main)](https://coveralls.io/github/ObservationalExpansions/flex?branch=main)


## Installation
Expand Down
52 changes: 50 additions & 2 deletions tests/test_flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,32 @@ def test_flex_initialization():
with pytest.raises(ValueError):
flex.FLEX(rscl, mmax, nmax, R, phi, mass, velocity[:-1])

# Test nonsense inputs
with pytest.raises(ValueError):
flex.FLEX(rscl, mmax, nmax, True, phi, mass, velocity)
with pytest.raises(ValueError):
flex.FLEX(rscl, mmax, nmax, R, True, mass, velocity)
with pytest.raises(ValueError):
flex.FLEX(rscl, mmax, nmax, R, phi, mass='nonsense')
with pytest.raises(ValueError):
flex.FLEX(rscl, mmax, nmax, R, phi, velocity='nonsense')

def test_flex_version():
assert isinstance(flex.__version__, str)

def test_flex_scalars():
# Create a FLEX instance
rscl = 1.0
mmax = 2
nmax = 10
R = np.linspace(0.1, 5.0, 100)
phi = np.linspace(0, 2*np.pi, 100)
mass = 1.0
velocity = 1.0

F = flex.FLEX(rscl, mmax, nmax, R, phi, mass, velocity)


def test_flex_total_power():
# Create a FLEX instance
rscl = 1.0
Expand All @@ -59,7 +82,15 @@ def test_flex_total_power():
mass = np.random.uniform(0, 1, 100)
velocity = np.random.uniform(0, 100, 100)

F = flex.FLEX(rscl, mmax, nmax, R, phi, mass, velocity)
# test the slower, careful, newaxis version
F = flex.FLEX(rscl, mmax, nmax, R, phi, mass, velocity, newaxis=True)

# test the faster vectorised version
G = flex.FLEX(rscl, mmax, nmax, R, phi, mass, velocity)

# check that both methods give the same coefficients
np.testing.assert_allclose(F.coscoefs, G.coscoefs)
np.testing.assert_allclose(F.sincoefs, G.sincoefs)

# Compute total power in each harmonic
totalm = np.linalg.norm(np.sqrt(F.coscoefs**2 + F.sincoefs**2), axis=1)
Expand All @@ -68,4 +99,21 @@ def test_flex_total_power():
assert totalm.shape[0] == mmax + 1

# Check that totalm values are non-negative
assert np.all(totalm >= 0)
assert np.all(totalm >= 0)


def test_flex_total_normalisation():
# Create a FLEX instance
rscl = 1.0
mmax = 0
nmax = 1
R = np.linspace(0.1, 5.0, 100)
phi = np.linspace(0, 2*np.pi, 100)
mass = np.ones(100)

F = flex.FLEX(rscl, mmax, nmax, R, phi, mass)

F.laguerre_reconstruction(R, phi)

# check the values for the norm
#print(F.reconstruction)