Skip to main content

Fast histogramming in Python built on pybind11 and OpenMP.

Project description

pygram11

Documentation Status Actions 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.7 and binary wheels are provided for those versions.

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])

Manually controlling OpenMP acceleration with context managers:

>>> with pygram11.omp_disabled():  # disable all thresholds.
...     result, _ = pygram11.histogram(x, bins=10, range=(-3, 3))
...
>>> with pygram11.omp_forced(key="thresholds.var1d"):  # force a single threshold.
...     result, _ = pygram11.histogram(x, bins=[-3, -2, 0, 2, 3])
...

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).
  • To calculate histograms in Python on a GPU, see cupy.histogram.

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

pygram11-0.12.2.tar.gz (481.3 kB view details)

Uploaded Source

Built Distributions

pygram11-0.12.2-cp310-cp310-musllinux_1_1_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pygram11-0.12.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (506.7 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64

pygram11-0.12.2-cp310-cp310-macosx_10_9_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pygram11-0.12.2-cp39-cp39-musllinux_1_1_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pygram11-0.12.2-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (507.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

pygram11-0.12.2-cp39-cp39-macosx_10_9_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pygram11-0.12.2-cp38-cp38-musllinux_1_1_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pygram11-0.12.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (506.6 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.12.2-cp38-cp38-macosx_10_9_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygram11-0.12.2-cp37-cp37m-musllinux_1_1_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

pygram11-0.12.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (477.5 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

pygram11-0.12.2-cp37-cp37m-macosx_10_9_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file pygram11-0.12.2.tar.gz.

File metadata

  • Download URL: pygram11-0.12.2.tar.gz
  • Upload date:
  • Size: 481.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for pygram11-0.12.2.tar.gz
Algorithm Hash digest
SHA256 61b67f64d2ce126d5ddc799385317f56dbc01d76381f953916a1be344adcdbbe
MD5 21a993792a80ca69c64fbd3430d1a5c7
BLAKE2b-256 331561d29fc1a87e83c2dc0027be885c4b36f24bd01b5b96471f91bf7a42eacc

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4388e1e3c8fa9b5beadf041472a3115f39a85ebe8a91b39b9fc3d011db30d068
MD5 57a651e5b27f68ef6cffbe8a63095f52
BLAKE2b-256 63684fc2b7ca3745b2fcc208f9500730e8ea4dcf2e0c945c65f1f4299c0e1bb4

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 07e40da116f198eb20c7c09213aeabfd5e2a66914cb74c9284d279e3b328c3f2
MD5 0135abb1404191fee20712af5ce04aa8
BLAKE2b-256 3a5511c408f052ed659412a49daf3545f8f5dd47ceacaef7615f0e43b22e5713

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7157281b6e17d5cd8b96fcb8a18c4d31c34eb6f193bd7dedfada349bacea76e0
MD5 a34fff953d967d49a387be30d20f9402
BLAKE2b-256 7075fb744b04675dd84a45104870583379d9ae6214c5b682929f76f133d0d0c5

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 8d7945fe7622826ae00f5efe427914b65b498d06be22ebde73d94a10f0961c9e
MD5 2fa23863fccc9820b4590af697b86733
BLAKE2b-256 52a95d890ed414f8dac6a82c9bb6f13526b3a16ab889541b057631de33ca9bba

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 1053701aec9a96e0597a55df75d3ce823886794212446c713fd986c3b02f24d7
MD5 dd08501e7a3f9759d004330cb0c65a1d
BLAKE2b-256 02f2b18302b5e9295af1d01d77d57a726c9ba61265078f732f0bfdcade79d3fb

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b86e7c5ec33b52f6d74019a2708813cf41e15e54e6259cc6a2bc92e18ec49740
MD5 b08790d6a03bb829d3f4c1dd177e4a5b
BLAKE2b-256 409728a00cc797f33d4953784a8411dfe32a2ad1cd0a8a5dd11253c08f9db9ab

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 5aec8925394ebd730a386d276a626d36acca0690373fce038fef653498ea7215
MD5 cb1ee470bc0b64157e8204949cead496
BLAKE2b-256 afc0675562824a8d161d57dfdca1e9ecc5f4703cba0275d72cd5f804b44000d5

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 79b060e0b852c349c3e0b4b48e0d67e64e47293dadaf3f7a6eb3a52d2fccd546
MD5 f1e66ab6269265d85949294f6c2e1bf5
BLAKE2b-256 b0536d386a4ccd293ef21a4e7be0fefcb4030adf61f457437e63498150d84480

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a52e89650982cd2ed57f67bca7cdf007107a54a6696f37ab81438275375a615e
MD5 0ed067937b03f5ab48ff7c522bb73041
BLAKE2b-256 335e35f34eb713b87601511ac6930cf3ad2a39c2dc983c1e29bfd98972677978

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp37-cp37m-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 0085ad1d77d7e8c9d826c6a22e31bb46fb4d7489feb5dcbbc60f77f589ea13a7
MD5 488a5a7ed975b2aa346dc00dc85eac05
BLAKE2b-256 5e748747b9b7e46bcb11d15524ac8537f9030e02d0d3a4e245e3a2b1d76adf11

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 d79efac1b7f8edf7cc038d1eb43664be8741bd2543df76e36cb224cb8a3d9ca0
MD5 9af8e2d1b6614058e51e07b55c49172f
BLAKE2b-256 0b691a27b81f99d258751ace22f0acc02b53182f21d56e32f84f93fe959d5c8c

See more details on using hashes here.

File details

Details for the file pygram11-0.12.2-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygram11-0.12.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 099fd26d874b923ef29d44747277da007533eb73f24bc8f96b2fff50fb82a950
MD5 21eebb9b87ada76a1581554043ae639d
BLAKE2b-256 69773baa6b84a6ff3540666f98c01c72edc911d927788013743d096534f3b08f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page