Git Product home page Git Product logo

hierarchical_peak_finding's Introduction

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 and valley regions can be nested, for example, when a large peak region contains smaller subpeak regions.
  • Based on a one-pass algorithm that finds all peak regions and orders them into a tree.
  • Classes for peak/valley objects and tree objects.
  • Optional interfaces to matplotlib, pandas and polars.

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]
>>> print(peakoscope.tree(data))
0:10
├─5:10
│ ├─9:10
│ └─6:8
└─1:4
  └─2:3

From the tree, select default peak regions and print their subarrays of data:

>>> for peak in peakoscope.tree(data).size_filter():
...    print(peak.subarray(data))
... 
[80]
[70, 70]
[30, 40, 30]

Howto files

The github repo contains tutorials and a glossary:

Authors

License

Copyright (C) 2021-2024 Eivind Tøstesen. This software is licensed under GPLv3

Citation

Citation can include one or more of:

hierarchical_peak_finding's People

Contributors

eivindtostesen avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

review-concepts

hierarchical_peak_finding's Issues

Peaks in pandas

Peaks_in_pandas.py has repetitive code and does not seem very pandorable.

PeakTree.filter() parameters

PeakTree.filter is currently the method for finding or selecting peaks. It has a single parameter maxsize, but it is intended to have more parameters. Some of these should be upper or lower bounds on some node properties.

But a conflict arises with new parameters. Some filtering (including bounds) is a function of each node independently. Other filtering (including maxsize) depends on the whole input list, because it may involve some kind of sorting. For example, "smaller than 5" is very different from "smaller than the others".

The order of filtering steps matters if sorting is involved, unlike independent filters that logically are applied as a series of ANDs.

In my opinion, rather than specifying the order of filters as an argument to filter, the order of doing things should be specified by the order of function/method calls.

One pass algorithm

The ongoing move described in issue #15 (from label-indexed, resampled data to position-indexed data) also allows the algorithms to be simplified to fewer passes through data.

Copy, compress or reference data set?

The data set Y could be, for example, a time series of stock prices. The P = PeakTree(Y) object is metadata that describes features of Y.

  • P is standalone: After initialization, it does not depend on the existense of Y. The idea was that Y could be too big to keep in RAM, so keeping it should be optional. In old versions (tags v0.1.0 - v0.2.1), P was typically smaller than Y.
  • In normal usage, as it turned out, Y is kept available all the time (used e.g. for plotting).
  • Since tag v0.3.0, for some data sets, P._data is just Y sorted differently. And P._data is typically almost equal in size to Y. So there is redundancy in storing both Y and P._data.
  • The current version has new slice-like objects: SliceStr that is independent of Y and NumSlice that has a reference to Y and depends on its existence. Should PeakTree also have a reference to Y instead of P._data?
  • In future, Y will be referenced by default, but objects that are independent of Y should be possible.
  • How can an object having a reference to Y (as a data attribute) be serialized? Should Y be (recursively) serialized?
  • There is a NumSlice for each tree node and they should not all serialize Y.
  • In future, if tree pruning is to be developed, then P._data in its current form may not contain sufficient information. But Y will.

CLI

Could be nice to have: Command line interface

Bug in for loop lambdas

for name in ("root_path top_path subtree high_descendants "
"low_descendants full_nodes leaf_nodes "
"branch_nodes linear_nodes").split():
setattr(self, name, lambda n: list(
getattr(self.rootself, name)(n)))
self.set_definitions(**kwargs)

Lambdas defined in for loop become equal

Valleys

Valley finding has not yet been implemented

Repr, str, init

Towards an eval-uable repr, alternate constructors and different str formats (for Peaktree and HyperPeakTree).

Position-based vs label-based indexing

The data set Y could be, for example, a time series of stock prices. The P = PeakTree(Y) object is a tree structure that describes features of Y.

Position-based vs label-based indexing is an issue in three cases:

  1. Y has an integer index, but it also has labels, for example time stamps.
  2. P has internal data as dicts, and each dict has both keys and integer positions (available as P._index).
  3. Peaks are located by starts and stops that can be either integers (as in slices of Y) or labels (pairs of time stamps).

In previous versions

  • The idea was that all indexing should be label-based, since integer positions would be tied to the Y array and not be robust to resampling of the data.
  • Starts and stops should not be necessary to compute, but possible.
  • P's dict keys was argmin labels, which approximately located the peaks.

In future versions, maybe

  • Starts and stops are computed by default. Easier to understand than argmin positions.
  • Integer slice notation will be used to locate peaks, by default. Much more lightweight than pairs of time stamps. But requires Y for reference.
  • P dict keys can be changed freely
  • Label-based indexing of Y should not be expected, but possible

Dataframe notebook(s)

Please create tutorial(s) on how to make dataframes with peaks_in_pandas and peaks_in_polars

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.