Skip to content

Commit

Permalink
Merge branch 'master' into v0.4-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
transientlunatic authored Jan 7, 2025
2 parents d73f8b9 + 9740c56 commit d540e12
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 4 deletions.
6 changes: 6 additions & 0 deletions heron/injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def make_injection(
logger.info(f"Saving framefile to {filename}")
injection.write(filename, format="gwf")

if psdfile:
# Write the PSD file to an ascii file
filename = f"{detector.abbreviation}_{psdfile}.dat"
psd_model.to_file(filename)

return injections


Expand Down Expand Up @@ -156,5 +161,6 @@ def injection(settings):
injection_parameters=parameters,
detectors=detector_dict,
framefile="injection",
psdfile="psd",
)
data = injections
4 changes: 3 additions & 1 deletion heron/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ class WaveformSurrogate(WaveformModel):


class PSDModel:
pass

def to_file(self, filename, *args, **kwargs):
data = self.twocolumn(*args, **kwargs)
np.savetxt(filename, data)

class PSDApproximant(PSDModel):
pass
10 changes: 10 additions & 0 deletions heron/models/lalnoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def frequency_domain(
psd = PSD(psd_data, frequencies=frequencies)
return psd

def twocolumn(self, *args, **kwargs):
"""
Produce the PSD in two-column format.
"""
psd = self.frequency_domain(*args, **kwargs)
frequencies = psd.frequencies.value
data = np.array(psd.data)

return np.vstack([frequencies, data]).T

def covariance_matrix(self, times):
"""
Return a time-domain representation of this power spectral density.
Expand Down
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ click
asimov
pesummary
nessai
gpytorch
torch
torchvision
elk-waveform
gpytorch==1.0.1
torch==2.4.0
torchvision==0.5.0
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ sphinx-versions
kentigern
sphinxcontrib-bibtex
numpydoc==1.8.0
git+https://github.com/transientlunatic/sphinx-daniel-theme.git
nbsphinx==0.9.5
13 changes: 13 additions & 0 deletions tests/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,16 @@ def test_waveform_mass_no_units(self):
"mass_2": mass2.to(u.kilogram).value})

self.assertTrue(time_domain_1['plus'].data == time_domain_2['plus'].data)


class _GenericPSD(unittest.TestCase):

@classmethod
def setUpClass(self):
self.psd_model = AdvancedLIGO

def test_frequency_series_ascii_two_column(self):
"""Test that a frequency series is correctly produced."""
frequency_series = self.psd_model().twocolumn()

self.assertTrue(frequency_series.ndim == 2)
10 changes: 10 additions & 0 deletions tests/models/test_lalnoise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import unittest

from heron.models.lalnoise import AdvancedLIGO
from . import _GenericPSD

class TestAdvancedLIGO(_GenericPSD):

@classmethod
def setUpClass(self):
self.psd_model = AdvancedLIGO
1 change: 1 addition & 0 deletions tests/test_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ def test_multiple_inject(self):
detectors={"AdvancedLIGOHanford": "AdvancedLIGO",
"AdvancedLIGOLivingston": "AdvancedLIGO"},
framefile="test",
psdfile="psd"
)

0 comments on commit d540e12

Please sign in to comment.