Skip to content

Commit

Permalink
Fix error in average run speed in situation where runstats data is un…
Browse files Browse the repository at this point in the history
…available. Closes #19 (#23)

Co-authored-by: Deborah Ferguson <[email protected]>
  • Loading branch information
deborahferguson and Deborah Ferguson authored Apr 3, 2024
1 parent 49e5ab9 commit f0aee48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mayawaves/coalescence.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ def orbital_frequency(self) -> tuple:
@property
def average_run_speed(self) -> float:
"""Average speed of the simulation in M/hr."""
if "runstats" not in self.__h5_file:
warnings.warn('Runstats information is not available for this coalescence.')
return None
speed_column = self.__h5_file["runstats"].attrs["header"].tolist().index("speed (hours^-1)")
return float(np.mean(self.__h5_file["runstats"][:, speed_column], axis=0))

Expand Down
7 changes: 7 additions & 0 deletions tests/test_coalescence.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,13 @@ def test_eccentricity_and_mean_anomaly_at_time(self, compactobject_momentum_vect
def test_average_run_speed(self):
self.assertTrue(np.isclose(TestCoalescence.coalescence.average_run_speed, 54.5613306725, atol=1e-4))

#runstats not available
temp_coalescence = Coalescence(os.path.join(TestCoalescence.CURR_DIR,
"resources/sample_etk_simulations/GW150914.h5"))
runspeed = temp_coalescence.average_run_speed
temp_coalescence.close()
self.assertIsNone(runspeed)

def test_l_max(self):
self.assertEqual(TestCoalescence.coalescence.l_max, 4)

Expand Down

0 comments on commit f0aee48

Please sign in to comment.