Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
waveforms
lvcnrpy
Commits
6e235270
Commit
6e235270
authored
Feb 14, 2018
by
Sebastian Khan
Browse files
Options
Browse Files
Download
Plain Diff
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
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
1 deletion
+50
-1
lvcnrpy/format/errors.py
lvcnrpy/format/errors.py
+9
-0
lvcnrpy/format/specs.py
lvcnrpy/format/specs.py
+31
-1
lvcnrpy/test/test_lvcnrcheck.py
lvcnrpy/test/test_lvcnrcheck.py
+10
-0
No files found.
lvcnrpy/format/errors.py
View file @
6e235270
...
...
@@ -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
)
lvcnrpy/format/specs.py
View file @
6e235270
...
...
@@ -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
in
valid)"
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
):
...
...
lvcnrpy/test/test_lvcnrcheck.py
View file @
6e235270
...
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment