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

Add mass-vs-time ordering interfield spec + tests

parent 4d0cec6c
Pipeline #12468 passed with stage
in 57 seconds
......@@ -83,7 +83,8 @@ format2 = OrderedDict((
('LNhatz-vs-time', LNhatzVsTime),
('Omega-vs-time', OmegaVsTime)))
format2Interfield = OrderedDict(())
format2Interfield = OrderedDict((
('mass-vs-time-ordering', MassVsTimeOrdering),))
format3 = OrderedDict((
('remnant-mass-vs-time', RemnantMassVsTime),
......
......@@ -552,6 +552,29 @@ class OmegaVsTime(ROMSplineSpec):
name = 'Omega-vs-time'
class MassVsTimeOrdering(InterfieldSpec):
"""Specification for the ordering of fields `mass1/mass2-vs-time``"""
name = "mass-vs-time-ordering"
validMsg = "mass1-vs-time >= mass2-vs-time"
invalidMsg = "mass1-vs-time < mass2-vs-time"
def valid(self, sim):
mass1VsTimeValid = Mass1VsTime().valid(sim)
mass2VsTimeValid = Mass2VsTime().valid(sim)
if not isinstance(mass1VsTimeValid, err.Valid):
return err.InvalidInterfields(self)
if not isinstance(mass2VsTimeValid, err.Valid):
return err.InvalidInterfields(self)
mass1VsTime = sim['mass1-vs-time/Y'][0]
mass2VsTime = sim['mass2-vs-time/Y'][0]
if mass1VsTime >= mass2VsTime:
return err.ValidInterfield(self)
else:
return err.InvalidInterfield(self)
# Format 3
class RemnantMassVsTime(ROMSplineSpec):
"""Specification for the `remnant-mass-vs-time`` field"""
......
......@@ -94,6 +94,7 @@ templateOutput = """# Format 1
# Format 2 (Interfield)
- [=] mass-vs-time-ordering (mass1-vs-time >= mass2-vs-time)
# Format 3
......@@ -932,6 +933,10 @@ class TestMass1VsTime(TestROMSpline):
('- [WRONG TYPE] mass1-vs-time '
'(<class \'h5py._hl.dataset.Dataset\'>) '
'(Type must be <class \'h5py._hl.group.Group\'>)'))
self.setNamedOutput(
'mass-vs-time-ordering',
('- [INVALID FIELDS] mass-vs-time-ordering '
'(Field dependencies are invalid)'))
output = helper.lvcnrcheck(['-f', '3', self.f.name])
assert output.strip() == self.output
......@@ -943,6 +948,10 @@ class TestMass1VsTime(TestROMSpline):
'(<class \'h5py._hl.group.Group\'>) '
'(Field has subfields [invalid-1, invalid-2] '
'but should have [X, Y, deg, errors, tol])'))
self.setNamedOutput(
'mass-vs-time-ordering',
('- [INVALID FIELDS] mass-vs-time-ordering '
'(Field dependencies are invalid)'))
output = helper.lvcnrcheck(['-f', '3', self.f.name])
assert output.strip() == self.output
......@@ -958,6 +967,10 @@ class TestMass2VsTime(TestROMSpline):
('- [WRONG TYPE] mass2-vs-time '
'(<class \'h5py._hl.dataset.Dataset\'>) '
'(Type must be <class \'h5py._hl.group.Group\'>)'))
self.setNamedOutput(
'mass-vs-time-ordering',
('- [INVALID FIELDS] mass-vs-time-ordering '
'(Field dependencies are invalid)'))
output = helper.lvcnrcheck(['-f', '3', self.f.name])
assert output.strip() == self.output
......@@ -969,6 +982,10 @@ class TestMass2VsTime(TestROMSpline):
'(<class \'h5py._hl.group.Group\'>) '
'(Field has subfields [invalid-1, invalid-2] '
'but should have [X, Y, deg, errors, tol])'))
self.setNamedOutput(
'mass-vs-time-ordering',
('- [INVALID FIELDS] mass-vs-time-ordering '
'(Field dependencies are invalid)'))
output = helper.lvcnrcheck(['-f', '3', self.f.name])
assert output.strip() == self.output
......@@ -1390,6 +1407,21 @@ class TestOmegaVsTime(TestROMSpline):
assert output.strip() == self.output
class TestMassVsTimeOrdering(TestInterfield):
name = 'mass-vs-time-ordering'
def test_invalid_ordering(self):
self.setOutput(
('- [INVALID INTERFIELD] mass-vs-time-ordering '
'(mass1-vs-time < mass2-vs-time)'))
self.setNamedDataset('mass1-vs-time/Y', np.array([1.0]*10))
self.setNamedDataset('mass2-vs-time/Y', np.array([4.0]*10))
output = helper.lvcnrcheck(['-f', '3', self.f.name])
assert output.strip() == self.output
class TestRemnantMassVsTime(TestROMSpline):
name = 'remnant-mass-vs-time'
......
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