Skip to main content

pygram11

Documentation Status Actions Status builds.sr.ht status PyPI version Conda Forge Python Version

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.

Metadata

Release files for pygram11 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygram11 0.11.0
File Size Uploaded
pygram11-0.11.0.tar.gz 459.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pygram11 0.11.0
File
pygram11-0.11.0-cp39-cp39-manylinux2010_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.12+ x86-64 Details
pygram11-0.11.0-cp39-cp39-macosx_10_9_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.9+ x86-64 Details
pygram11-0.11.0-cp38-cp38-manylinux2010_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.12+ x86-64 Details
pygram11-0.11.0-cp38-cp38-macosx_10_9_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.9+ x86-64 Details
pygram11-0.11.0-cp37-cp37m-manylinux2010_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64 Details
pygram11-0.11.0-cp37-cp37m-macosx_10_9_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64 Details
pygram11-0.11.0-cp36-cp36m-manylinux2010_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 Details
pygram11-0.11.0-cp36-cp36m-macosx_10_9_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.9+ x86-64 Details

Total release size: 6.2 MB

Release files / pygram11-0.11.0.tar.gz

Download URL pygram11-0.11.0.tar.gz
Size 459.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a593c13a7d0ef4311958f0888c976656740e10d00057155a1ccae19cfbdb393d
BLAKE2b-256 checksum
How to use checksums
d4658e25bd9089bb5cc2fcab1db414aa10e74e81e41d8988db9c81d6f33f667a
Upload date
Uploaded using Trusted Publishing?
What is 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.56.2 CPython/3.9.1

Release files / pygram11-0.11.0-cp39-cp39-manylinux2010_x86_64.whl

Download URL pygram11-0.11.0-cp39-cp39-manylinux2010_x86_64.whl
Size 500.2 kB
Tags CPython 3.9 Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
0507f0c2bd007f5e6c301cd1a84f9fdbce43c51089c6a8eb3189f49d495e50b7
BLAKE2b-256 checksum
How to use checksums
b0b0c8b1d413a665f8f497a521cfe520748dce612e254df238dfb3df9048b40a
Upload date
Uploaded using Trusted Publishing?
What is 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.56.2 CPython/3.9.1

Release files / pygram11-0.11.0-cp39-cp39-macosx_10_9_x86_64.whl

Download URL pygram11-0.11.0-cp39-cp39-macosx_10_9_x86_64.whl
Size 953.4 kB
Tags CPython 3.9 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
fcc33f311272e0c59d5c7a69d170db2b3ef17306cd4fc3b1efc55f937033628d
BLAKE2b-256 checksum
How to use checksums
6710561f07bba12729be3a48aae10891405bef068f56398fa860707839a73234
Upload date
Uploaded using Trusted Publishing?
What is 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.56.2 CPython/3.9.1

Release files / pygram11-0.11.0-cp38-cp38-manylinux2010_x86_64.whl

Download URL pygram11-0.11.0-cp38-cp38-manylinux2010_x86_64.whl
Size 499.0 kB
Tags CPython 3.8 Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
694a660bd89661090ef57eed37e691034113ce504f960f1860c4fc62924657ed
BLAKE2b-256 checksum
How to use checksums
303bca5388e111a42ea9e5d74520d5b5be75594a6adb264f5f9f4f2a83100e44
Upload date
Uploaded using Trusted Publishing?
What is 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.56.2 CPython/3.9.1

Release files / pygram11-0.11.0-cp38-cp38-macosx_10_9_x86_64.whl

Download URL pygram11-0.11.0-cp38-cp38-macosx_10_9_x86_64.whl
Size 953.4 kB
Tags CPython 3.8 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
184c3cc49414b27d36f5ba0816078220f4e67648fe014520c07946dfdd7a9cbd
BLAKE2b-256 checksum
How to use checksums
1887c36aeeba263d451e7d165326eb33a898ca1a07db652064c96c1890e9c924
Upload date
Uploaded using Trusted Publishing?
What is 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.56.2 CPython/3.9.1

Release files / pygram11-0.11.0-cp37-cp37m-manylinux2010_x86_64.whl

Download URL pygram11-0.11.0-cp37-cp37m-manylinux2010_x86_64.whl
Size 472.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
4d437169d2ecd97fe74800ebc662c9d0c7cecc843dc5d1c157c58ef228815081
BLAKE2b-256 checksum
How to use checksums
fe2407289ca20f6db845c43df5165d64443b9be4145df31a8bffb2742b515352
Upload date
Uploaded using Trusted Publishing?
What is 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.56.2 CPython/3.9.1

Release files / pygram11-0.11.0-cp37-cp37m-macosx_10_9_x86_64.whl

Download URL pygram11-0.11.0-cp37-cp37m-macosx_10_9_x86_64.whl
Size 919.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
ed363f20710d50d44b6b14a83d5eef268e0d7ffae5cfb7e39609341737db8525
BLAKE2b-256 checksum
How to use checksums
1c798a491fd6e6c8738796f4121491181cdc5f8e7ecbe3fe95a385998e0b996b
Upload date
Uploaded using Trusted Publishing?
What is 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.56.2 CPython/3.9.1

Release files / pygram11-0.11.0-cp36-cp36m-manylinux2010_x86_64.whl

Download URL pygram11-0.11.0-cp36-cp36m-manylinux2010_x86_64.whl
Size 472.6 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
1a22084e02d8d340f2f34d70d89a59ec19b9d381411df32bf4ad515ef3587981
BLAKE2b-256 checksum
How to use checksums
cda3f03fa63f9d2bb0cb739968bd1ea666461c8746a6a0c74e02568aaa7b0db0
Upload date
Uploaded using Trusted Publishing?
What is 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.56.2 CPython/3.9.1

Release files / pygram11-0.11.0-cp36-cp36m-macosx_10_9_x86_64.whl

Download URL pygram11-0.11.0-cp36-cp36m-macosx_10_9_x86_64.whl
Size 919.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
04713a378cd6747c87ee71f98ffa029ba2a99a383178f18769b61f3bc2700d0c
BLAKE2b-256 checksum
How to use checksums
2b2b1112ee938e2f938b74fba799954335ef90d1566746ddff14513e8c1c99c4
Upload date
Uploaded using Trusted Publishing?
What is 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.56.2 CPython/3.9.1

Release history Release notifications | RSS feed

0.12.1

9 release files

0.11.1

9 release files

This release

0.11.0 This release

9 release files

0.9.1

10 release files

0.9.0

10 release files

0.8.2

10 release files

0.8.1

10 release files

0.8.0

10 release files

0.7.3

10 release files

0.6.1

7 release files

0.6.0

7 release files

0.5.2

9 release files

0.5.1

7 release files

0.5.0

7 release files

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.14

1 release file

0.1.13

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page