Fast histogramming in Python build on pybind11 and OpenMP.
Project description
pygram11
Simple and fast histogramming in Python accelerated with OpenMP (with help from pybind11).
pygram11
provides fast functions for calculating histograms (and the
variance in each bin). The API is very simple; documentation can be
found here (you'll also find some
benchmarks
there).
Installing
Python 3 releases supported by both pybind11 and NumPy should be compatible with pygram11. Python version 3.6 (or later) and NumPy version 1.16+ are supported by tests (and have binary releases). To build and install from source you'll just need a compiler with support for C++11 and OpenMP. The only runtime dependency is NumPy.
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
All you need is a C++11 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. With those dependencies met, simply
run:
pip install git+https://github.com/douglasdavis/pygram11.git@master
In Action
A histogram (with fixed bin width) of weighted data in one dimension:
>>> x = np.random.randn(10000)
>>> w = np.random.uniform(0.8, 1.2, 10000)
>>> 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 = np.random.randn(1000000)
>>> h, err = pygram11.histogram(x, bins=20, range=(-3, 3), flow=True)
A histogram in two dimensions with variable width bins:
>>> x = np.random.randn(10000)
>>> y = np.random.randn(10000)
>>> xbins = [-2.0, -1.0, -0.5, 1.5, 2.0]
>>> ybins = [-3.0, -1.5, -0.1, 0.8, 2.0]
>>> 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):
>>> weights = pd.DataFrame({"weight_a" : np.abs(np.random.randn(10000)),
... "weight_b" : np.random.uniform(0.5, 0.8, 10000),
... "weight_c" : np.random.rand(10000)})
>>> data = np.random.randn(10000)
>>> 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
- There is an effort to develop an object oriented histogramming library for Python called boost-histogram. This library will be feature complete w.r.t. everything a physicist needs with 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 Distributions
Built Distributions
File details
Details for the file pygram11-0.10.2-cp39-cp39-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp39-cp39-manylinux2010_x86_64.whl
- Upload date:
- Size: 266.7 kB
- Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2272b96760e0e0d8b5c3a96437087f9da20a1afa8465c66e31b9b224cfa7d94f |
|
MD5 | 44274ad8c84b1832b97cd7150306fd25 |
|
BLAKE2b-256 | 167069b9c0df6a188be1754bea0f165f57ecd4910172134bcdd46c83d6350ab7 |
File details
Details for the file pygram11-0.10.2-cp39-cp39-manylinux2010_i686.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp39-cp39-manylinux2010_i686.whl
- Upload date:
- Size: 283.8 kB
- Tags: CPython 3.9, manylinux: glibc 2.12+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 551a728e60c35bb947e8cd2bb2e017881c51f247e9b241b02c8eae6c1dde9e6f |
|
MD5 | c20605e328290ea958e7c64407637629 |
|
BLAKE2b-256 | e8b9f1fc14bcb32b1125d11991f9f4f3bef8e31e4aabcf7e72e71ab5ba56ccb2 |
File details
Details for the file pygram11-0.10.2-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 402.5 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf46b1aafcc05eda95674f524dd5d2a402c8f4636d0f4ea3f9d6c9d18430dc04 |
|
MD5 | dbd3c913dc80d3282fb870197e02a3e4 |
|
BLAKE2b-256 | 2b7fd93cd25470a45246d975e407a0c8f6ed24a83a33a0343959df6a5116d1f5 |
File details
Details for the file pygram11-0.10.2-cp38-cp38-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp38-cp38-manylinux2010_x86_64.whl
- Upload date:
- Size: 266.8 kB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8192ed23e5fe4d7ebcc593a72f75263ac4bfea7e15c7bb19cf8ba69a3be7ef82 |
|
MD5 | a140c9c21e3b67c3d8226fa7795c114b |
|
BLAKE2b-256 | ca5a788136afb4025a2673fd6c6c5f69db507b0c7b4c0944bd4cb0801de2d7e1 |
File details
Details for the file pygram11-0.10.2-cp38-cp38-manylinux2010_i686.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp38-cp38-manylinux2010_i686.whl
- Upload date:
- Size: 283.8 kB
- Tags: CPython 3.8, manylinux: glibc 2.12+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 729349e07e30329732f465cd1be1473644b5a5bea9318773905845b8e3aaae5f |
|
MD5 | 7ad2f6e75de0f4696f7d43be1eb29756 |
|
BLAKE2b-256 | 9b4712a9ae868b87cbf9e929a8242ff57235f80d4ebeaf662d7ad754c352200e |
File details
Details for the file pygram11-0.10.2-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 402.9 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f20315ad356402753762fad17b5f485d0d6e94c5368570e1ebeacc2bdae1e73 |
|
MD5 | a2aad3378cb59766dacf92f4133a1a00 |
|
BLAKE2b-256 | d8bdb228eda7ec0f9bb1bfe0dbc4bcb2851d1b79f39e24aed3064c5426d555a5 |
File details
Details for the file pygram11-0.10.2-cp37-cp37m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp37-cp37m-manylinux2010_x86_64.whl
- Upload date:
- Size: 265.4 kB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3af73653dfc411d95af7fcb321f357db37bb9c1fe7ff24c5d8602287296071e1 |
|
MD5 | 73a463ae1aae70973d9daf9dfcaa34de |
|
BLAKE2b-256 | dee966182a7d4a7ac89975e9af41a014932757445a2bde87a17264685e26ef2e |
File details
Details for the file pygram11-0.10.2-cp37-cp37m-manylinux2010_i686.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp37-cp37m-manylinux2010_i686.whl
- Upload date:
- Size: 281.1 kB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46c571a85be1d4852cf26cdae99551f60c8ffead83cdbf56bb755f7eaf2039fc |
|
MD5 | 2be7c3fef93b9204445dbe82456dd73b |
|
BLAKE2b-256 | ac3a7f0a335c787eb5e44c69fe4aafc788f2b9c97ea00b8f0ee864d5b4f6d07f |
File details
Details for the file pygram11-0.10.2-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 398.8 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2504c2c65e10983d5d601b154b528cb063a9463e0b167ff319aa873c6bbbab6e |
|
MD5 | 468c6aa70f68af92958d8811f074e6a1 |
|
BLAKE2b-256 | b342241faee9c6e9bab5c33c5b01c1d5d9fd1c8c6ca7299e5fb49216618c4996 |
File details
Details for the file pygram11-0.10.2-cp36-cp36m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp36-cp36m-manylinux2010_x86_64.whl
- Upload date:
- Size: 265.3 kB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6ab476cbfa33451ad4ed2d62fa8518fda3b16a0268b863145c6d26634be7a6a |
|
MD5 | 8c605c972b5ec154e157db4f5c627539 |
|
BLAKE2b-256 | 0c4d7383a9c1d082664337279455d41a032771f8f56da45699754082e00681c4 |
File details
Details for the file pygram11-0.10.2-cp36-cp36m-manylinux2010_i686.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp36-cp36m-manylinux2010_i686.whl
- Upload date:
- Size: 281.0 kB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 069d4015df1f4ee37146b96e096d31378e9efbf941b9bd3ef31863509b81af68 |
|
MD5 | ba63b9bd8cde5df077ade9c0072fb09f |
|
BLAKE2b-256 | 0fc12c9e36c11ed4c5b1c6284381955d55e8e87b0f37e1e90e8e710b92cac24c |
File details
Details for the file pygram11-0.10.2-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.10.2-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 398.8 kB
- Tags: CPython 3.6m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eb4f3c8283689b74a87b849772fef8eef9b78e138080a8214b2b8fb2b678ccd |
|
MD5 | 1b2fd27bfec3fb4b739da436a1331919 |
|
BLAKE2b-256 | e1506f52f7a9d967a9868620e0585ff30169d6c2db0a6571c63461a5288e9ee3 |