Skip to main content

Fast histogramming in python built on pybind11 and OpenMP.

Project description

pygram11

Build Status builds.sr.ht status Documentation Status PyPI - Wheel 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 their statistical uncertainties). The API is very simple; documentation can be found here (you'll also find some benchmarks there).

Note: the last version of pygram11 supporting Python 2 is 0.5.2.

Installing

pygram11 only requires NumPy. To build from source you'll need a C++ compiler with C++11 support.

From PyPI

Binary wheels are provided for Linux (starting with version 0.5.0) and macOS (starting with version 0.5.1), they can be installed from PyPI via pip.

pip install pygram11

From conda-forge

For a simple installation process 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) can 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

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. If you have a modern GCC verion on Linux, you probably don't have to worry about anything. If you are on macOS, you'll probably want to install libomp from Homebrew.

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 as a git submodule for installations from source.

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=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

pygram11-0.6.1.tar.gz (149.3 kB view details)

Uploaded Source

Built Distributions

pygram11-0.6.1-cp38-cp38-manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.6.1-cp38-cp38-macosx_10_9_x86_64.whl (325.7 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygram11-0.6.1-cp37-cp37m-manylinux2010_x86_64.whl (1.3 MB view details)

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

pygram11-0.6.1-cp37-cp37m-macosx_10_9_x86_64.whl (322.9 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.6.1-cp36-cp36m-manylinux2010_x86_64.whl (1.3 MB view details)

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

pygram11-0.6.1-cp36-cp36m-macosx_10_9_x86_64.whl (322.9 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.6.1.tar.gz
  • Upload date:
  • Size: 149.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pygram11-0.6.1.tar.gz
Algorithm Hash digest
SHA256 eea52496b4af3b6e0d65414031d2b5124ae598e4e97bcb64b46e5c1b67000e12
MD5 e7fb4bfdb5ef9658d375004c5b04215f
BLAKE2b-256 ea2d9fdf69cb2f00d54b05064d17f14c76a2253951f34408873b5d726e1d6231

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.6.1-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.5

File hashes

Hashes for pygram11-0.6.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 c546c90274943166493af866ad1b104d906ccf90882128c64257b8d4e8bf7d0b
MD5 b45ce03e8394c9c4d99631495c151a58
BLAKE2b-256 bf6580dc2856158be4ec35a083141574ff970c717940eecdce2341a09585453b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.6.1-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 325.7 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pygram11-0.6.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 06d6d6703cdce9719c7c173e5e12e43dc836b8fb15cd05986d48f5198176f805
MD5 ecf585541c664a607f629158032d3b70
BLAKE2b-256 5f93e5543968c26a4c44dd240b9ac1e4831ec1f138900bc85b0d58589c6c8360

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.6.1-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.5

File hashes

Hashes for pygram11-0.6.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6cb31a5ca6c7800f5cb8ef6fe05b6af315d580291c6627a44ac9e40fd8b1e15a
MD5 679af0f66c7c0432584c3234014459ab
BLAKE2b-256 26a5ea77b8c0de06094278be1e407b56211497e16ebe29a338d435cd0f562588

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.6.1-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 322.9 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pygram11-0.6.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b78ed533eabe36cfeb6d83b3f2bc35624d9b62227296f4f6f79760e0861deb2f
MD5 a2115f6d59198fb74c7ded6b8fadf89a
BLAKE2b-256 f389c88f6d915d9ef85a446799e4b3cdc4c70f21bb1cb062c7a8e4d032c6100d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.6.1-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.5

File hashes

Hashes for pygram11-0.6.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 78b5a0fa98070d1bc0fe394f1964cd10b44abf520dad6f06a48da6181a152bef
MD5 1a5697bfe13875df029ed8aa9ff6d6b5
BLAKE2b-256 35b268d6e05c3ff694771621f9890674d799cff8fff8a4583c16ea33819f6246

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.6.1-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 322.9 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pygram11-0.6.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8a85c76dc2f918228ad873dc27b33e711ba77f94c15e5eedb80b603a33947900
MD5 19e3d9a108e393ac0e4433e8a3f854a1
BLAKE2b-256 5467042234e633a40de2790193c3fa338c1d1c7f468c03c5e904eefd04c387e8

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