Skip to content

eivindtostesen/hierarchical_peak_finding

Repository files navigation

Peakoscope

PyPI version Code style: black

Peakoscope is a python package for hierarchical analysis of peak and valley regions in numeric data.

peak plot

  • Peak regions can be nested, for example, when a large peak region contains smaller subpeak regions.
  • A one-pass algorithm that finds all nested regions and orders them into a tree.
  • Trees that can filtered, traversed, partitioned, pruned, grafted and serialized.
  • Optional interfaces: matplotlib, pandas, polars, CLI and object-oriented.

Usage examples

Compute the tree of nested peak regions in a data set:

>>> import peakoscope
>>> data = [10, 30, 40, 30, 10, 50, 70, 70, 50, 80]
>>> peaktree = peakoscope.tree(data)
>>> print(peaktree)
0:10
├─5:10
│ ├─9:10
│ └─6:8
└─1:4
  └─2:3

Print the tree minus its root:

>>> peaktree = peakoscope.tree(data, forest=True)
>>> print(peaktree - peaktree.roots())
5:10
├─9:10
└─6:8
1:4
└─2:3

Print the leaf nodes (which are local maxima in data) and corresponding slices of data:

>>> for leaf in peaktree.leaf_nodes():
...    print(leaf, leaf.subarray(data))
...
9:10 [80]
6:8 [70, 70]
2:3 [40]

Documentation

Demo, tutorials and a glossary:

Authors

License

Copyright (C) 2021-2025 Eivind Tøstesen. This software is licensed under GPL-3.0-or-later

Citation

Citation can include one or more of:

About

Data analysis of peak and valley regions

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors