• Stars
    star
    132
  • Rank 274,205 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python histogram library - histograms as updateable, fully semantic objects with visualization tools. [P]ython [HYST]ograms.

physt Physt logo

P(i/y)thon h(i/y)stograms. Inspired (and based on) numpy.histogram, but designed for humans(TM) on steroids(TM).

The goal is to unify different concepts of histograms as occurring in numpy, pandas, matplotlib, ROOT, etc. and to create one representation that is easily manipulated with from the data point of view and at the same time provides nice integration into IPython notebook and various plotting options. In short, whatever you want to do with histograms, physt aims to be on your side.

ReadTheDocs Join the chat at https://gitter.im/physt/Lobby PyPI downloads PyPI version Anaconda-Server Badge Anaconda-Server Badge Code style: black

Simple example

from physt import h1

# Create the sample
heights = [160, 155, 156, 198, 177, 168, 191, 183, 184, 179, 178, 172, 173, 175,
           172, 177, 176, 175, 174, 173, 174, 175, 177, 169, 168, 164, 175, 188,
           178, 174, 173, 181, 185, 166, 162, 163, 171, 165, 180, 189, 166, 163,
           172, 173, 174, 183, 184, 161, 162, 168, 169, 174, 176, 170, 169, 165]

hist = h1(heights, 10)           # <--- get the histogram data
hist << 190                      # <--- add a forgotten value
hist.plot()                      # <--- and plot it

Heights plot

2D example

from physt import h2
import seaborn as sns

iris = sns.load_dataset('iris')
iris_hist = h2(iris["sepal_length"], iris["sepal_width"], "human", bin_count=[12, 7], name="Iris")
iris_hist.plot(show_zero=False, cmap="gray_r", show_values=True);

Iris 2D plot

3D directional example

import numpy as np
from physt import special_histograms

# Generate some sample data
data = np.empty((1000, 3))
data[:,0] = np.random.normal(0, 1, 1000)
data[:,1] = np.random.normal(0, 1.3, 1000)
data[:,2] = np.random.normal(1, .6, 1000)

# Get histogram data (in spherical coordinates)
h = special_histograms.spherical(data)

# And plot its projection on a globe
h.projection("theta", "phi").plot.globe_map(density=True, figsize=(7, 7), cmap="rainbow")

Directional 3D plot

See more in docstring's and notebooks:

Installation

Using pip:

pip install physt

or conda:

conda install -c janpipek physt

Features

Implemented

  • 1D histograms
  • 2D histograms
  • ND histograms
  • Some special histograms
    • 2D polar coordinates (with plotting)
    • 3D spherical / cylindrical coordinates (beta)
  • Adaptive rebinning for on-line filling of unknown data (beta)
  • Non-consecutive bins
  • Memory-effective histogramming of dask arrays (beta)
  • Understands any numpy-array-like object
  • Keep underflow / overflow / missed bins
  • Basic numeric operations (* / + -)
  • Items / slice selection (including mask arrays)
  • Add new values (fill, fill_n)
  • Cumulative values, densities
  • Simple statistics for original data (mean, std, sem) - only for 1D histograms
  • Plotting with several backends
    • matplotlib (static plots with many options)
    • vega (interactive plots, beta, help wanted!)
    • folium (experimental for geo-data)
    • plotly (very basic, help wanted!)
    • ascii (experimental)
  • Algorithms for optimized binning
    • human-friendly
    • mathematical
  • IO, conversions
    • I/O JSON
    • I/O xarray.DataSet (experimental)
    • O ROOT file (experimental)
    • O pandas.DataFrame (basic)

Planned

  • Rebinning
    • using reference to original data?
    • merging bins
  • Statistics (based on original data)?
  • Stacked histograms (with names)
  • Potentially holoviews plotting backend (instead of the discontinued bokeh one)

Not planned

  • Kernel density estimates - use your favourite statistics package (like seaborn)
  • Rebinning using interpolation - it should be trivial to use rebin (https://github.com/jhykes/rebin) with physt

Rationale (for both): physt is dumb, but precise.

Dependencies

  • Python 3.7+
  • Numpy 1.20+
  • (optional) matplotlib - simple output
  • (optional) xarray - I/O
  • (optional) uproot - I/O
  • (optional) astropy - additional binning algorithms
  • (optional) folium - map plotting
  • (optional) vega3 - for vega in-line in IPython notebook (note that to generate vega JSON, this is not necessary)
  • (optional) xtermcolot - for ASCII color maps
  • (testing) pytest, pandas
  • (docs) sphinx, sphinx_rtd_theme, ipython

Publicity

Talk at PyData Berlin 2018:

Contribution

I am looking for anyone interested in using / developing physt. You can contribute by reporting errors, implementing missing features and suggest new one.

Thanks to:

Patches:

Alternatives and inspirations

More Repositories

1

pydiq

Simple DICOM browser in Python (currently not maintained)
Python
28
star
2

iso639-python

A simple library for working with ISO639-2
Python
17
star
3

eda-polars-way

Tutorial: Exploratory Data Analysis, the Polars Way
Jupyter Notebook
16
star
4

pyearcal

Generate year calendar in Python (used for years 2014-2022 already).
Python
7
star
5

gamma_index

Small Python library for calculation of gamma index.
C
6
star
6

pandas-units-extension

Units extension array for pandas based on astropy
Python
4
star
7

geant4-template

Simple working Geant4 application to fill with your code
C++
4
star
8

g4application-dicom

DICOM plugin for g4application.
C++
4
star
9

advent-of-code-2020

Attempt to revive C++ a bit again.
C++
3
star
10

geant4-hdf5-tools

Tools for use of HDF5 in Geant4
C++
3
star
11

boadata

(B)rowser (O)f (A)rbitrary Data - a Python GUI browser of data.
Python
3
star
12

anonymize_dicom

A Python library for anonymizing DICOM files.
Python
2
star
13

pyvo-prednaska

Presentation and code for the talk at PyVo, March 2017 (in Czech).
Jupyter Notebook
2
star
14

pandas-watching-movies

Jupyter Notebook
2
star
15

g4application

A simple modular application for Geant 4.
C++
2
star
16

scoring_browser

Simple Qt4 & Python application for browsing scoring outputs in Geant4
Python
2
star
17

boaphys

Several physics calculations (for my personal use)
Python
1
star
18

Physt.jl

Physt reimplementation in Julia.
Julia
1
star
19

oookbook

A book exchange website. [discontinued]
1
star
20

chagallpy

[NOT MAINTAINED CURRENTLY] Static, mostly JS-free web gallery based on WOWP framework
Python
1
star
21

py42195

How fast will (a) Python cover 42195 meters? Tiny library for paces & distances.
Python
1
star
22

fbmi-python-course

Jupyter Notebook
1
star