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

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

Uploaded Source

Built Distributions

pygram11-0.8.0-cp38-cp38-manylinux2010_x86_64.whl (265.6 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pygram11-0.8.0-cp38-cp38-manylinux1_x86_64.whl (203.3 kB view details)

Uploaded CPython 3.8

pygram11-0.8.0-cp38-cp38-macosx_10_9_x86_64.whl (396.5 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygram11-0.8.0-cp37-cp37m-manylinux2010_x86_64.whl (263.5 kB view details)

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

pygram11-0.8.0-cp37-cp37m-manylinux1_x86_64.whl (204.5 kB view details)

Uploaded CPython 3.7m

pygram11-0.8.0-cp37-cp37m-macosx_10_9_x86_64.whl (392.5 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygram11-0.8.0-cp36-cp36m-manylinux2010_x86_64.whl (263.5 kB view details)

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

pygram11-0.8.0-cp36-cp36m-manylinux1_x86_64.whl (204.0 kB view details)

Uploaded CPython 3.6m

pygram11-0.8.0-cp36-cp36m-macosx_10_9_x86_64.whl (392.5 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pygram11-0.8.0.tar.gz
  • Upload date:
  • Size: 529.2 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.8.0.tar.gz
Algorithm Hash digest
SHA256 d14a5b792ff17b6f6dea66d045d3033c670d77f81754a17f22f5b0899da77464
MD5 b79ae97cb891543648f300624f02b435
BLAKE2b-256 6971a8386699ec884e370cd40b33081c69dfaa3f9da6dd161c7d553b5290d873

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 265.6 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.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for pygram11-0.8.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b5972e4718283ca161e146fd6089180cbcfd174ae1a270dbe088d937cfa246c4
MD5 739b5f3dd05a163913e6f37363b9596f
BLAKE2b-256 52b12fea671c9fb04ec7903c7e87514d81394b8c96396021c9bd0e9a469d009a

See more details on using hashes here.

File details

Details for the file pygram11-0.8.0-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: pygram11-0.8.0-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 203.3 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for pygram11-0.8.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 def6e43333b5f05b0a2186fa4854382904548a8e1263c32fbfbc689f8712f820
MD5 9f396f1598b8dfc075175d8098fdb7d9
BLAKE2b-256 cc42b285373a3ed2ec5ab5fb3d910073b6a07de59a0527b48a44bb16d42ab69b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 396.5 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.8.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a6310d7ef0c442c82e6d42b6a0310d117458f92dd53be08dcee24aac39e1f5b7
MD5 3497a50908dbfac58cea080110b21396
BLAKE2b-256 41ca90f73975ab3804d4661da4b262046577f4af7d87cd84ecac4305d7df3749

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 263.5 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.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for pygram11-0.8.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a6f860501cf9600befc6d4b9e90ca2edf6327e8b115b08de849ab943a99e99ec
MD5 977bcb331ba53bc88319376ee76150d3
BLAKE2b-256 a8e65ab29884a23763d28b9fc59fd55c2aa6b4a5e35d2946989c41032522a4e9

See more details on using hashes here.

File details

Details for the file pygram11-0.8.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pygram11-0.8.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 204.5 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for pygram11-0.8.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a1fa67ad36e2f091a4938e759722696daf95fac7a1f0f33dd67869fe1a1af248
MD5 16b02e15328db430e8d4faf19a33f8a6
BLAKE2b-256 aba3d47567503397213c7b2789d08680f54c61c0fbd6e7fd06c652f4920099e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 392.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.8.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7408b5a4d883faec2f4709d715bcf15ecdcf9b158cf277836ce4cbfebf5b3b00
MD5 44fe70593f8ee60f14e8dce900c09c04
BLAKE2b-256 c34fa26cec18d40430ac978c8c45a6211aa6f988010666a95a57a82b80e21553

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 263.5 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.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for pygram11-0.8.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f2e882f2163d294cb4216d2fb00bf98c937e48db0508bfcec15d45dd3ca7f36d
MD5 01e6e21b54f0a030536233220cf79693
BLAKE2b-256 81cb2732b65a4566ab0c7261052eb77d391d73e2f90574ef1e1ad3f535f5faf5

See more details on using hashes here.

File details

Details for the file pygram11-0.8.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pygram11-0.8.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 204.0 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for pygram11-0.8.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 72e7ebd531c9ed768a12f03629c082b67a2cab2b6204691862bc27d5881ae3cd
MD5 0981222f19e3e5105bd1579663c9ebbb
BLAKE2b-256 efcafe32eb2861e3b8714607428b86c2921847a82744b2fd6387a4f3f84472e9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygram11-0.8.0-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 392.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.8.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 50ef1f554769457356753252a7e991ba6d5f0d5962207bde18185e0f249bdbd2
MD5 fe04dea09f6a841a6bff7eed010feec3
BLAKE2b-256 8e297ab3ecd468981793af744db9f2f0a856489cfce622518232326484c1f777

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