Skip to main content

Compression for photon-noise limited images which keeps losses within the Poisson noise envelope

Project description

PYMECompress

testing conda pypi pyversions

Compression for photon-noise limited images which keeps losses within the Poisson noise envelope

PYMECompress consists of four parts:

  • a fork of the Basic Compression Library originally by Marcus Geelnard, modified to include a heavily optimized huffman coder (BCL license is avalable under pymecompress/bcl/doc/manual.pdf and would appear to be BSD compatible)

  • a fast, AVX optimized, quantizer to perform "within noise level" quantization of photon-limited images

  • a python wrapper of the above. Note that at this point, only huffman coding and quantization are exposed to python

  • numcodecs codecs (experimental) to permit simple usage with other IO packages - e.g. Zarr

Together they offer a single core throughput of ~500 -600MB/s

Installation

conda

Prebuilt binaries of PYMEcompress are available as a conda package (pymecompress) on the david_baddeley conda channel for python 2.7, 3.6 & 3.7, and installable via:

conda install -c david_baddeley pymecompress

source

If you want to modify/contribute to the package you will have to build from source.

Because we use gcc compiler extensions for avx opcodes, we must use gcc/clang for compilation, regardless of platform.

On OSX / linux, a standard python setup.py install or python setup.py develop should work.

On Windows, you need to install mingw and run the build step first so that you can pass the compiler flag to python setup.py build - i.e. :

python setup.py build --compiler=mingw32
python setup.py install

A suitable environment for building pymecompress can be created using the following conda command conda create -n <name> python=x.x numpy cython libpython m2w64-toolchain

pip

Installation via pip is also available:

pip install pymecompress

although binary wheels are not available for all platforms so you may need to set up a build environment (gcc/mingw, as described for source installation) first.

Usage

numcodecs codecs

import numpy as np
from pymecompress import codecs

# vanilla huffman coding (lossless). NB - input buffer must be bytes/uint8
huff = codecs.Huffman()
d = np.ones(1000)
assert np.allclose(huff.decode(huff.encode(d.view('uint8'))).view(d.dtype), d)


# with quantisation NB: input data type MUST be uint16
huffq = codecs.HuffmanQuant16(offset=0, scale=1.0)
ds = np.linspace(1,2**15).astype('uint16')

assert np.all((huffq.decode(huffq.encode(ds)) - ds.astype('f')) < np.sqrt(ds))

As a Zarr compression filter

VERY EXPERIMENTAL!

This is not yet well tested, but should work as described in https://zarr.readthedocs.io/en/stable/api/codecs.html. In brief ...

import zarr
from pymecompress import codecs
z = zarr.zeros(1000000, dtype='uint16', compressor=codecs.HuffmanQuant16(offset=0, scale=1))

NB To be able to read/open files saved using the pymecompress codecs you will probably need to run from pymecompress import codecs to register the codecs with numcodecs before trying to open the file.

Directly calling functions

As you need to supply the original size to the decompression function, these are most suitable when putting the compressed data in an external wrapper e.g. PYMEs' PZFFormat which keeps track of the original data dimensions and dtype (we save a couple of bytes and a seek over using the codec versions above).

import numpy as np
import pymecompress

data = np.linspace(1,2**15).astype('uint16')

nbytes = data.nbytes
c = pymecompress.HuffmanCompressQuant(data, quantizationOffset, quantizationScale).to_string()
decompressed = pymecompress.HuffmanDecompress(np.fromstring(c, 'u1'), nbytes)
dequantized = (quantisationScale*decompressed)**2 + quantizationOffset

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymecompress-0.3.6.tar.gz (156.8 kB view details)

Uploaded Source

Built Distributions

pymecompress-0.3.6-cp311-cp311-macosx_12_0_x86_64.whl (93.1 kB view details)

Uploaded CPython 3.11 macOS 12.0+ x86-64

pymecompress-0.3.6-cp39-cp39-win_amd64.whl (399.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

pymecompress-0.3.6-cp38-cp38-win_amd64.whl (414.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

pymecompress-0.3.6-cp37-cp37m-win_amd64.whl (349.0 kB view details)

Uploaded CPython 3.7m Windows x86-64

File details

Details for the file pymecompress-0.3.6.tar.gz.

File metadata

  • Download URL: pymecompress-0.3.6.tar.gz
  • Upload date:
  • Size: 156.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pymecompress-0.3.6.tar.gz
Algorithm Hash digest
SHA256 cc13a7ed0b19edf3367ab2de5ef7fb3b28791c91fae7409d8a5fe70ae7596de7
MD5 0be66682fb138fe7f94c570230b3f715
BLAKE2b-256 af4f943f13b22fbd392dc5fd2052ca45d99ddbe2662823dd0e6456b5322f7331

See more details on using hashes here.

File details

Details for the file pymecompress-0.3.6-cp311-cp311-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp311-cp311-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 9522737bb04f7ff00e946eb22b65d34fe0c86061949d92d79668df82517a30ce
MD5 68a5d86128f48aa504a8dbfff86720f2
BLAKE2b-256 1d12d44f4e54e8660025cac12e83811a3f52cd9bc605f4ccdf88f038536d8bd9

See more details on using hashes here.

File details

Details for the file pymecompress-0.3.6-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3057288db6dea9c2c543fe03aa9462ac55c3934179bf26fd99a8bc9a6312e554
MD5 8ae947e1eaf0e09a26f647462705feb0
BLAKE2b-256 2909f2991948bd1568569f3cd3f73fdd46aaea03dfb630c818da6dc02a6744c2

See more details on using hashes here.

File details

Details for the file pymecompress-0.3.6-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 fd1f2a117e5826ab8056b9c804c7d3d0978646e008ec5ca59090f61e1b4726ec
MD5 c07f8450440f932ed27703dabc617d42
BLAKE2b-256 cdb12515aed765238db841e9e135480dbf5adce27c35dabcce1548a79634580f

See more details on using hashes here.

File details

Details for the file pymecompress-0.3.6-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pymecompress-0.3.6-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 349.0 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.11.3 pkginfo/1.8.3 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.7.16

File hashes

Hashes for pymecompress-0.3.6-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 f22505e38c46ef51c18094a128452bd8bb2ccdebc687c7b9ce90345cee4889ba
MD5 ff36b09ada952e4a49dc10c55774e5a4
BLAKE2b-256 fa496a0a58bf13fa237d148b36e96b66953e6ba03144ae5acb83979646a081ae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page