Commit 9facf6fd authored by Sebastian Khan's avatar Sebastian Khan
Browse files

add Omega monotonicity test

fix inheritance
parent 646c65e6
Pipeline #12661 failed with stage
in 1 minute and 2 seconds
......@@ -84,7 +84,8 @@ format2 = OrderedDict((
('Omega-vs-time', OmegaVsTime)))
format2Interfield = OrderedDict((
('mass-vs-time-ordering', MassVsTimeOrdering),))
('mass-vs-time-ordering', MassVsTimeOrdering),
('Omega-vs-time-monotonicity', OmegaVsTimeMonotonicity),))
format3 = OrderedDict((
('remnant-mass-vs-time', RemnantMassVsTime),
......
......@@ -174,7 +174,7 @@ class InterfieldSpec(Spec):
"""Specification for relationship between mutliple fields"""
dtype = basestring
validMsg = "(Relationship betwen fields is valid)"
invalidMsg = "(Relationship betwen fields is valid)"
invalidMsg = "(Relationship betwen fields is invalid)"
def valid(self, sim):
return err.ValidInterfield(self)
......@@ -215,6 +215,24 @@ def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):
"""
return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
def ismonotonic(x):
"""A Function for testing is a list/array is monotonic
**References**
- https://stackoverflow.com/questions/4983258/python-how-to-check-list-monotonicity
Parameters
----------
a: list or numpy array of values to test.
Returns
-------
isclose: bool
Return True if the list x is monotonic and False otherwise.
"""
dx = np.diff(x)
return np.all(dx <= 0) or np.all(dx >= 0)
# General Fields
class Type(Spec):
......@@ -584,6 +602,23 @@ class OmegaVsTime(ROMSplineSpec):
"""Specification for the `Omega-vs-time` field"""
name = 'Omega-vs-time'
class OmegaVsTimeMonotonicity(InterfieldSpec):
"""Specification for the `Omega-vs-time` field"""
name = 'Omega-vs-time Monotonicity'
validMsg = "Omega pass monotonicity test"
invalidMsg = "Omega is not monotonic: Suggest downgrading to Format=1"
def valid(self, sim):
OmegaVsTimeValid = OmegaVsTime().valid(sim)
if not isinstance(OmegaVsTimeValid, err.Valid):
return err.InvalidInterfields(self)
Omegas = sim['Omega-vs-time/Y'][:]
if ismonotonic(Omegas):
return err.ValidInterfield(self)
else:
return err.InvalidInterfield(self)
class MassVsTimeOrdering(InterfieldSpec):
"""Specification for the ordering of fields `mass1/mass2-vs-time``"""
......
......@@ -1492,6 +1492,20 @@ class TestOmegaVsTime(TestROMSpline):
assert returncode == 1
class TestOmegaVsTimeMonotonicity(TestInterfield):
name = 'omega-vs-time-monotonicity'
def test_invalid_ordering(self):
self.setOutput(
('- [INVALID INTERFIELD] omega-vs-time-monotonicity '
'(Omega is not monotonic: Suggest downgrading to Format=1)'))
self.setNamedDataset('Omega-vs-time/Y', np.array([1,2,4,3]))
(output, returncode) = helper.lvcnrcheck(['-f', '3', self.f.name], returncode=True)
assert output.strip() == self.output
assert returncode == 1
class TestMassVsTimeOrdering(TestInterfield):
name = 'mass-vs-time-ordering'
......
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