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.2.tar.gz
.
File metadata
- Download URL: pygram11-0.11.2.tar.gz
- Upload date:
- Size: 459.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64e082ff958e2986f4fcd149b4d3b18544be7900b2c55cf173f07dc0743c380d |
|
MD5 | fe94168e478a37d35ab6f7c7c9895fd8 |
|
BLAKE2b-256 | c07b0518b720d0dbc099af32be9f8193143213aaca1433ad39225df14c1df5b9 |
File details
Details for the file pygram11-0.11.2-cp39-cp39-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.2-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.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68956747b8a59bb349d483dcbed050473c9276357ecb2372cde80ca0c7feaaa1 |
|
MD5 | 3e6ed8351f4c0b07578888221d09b88d |
|
BLAKE2b-256 | 522df0d178bfd71de3da918773ac6f1921d812e29d4121594a0258252930c2f2 |
File details
Details for the file pygram11-0.11.2-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: pygram11-0.11.2-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 828.7 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1bccd80ca78f790a0095ba49156fc77a3bcb6d04ad7a7ea06bfd0e3ec65b782 |
|
MD5 | 59842fd28ef5d3f6275ec967d6709c71 |
|
BLAKE2b-256 | ba1b35b7308909cddd73c762065d33109ca092ed30f690fa6e699804a11a244f |
File details
Details for the file pygram11-0.11.2-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.2-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.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69d2c164573551e97ec0934bcdf631920addf8db0ffaf6d2422e0e70b91fe457 |
|
MD5 | 73cd7d251cc44188c0d73a5eca98b442 |
|
BLAKE2b-256 | a2ddc7452bb2a8ad0e159ccb986822be564b7b792a8943c45266d7d1850fa0de |
File details
Details for the file pygram11-0.11.2-cp38-cp38-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.2-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.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b603d4236f929fe869c1f47b97c75476bd8bef01ce69984492a99556c752a8c8 |
|
MD5 | a2ed2f8590f59edb86ff82a7740b9eb0 |
|
BLAKE2b-256 | 57cddd996fb20e025a857d20f4cf24ce79022dc8e38e2233c7de2ba838d5a022 |
File details
Details for the file pygram11-0.11.2-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.2-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.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 092daa02d3e59fc49433ce2c5356589e35293477449410aff0978f3f9db923bc |
|
MD5 | a88a6f534e6f98022f48c303db0e023d |
|
BLAKE2b-256 | 16459c0bbee581c3f8ea29b2c0f148ae1945708e2055113d843443ced15b55f3 |
File details
Details for the file pygram11-0.11.2-cp37-cp37m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.2-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.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0182f28ab4fdb758f0358438dfb1554f1c357b9212a4defc72fb5512cb348945 |
|
MD5 | 6984ceff3d13d9debffd5cbf5ec61dea |
|
BLAKE2b-256 | 20ff8375f102914e0aff401b266b93c8e87bcdd746b54fbd1e11b07e1f14e4ba |
File details
Details for the file pygram11-0.11.2-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.2-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.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a063b2d9b8596918846e3b4be68d5648f39457aaddf5837a7ebb83458bfb9bd |
|
MD5 | f17a39a936abd0aaf5e1c5c5b7ec21f6 |
|
BLAKE2b-256 | 74431aaad7026a9e4d4b4182eb46a54ce4753af3cfe07017a3fdc61359da336f |
File details
Details for the file pygram11-0.11.2-cp36-cp36m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.2-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.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea38572c1ac143a65b51f34a40898715860cef3ad457305398ebe641f2c1c63d |
|
MD5 | 6bf9749bf86fb5db1b51e4e0ac34909e |
|
BLAKE2b-256 | 06e3377d0a1d62eed0b1775fce737835ac045137fc42f8aab4093c48ceb8268c |
File details
Details for the file pygram11-0.11.2-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.11.2-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.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 144b397aaa78156abb4f811b182e56e8e6009a1a1e17c592826f98ffee4e3fda |
|
MD5 | fdc085c084c6b0f7f7f916f46d6e4320 |
|
BLAKE2b-256 | fe02d55db147da510acc7dca1925c4ec5c9bbe18947a0df5279a7cd93e6919f1 |