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

If you're not sure about the file name format, learn more about wheel file names.

pymecompress-0.3.6-cp313-cp313-win_amd64.whl (129.3 kB view details)

Uploaded CPython 3.13Windows x86-64

pymecompress-0.3.6-cp313-cp313-macosx_15_0_x86_64.whl (84.1 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

pymecompress-0.3.6-cp313-cp313-macosx_15_0_arm64.whl (77.7 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

pymecompress-0.3.6-cp312-cp312-win_amd64.whl (129.4 kB view details)

Uploaded CPython 3.12Windows x86-64

pymecompress-0.3.6-cp312-cp312-macosx_15_0_x86_64.whl (84.8 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

pymecompress-0.3.6-cp312-cp312-macosx_15_0_arm64.whl (78.4 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

pymecompress-0.3.6-cp311-cp311-win_amd64.whl (131.9 kB view details)

Uploaded CPython 3.11Windows x86-64

pymecompress-0.3.6-cp311-cp311-macosx_15_0_x86_64.whl (83.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

pymecompress-0.3.6-cp311-cp311-macosx_15_0_arm64.whl (77.5 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

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

Uploaded CPython 3.11macOS 12.0+ x86-64

pymecompress-0.3.6-cp310-cp310-win_amd64.whl (131.0 kB view details)

Uploaded CPython 3.10Windows x86-64

pymecompress-0.3.6-cp310-cp310-macosx_15_0_x86_64.whl (83.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

pymecompress-0.3.6-cp310-cp310-macosx_15_0_arm64.whl (77.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

pymecompress-0.3.6-cp39-cp39-macosx_15_0_x86_64.whl (84.3 kB view details)

Uploaded CPython 3.9macOS 15.0+ x86-64

pymecompress-0.3.6-cp39-cp39-macosx_15_0_arm64.whl (78.2 kB view details)

Uploaded CPython 3.9macOS 15.0+ ARM64

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.7mWindows 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-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1ee65f55c00015b8b8c9f7f2adf695ccc1de097b78c8823e3efb41abfd233a78
MD5 5b8a9aeeb4b9c5e2cc52238d77f20487
BLAKE2b-256 86d6f12ec986d5ecd24fc1df1c1fab6919acbf9df4a68578a5739da863402154

See more details on using hashes here.

File details

Details for the file pymecompress-0.3.6-cp313-cp313-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0653e05c28303c916dcc9029f7c331c550a7c941849f1dce9efd76f5e708f30a
MD5 56e5ea09f0b3edd53a7f7b4c771a7aa0
BLAKE2b-256 e0c0f8c13aa51583cda52389a98c76f2c15c969c616da65be572849b122f26d1

See more details on using hashes here.

File details

Details for the file pymecompress-0.3.6-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 549bdeccb7ac1fb81c7b6bf12bcb8bca501894624d3e85f62ee092d129fa0db4
MD5 3600dd6d840a44c52c312cdf4b1aa246
BLAKE2b-256 2f1d3bf85164c7406980a1d421032e5a550309c3c4fa567df0a07cf1d1236f9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 38f5fb9edd68dcb29a9d172ccc058da61a85edef9799e0a866de8a288c63fd30
MD5 7f91e23968b8da7e2bfa7913fa1d288b
BLAKE2b-256 3a782ac29001fa44b181d2f97d6ee45c509eea00d2da268001fe91765ee7676a

See more details on using hashes here.

File details

Details for the file pymecompress-0.3.6-cp312-cp312-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 41430468df4639a42a860351ca5b2872c6e17798633decd84f37748f440b29af
MD5 f98f6f5ff9a0703b8694fc2103f2d7be
BLAKE2b-256 1c2d740b777218118243dd5beef4cf99feb9d9681287c19de6a0e875fcd008e3

See more details on using hashes here.

File details

Details for the file pymecompress-0.3.6-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 ef54ff0aff96017d2a5d401e3d04f4e0c15fd3e0f86918f756dd39662b464c0e
MD5 5462ce13a9b0afb6c61cc0d231dc1510
BLAKE2b-256 0a54a05d14f5d6390df4bcb5c32b7eddcc0a63184257e2f842902c1a234a8445

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 dd9186462b2c9d0b56715d395054c4a09a1e8d13a2e9214f90a0cd5dbd6749c2
MD5 697e2baca18ee83df914218759495c29
BLAKE2b-256 d53960624b03543340e59cf3efb8628d65bd46180dd05374ccb6a2b8ec93e8a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 de9e22f000768dc414682c10436471fc8dcfc3580e9dfdb16d4b77e8fa4bd214
MD5 3f7000b7f7239d5e1297a03dc58db2f1
BLAKE2b-256 3c88d0753f78cf56a5a8514fd1e0285bbaeb9ff3b44acaf00845325f072900e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 4df4757a06929b95c6b3b1ec260315a9ceb33e450ba88f460cfe2be8aa158969
MD5 d4bc7174818a2ec2d0220aca608a00ed
BLAKE2b-256 20d35ba5c4dd9597b34295691d6efcffde0eabfe62d49ae24c03664b5ab7cd2e

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-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 aaa9976473ba9687b0a8057192060973688e3e9edcabb492674d3ac9f20a4677
MD5 3f881ff1b25908aa1c89e85e09bfc929
BLAKE2b-256 68313190dbea0fdd6b617f4484d20acc00f254d04c80c9f8119fb96c99f5e2a4

See more details on using hashes here.

File details

Details for the file pymecompress-0.3.6-cp310-cp310-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 9f7003d6a449d3fb8d769462ea0d94f61527854d48e59830bbc25e7817c05a70
MD5 648c669736fc384f45be969cbf96ac67
BLAKE2b-256 d74442e2f4093af08f86a18bdf8febfe741c1afd9703314af89b4b8224ab0f17

See more details on using hashes here.

File details

Details for the file pymecompress-0.3.6-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 d06a69d64a4d534b6124f73f9eb212b6702bbd9e1a73e3bc44db10c0f88dc429
MD5 c3d36fdde10786004cc9d76509846d35
BLAKE2b-256 004a9e497ab586c7f46be4c51d1905fe9a297d4ad420a77001815777055a594a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pymecompress-0.3.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 399.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

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-cp39-cp39-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp39-cp39-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 513251461ea5bfc42061cc270da31e63cfd99f471d25c4923450b8b0a85e8d5e
MD5 da306c50500e883691176fc2f6ddfadb
BLAKE2b-256 45cab5b2184fc07f9ce72c557e79d00c172a91a2670dc003430f990fd164c63e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymecompress-0.3.6-cp39-cp39-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 bd9a2917761ffbd6ccb0edebca8ca46c95aa78de811325245c0e8bd8b0f330c7
MD5 04581a33e6fa3ab813112b7987e02a16
BLAKE2b-256 2a5277b8efbb1cadaa341255424ea418d958ab97d9250582efa7251d21415206

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pymecompress-0.3.6-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 414.6 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

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 Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page