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 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
Using pygram11 only requires NumPy. To build and install from source you'll need NumPy pre-installed and a compiler with support for C++11 and OpenMP.
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
When installing from source you'll need NumPy pre-installed 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'll probably want to install libomp
from Homebrew.
pip install numpy
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 weights or overflow).
- 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.7.3.tar.gz
.
File metadata
- Download URL: pygram11-0.7.3.tar.gz
- Upload date:
- Size: 531.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72ac1a62461c6bcba08e8b7ec81098ca266c5d44c84e3fe61ce07d52fe95e1d8 |
|
MD5 | 869810e4ecfb2bcba240c66f020646ce |
|
BLAKE2b-256 | 5274e843615190de597637bedaecb67af24148b0070a7b96a12cf9ad6a7a4db7 |
File details
Details for the file pygram11-0.7.3-cp38-cp38-manylinux2014_x86_64.whl
.
File metadata
- Download URL: pygram11-0.7.3-cp38-cp38-manylinux2014_x86_64.whl
- Upload date:
- Size: 406.6 kB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6932d4264e2517444e8755d32d66a852b1a1256545e22e37b6df2f2ee2a3b5cf |
|
MD5 | 9b8e46b71bfafee07e264e478e944c91 |
|
BLAKE2b-256 | 3f37405c81069e3dc05a88aa0f05ebfef315dc6176c306c1e56146a96fa0389d |
File details
Details for the file pygram11-0.7.3-cp38-cp38-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.7.3-cp38-cp38-manylinux2010_x86_64.whl
- Upload date:
- Size: 382.6 kB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77a0c1e627a0145450773365bb3a13e600cda932d018b8f6c8c6642df4c2d25b |
|
MD5 | d629b55abf34ac440771af76210aacb9 |
|
BLAKE2b-256 | 105dd669e76bcc89cad52389fe0514f9ecfceb960e054eac0ead5c8a957aac28 |
File details
Details for the file pygram11-0.7.3-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.7.3-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 488.8 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37b2e11eefb6d310f3782f99177acd66eda6b818b4d747f4460764ddb995d66d |
|
MD5 | 5ef99fd002930cbe91ef8114399a7043 |
|
BLAKE2b-256 | 259ccd06a3621fd0d3a8e2fbc902073e12223daa76ec624eaf9e9c497b327a79 |
File details
Details for the file pygram11-0.7.3-cp37-cp37m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: pygram11-0.7.3-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 406.9 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bae62c9fec4b1f92adae62e535fd3d1e6c49daa0f8a96d04e580d436affccace |
|
MD5 | 6349b0830932ff05749afa391d0526ad |
|
BLAKE2b-256 | fc3f6e106a20cdd2e639c0edfb7d883589913a66a0c8a090d2cb725e1174b8b9 |
File details
Details for the file pygram11-0.7.3-cp37-cp37m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.7.3-cp37-cp37m-manylinux2010_x86_64.whl
- Upload date:
- Size: 382.7 kB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | edecf442ecfb2f31011f0b6bdd26529b7ad5f893cbb881674cc3db0d34efce68 |
|
MD5 | c976a44b8e505714b7a6046b9d9abc9a |
|
BLAKE2b-256 | 3ada1be11b05a63877f439128234082afc1d2727e8841df83c58ec0606dc1e6c |
File details
Details for the file pygram11-0.7.3-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.7.3-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 483.5 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c7b6b4f79dec63ef35fbc9bea25bbcdf25f20e6f30a2f91657213f18b4521b8 |
|
MD5 | be375defa16b470ed21fd9d4a8ae573f |
|
BLAKE2b-256 | e4f521cbfcff5d8cca83e92c77617ec8a5125acec4363b617576c6be7a0ce13d |
File details
Details for the file pygram11-0.7.3-cp36-cp36m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: pygram11-0.7.3-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 406.8 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00ba3fcea5be1f57444ccd2b83622b0aac62261bb644d86e768a68c27ee5084e |
|
MD5 | 94ae7ecea8b5a6b8742a64189eff3093 |
|
BLAKE2b-256 | 2bb8b20c41b14755092aa4a78197113c2d53f71b8d9335ba47a6a9176e75d152 |
File details
Details for the file pygram11-0.7.3-cp36-cp36m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.7.3-cp36-cp36m-manylinux2010_x86_64.whl
- Upload date:
- Size: 382.6 kB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e8990da8101640ef7c010fba91a7a46ad6b3a80c084c3840636a3e2d38601de |
|
MD5 | 893c4b58e4151cbc17cf65873a8a458c |
|
BLAKE2b-256 | 1c8ea7136077ce798fa5d37ac66c56340364db04671f4016c2959559fdc7db26 |
File details
Details for the file pygram11-0.7.3-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.7.3-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 483.5 kB
- Tags: CPython 3.6m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed35448da1be98032ff18328ba58153f5b519fb855e77247adc78ddfbae3f0a7 |
|
MD5 | b5dc86caf3cb5e33fc6af36f6c3412f5 |
|
BLAKE2b-256 | 1ec2500b290ca5e09b0f2cf6d8f4f3f0c504a33535e6f221f95577334670bf57 |