Commit 90039676 authored by Gregory Ashton's avatar Gregory Ashton

Adds basic tests

- Test for simulated data
- Test likelihood evaluation
- Add gitlab-ci.yml
- Remove lal and lalsim which aren't directly pip installable
- Add coverage and pipeline status to README
- Adds coverage report
- Update README.md with instructions on testing and coverage
parent 42657bc3
Pipeline #15450 passed with stages
in 1 minute and 8 seconds
# This script is an edited version of the example found at
# https://git.ligo.org/lscsoft/example-ci-project/blob/python/.gitlab-ci.yml
# Each 0th-indendation level is a job that will be run within GitLab CI
# The only exception are a short list of reserved keywords
#
# https://docs.gitlab.com/ee/ci/yaml/#gitlab-ci-yml
# stages is a reserved keyword that defines job dependencies and
# parallelization. each stage runs in parallel but must complete
# before the next stage begins
stages:
- test
- deploy
# test example on Debian 8 "jessie"
exitcode-jessie:
stage: test
image: ligo/software:jessie
script:
- pip install -r requirements.txt
- pip install coverage
- pip install coverage-badge
- coverage run tests.py
- coverage html
- coverage-badge -o coverage.svg
artifacts:
paths:
- htmlcov/
- coverage.svg
pages:
stage: deploy
dependencies:
- exitcode-jessie
script:
- mv htmlcov/ public/
- mv coverage.svg public/
artifacts:
paths:
- public
expire_in: 30 days
#only:
#- master
[![pipeline status](https://git.ligo.org/Monash/peyote/badges/master/pipeline.svg)](https://git.ligo.org/Monash/peyote/commits/master)
[![coverage report](https://monash.docs.ligo.org/peyote/coverage.svg)](
https://monash.docs.ligo.org/peyote/)
# PEYOte
Fulfilling all your GW dreams.
......@@ -34,4 +38,28 @@ $ make; make install
** warning **: in the configure line here, we have disabled everything except lalsimulation. If you need other modules, see `./configure --help`.
You could also `pip install lal, lalsuite`.
\ No newline at end of file
You could also `pip install lal, lalsuite`.
## Tests and coverage
To locally test the code
```bash
$ python tests.py
```
To locally generate a coverage report
```bash
$ pip install coverage
$ coverage run tests.py
$ coverage html
```
This will generate a directory `htmlcov`, to see detailed coverage navigate
from your browser to the file `peyote/htmlcov/index.html`.
The coverage report for master can be seen here:
[https://monash.docs.ligo.org/peyote/](https://monash.docs.ligo.org/peyote/).
import unittest
import numpy as np
import os
import shutil
import peyote
import logging
class Test(unittest.TestCase):
outdir = 'TestDir'
dir_path = os.path.dirname(os.path.realpath(__file__))
# Run a script to produce standard data
msd = {} # A dictionary of variables saved in make_standard_data.py
execfile(dir_path + '/tutorials/make_standard_data.py', msd)
@classmethod
def setUpClass(self):
if os.path.isdir(self.outdir):
try:
shutil.rmtree(self.outdir)
except OSError:
logging.warning(
"{} not removed prior to tests".format(self.outdir))
@classmethod
def tearDownClass(self):
if os.path.isdir(self.outdir):
try:
shutil.rmtree(self.outdir)
except OSError:
logging.warning(
"{} not removed prior to tests".format(self.outdir))
def test_make_standard_data(self):
" Load in the saved standard data and compare with new data "
# Load in the saved standard data
frequencies_saved, hf_real_saved, hf_imag_saved = np.loadtxt(
self.dir_path + '/tutorials/standard_data.txt').T
hf_signal_and_noise_saved = hf_real_saved + 1j * hf_imag_saved
self.assertTrue(
all(self.msd['frequencies'] == frequencies_saved))
self.assertTrue(
all(self.msd['hf_signal_and_noise'] == hf_signal_and_noise_saved))
def test_calculate_likelihood_for_standard_data(self):
pS = self.msd['simulation_parameters']
pN = self.msd['simulation_parameters'].copy()
pN['luminosity_distance'] = 1e6
likelihood = peyote.likelihood.likelihood(
[self.msd['IFO']], self.msd['source'])
loglS = likelihood.loglikelihood(pS)
loglN = likelihood.loglikelihood(pN)
self.assertAlmostEqual(
loglS - loglN,
36573752.328521997, 5)
if __name__ == '__main__':
unittest.main()
import peyote
import os
import numpy as np
np.random.seed(10)
time_duration = 1.
sampling_frequency = 4096.
simulation_parameters = dict(
mass_1=36.,
mass_2=29.,
spin_1=[0, 0, 0],
spin_2=[0, 0, 0],
luminosity_distance=410.,
inclination_angle=0.,
waveform_phase=0.,
waveform_approximant='IMRPhenomPv2',
reference_frequency=50.,
ra=0,
dec=1,
geocent_time=0,
psi=1
)
source = peyote.source.BinaryBlackHole(
'BBH', sampling_frequency, time_duration)
hf_signal = source.frequency_domain_strain(simulation_parameters)
IFO = peyote.detector.H1
hf_noise, frequencies = IFO.power_spectral_density.get_noise_realisation(
sampling_frequency, time_duration)
IFO.set_data(frequency_domain_strain=hf_noise)
IFO.inject_signal(source, simulation_parameters)
IFO.set_spectral_densities(frequencies)
IFO.whiten_data()
hf_signal_and_noise = IFO.data
if __name__ == '__main__':
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(dir_path + '/standard_data.txt', 'w+') as f:
np.savetxt(
f,
np.column_stack([frequencies,
hf_signal_and_noise.view(float).reshape(-1, 2)]),
header='frequency hf_real hf_imag')
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment