Skip to main content

Fast histogramming in Python built on pybind11 and OpenMP.

Project description

pygram11

Documentation Status Actions Status PyPI version Conda Forge Python Version

Simple and fast histogramming in Python accelerated with OpenMP with help from pybind11.

pygram11 provides functions for very fast histogram calculations (and the variance in each bin) in one and two dimensions. The API is very simple; documentation can be found here (you'll also find some benchmarks there).

Installing

From PyPI

Binary wheels are provided for Linux and macOS. They can be installed from PyPI via pip:

pip install pygram11

From conda-forge

For installation via the conda package manager pygram11 is part of conda-forge.

conda install pygram11 -c conda-forge

Please note that on macOS the OpenMP libraries from LLVM (libomp) and Intel (libiomp) may clash if your conda environment includes the Intel Math Kernel Library (MKL) package distributed by Anaconda. You may need to install the nomkl package to prevent the clash (Intel MKL accelerates many linear algebra operations, but does not impact pygram11):

conda install nomkl ## sometimes necessary fix (macOS only)

From Source

You need is a C++14 compiler and OpenMP. If you are using a relatively modern GCC release on Linux then you probably don't have to worry about the OpenMP dependency. If you are on macOS, you can install libomp from Homebrew (pygram11 does compile on Apple Silicon devices with Python version >= 3.9 and libomp installed from Homebrew). With those dependencies met, simply run:

git clone https://github.com/douglasdavis/pygram11.git --recurse-submodules
cd pygram11
pip install .

Or let pip handle the cloning procedure:

pip install git+https://github.com/douglasdavis/pygram11.git@main

Tests are run on Python versions >= 3.7 and binary wheels are provided for those versions.

In Action

A histogram (with fixed bin width) of weighted data in one dimension:

>>> rng = np.random.default_rng(123)
>>> x = rng.standard_normal(10000)
>>> w = rng.uniform(0.8, 1.2, x.shape[0])
>>> h, err = pygram11.histogram(x, bins=40, range=(-4, 4), weights=w)

A histogram with fixed bin width which saves the under and overflow in the first and last bins:

>>> x = rng.standard_normal(1000000)
>>> h, __ = pygram11.histogram(x, bins=20, range=(-3, 3), flow=True)

where we've used __ to catch the None returned when weights are absent. A histogram in two dimensions with variable width bins:

>>> x = rng.standard_normal(1000)
>>> y = rng.standard_normal(1000)
>>> xbins = [-2.0, -1.0, -0.5, 1.5, 2.0, 3.1]
>>> ybins = [-3.0, -1.5, -0.1, 0.8, 2.0, 2.8]
>>> h, err = pygram11.histogram2d(x, y, bins=[xbins, ybins])

Manually controlling OpenMP acceleration with context managers:

>>> with pygram11.omp_disabled():  # disable all thresholds.
...     result, _ = pygram11.histogram(x, bins=10, range=(-3, 3))
...
>>> with pygram11.omp_forced(key="thresholds.var1d"):  # force a single threshold.
...     result, _ = pygram11.histogram(x, bins=[-3, -2, 0, 2, 3])
...

Histogramming multiple weight variations for the same data, then putting the result in a DataFrame (the input pandas DataFrame will be interpreted as a NumPy array):

>>> N = 10000
>>> weights = pd.DataFrame({"weight_a": np.abs(rng.standard_normal(N)),
...                         "weight_b": rng.uniform(0.5, 0.8, N),
...                         "weight_c": rng.uniform(0.0, 1.0, N)})
>>> data = rng.standard_normal(N)
>>> count, err = pygram11.histogram(data, bins=20, range=(-3, 3), weights=weights, flow=True)
>>> count_df = pd.DataFrame(count, columns=weights.columns)
>>> err_df = pd.DataFrame(err, columns=weights.columns)

I also wrote a blog post with some simple examples.

Other Libraries

  • boost-histogram provides Pythonic object oriented histograms.
  • Simple and fast histogramming in Python using the NumPy C API: fast-histogram (no variance or overflow support).
  • To calculate histograms in Python on a GPU, see cupy.histogram.

If there is something you'd like to see in pygram11, please open an issue or pull request.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

pygram11-0.13.0.tar.gz (495.0 kB view details)

Uploaded Source

Built Distributions

pygram11-0.13.0-cp311-cp311-musllinux_1_1_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pygram11-0.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (718.5 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pygram11-0.13.0-cp311-cp311-macosx_12_0_arm64.whl (898.1 kB view details)

Uploaded CPython 3.11 macOS 12.0+ ARM64

pygram11-0.13.0-cp311-cp311-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pygram11-0.13.0-cp310-cp310-musllinux_1_1_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pygram11-0.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (718.5 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pygram11-0.13.0-cp310-cp310-macosx_12_0_arm64.whl (898.0 kB view details)

Uploaded CPython 3.10 macOS 12.0+ ARM64

pygram11-0.13.0-cp310-cp310-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pygram11-0.13.0-cp39-cp39-musllinux_1_1_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pygram11-0.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (719.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pygram11-0.13.0-cp39-cp39-macosx_12_0_arm64.whl (898.1 kB view details)

Uploaded CPython 3.9 macOS 12.0+ ARM64

pygram11-0.13.0-cp39-cp39-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pygram11-0.13.0-cp38-cp38-musllinux_1_1_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pygram11-0.13.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (719.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pygram11-0.13.0-cp38-cp38-macosx_12_0_arm64.whl (898.1 kB view details)

Uploaded CPython 3.8 macOS 12.0+ ARM64

pygram11-0.13.0-cp38-cp38-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

Details for the file pygram11-0.13.0.tar.gz.

File metadata

  • Download URL: pygram11-0.13.0.tar.gz
  • Upload date:
  • Size: 495.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for pygram11-0.13.0.tar.gz
Algorithm Hash digest
SHA256 8cc6b27a558385f99b61d45db66c814604e3f3006ebf0744f362aaa913e69176
MD5 2a6bbead77388e6ea8082d5c89da0466
BLAKE2b-256 514c307b2b56cb5650c4103ecf40ec68aff910bac78c1964933fcca9ed2f4ef3

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f83fb66387b6223a842afb5660c229429643883d740809390123316d176200a3
MD5 e5105be4b11857fe8743758892b91cdc
BLAKE2b-256 b20a201c221237b2d62b2ebeee4bc7d8f8f36bfc27dbc47a7efeed706103e93b

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4b21ca0e81dac1fde2786582f4fdd4ecb0aefaa9f72ce45259950aa06e08a86d
MD5 6ce64d178161d32bb4f83896d4dce05d
BLAKE2b-256 c1c78542c24e10d25a5fca43c550a78ba0eb4e22b1fdca2912cf5538e34fa6d5

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp311-cp311-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 273b15034365102f91cc1b152b2dc019ce3f34906c7822390ebe69c907028df8
MD5 a816a78a893fc3e050f3641c13a7324d
BLAKE2b-256 b53fc4792d98debf5266ebf32b0a2bc7465e08b75331767ff250f01cb597626b

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d2dde3702aecd90601c6f79293f928391ae2ffa691a0f2c75f3dc87e856b98e6
MD5 bc1d7e5e0e07a6b467510a2d01c38913
BLAKE2b-256 f1cf019caad5047aac0474cd0811c98ebf9627b3ab50a041ac3906c554971218

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 73994b807f074eb1c0bc0b7b38042515b049035eb17217641d7d329b9e2c82ed
MD5 f3f139eba2307d8f98af80983393a5af
BLAKE2b-256 85f0efe56a302d75264d28e5d2142923c344400a8dd6aaadf210f09bf92de160

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bb3018224a095e1411610da0678e7dfde18186b3dc0ad234a370e424362e0148
MD5 5b0ef6b35395cf0562a6176209c82069
BLAKE2b-256 c54006164c6a403e17f61ad803ffb007d892479bd6441de1c264f2cef68c3907

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 4d2d1f257e70542181cf3f1cb874ff35f2444a89b699f9fbc0fadae2cd75add4
MD5 3e9360b920c53a51887733368d08d428
BLAKE2b-256 67a503b8a9756ff63bf48556cb764de54ee7ec25379b58f58132b19493710947

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 24b2f3945b5527662d02841a4157a17de2065fbfb146a3d765412d12876058e4
MD5 46de1b3ffc2c882112e9e62edacc61cf
BLAKE2b-256 64147413a5056cac87ffe52c4189aa11e42dd460eacffeb906fbf78ec8c6f596

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f3285b69a8bed29fb16082332efce4479d3fe047c1fac347d70ca0bb238a05b1
MD5 98c51edbff4032895049ba492287cea4
BLAKE2b-256 ac370b9564b72cf8a007f4e686fc6fa2b2ee0b3b4e7e2e2e1ed4d30ea6bc4384

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff175026f95141a158ba312d39ff5a4ccd64d970cfca9e1ab9dcf1da0fc76c6c
MD5 f17042ff5e35f49f38fe77cc90716899
BLAKE2b-256 6df65b3ac00af58e4f7eb85d8c61f59da76ad0b3475167f11df48f889645bcec

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp39-cp39-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 ba4405af0e2ef3a12657cc8b7b1762fd17c13700877d2c73d3af19426b4d765b
MD5 6de71f756b80990ca077f5317143086f
BLAKE2b-256 6d65cec25477a9d43254fd3db30cefd4e4b9db469ac35a3b3a654f89e30d4288

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1e8c0ddc398b2c8337056ca612be68ed0336720f630b2d983a96d44cfeed1d0e
MD5 8109d5fb8da6cffce8d311be50832bb0
BLAKE2b-256 a9f8c8c3bb1cdf68e9f891f44c6b3555c8dde51ed39791744c1b85b151fa472e

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3f30c460196864e196eca25fea23d2b169998055068efa79ea4f5e247420ae3f
MD5 84e5d8a689c8feb109733febc18789b1
BLAKE2b-256 373a0fda995d71a03aca417a1cae5d90039a34f4407e90462ea64dbb306fb580

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a77c64270cdb3571736e425bfebcae14110d42d7682728ccd0f764ebb91bf812
MD5 ecf006bbf48f610a58894663db0d0f41
BLAKE2b-256 9d87db7049760d04d8bbcb99a693123dd2780565274970da3e244382946a418a

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp38-cp38-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp38-cp38-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 6ec44f3da876c744989e83fb2e7fe05d1c0fe6ebe83aadfb44e862b03e66ea68
MD5 c9e91da30a621aeff7975fce441ae40b
BLAKE2b-256 56f9e475cd8b9ea9c62ccd8103a2c836079201bce5b2fdcc24f8719b23932bf1

See more details on using hashes here.

File details

Details for the file pygram11-0.13.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.13.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4ca7798913a9f238ad25d6cda0e5da8f4994dda31efaf7744a5e8be79e86ebf2
MD5 f17a0eee2ccbe59a25f103e4c3a9bbca
BLAKE2b-256 4b2f3289f1211b496caa5a1baabd21f3149923cb063a5f5c036518a7eba089be

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