Fast histogramming in Python built on pybind11 and OpenMP.
Project description
pygram11
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
Built Distributions
File details
Details for the file pygram11-0.11.1.tar.gz
.
File metadata
- Download URL: pygram11-0.11.1.tar.gz
- Upload date:
- Size: 459.8 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.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e9cad28d77d8f6ee05456cfc10b4334c77e3f080efff9b3b401c6727581385b |
|
MD5 | b88e11458e8fcf9d3b2a5b80fcb787fe |
|
BLAKE2b-256 | 01cecdc80da8d16e69da87ea9af857f30ce26b5a546642528b139db24858d42b |
File details
Details for the file pygram11-0.11.1-cp39-cp39-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.1-cp39-cp39-manylinux2010_x86_64.whl
- Upload date:
- Size: 500.6 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.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eeea60e87901f814b611c625dce96610241bde31504f48a5e45edd6b830fedf |
|
MD5 | 04035f43e00bff46ef1ae36bb19d2a8b |
|
BLAKE2b-256 | d1e2796dc8297136b73e763734c8c7e9ed8dca01adff8f65e60776f881d4ef4d |
File details
Details for the file pygram11-0.11.1-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.1-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 953.8 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.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0a51ee6ec15ac9bf0bc7066aae62cc8f2910fd6ed72e5b30a43833742e6cb7a |
|
MD5 | ac09e8f062cfee2a20b735a9dbd6636d |
|
BLAKE2b-256 | 0ea905d4536dac523f1065cfd31a35e1f3f8db3c34e3f1229e374843980adc92 |
File details
Details for the file pygram11-0.11.1-cp38-cp38-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.1-cp38-cp38-manylinux2010_x86_64.whl
- Upload date:
- Size: 499.4 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.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37c424f17e29809c48290b18e8915704ad06bb5e352f7ed50eaca779537be4fa |
|
MD5 | ec8beceb4c112378c1cd9e9518a412d0 |
|
BLAKE2b-256 | db37c56d2addc11fa9261f6f55be4f7815c19169c053112d593a11a9086f2226 |
File details
Details for the file pygram11-0.11.1-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.1-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 953.8 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.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69c90350c5f839ddd390964fea1442c565593e3f56d4cf3c1c49d4c4d21f04fd |
|
MD5 | bfbff035f6194ffe1f75775dbe6c506c |
|
BLAKE2b-256 | 2009a6624323e9f6f3cc650c232b088bc395a4ed5d50fa3dbd49be29d33a86cc |
File details
Details for the file pygram11-0.11.1-cp37-cp37m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.1-cp37-cp37m-manylinux2010_x86_64.whl
- Upload date:
- Size: 473.2 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.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41beca1db1dc62bbf92ab19bcf28c7d0aefac29b06459fb3ce5f5762bda18387 |
|
MD5 | 18d39079aafa8f020f8e540541af2f0c |
|
BLAKE2b-256 | ae7ac46c97a65e0b6d149bfe74b4a77cd1bd7b2947159113e5b6bab58bf8c7b1 |
File details
Details for the file pygram11-0.11.1-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.1-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 920.1 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.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7865fb7e38eb56428bda0957e69a8f06cc45359f4d1a7ee5bbbc7377ee776d6e |
|
MD5 | 8f46383ed038b8a7dfc0d5940bedbd00 |
|
BLAKE2b-256 | a65ce028999869adda9c0ca59229b7f899f841ad8249ab94ad99e4676efb65c0 |
File details
Details for the file pygram11-0.11.1-cp36-cp36m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.1-cp36-cp36m-manylinux2010_x86_64.whl
- Upload date:
- Size: 473.0 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.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ca3877c78516672c806b93cab5d174bf5b381287f4c9bfcbc3cdf6c98c160ff |
|
MD5 | bbdaaac9cd7a0850cee7323c4b537597 |
|
BLAKE2b-256 | 44771b8ee1c2ca0195ceae88a39763f2be8366b705be04eba002838c27e37126 |
File details
Details for the file pygram11-0.11.1-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.1-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 920.1 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.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5356c1a904b99f519516defdd1aac476414ffa1f17f41bff747d123a6332a008 |
|
MD5 | 502e9a3ce0f36b1ed833e45b6e00684b |
|
BLAKE2b-256 | 5cd42a7ee0503a0b7d08e162b4aea6d161fc271c681bab0aa1a711e375b4e513 |