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

Add interfield logic to lvcnrcheck

parent d38d6ac6
......@@ -20,7 +20,7 @@ import numpy as np
from lvcnrpy.Sim import Sim
from colorama import Fore, Back, Style
import h5py as h5
from lvcnrpy.format.format import format1, format2, format3
from lvcnrpy.format.format import format1, format1Interfield, format2, format3
import lvcnrpy.format.specs as specs
import lvcnrpy.format.errors as err
import sys
......@@ -44,14 +44,19 @@ args = parser.parse_args()
# Define output syntax for a single field report
FIELD = u'- [{0:s}{{0:s}}{1:s}] {{1:s}} ({{2:}}) {{3:}}'
INTERFIELD = u'- [{0:s}{{0:s}}{1:s}] {{1:s}} {{2:}}'
if args.col:
# Define possible field output templates
FIELD_VALID = FIELD.format(Fore.GREEN, Style.RESET_ALL)
FIELD_INVALID = FIELD.format(Fore.RED, Style.RESET_ALL)
INTERFIELD_VALID = INTERFIELD.format(Fore.GREEN, Style.RESET_ALL)
INTERFIELD_INVALID = INTERFIELD.format(Fore.RED, Style.RESET_ALL)
else:
# Define possible field output templates without color
FIELD_VALID = FIELD.format('', '')
FIELD_INVALID = FIELD.format('', '')
INTERFIELD_VALID = INTERFIELD.format('', '')
INTERFIELD_INVALID = INTERFIELD.format('', '')
def checkField(sim, field):
......@@ -81,6 +86,22 @@ def checkField(sim, field):
print FIELD_INVALID.format(valid.name, field.name, value, msg).strip()
return 1
def checkInterfield(sim, interfield):
# Check validity of interfield against specification class `interfield`
valid = interfield.valid(sim)
# Condition on its type of validity
if isinstance(valid, err.Valid):
print INTERFIELD_VALID.format(
valid.name, interfield.name, valid.msg).strip()
return 0
else:
print INTERFIELD_INVALID.format(
valid.name, interfield.name, valid.msg).strip()
return 1
if __name__ == '__main__':
# Initialise checkInt. checkInt = 0 for pass and >0 for fail.
......@@ -99,6 +120,14 @@ if __name__ == '__main__':
print('')
# Format 1 interfield checks
print('# Format 1 (Interfield)\n')
for interfieldKey, interfield in format1Interfield.items():
checkInt += checkInterfield(sim, interfield())
print('')
# Determine format level to check
fmt = args.format or sim.att('Format') or 1
......
......@@ -60,6 +60,8 @@ format1 = OrderedDict((
("eccentricity", Eccentricity),
("mean_anomaly", MeanAnomaly))))))
format1Interfield = OrderedDict(())
format2 = OrderedDict((
('mass1-vs-time', Mass1VsTime),
('mass2-vs-time', Mass2VsTime),
......
......@@ -67,6 +67,9 @@ templateOutput = """# Format 1
- [=] eccentricity (1.0)
- [=] mean_anomaly (1.0)
# Format 1 (Interfield)
# Format 2
- [=] mass1-vs-time (<class 'h5py._hl.group.Group'>)
......
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