Skip to content

Commit

Permalink
Merge pull request #4 from transientlunatic/v0.4-preview
Browse files Browse the repository at this point in the history
Create v0.4
  • Loading branch information
transientlunatic authored Jan 7, 2025
2 parents 9740c56 + d540e12 commit 4017001
Show file tree
Hide file tree
Showing 16 changed files with 726 additions and 398 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Documentation
on:
push:
branches:
- master
- v*-preview

jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Build HTML Docs
run: |
sudo apt install pandoc
pip install sphinx sphinx-multiversion
pip install kentigern
pip install -r requirements.txt
pip install -r requirements_dev.txt
pip install .
cd docs
make html
- name: SCP Deploy HTML Docs
uses: horochx/[email protected]
with:
local: docs/_build/html/*
remote: /home/danwilliams/code.daniel-williams.co.uk/heron/${{ github.ref_name }}
host: ${{ secrets.sshhost }}
user: ${{ secrets.sshuser }}
key: ${{ secrets.sshkey }}
44 changes: 13 additions & 31 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,29 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
name: Tests
on:
push:
branches: [ review ]
branches:
- master
- v*-preview
pull_request:
branches: [ review ]
branches:
- master

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
test:
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Build HTML Docs

- name: Install dependencies
run: |
sudo apt install pandoc
pip install sphinx
pip install kentigern
pip install -r requirements.txt
pip install -r requirements_dev.txt
pip install .
cd docs
make html
pip install -r requirements_test.txt
- name: SCP Deploy HTML Docs
uses: horochx/[email protected]
with:
local: docs/_build/html/*
remote: /home/danwilliams/code.daniel-williams.co.uk/heron/review
host: ${{ secrets.sshhost }}
user: ${{ secrets.sshuser }}
key: ${{ secrets.sshkey }}
- name: Run Tests
run: |
python -m unittest discover tests/
11 changes: 7 additions & 4 deletions heron/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import click

from gwpy.timeseries import TimeSeries
from .types import TimeSeries
import astropy.units as u

from nessai.flowsampler import FlowSampler
Expand Down Expand Up @@ -84,6 +84,7 @@ def heron_inference(settings):
if "data files" in settings.get("data", {}):
# Load frame files from disk
for ifo in settings["interferometers"]:
print(f"Loading {ifo} data")
logger.info(
f"Loading {ifo} data from "
f"{settings['data']['data files'][ifo]}/{settings['data']['channels'][ifo]}"
Expand All @@ -93,14 +94,16 @@ def heron_inference(settings):
channel=settings["data"]["channels"][ifo],
format="gwf",
)
elif "injection" in other_settings:
pass
#elif "injection" in other_settings:
# pass

# Make Likelihood
if len(settings["interferometers"]) > 1:
likelihoods = []
print("Creating likelihoods")
waveform_model = KNOWN_WAVEFORMS[settings["waveform"]["model"]]()
for ifo in settings["interferometers"]:
print(f"\t {ifo}")
likelihoods.append(
KNOWN_LIKELIHOODS[settings.get("likelihood").get("function")](
data[ifo],
Expand All @@ -113,7 +116,7 @@ def heron_inference(settings):
),
)
)
likelihood = MultiDetector(*likelihoods)
likelihood = MultiDetector(*likelihoods)

priors = heron.priors.PriorDict()
priors.from_dictionary(settings["priors"])
Expand Down
33 changes: 19 additions & 14 deletions heron/injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@


def make_injection(
waveform=IMRPhenomPv2,
injection_parameters={},
times=None,
detectors=None,
framefile=None,
psdfile=None,
waveform=IMRPhenomPv2,
injection_parameters={},
duration=32,
sample_rate=4096,
times=None,
detectors=None,
framefile=None,
):

parameters = {"ra": 0, "dec": 0, "psi": 0, "theta_jn": 0, "phase": 0}
Expand All @@ -34,7 +35,7 @@ def make_injection(
waveform = waveform()

if times is None:
times = np.linspace(-0.5, 0.1, int(0.6 * 4096))
times = np.linspace(parameters['gpstime']-duration+2, parameters['gpstime']+2, int(duration * sample_rate))
waveform = waveform.time_domain(
parameters,
times=times,
Expand All @@ -45,16 +46,19 @@ def make_injection(
logger.info(f"Making injection for {detector}")
psd_model = KNOWN_PSDS[psd_model]()
detector = KNOWN_IFOS[detector]()
if times is None:
times = waveform['plus'].times.value
data = psd_model.time_series(times)
print(data)

channel = f"{detector.abbreviation}:Injection"
injection = data + waveform.project(detector)
injection.channel = channel
injections[detector.abbreviation] = injection
likelihood = TimeDomainLikelihood(injection, psd=psd_model)
snr = likelihood.snr(waveform.project(detector))
# likelihood = TimeDomainLikelihood(injection, psd=psd_model)
# snr = likelihood.snr(waveform.project(detector))

logger.info(f"Optimal Filter SNR: {snr}")
#logger.info(f"Optimal Filter SNR: {snr}")

if framefile:
filename = f"{detector.abbreviation}_{framefile}.gwf"
Expand Down Expand Up @@ -115,21 +119,20 @@ def make_injection_zero_noise(
logger.info(f"Saving framefile to {filename}")
injection.write(filename, format="gwf")

return injections

def injection_parameters_add_units(parameters):
UNITS = {"luminosity_distance": u.megaparsec, "m1": u.solMass, "m2": u.solMass}

for parameter, value in parameters.items():
if not isinstance(value, u.Quantity):
if not isinstance(value, u.Quantity) and (parameter in UNITS.keys()):
parameters[parameter] = value * UNITS[parameter]
return parameters


@click.command()
@click.option("--settings")
def injection(settings):

click.secho("Creating an injection with the heron injection engine")

settings = load_yaml(settings)

if "logging" in settings:
Expand All @@ -153,6 +156,8 @@ def injection(settings):
}
injections = make_injection(
waveform=IMRPhenomPv2,
duration=settings["duration"],
sample_rate=settings["sample rate"],
injection_parameters=parameters,
detectors=detector_dict,
framefile="injection",
Expand Down
Loading

0 comments on commit 4017001

Please sign in to comment.