Skip to content
Snippets Groups Projects
Commit 6e235270 authored by Sebastian Khan's avatar Sebastian Khan
Browse files

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

Mass ordering check omega check

See merge request !9
parents 646c65e6 269de7aa
Branches mass-ordering-check
No related tags found
2 merge requests!9Mass ordering check omega check,!8Mass ordering check
Pipeline #
...@@ -120,3 +120,12 @@ class InvalidInterfields(Error): ...@@ -120,3 +120,12 @@ class InvalidInterfields(Error):
"""Interfield check failed because the field dependencies are invalid""" """Interfield check failed because the field dependencies are invalid"""
name = "INVALID FIELDS" name = "INVALID FIELDS"
msg = "(Field dependencies are invalid)" 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): ...@@ -174,7 +174,7 @@ class InterfieldSpec(Spec):
"""Specification for relationship between mutliple fields""" """Specification for relationship between mutliple fields"""
dtype = basestring dtype = basestring
validMsg = "(Relationship betwen fields is valid)" validMsg = "(Relationship betwen fields is valid)"
invalidMsg = "(Relationship betwen fields is valid)" invalidMsg = "(Relationship betwen fields is invalid)"
def valid(self, sim): def valid(self, sim):
return err.ValidInterfield(self) return err.ValidInterfield(self)
...@@ -215,6 +215,24 @@ def isclose(a, b, rel_tol=1e-09, abs_tol=0.0): ...@@ -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) 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 # General Fields
class Type(Spec): class Type(Spec):
...@@ -583,6 +601,18 @@ class LNhatzVsTime(ROMSplineSpec): ...@@ -583,6 +601,18 @@ class LNhatzVsTime(ROMSplineSpec):
class OmegaVsTime(ROMSplineSpec): class OmegaVsTime(ROMSplineSpec):
"""Specification for the `Omega-vs-time` field""" """Specification for the `Omega-vs-time` field"""
name = 'Omega-vs-time' 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): class MassVsTimeOrdering(InterfieldSpec):
......
...@@ -1491,6 +1491,16 @@ class TestOmegaVsTime(TestROMSpline): ...@@ -1491,6 +1491,16 @@ class TestOmegaVsTime(TestROMSpline):
assert output.strip() == self.output assert output.strip() == self.output
assert returncode == 1 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): class TestMassVsTimeOrdering(TestInterfield):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment