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
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
# test with as many cores as possible for speed
pytest legwork -n=auto --cov=./ --cov-report=xml
- name: Get Coverage
uses: orgoro/coverage@v3.1
uses: orgoro/coverage@v3.2
with:
coverageFile: ./coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,8 @@ having two when we could just set `f_dom=2 f_orb`
*TW 22/06/24*
- Update to Python 3.11 and various dependencies
- Fix deprecations based on these updates
- Add __repr__ and __len__ functions for the Source class and its subclasses
- Add __repr__ and __len__ functions for the Source class and its subclasses

## 0.5.1
*TW 11/01/25*
- [Issue [#116](https://github.com/TeamLEGWORK/LEGWORK/issues/116)] LEGWORK will now raise errors if invalid harmonics are supplied
2 changes: 1 addition & 1 deletion legwork/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.0"
__version__ = "0.5.1"
8 changes: 8 additions & 0 deletions legwork/strain.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def h_0_n(m_c, f_orb, ecc, n, dist, position=None, polarisation=None, inclinatio
arrayed_args, _ = utils.ensure_array(m_c, f_orb, ecc, n, dist)
m_c, f_orb, ecc, n, dist = arrayed_args

# raise a value error if any n is less than 1
if np.any(n < 1):
raise ValueError("All harmonics must be greater than or equal to 1")

# if one timestep then extend dimensions
if f_orb.ndim != 2:
f_orb = f_orb[:, np.newaxis]
Expand Down Expand Up @@ -190,6 +194,10 @@ def h_c_n(m_c, f_orb, ecc, n, dist, position=None, polarisation=None, inclinatio
arrayed_args, _ = utils.ensure_array(m_c, f_orb, ecc, n, dist)
m_c, f_orb, ecc, n, dist = arrayed_args

# raise a value error if any n is less than 1
if np.any(n < 1):
raise ValueError("All harmonics must be greater than or equal to 1")

# if one timestep then extend dimensions
if f_orb.ndim != 2:
f_orb = f_orb[:, np.newaxis]
Expand Down
15 changes: 15 additions & 0 deletions legwork/tests/test_strains.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ def test_strain_conversion(self):
fn_dot = utils.fn_dot(m_c, f_orb, e, n)

self.assertTrue(np.allclose(should_be_fn_dot, fn_dot))

def test_bad_harmonics(self):
"""Make sure fn_dot fails when given harmonics < 1"""

n_values = 100000

m_c = np.random.uniform(0, 10, n_values) * u.Msun
dist = np.random.uniform(0, 30, n_values) * u.kpc
f_orb = 10**(np.random.uniform(-5, -1, n_values)) * u.Hz
e = np.random.uniform(0, 0.9, n_values)

with self.assertRaises(ValueError):
strain.h_0_n(m_c, f_orb, e, [0, 1, 2], dist)
with self.assertRaises(ValueError):
strain.h_c_n(m_c, f_orb, e, [0, 1, 2], dist)
6 changes: 6 additions & 0 deletions legwork/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@ def integrand2(theta, phi, psi, inc):
[0, np.pi / 2]]) # inc

self.assertAlmostEqual(result, 0.12)

def test_bad_harmonics(self):
"""Make sure fn_dot fails when given harmonics < 1"""

with self.assertRaises(ValueError):
utils.fn_dot(m_c=10*u.Msun, f_orb=10*u.mHz, e=0.1, n=0)
3 changes: 3 additions & 0 deletions legwork/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ def fn_dot(m_c, f_orb, e, n):
fn_dot : `float/array`
Rate of change of nth frequency
"""
if np.any(n < 1):
raise ValueError("All harmonics must be greater than or equal to 1")

fn_dot = (48 * n) / (5 * np.pi) * (c.G * m_c)**(5/3) / c.c**5 * (2 * np.pi * f_orb)**(11/3) * peters_f(e)

# simplify units if present
Expand Down
Loading