Skip to main content

Fast histogramming in python built on pybind11 and OpenMP.

Project description

pygram11

Actions Status builds.sr.ht status Documentation Status

PyPI version Conda Forge

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

This version

0.7.2

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.7.2.tar.gz (531.9 kB view details)

Uploaded Source

Built Distributions

pygram11-0.7.2-cp38-cp38-manylinux2014_x86_64.whl (384.5 kB view details)

Uploaded CPython 3.8

pygram11-0.7.2-cp38-cp38-manylinux2010_x86_64.whl (360.5 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.7.2-cp38-cp38-macosx_10_9_x86_64.whl (453.9 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygram11-0.7.2-cp37-cp37m-manylinux2014_x86_64.whl (386.3 kB view details)

Uploaded CPython 3.7m

pygram11-0.7.2-cp37-cp37m-manylinux2010_x86_64.whl (362.1 kB view details)

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

pygram11-0.7.2-cp37-cp37m-macosx_10_9_x86_64.whl (449.5 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.7.2-cp36-cp36m-manylinux2014_x86_64.whl (386.2 kB view details)

Uploaded CPython 3.6m

pygram11-0.7.2-cp36-cp36m-manylinux2010_x86_64.whl (361.9 kB view details)

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

pygram11-0.7.2-cp36-cp36m-macosx_10_9_x86_64.whl (449.5 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.7.2.tar.gz
  • Upload date:
  • Size: 531.9 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

Hashes for pygram11-0.7.2.tar.gz
Algorithm Hash digest
SHA256 87dc2595d23c7f603cb55ab430bb21042dd7877a6937517c45eb7887cfd62572
MD5 509064048a1f513ce4f351161747f2a7
BLAKE2b-256 55a6f7159fdfa86b38b4508d045fa28b91d18bfd8cc6d407e2938f980a3bbd55

See more details on using hashes here.

File details

Details for the file pygram11-0.7.2-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: pygram11-0.7.2-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 384.5 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.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.2-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f4b6f23e0509db7dd022579bf4cde6762fa00da27dac3c2098fc4e40d8ea9693
MD5 328b6b2b7b152b9266944a202238163c
BLAKE2b-256 5e0b31cef8dab8b79255aec61ca93b0da67f0f39c776a87aad4ad3901c227ed8

See more details on using hashes here.

File details

Details for the file pygram11-0.7.2-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pygram11-0.7.2-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 360.5 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.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 773d737e184d4004761293f125f42eb7c16e8e75f541d38f0b790bfc059f790a
MD5 fb881088a0b505e9807a4fda1eaf4637
BLAKE2b-256 d3718faf393202c6b078fe24d832027dbe181623129df1cfa3dcb5c1af95c26c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.2-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 453.9 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

Hashes for pygram11-0.7.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 904cd7479ac954976c28365aaae14f0a1f85a98a5c129c040ec5bfd61dde71d0
MD5 a2bd056c9fa464c3c341bf80c5d1e841
BLAKE2b-256 4c1a07da068cd4d2094060ce197ad8e0ed66d14fbb4b2118cd853e2e08e40910

See more details on using hashes here.

File details

Details for the file pygram11-0.7.2-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: pygram11-0.7.2-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 386.3 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.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.2-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9daabe91028b0d00572d5aa37aacf9c367df0583159246003b8eb6a3d6fa88fc
MD5 31b33f39fe108be5d017c14f5e630201
BLAKE2b-256 c06aa8eabfcf7846e4872c1fd01c52ed0e1054346d7a080dfabd0ec867c97fbc

See more details on using hashes here.

File details

Details for the file pygram11-0.7.2-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pygram11-0.7.2-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 362.1 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.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.2-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 66e76c32694377a038142626acc7bdc9b01a9c32759bfc076ea27cd1bb80ebc7
MD5 9870478084ca0e599d6c02a318d37457
BLAKE2b-256 8e9c0ec4e1068bd35560842a3f02004ba971679ab8a89b4da90c77b4e497d22b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.7.2-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 449.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

Hashes for pygram11-0.7.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 696f50b65f5355b849aa23dfc996fb8d9d4a3279bbd68af88d0f2de8a4377b88
MD5 8867611bb5ebc5378224b715a85e7fb1
BLAKE2b-256 96f49b278970e9b15848a8a0c8e8ba398e2be2cedfd13bd0f40cd5b5463f32de

See more details on using hashes here.

File details

Details for the file pygram11-0.7.2-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: pygram11-0.7.2-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 386.2 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.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.2-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e6fca46a9be5105a5f6c9b98823f567c7302e34dab7174a865c782cdade716a
MD5 e2cf30de7554219ab6faf9daf0b0186d
BLAKE2b-256 9303c0653acc311952808edc5af3328d44dec70d268512c8ee9241f987ba6c6d

See more details on using hashes here.

File details

Details for the file pygram11-0.7.2-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pygram11-0.7.2-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 361.9 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.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for pygram11-0.7.2-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 228612c1dd70480cdbc2872e69934f5f4ea3fdae5418670e4626639b84a8305a
MD5 e3c40641d7c15e0f2c47dc048192feef
BLAKE2b-256 7ff29ba205f8b2fe731ff09cddd1e1119e4b4b054000e46100b3fea6e71c618f

See more details on using hashes here.

File details

Details for the file pygram11-0.7.2-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pygram11-0.7.2-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 449.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

Hashes for pygram11-0.7.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3ea712a498fcca5eb3b4b3abadacccf01a0d2ce33c5dee6318cd35082f879be7
MD5 a4fd58607f98f9def134665fa075c2c4
BLAKE2b-256 9668d7620a5d3336b95a59e89f8e7f04bbcd4a62c962979cd930d9a9f3d7327c

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