Skip to content

Commit

Permalink
reports if data file is NeXus or not
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Dec 10, 2016
1 parent 163c2cb commit 26b88d0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 39 deletions.
18 changes: 12 additions & 6 deletions src/punx/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ def validate(self):
start the validation process from the file root
'''
self.validate_HDF5_group(self.h5)
self.validate_default_plot()
t = self.validate_default_plot()
f = finding.TF_RESULT[t]
title = "valid NeXus data file"
msg = ''
self.new_finding(title, "/", f, msg)

def validate_HDF5_group(self, group):
'''
Expand Down Expand Up @@ -711,16 +715,17 @@ def validate_default_plot(self):
'''
candidates = self.identify_default_plot_candidates()
if self.default_plot_addr_v3(candidates['v3']) is not None:
return
return True
elif self.default_plot_addr_v2(candidates['v2']) is not None:
return
return True
elif self.default_plot_addr_v1(candidates['v1']) is not None:
return
return True
elif self.no_NXdata_children_of_NXentry(candidates['niac2016']):
return
return True

m = 'no default plot: not a NeXus file'
m = '/NXentry/NXdata but no default plot: not a NeXus file'
self.new_finding('NeXus default plot', '/NXentry/NXdata/field', finding.ERROR, m)
return False

def identify_default_plot_candidates(self):
'''
Expand Down Expand Up @@ -781,6 +786,7 @@ def identify_default_plot_candidates(self):
continue
if self.get_hdf5_attribute(ss_node, 'signal') is not None:
k = ss_node.name + '@signal'
# TODO: verify the value is a number (either as float, int, or str of some sort)
candidates['v2'][k] = '/NXentry/NXdata/field@signal'
candidates['v1'][k] = '/NXentry/NXdata/field@signal'
return candidates
Expand Down
2 changes: 1 addition & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_expected_output__line_by_line(self):
expected = str(self.expected_output[item]).rstrip()
if actual != expected:
_test = True # for debugging break point
msg = "validation different on line " + str(item) + ':'
msg = "validation different on line " + str(item+1) + ':'
msg += '\n expected: ' + str(expected)
msg += '\n reported: ' + str(actual)
self.assertEqual(expected, actual, msg)
Expand Down
5 changes: 3 additions & 2 deletions tests/validate_33id_spec_22_2D.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
address validation status comment(s)
======================================== ================================== ====== ================================================
/ @NX_class OK file root (assumed): NXroot
/ valid NeXus data file OK
/ NXDL review TODO validate with NXroot specification (incomplete)
/@HDF5_Version validItemName NOTE relaxed re: [A-Za-z_][\w_]*
/@SPEC_comments validItemName NOTE relaxed re: [A-Za-z_][\w_]*
Expand Down Expand Up @@ -807,13 +808,13 @@ address validation stat
======= ===== ===========================================================
status count description
======= ===== ===========================================================
OK 263 meets NeXus specification
OK 264 meets NeXus specification
NOTE 514 does not meet NeXus specification, but acceptable
WARN 0 does not meet NeXus specification, not generally acceptable
ERROR 0 violates NeXus specification
TODO 7 validation not implemented yet
UNUSED 17 optional NeXus item not used in data file
COMMENT 0 comment from the punx source code
-- -- --
TOTAL 801 --
TOTAL 802 --
======= ===== ===========================================================
49 changes: 25 additions & 24 deletions tests/validate_compression.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
========================== ============================ ====== ====================================================
address validation status comment(s)
========================== ============================ ====== ====================================================
/ @NX_class OK file root (assumed): NXroot
/ NXDL review TODO validate with NXroot specification (incomplete)
/NXentry/NXdata/field NeXus default plot ERROR no default plot: not a NeXus file
/SASentry validItemName NOTE relaxed re: [A-Za-z_][\w_]*
/SASentry NXDL review TODO validate with NXentry specification (incomplete)
/SASentry@NX_class attribute data type NOTE variable length string: ['NXentry']
/SASentry@NX_class @NX_class OK known: NXentry
/SASentry/SASdata validItemName NOTE relaxed re: [A-Za-z_][\w_]*
/SASentry/SASdata NXDL review TODO validate with NXdata specification (incomplete)
/SASentry/SASdata NXdata group default plot v1 WARN NXdata group does not define a default plot using v1
/SASentry/SASdata@NX_class attribute data type NOTE variable length string: ['NXdata']
/SASentry/SASdata@NX_class @NX_class OK known: NXdata
/SASentry/SASdata/I NXdata@ignoreExtraFields UNUSED field ignored per NXDL specification
/SASentry/SASdata/I@signal NXdata group default plot v1 ERROR expected @signal=1, found: I
/SASentry/SASdata/I@signal NeXus default plot v2 ERROR expected @signal=1, found: I
/SASentry/SASdata/I@signal attribute data type NOTE variable length string: ['I']
/SASentry/SASdata/Idev NXdata@ignoreExtraFields UNUSED field ignored per NXDL specification
/SASentry/SASdata/Q NXdata@ignoreExtraFields UNUSED field ignored per NXDL specification
========================== ============================ ====== ====================================================
========================== ============================ ====== =====================================================
address validation status comment(s)
========================== ============================ ====== =====================================================
/ valid NeXus data file ERROR
/ @NX_class OK file root (assumed): NXroot
/ NXDL review TODO validate with NXroot specification (incomplete)
/NXentry/NXdata/field NeXus default plot ERROR /NXentry/NXdata but no default plot: not a NeXus file
/SASentry validItemName NOTE relaxed re: [A-Za-z_][\w_]*
/SASentry NXDL review TODO validate with NXentry specification (incomplete)
/SASentry@NX_class attribute data type NOTE variable length string: ['NXentry']
/SASentry@NX_class @NX_class OK known: NXentry
/SASentry/SASdata validItemName NOTE relaxed re: [A-Za-z_][\w_]*
/SASentry/SASdata NXDL review TODO validate with NXdata specification (incomplete)
/SASentry/SASdata NXdata group default plot v1 WARN NXdata group does not define a default plot using v1
/SASentry/SASdata@NX_class attribute data type NOTE variable length string: ['NXdata']
/SASentry/SASdata@NX_class @NX_class OK known: NXdata
/SASentry/SASdata/I NXdata@ignoreExtraFields UNUSED field ignored per NXDL specification
/SASentry/SASdata/I@signal NXdata group default plot v1 ERROR expected @signal=1, found: I
/SASentry/SASdata/I@signal NeXus default plot v2 ERROR expected @signal=1, found: I
/SASentry/SASdata/I@signal attribute data type NOTE variable length string: ['I']
/SASentry/SASdata/Idev NXdata@ignoreExtraFields UNUSED field ignored per NXDL specification
/SASentry/SASdata/Q NXdata@ignoreExtraFields UNUSED field ignored per NXDL specification
========================== ============================ ====== =====================================================

