https://github.com/borgwardtlab/topf
Topological peak filtering
https://github.com/borgwardtlab/topf
peak-detection persistent-homology topological-data-analysis
Last synced: about 1 year ago
JSON representation
Topological peak filtering
- Host: GitHub
- URL: https://github.com/borgwardtlab/topf
- Owner: BorgwardtLab
- License: bsd-3-clause
- Created: 2018-10-18T08:22:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-29T12:04:29.000Z (almost 6 years ago)
- Last Synced: 2025-03-28T02:03:34.295Z (about 1 year ago)
- Topics: peak-detection, persistent-homology, topological-data-analysis
- Language: Python
- Size: 89.8 KB
- Stars: 6
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README

# Topf — Topological peak filtering
`topf` is a small library for Python 3 that permits the detection and
subsequent filtering of peaks in one-dimensional functions. The method
is based on a topological notion of *prominence* or *persistence* of a
peak with respect to all other peaks.
# Dependencies
- Python 3.7
- `numpy`
# Installation
- Clone the repository
- `poetry install` (for local development)
- `pip3 install .` (for global usage)
# Usage
Install the library using `pip3 install topf`. You can then access the
main class, `PersistenceTransformer` by issuing `import topf`. As
a simple example, we load the file `example.txt`, depict its peaks,
and filter the smallest ones:
```python
import topf
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
data = np.genfromtxt('example.txt') # load data
transformer = topf.PersistenceTransformer() # prepare transformer
peaks = transformer.fit_transform(data) # transform data into peaks
# First, let's plot the original data. We can see that there is
# quite a number of relatively small peaks.
plt.subplot(3, 1, 1)
sns.lineplot(x=data[:, 0], y=data[:, 1])
# Second, let's show the transformed data. Here, every non-zero
# point depicts the *prominence* of a peak.
plt.subplot(3, 1, 2)
sns.lineplot(x=peaks[:, 0], y=peaks[:, 1])
# Third, let's show an example of filtering. At present, there is
# no automated way of doing so.
filtered_data = data[peaks[:, 1] > 4] # only keep high peaks
plt.subplot(3, 1, 3)
sns.lineplot(x=data[:, 0], y=data[:, 1], alpha=0.5)
sns.scatterplot(
x=filtered_data[:, 0],
y=filtered_data[:, 1],
)
plt.tight_layout()
plt.show()
```
This file is also available as [`example.py`](examples/example.py) in this
repository (with some minor modifications to simplify usage).
It will result in the following output:

# Licence notice
The icon of this project was created by Freepik from www.flaticon.com and is licensed by CC 3.0 BY.