Skip to content

Commit d0c7c16

Browse files
authored
Merge pull request silx-kit#336 from t20100/test-sperr
Added test of sperr v0.2 missing values
2 parents 23eb473 + 17c6ac0 commit d0c7c16

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed
File renamed without changes.

test/sperr_v0.2_missing_val.h5

6.49 KB
Binary file not shown.

test/test.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,37 @@ def testZfp(self):
145145

146146
@unittest.skipUnless(h5py.h5z.filter_avail(hdf5plugin.SPERR_ID),
147147
"Sperr filter not available")
148-
def testSperr(self):
149-
"""Test reading Sperr compressed data"""
148+
def testSperrV0_1(self):
149+
"""Test reading Sperr compressed data with v0.1 of the filter"""
150150
dirname = os.path.abspath(os.path.dirname(__file__))
151-
for fname in ["sperr.h5"]:
152-
fname = os.path.join(dirname, fname)
153-
self.assertTrue(os.path.exists(fname),
154-
"Cannot find %s file" % fname)
155-
with h5py.File(fname, "r") as h5:
156-
compressed = h5["f64_sperr"][()]
157-
original = h5["f64_original"][()]
158-
self.assertTrue(original.shape == compressed.shape,
159-
"Incorrect shape")
160-
self.assertTrue(original.dtype == compressed.dtype,
161-
"Incorrect dtype")
162-
self.assertTrue(numpy.allclose(original, compressed, atol=1e-3),
163-
"Values should be close")
151+
fname = os.path.join(dirname, "sperr_v0.1.h5")
152+
self.assertTrue(os.path.exists(fname),
153+
"Cannot find %s file" % fname)
154+
with h5py.File(fname, "r") as h5:
155+
compressed = h5["f64_sperr"][()]
156+
original = h5["f64_original"][()]
157+
self.assertTrue(original.shape == compressed.shape,
158+
"Incorrect shape")
159+
self.assertTrue(original.dtype == compressed.dtype,
160+
"Incorrect dtype")
161+
self.assertTrue(numpy.allclose(original, compressed, atol=1e-3),
162+
"Values should be close")
163+
164+
@unittest.skipUnless(h5py.h5z.filter_avail(hdf5plugin.SPERR_ID),
165+
"Sperr filter not available")
166+
def testSperrV0_2MissingValue(self):
167+
"""Test reading Sperr compressed data with NaN values"""
168+
dirname = os.path.abspath(os.path.dirname(__file__))
169+
fname = os.path.join(dirname, "sperr_v0.2_missing_val.h5")
170+
self.assertTrue(os.path.exists(fname),
171+
"Cannot find %s file" % fname)
172+
with h5py.File(fname, "r") as h5:
173+
compressed = h5["f64_sperr"][()]
174+
self.assertTrue(compressed.shape == (128, 64), "Incorrect shape")
175+
self.assertTrue(compressed.dtype == numpy.float64, "Incorrect dtype")
176+
self.assertTrue(numpy.isnan(compressed[0, 1]))
177+
self.assertTrue(numpy.isnan(compressed[0, 10]))
178+
self.assertTrue(numpy.isnan(compressed[1, 36]))
164179

165180
@unittest.skipUnless(h5py.h5z.filter_avail(hdf5plugin.SZ_ID),
166181
"SZ filter not available")

0 commit comments

Comments
 (0)