This release is a pre-release and may not be stable for production use.
pygram11
Simple and fast histogramming in Python via pybind11 and accelerated with OpenMP.
pygram11 provides fast functions for calculating histograms (and
their statistical uncertainties). The API is very simple,
documentation found here (you'll
also find some
benchmarks
there). I also wrote a blog
post with some simple
examples.
Installing
pygram11 only requires NumPy at runtime. To build from source, you'll just need a C++ compiler with C++11 support.
From PyPI
Binary wheels are provided for Linux and macOS, they can be installed from PyPI via pip. These builds include OpenMP acceleration.
pip install pygram11
From conda-forge
For a simple installation process via the conda package manager
pygram11 is part of
conda-forge. These builds
include OpenMP acceleration.
conda install pygram11 -c conda-forge
From Source
pip install git+https://github.com/douglasdavis/pygram11.git@master
To ensure OpenMP acceleration in a build from source, read the OpenMP section of the docs.
Note: For releases older than v0.5, when building from source or
PyPI, pybind11 was required to be explicitly installed before
pygram11 (because setup.py used pybind11 to determine include
directories). Starting with v0.5 pybind11 is bundled with the source
for non-binary (conda-forge or wheel) installations.
In Action
A histogram (with fixed bin width) of weighted data in one dimension, accelerated with OpenMP:
>>> x = np.random.randn(10000)
>>> w = np.random.uniform(0.8, 1.2, 10000)
>>> h, staterr = pygram11.histogram(x, bins=40, range=(-4, 4), weights=w, omp=True)
A histogram with fixed bin width which saves the under and overflow in
the first and last bins (using __ to catch the None returned due
to the absence of weights):
>>> x = np.random.randn(1000000)
>>> h, __ = pygram11.histogram(x, bins=20, range=(-3, 3), flow=True, omp=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, __ = 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, omp=True)
>>> count_df = pd.DataFrame(count, columns=["a", "b", "c"])
>>> err_df = pd.DataFrame(err, columns=["a", "b", "c"])
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.
Metadata
Release files for pygram11 0.5.1.dev0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pygram11-0.5.1.dev0.tar.gz | 146.5 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pygram11-0.5.1.dev0-cp37-cp37m-manylinux1_x86_64.whl | CPython 3.7 | CPython 3.7 pymalloc | Linux glibc 2.5+ x86-64 | Details |
| pygram11-0.5.1.dev0-cp36-cp36m-manylinux1_x86_64.whl | CPython 3.6 | CPython 3.6 pymalloc | Linux glibc 2.5+ x86-64 | Details |
| pygram11-0.5.1.dev0-cp27-cp27m-manylinux1_x86_64.whl | CPython 2.7 | CPython 2.7 pymalloc | Linux glibc 2.5+ x86-64 | Details |
Total release size: 4.8 MB
Release files / pygram11-0.5.1.dev0.tar.gz
| Download URL | pygram11-0.5.1.dev0.tar.gz |
|---|---|
| Size | 146.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7cf81f0a675dc39f9b2aad8f1b550f3c4a1878eef6cc6886389939cac5595f3d
|
|
BLAKE2b-256 checksum How to use checksums |
9dd68e5fd440adf4c6f1d1836039468895927e9cd60a65732ad67aad65312231
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4
|
Release files / pygram11-0.5.1.dev0-cp37-cp37m-manylinux1_x86_64.whl
| Download URL | pygram11-0.5.1.dev0-cp37-cp37m-manylinux1_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
c6349a1f5f09cb6c89c8045f4c7397a34ef2080ff40d23cc8596325edaad73a7
|
|
BLAKE2b-256 checksum How to use checksums |
184cc5c810939da4ca9aa7e4fc99f1fc9aaad9a074684a87b527ee4313ae36a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4
|
Release files / pygram11-0.5.1.dev0-cp36-cp36m-manylinux1_x86_64.whl
| Download URL | pygram11-0.5.1.dev0-cp36-cp36m-manylinux1_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
865c91a81cf842c46eba7af790d16fbda22e77d4a40e1730cfe251d3fc6d03a6
|
|
BLAKE2b-256 checksum How to use checksums |
138ee196340a0d436dcbf2b97686d63a76f97c25afa20b339ead415aca591563
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4
|
Release files / pygram11-0.5.1.dev0-cp27-cp27m-manylinux1_x86_64.whl
| Download URL | pygram11-0.5.1.dev0-cp27-cp27m-manylinux1_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
1b2771d4f9d63cc5c5f088cfd73470aa5a697305ca2ee7e14f4af85845b348d6
|
|
BLAKE2b-256 checksum How to use checksums |
168c6a08a16ce458b79485ca26a551cb07ba02dd9d6c39246e18cd7eff6d5826
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4
|