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.6 through 3.9 (binary wheels are provided for those versions); an earlier version of Python 3 might work, but this is not guaranteed (and you will have to manually remove the >= 3.6 requirement in the setup.cfg file).

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).
  • If you want to calculate histograms on a GPU in Python, check out cupy.histogram. They only have 1D histograms (no weights or overflow).

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.12.0.tar.gz (462.2 kB view details)

Uploaded Source

Built Distributions

pygram11-0.12.0-cp39-cp39-manylinux2010_x86_64.whl (502.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

pygram11-0.12.0-cp39-cp39-macosx_11_0_arm64.whl (843.2 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pygram11-0.12.0-cp39-cp39-macosx_10_9_x86_64.whl (947.5 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pygram11-0.12.0-cp38-cp38-manylinux2010_x86_64.whl (502.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.12.0-cp38-cp38-macosx_10_9_x86_64.whl (947.2 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygram11-0.12.0-cp37-cp37m-manylinux2010_x86_64.whl (474.3 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

pygram11-0.12.0-cp37-cp37m-macosx_10_9_x86_64.whl (906.8 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.12.0-cp36-cp36m-manylinux2010_x86_64.whl (474.3 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

pygram11-0.12.0-cp36-cp36m-macosx_10_9_x86_64.whl (907.0 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.12.0.tar.gz
  • Upload date:
  • Size: 462.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygram11-0.12.0.tar.gz
Algorithm Hash digest
SHA256 41092f69dea6a3037de8a8f1d9cd55a9cbdb76ba4846c0b5523c61cd71f14e62
MD5 831630f75281969be1189bc56173c6ae
BLAKE2b-256 cfa3d1dc6fb338858ef2208f8fc7719055f48e61f9768a3de3a0374039c8ddc1

See more details on using hashes here.

File details

Details for the file pygram11-0.12.0-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pygram11-0.12.0-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 502.5 kB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygram11-0.12.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b76d93babf23ce9183e091428c8bb398671f8d60a2e70bb156dff2f58859c5f7
MD5 cccd783e8af118a0de46024e8ca88928
BLAKE2b-256 19a71437d76a127a8fb7d834fb8b68a3cbc9c8591380c126ca6704c88574a1ee

See more details on using hashes here.

File details

Details for the file pygram11-0.12.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: pygram11-0.12.0-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 843.2 kB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygram11-0.12.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 caf529734e2a31bebf1c6454998b23f11bc9b738be0ab8c5bfc61e0188500901
MD5 45f9140e481a58b6649d058b088e38a8
BLAKE2b-256 c3b22790bcc9ec63781ef998ba0ff8ceaf2eca4f4a2059a2847ee3ca191a4ed9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.12.0-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 947.5 kB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygram11-0.12.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ca27be3fca1e9d994443edd90b92602ee1636bef6b1629b64aa92cb04c7a2b30
MD5 44e3ccab7b9a64f44839a3a0f4f35572
BLAKE2b-256 21a2720b3ceb4aaf94f0e9a4a42954f5d0d93f6b91bf127ca6b0c1dbf0f74dd8

See more details on using hashes here.

File details

Details for the file pygram11-0.12.0-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pygram11-0.12.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 502.8 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygram11-0.12.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 fd10caec96f7ba43866fb6015dfc2854d6452a27aca46ed6afdff6e6c562c36e
MD5 b67c595ebb144a27586d884851cc2660
BLAKE2b-256 e65d06ad084f569de2762de06ec66b487c593e5d296c57346fc055b93171fee0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.12.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 947.2 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygram11-0.12.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 20c27ac177c223c687a4d94d2d5acd91fd0dfd8242120435c0890f708dd3fe74
MD5 84f95ac2a606d948fcd02cbda72b67b1
BLAKE2b-256 da9e7cb170d74e691e82f3c4e2469e89e20c28fcfd761d489e1ad5d6f4985654

See more details on using hashes here.

File details

Details for the file pygram11-0.12.0-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pygram11-0.12.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 474.3 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygram11-0.12.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b595b419adaede176a90229749a73fbeb55f379cd7ac8c42725c5392bf469ee0
MD5 d09d7e3013690ebf99a79452ca83c214
BLAKE2b-256 06470a47b4e342829cf72d341e81ad09ad7456c2fbe0c5f3e8a07c0b5c1f2f8b

See more details on using hashes here.

File details

Details for the file pygram11-0.12.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pygram11-0.12.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 906.8 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygram11-0.12.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 19e0738212d6625bbaa4057a043bd2029550bb8bb9996bf17d7ae71070968a8e
MD5 dcdc50ddb3b2ba1e5a3307ec3ba492a0
BLAKE2b-256 ed62a4bd4159a74633f63552dd20569bea4070672c4bcd983bec583e3a5f4f8d

See more details on using hashes here.

File details

Details for the file pygram11-0.12.0-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pygram11-0.12.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 474.3 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygram11-0.12.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b64ae49c4be8dc664da29aaa41a15a4d87383a544dbd61ceab6d7b8e26186342
MD5 cd401785ac92326ce42e88ef44e6c1cc
BLAKE2b-256 5dcc3d67394b12809433cc4eb7fc752b80aaa3ec4cc8f56944e64cac028372b8

See more details on using hashes here.

File details

Details for the file pygram11-0.12.0-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pygram11-0.12.0-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 907.0 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygram11-0.12.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cc9fd0da8cf065fd844f5ed337e05e687b7bc1af53b79e161272493d53ee1971
MD5 c3726c5fac9d9a7132e2fdc11c975dd4
BLAKE2b-256 be51ac2ec5519b9bd3d041945cd0c0984ba0d85231edfff282f694d0bb486c22

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