From 26b88d04bcffd87ab980fe2e3031d61942b31341 Mon Sep 17 00:00:00 2001 From: jemian Date: Fri, 9 Dec 2016 19:09:34 -0600 Subject: [PATCH] reports if data file is NeXus or not --- src/punx/validate.py | 18 +++++++---- tests/common.py | 2 +- tests/validate_33id_spec_22_2D.txt | 5 +-- tests/validate_compression.txt | 49 +++++++++++++++--------------- tests/validate_example_mapping.txt | 5 +-- tests/validate_writer_1_3.txt | 5 +-- tests/validate_writer_2_1.txt | 5 +-- 7 files changed, 50 insertions(+), 39 deletions(-) diff --git a/src/punx/validate.py b/src/punx/validate.py index b3f58765..9cccf6c4 100644 --- a/src/punx/validate.py +++ b/src/punx/validate.py @@ -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): ''' @@ -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): ''' @@ -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 diff --git a/tests/common.py b/tests/common.py index c0f7cc4f..707089cc 100644 --- a/tests/common.py +++ b/tests/common.py @@ -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) diff --git a/tests/validate_33id_spec_22_2D.txt b/tests/validate_33id_spec_22_2D.txt index 27bc2e48..e3d6a193 100644 --- a/tests/validate_33id_spec_22_2D.txt +++ b/tests/validate_33id_spec_22_2D.txt @@ -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_]* @@ -807,7 +808,7 @@ 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 @@ -815,5 +816,5 @@ 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 -- ======= ===== =========================================================== diff --git a/tests/validate_compression.txt b/tests/validate_compression.txt index 98d177e6..4cb46ad1 100644 --- a/tests/validate_compression.txt +++ b/tests/validate_compression.txt @@ -1,25 +1,26 @@ -========================== ============================ ====== ==================================================== -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 @@ -27,10 +28,10 @@ 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 -- ======= ===== =========================================================== diff --git a/tests/validate_example_mapping.txt b/tests/validate_example_mapping.txt index 0ba41a75..fb80b63a 100644 --- a/tests/validate_example_mapping.txt +++ b/tests/validate_example_mapping.txt @@ -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) @@ -236,7 +237,7 @@ 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 @@ -244,5 +245,5 @@ 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 -- ======= ===== =========================================================== diff --git a/tests/validate_writer_1_3.txt b/tests/validate_writer_1_3.txt index e9436fd3..9c87eeb9 100644 --- a/tests/validate_writer_1_3.txt +++ b/tests/validate_writer_1_3.txt @@ -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) @@ -21,7 +22,7 @@ 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 @@ -29,5 +30,5 @@ 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 -- ======= ===== =========================================================== diff --git a/tests/validate_writer_2_1.txt b/tests/validate_writer_2_1.txt index e907f88a..6cf1e924 100644 --- a/tests/validate_writer_2_1.txt +++ b/tests/validate_writer_2_1.txt @@ -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) @@ -37,7 +38,7 @@ 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 @@ -45,5 +46,5 @@ 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 -- ======= ===== ===========================================================