Skip to main content

Fast histogramming in Python built on pybind11 and OpenMP.

Project description

pygram11

Documentation Status Actions Status builds.sr.ht 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])

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

Uploaded Source

Built Distributions

pygram11-0.11.0-cp39-cp39-manylinux2010_x86_64.whl (500.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

pygram11-0.11.0-cp39-cp39-macosx_10_9_x86_64.whl (953.4 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pygram11-0.11.0-cp38-cp38-manylinux2010_x86_64.whl (499.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.11.0-cp38-cp38-macosx_10_9_x86_64.whl (953.4 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygram11-0.11.0-cp37-cp37m-manylinux2010_x86_64.whl (472.8 kB view details)

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

pygram11-0.11.0-cp37-cp37m-macosx_10_9_x86_64.whl (919.8 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.11.0-cp36-cp36m-manylinux2010_x86_64.whl (472.6 kB view details)

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

pygram11-0.11.0-cp36-cp36m-macosx_10_9_x86_64.whl (919.7 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.11.0.tar.gz
  • Upload date:
  • Size: 459.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pygram11-0.11.0.tar.gz
Algorithm Hash digest
SHA256 a593c13a7d0ef4311958f0888c976656740e10d00057155a1ccae19cfbdb393d
MD5 9742a32eb3a55c5d5b074738b27f8ada
BLAKE2b-256 d4658e25bd9089bb5cc2fcab1db414aa10e74e81e41d8988db9c81d6f33f667a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.11.0-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 500.2 kB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pygram11-0.11.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 0507f0c2bd007f5e6c301cd1a84f9fdbce43c51089c6a8eb3189f49d495e50b7
MD5 7c35749cdd95914cfec84207ce10c3f9
BLAKE2b-256 b0b0c8b1d413a665f8f497a521cfe520748dce612e254df238dfb3df9048b40a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.11.0-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 953.4 kB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pygram11-0.11.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fcc33f311272e0c59d5c7a69d170db2b3ef17306cd4fc3b1efc55f937033628d
MD5 6da571de8d016e82ed1ffe22d23efe57
BLAKE2b-256 6710561f07bba12729be3a48aae10891405bef068f56398fa860707839a73234

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.11.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 499.0 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pygram11-0.11.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 694a660bd89661090ef57eed37e691034113ce504f960f1860c4fc62924657ed
MD5 b92ac6cbecbf32f00a6b32cfbf8fbb3f
BLAKE2b-256 303bca5388e111a42ea9e5d74520d5b5be75594a6adb264f5f9f4f2a83100e44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.11.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 953.4 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pygram11-0.11.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 184c3cc49414b27d36f5ba0816078220f4e67648fe014520c07946dfdd7a9cbd
MD5 8583ef309d4e33fb24d05abb948ce2d5
BLAKE2b-256 1887c36aeeba263d451e7d165326eb33a898ca1a07db652064c96c1890e9c924

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.11.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 472.8 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pygram11-0.11.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 4d437169d2ecd97fe74800ebc662c9d0c7cecc843dc5d1c157c58ef228815081
MD5 3157c6970511b0aa4e1282656cee2bbd
BLAKE2b-256 fe2407289ca20f6db845c43df5165d64443b9be4145df31a8bffb2742b515352

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.11.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 919.8 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pygram11-0.11.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ed363f20710d50d44b6b14a83d5eef268e0d7ffae5cfb7e39609341737db8525
MD5 b8feedcc864567cd2d2347d2c03339ef
BLAKE2b-256 1c798a491fd6e6c8738796f4121491181cdc5f8e7ecbe3fe95a385998e0b996b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.11.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 472.6 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pygram11-0.11.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 1a22084e02d8d340f2f34d70d89a59ec19b9d381411df32bf4ad515ef3587981
MD5 42987a60074081a91c73be5edaba4d85
BLAKE2b-256 cda3f03fa63f9d2bb0cb739968bd1ea666461c8746a6a0c74e02568aaa7b0db0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.11.0-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 919.7 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pygram11-0.11.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 04713a378cd6747c87ee71f98ffa029ba2a99a383178f18769b61f3bc2700d0c
MD5 99143fb7ea3479e07796d042de273d8f
BLAKE2b-256 2b2b1112ee938e2f938b74fba799954335ef90d1566746ddff14513e8c1c99c4

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