Commit 5574d1aa authored by Edward Fauchon-Jones's avatar Edward Fauchon-Jones
Browse files

Merge branch 'add-phase-sense-check'

parents 0ed8a149 f2b37d32
Pipeline #25324 passed with stage
in 2 minutes and 22 seconds
......@@ -62,7 +62,8 @@ format1 = OrderedDict((
format1Interfield = OrderedDict((
("mass-ordering", MassOrdering),
("peak-near-zero", PeakNearZero)))
("peak-near-zero", PeakNearZero),
("phase-sense", PhaseSense)))
format2 = OrderedDict((
('mass1-vs-time', Mass1VsTime),
......
......@@ -18,6 +18,7 @@ from . import errors as err
import numpy as np
import re
from scipy.interpolate import insert, splrep, PPoly
from scipy.interpolate import InterpolatedUnivariateSpline as IUS
class Spec(object):
......@@ -907,3 +908,34 @@ class PeakNearZero(InterfieldSpec):
" which is greater than {1:.2f}M from zero").format(
maximumPoint, tol)
return err.InvalidInterfield(self)
class PhaseSense(InterfieldSpec):
"""Specification for the sense of the waveform pahse"""
name = "phase-sense"
validMsg = "(2,2) phase is decreasing on average"
invalidMsg = "(2,2) phase is not decreasing on average"
def valid(self, sim):
# Validate (2,2) multipole moment phase
phaseMode = Phaselm(name='phase_l2_m2')
phaseModeValid = phaseMode.valid(sim)
if not isinstance(phaseModeValid, err.Valid):
self.invalidMsg = "phase_l2_m2 is invalid"
return err.InvalidInterfields(self)
# Determine sense from middle of pre-merger waveform
phase = np.array([sim['phase_l2_m2/X'][:], sim['phase_l2_m2/Y'][:]])
t0 = phase[0][0]*(3.0/4.0)
if t0 >= 0:
self.invalidMsg = "no (2,2) phase before 0M"
return err.InvalidInterfields(self)
t1 = t0*(1.0/3.0)
X = np.arange(t0, t1, 0.1)
Y = IUS(*phase, k=5)(X)
sense = np.mean(np.diff(Y))
if sense < 0:
return err.ValidInterfield(self)
else:
return err.InvalidInterfield(self)
......@@ -71,6 +71,7 @@ templateOutput = """# Format 1
- [=] mass-ordering (mass1 >= mass2)
- [=] peak-near-zero (waveform peak is at 0.05M which is less than 10.00M from zero)
- [=] phase-sense ((2,2) phase is decreasing on average)
# Format 2
......@@ -1761,6 +1762,11 @@ class TestPhaselm(TestROMSpline):
("- [WRONG TYPE] {0:s} "
"(<class \'h5py._hl.dataset.Dataset\'>) "
"(Type must be <class \'h5py._hl.group.Group\'>)").format(name))
if name == 'phase_l2_m2':
self.setNamedOutput(
'phase-sense',
('- [INVALID FIELDS] phase-sense '
'(Field dependencies are invalid)'))
(output, returncode) = helper.lvcnrcheck(['-f', '3', self.f.name], returncode=True)
assert output.strip() == self.output
......@@ -1773,6 +1779,11 @@ class TestPhaselm(TestROMSpline):
"(<class \'h5py._hl.group.Group\'>) "
"(Field has subfields [invalid-1, invalid-2] "
"but should have [X, Y, deg, errors, tol])").format(name))
if name == 'phase_l2_m2':
self.setNamedOutput(
'phase-sense',
('- [INVALID FIELDS] phase-sense '
'(Field dependencies are invalid)'))
(output, returncode) = helper.lvcnrcheck(['-f', '3', self.f.name], returncode=True)
assert output.strip() == self.output
......@@ -1869,3 +1880,47 @@ class TestPeakNearZero(TestInterfield):
(output, returncode) = helper.lvcnrcheck(['-f', '3', self.f.name], returncode=True)
assert output.strip() == self.output
assert returncode == 1
class TestPhaseSense(TestInterfield):
name = 'phase-sense'
def test_invalid_phase_sense(self):
self.setOutput(
('- [INVALID INTERFIELD] phase-sense '
'((2,2) phase is not decreasing on average)'))
nr = h5.File(self.f.name)
nr['phase_l2_m2']['Y'][:] *= -1.0
nr.close()
(output, returncode) = helper.lvcnrcheck(['-f', '3', self.f.name], returncode=True)
assert output.strip() == self.output
assert returncode == 1
def test_invalid_phase_zero_inspiral(self):
self.setOutput(
('- [INVALID FIELDS] phase-sense '
'(Field dependencies are invalid)'))
nr = h5.File(self.f.name)
nr['phase_l2_m2']['X'][:] -= nr['phase_l2_m2']['X'][0]
nr.close()
(output, returncode) = helper.lvcnrcheck(['-f', '3', self.f.name], returncode=True)
assert output.strip() == self.output
assert returncode == 1
def test_invalid_phase_positive_inspiral(self):
self.setOutput(
('- [INVALID FIELDS] phase-sense '
'(Field dependencies are invalid)'))
nr = h5.File(self.f.name)
nr['phase_l2_m2']['X'][:] += 10.0 - nr['phase_l2_m2']['X'][0]
nr.close()
(output, returncode) = helper.lvcnrcheck(['-f', '3', self.f.name], returncode=True)
assert output.strip() == self.output
assert returncode == 1
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