示例#1
0
        public void CanDefilterBZip2()
        {
            // # Works only with Linux! On Windows, deflate is used instead.
            // import numpy
            // import tables


            // fileName = 'bzip2.h5'
            // shape = (1000,)
            // atom = tables.Int32Atom()
            // filters = tables.Filters(complevel=9, complib='bzip2')

            // with tables.open_file(fileName, 'w') as f:
            //     dataset = f.create_carray(f.root, 'bzip2', atom, shape, filters=filters)
            //     dataset[:] = list(range(0, 1000))

            // Arrange
            var filePath = "./testfiles/bzip2.h5";
            var expected = Enumerable.Range(0, 1000).ToArray();

            H5Filter.Register(identifier: (H5FilterID)307, name: "bzip2", filterFunc: BZip2Helper.FilterFunc);

            // Act
            using var root = H5File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            var dataset = root.Dataset("bzip2");
            var actual  = dataset.Read <int>();

            // Assert
            Assert.True(actual.SequenceEqual(expected));
        }
示例#2
0
        public void CanDefilterBlosc2(string datasetName, bool shouldSuccess)
        {
            // import h5py
            // import hdf5plugin

            // def blosc_opts(complevel=9, complib='blosc:lz4', shuffle=True):
            //     shuffle = 2 if shuffle == 'bit' else 1 if shuffle else 0
            //     compressors = ['blosclz', 'lz4', 'lz4hc', 'snappy', 'zlib', 'zstd']
            //     complib = ['blosc:' + c for c in compressors].index(complib)
            //     args = {
            //         'compression': 32001,
            //         'compression_opts': (0, 0, 0, 0, complevel, shuffle, complib)
            //     }
            //     if shuffle:
            //         args['shuffle'] = False
            //     return args

            // with h5py.File('blosc.h5', 'w') as f:
            //     f.create_dataset('blosclz', data=list(range(0, 1000)), **blosc_opts(9, 'blosc:blosclz', True))
            //     f.create_dataset('lz4', data=list(range(0, 1000)), **blosc_opts(9, 'blosc:lz4', True))
            //     f.create_dataset('lz4hc', data=list(range(0, 1000)), **blosc_opts(9, 'blosc:lz4hc', True))
            //     f.create_dataset('snappy', data=list(range(0, 1000)), **blosc_opts(9, 'blosc:snappy', True))
            //     f.create_dataset('zlib', data=list(range(0, 1000)), **blosc_opts(9, 'blosc:zlib', True))
            //     f.create_dataset('zstd', data=list(range(0, 1000)), **blosc_opts(9, 'blosc:zstd', True))
            //     f.create_dataset('blosclz_bit', data=list(range(0, 1000)), **blosc_opts(9, 'blosc:blosclz', 'bit'))

            // Arrange
            var filePath = "./testfiles/blosc.h5";
            var expected = Enumerable.Range(0, 1000).ToArray();

            H5Filter.Register(identifier: (FilterIdentifier)32001, name: "blosc2", filterFunc: BloscHelper.FilterFunc);

            // Act
            using var root = H5File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            var dataset = root.Dataset(datasetName);

            if (shouldSuccess)
            {
                var actual = dataset.Read <int>();

                // Assert
                Assert.True(actual.SequenceEqual(expected));
            }
            else
            {
                var exception = Assert.Throws <Exception>(() => dataset.Read <int>());

                // Assert
                Assert.Contains("snappy", exception.InnerException.Message);
            }
        }
示例#3
0
        public void CanDefilterBlosc2(string datasetName, bool shouldSucceed)
        {
            // # https://github.com/silx-kit/hdf5plugin
            // import h5py
            // import hdf5plugin
            //
            // data = list(range(0, 1000))
            //
            // with h5py.File('blosc.h5', 'w') as f:
            //     f.create_dataset('blosclz',      data=data, **hdf5plugin.Blosc(cname='blosclz', clevel=9, shuffle=hdf5plugin.Blosc.SHUFFLE))
            //     f.create_dataset('lz4',          data=data, **hdf5plugin.Blosc(cname='lz4', clevel=9, shuffle=hdf5plugin.Blosc.SHUFFLE))
            //     f.create_dataset('lz4hc',        data=data, **hdf5plugin.Blosc(cname='lz4hc', clevel=9, shuffle=hdf5plugin.Blosc.SHUFFLE))
            //     f.create_dataset('snappy',       data=data, **hdf5plugin.Blosc(cname='snappy', clevel=9, shuffle=hdf5plugin.Blosc.SHUFFLE))
            //     f.create_dataset('zlib',         data=data, **hdf5plugin.Blosc(cname='zlib', clevel=9, shuffle=hdf5plugin.Blosc.SHUFFLE))
            //     f.create_dataset('zstd',         data=data, **hdf5plugin.Blosc(cname='zstd', clevel=9, shuffle=hdf5plugin.Blosc.SHUFFLE))
            //     f.create_dataset('blosclz_bit',  data=data, **hdf5plugin.Blosc(cname='zlib', clevel=9, shuffle=hdf5plugin.Blosc.BITSHUFFLE))

            // Arrange
            var filePath = "./testfiles/blosc.h5";
            var expected = Enumerable.Range(0, 1000).ToArray();

            H5Filter.Register(identifier: (H5FilterID)32001, name: "blosc2", filterFunc: BloscHelper.FilterFunc);

            // Act
            using var root = H5File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            var dataset = root.Dataset(datasetName);

            if (shouldSucceed)
            {
                var actual = dataset.Read <int>();

                // Assert
                Assert.True(actual.SequenceEqual(expected));
            }
            else
            {
                var exception = Assert.Throws <Exception>(() => dataset.Read <int>());

                // Assert
                Assert.Contains("snappy", exception.InnerException.Message);
            }
        }