Skip to main content

Compute histograms from XArray data.

Project description

XArray-Histogram

Compute and manipulate histograms from XArray data using BoostHistogram

PyPI GitHub release test status codecov Documentation Status

This package allows to compute histograms from and to XArray data. It relies on the Boost Histogram library giving better performances compared to numpy.histogram and the existing xhistogram. It also brings features such as integer/discrete bins or periodic bins.

Dask arrays are supported.

Vectorized manipulation and analysis of the resulting histogram(s) is provided via an XArray accessor.

Quick examples

Three functions are provided (histogram, histogram2d, and historamdd), similar to those from Numpy:

import xarray_histogram as xh
hist = xh.histogram(data, bins=100, range=(0, 10))

Bins can be specified directly via Boost axes for a finer control. The equivalent of the example above would be:

import boost_histogram.axis as bha
hist = xh.histogram(data, bins=[bha.Regular(100, 0., 10.)])

Multi-dimensional histogram can be computed, here in 2D for instance:

hist = xh.histogramdd(
    temp, chlorophyll,
    bins=[bha.Regular(100, -5., 40.), bha.Regular(100, 1e-3, 10, transform=bha.transform.log))
)

The histograms can be computed on the whole flattened arrays, but we can apply it to only some dimensions. For instance if we have an array of dimensions (time, lat, lon) we can retrieve the time evolution of its histogram:

hist = xh.histogram(temp, bins=[bha.Regular(100, 0., 10.)], dims=['lat', 'lon'])

Weights can be applied. Output histogram can be normalized

Accessor

An Xarray accessor is provided to do some vectorized manipulations on histogram data. Simply import xarray_histogram.accessor, and all arrays can then access methods through the hist property::

import xarray_histogram.accessor

hist = xh.histogram(temp, ...)

hist.hist.edges()
hist.hist.median()
hist.hist.ppf(q=0.75)

See the documentation for more details.

Documentation

Documentation available at https://xarray-histogram.readthedocs.io

Installation

From PyPI:

pip install xarray-histogram

From source:

git clone https://github.com/Descanonge/xarray-histogram
cd xarray-histogram
pip install -e .

TODO

Some features of Boost are not yet available:

  • Growing axes: Dask requires to know in advance the size of output chunks. This could reasonably be supported, at least when applying over the whole array (no looping dimensions).
  • Advanced storage/accumulators: they provide additional values on top of the count of samples falling into a bin. They require more than one number per bin, and a more complex sum of two histograms (possibly making histogram along chunked dimensions impossible).
  • The Unified Histogram Indexing could be implemented in the accessor to facilitate manipulation of histogram arrays.

Requirements

Tests and performance

To compare performances check this notebook.

Other packages

xhistogram already exists. It relies on Numpy functions (searchsorted) and thus does not benefit of some performance upgrades brought by Boost (see performance comparisons).

dask-histogram ports Boost-histogram for Dask. It does not support multi-dimensional arrays: one can still reshape the input array but this can incur performance penalties. Still, as it works directly with boost objects rather than Dask arrays all features of Boost should be available.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xarray_histogram-0.2.2.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xarray_histogram-0.2.2-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file xarray_histogram-0.2.2.tar.gz.

File metadata

  • Download URL: xarray_histogram-0.2.2.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for xarray_histogram-0.2.2.tar.gz
Algorithm Hash digest
SHA256 8f60b19e7dee2c6c4e55cdd5fcb42f1ef2b34b78e94c25b6997f0092ce1a911b
MD5 30e1975caebe6a10ed7fc8d5831c99e2
BLAKE2b-256 f05ec97ffb58df05343cc1ea34bea5658f051b0100e555183b17e0de8d05b909

See more details on using hashes here.

Provenance

The following attestation bundles were made for xarray_histogram-0.2.2.tar.gz:

Publisher: publish-to-pypi.yml on Descanonge/xarray-histogram

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xarray_histogram-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for xarray_histogram-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 90682f9575131e5ea5d96feba5f8679e8c3fae039018d5e38f497696d55ccd5c
MD5 9710d5c7313c9ce99876e4673d1cd74a
BLAKE2b-256 1438d1a8b0c8b7749fde76daa12ec3e63aa052cf37cacc2e9715377ce0197a99

See more details on using hashes here.

Provenance

The following attestation bundles were made for xarray_histogram-0.2.2-py3-none-any.whl:

Publisher: publish-to-pypi.yml on Descanonge/xarray-histogram

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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