======= ===== ===========================================================
status count description
======= ===== ===========================================================
OK 3 meets NeXus specification
NOTE 5 does not meet NeXus specification, but acceptable
WARN 1 does not meet NeXus specification, not generally acceptable
ERROR 3 violates NeXus specification
ERROR 4 violates NeXus specification
TODO 3 validation not implemented yet
UNUSED 3 optional NeXus item not used in data file
COMMENT 0 comment from the punx source code
-- -- --
TOTAL 18 --
TOTAL 19 --
======= ===== ===========================================================
5 changes: 3 additions & 2 deletions tests/validate_example_mapping.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
address validation status comment(s)
==================================================== =================================================== ====== =====================================================================================
/ @NX_class OK file root (assumed): NXroot
/ valid NeXus data file OK
/ NXDL review TODO validate with NXroot specification (incomplete)
/entry1 validItemName-strict OK strict re: [a-z_][a-z0-9_]*
/entry1 NXDL review TODO validate with NXentry specification (incomplete)
Expand Down Expand Up @@ -236,13 +237,13 @@ address validation
======= ===== ===========================================================
status count description
======= ===== ===========================================================
OK 149 meets NeXus specification
OK 150 meets NeXus specification
NOTE 55 does not meet NeXus specification, but acceptable
WARN 2 does not meet NeXus specification, not generally acceptable
ERROR 0 violates NeXus specification
TODO 16 validation not implemented yet
UNUSED 8 optional NeXus item not used in data file
COMMENT 0 comment from the punx source code
-- -- --
TOTAL 230 --
TOTAL 231 --
======= ===== ===========================================================
5 changes: 3 additions & 2 deletions tests/validate_writer_1_3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
address validation status comment(s)
============================ ============================= ====== ================================================
/ @NX_class OK file root (assumed): NXroot
/ valid NeXus data file OK
/ NXDL review TODO validate with NXroot specification (incomplete)
/Scan validItemName NOTE relaxed re: [A-Za-z_][\w_]*
/Scan NXDL review TODO validate with NXentry specification (incomplete)
Expand All @@ -21,13 +22,13 @@ address validation status comment(s)
======= ===== ===========================================================
status count description
======= ===== ===========================================================
OK 9 meets NeXus specification
OK 10 meets NeXus specification
NOTE 1 does not meet NeXus specification, but acceptable
WARN 0 does not meet NeXus specification, not generally acceptable
ERROR 0 violates NeXus specification
TODO 3 validation not implemented yet
UNUSED 2 optional NeXus item not used in data file
COMMENT 0 comment from the punx source code
-- -- --
TOTAL 15 --
TOTAL 16 --
======= ===== ===========================================================
5 changes: 3 additions & 2 deletions tests/validate_writer_2_1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
address validation status comment(s)
=========================================== ============================= ====== =====================================================
/ @NX_class OK file root (assumed): NXroot
/ valid NeXus data file OK
/ NXDL review TODO validate with NXroot specification (incomplete)
/entry validItemName-strict OK strict re: [a-z_][a-z0-9_]*
/entry NXDL review TODO validate with NXentry specification (incomplete)
Expand Down Expand Up @@ -37,13 +38,13 @@ address validation status
======= ===== ===========================================================
status count description
======= ===== ===========================================================
OK 26 meets NeXus specification
OK 27 meets NeXus specification
NOTE 0 does not meet NeXus specification, but acceptable
WARN 0 does not meet NeXus specification, not generally acceptable
ERROR 0 violates NeXus specification
TODO 5 validation not implemented yet
UNUSED 0 optional NeXus item not used in data file
COMMENT 0 comment from the punx source code
-- -- --
TOTAL 31 --
TOTAL 32 --
======= ===== ===========================================================

0 comments on commit 26b88d0

Please sign in to comment.