|
1 | 1 | # coding: utf-8 |
2 | 2 | # /*########################################################################## |
3 | 3 | # |
4 | | -# Copyright (c) 2019-2022 European Synchrotron Radiation Facility |
| 4 | +# Copyright (c) 2019-2023 European Synchrotron Radiation Facility |
5 | 5 | # |
6 | 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | 7 | # of this software and associated documentation files (the "Software"), to deal |
@@ -429,9 +429,38 @@ def testSelection(self): |
429 | 429 | self.assertEqual(hdf5plugin.get_filters(filters), ref) |
430 | 430 |
|
431 | 431 |
|
| 432 | +class TestSZ(unittest.TestCase): |
| 433 | + """Specific tests for SZ compression""" |
| 434 | + |
| 435 | + def testAbsoluteMode(self): |
| 436 | + """Test SZ's absolute mode is within required tolerance |
| 437 | +
|
| 438 | + See https://github.com/silx-kit/hdf5plugin/issues/267 |
| 439 | + """ |
| 440 | + tolerance = 0.01 |
| 441 | + |
| 442 | + numpy.random.seed(0) |
| 443 | + data = numpy.random.random(size=(1000, 25, 25)).astype(numpy.float32) |
| 444 | + |
| 445 | + compression = hdf5plugin.SZ(absolute=tolerance) |
| 446 | + |
| 447 | + with tempfile.TemporaryDirectory() as tempdir: |
| 448 | + filename = os.path.join(tempdir, "testsz.h5") |
| 449 | + with h5py.File(filename, 'w', driver="core", backing_store=False) as f: |
| 450 | + f.create_dataset('var', data=data, chunks=data.shape, **compression) |
| 451 | + f.flush() |
| 452 | + |
| 453 | + recovered_data = f["var"][:] |
| 454 | + |
| 455 | + self.assertTrue( |
| 456 | + numpy.allclose(data, recovered_data, atol=tolerance), |
| 457 | + f"Condition not fulfilled for {tolerance} -> {numpy.max(numpy.abs(recovered_data - data))}" |
| 458 | + ) |
| 459 | + |
| 460 | + |
432 | 461 | def suite(): |
433 | 462 | test_suite = unittest.TestSuite() |
434 | | - for cls in (TestHDF5PluginRW, TestPackage, TestRegisterFilter, TestGetFilters): |
| 463 | + for cls in (TestHDF5PluginRW, TestPackage, TestRegisterFilter, TestGetFilters, TestSZ): |
435 | 464 | test_suite.addTest(unittest.TestLoader().loadTestsFromTestCase(cls)) |
436 | 465 | return test_suite |
437 | 466 |
|
|
0 commit comments