Commit 6e235270 authored by Sebastian Khan's avatar Sebastian Khan

Merge branch 'mass-ordering-check-Omega-check' into 'mass-ordering-check'

Mass ordering check omega check

See merge request !9
parents 646c65e6 269de7aa
Pipeline #12678 passed with stage
in 1 minute and 3 seconds
......@@ -120,3 +120,12 @@ class InvalidInterfields(Error):
"""Interfield check failed because the field dependencies are invalid"""
name = "INVALID FIELDS"
msg = "(Field dependencies are invalid)"
class InvalidSequence(Error):
"""Defined sequence is not valid"""
name = "INVALID SEQUENCE"
msg = "({0:s})"
def __init__(self, spec):
self.msg = self.msg.format(spec.invalidMsg)
......@@ -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):
......@@ -583,6 +601,18 @@ class LNhatzVsTime(ROMSplineSpec):
class OmegaVsTime(ROMSplineSpec):
"""Specification for the `Omega-vs-time` field"""
name = 'Omega-vs-time'
invalidMsg = "Omega is not monotonic: Suggest downgrading to Format=1"
def valid(self, sim):
romSplineValid = super(OmegaVsTime, self).valid(sim)
if not isinstance(romSplineValid, err.Valid):
return romSplineValid
Omegas = sim['Omega-vs-time/Y'][:]
if ismonotonic(Omegas):
return romSplineValid
else:
return err.InvalidSequence(self)
class MassVsTimeOrdering(InterfieldSpec):
......
......@@ -1491,6 +1491,16 @@ class TestOmegaVsTime(TestROMSpline):
assert output.strip() == self.output
assert returncode == 1
def test_invalid_monotonicity(self):
self.setOutput(
('- [INVALID SEQUENCE] Omega-vs-time '
'(<class \'h5py._hl.group.Group\'>) '
'(Omega is not monotonic: Suggest downgrading to Format=1)'))
self.setNamedDataset('Omega-vs-time/Y', np.array([0,1,2,4,3,5,6,7,8,9]))
(output, returncode) = helper.lvcnrcheck(['-f', '3', self.f.name], returncode=True)
assert output.strip() == self.output
assert returncode == 1
class TestMassVsTimeOrdering(TestInterfield):
......
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