Python library for computing statistical depth of ensembles of contours. The library supports the Contour Band Depth and Inclusion Depth methods. It also supports finding the ensemble's modes of variation by using depth-based clustering. Finally, it offers visualization utilities like spaghetti plots and Contour Box Plots.
Project description
contour-depth
Python library for computing statistical depth of ensembles of contours. The library supports the Contour Band Depth and Inclusion Depth methods. It also supports finding the ensemble's modes of variation by using depth-based clustering. Finally, it offers visualization utilities like spaghetti plots and Contour Box Plots.
Installation
You can install the library via pip:
pip install contour-depth
Usage
To setup an environment follow the steps:
- Install a conda (we recommend using miniconda)
- Create environment:
conda create --name=test-env python=3.9
- Activate environment:
conda activate test-env
- Install dependencies with pip:
pip install contour-depth
andpip install matplotlib
. Other dependencies should be already available. - To test installation, from the root of the repository run
python visualize.py
. No errors should be raised.
from contour_depth import Depth, Metric
import contour_depth
import matplotlib.pyplot as plt
import scipy.signal
import numpy as np
import time
if __name__ == "__main__":
masks = contour_depth.synthetic_data.three_rings(num_masks=250, num_rows=256, num_cols=256, seed=42)
start = time.time()
#clusters = contour_depth.cluster_inclusion_matrix(masks=masks, num_clusters=3, depth=Depth.EpsilonInclusionDepth, metric=Metric.Depth, kmeans_random_seed=42)
clusters = contour_depth.cluster_optimized_eid(masks=masks, num_clusters=3, metric=Metric.Depth, kmeans_random_seed=42)
print(f"{(time.time() - start)*1000:.2f} ms to compute clusters")
height, width = masks[0].shape
out_image = np.zeros((height, width, 3), dtype=np.float32)
for mask, cluster in zip(masks, clusters):
grown_mask = scipy.signal.convolve2d(mask, np.ones((3, 3)), mode="same") > 0
mask_edge = grown_mask - mask
color = np.random.default_rng(cluster).random(3)
out_image += np.multiply.outer(mask_edge, color)
fig, ax = plt.subplots(1, 1)
ax.imshow(out_image / np.max(out_image))
plt.show()
Citation
If you use this library in your work and would like to cite it, please use the following BibTeX entry:
@misc{author_year_libraryname,
author = {Author Name},
title = {Library Name},
year = {Year},
publisher = {Publisher},
howpublished = {\url{link-to-paper}},
}
License
This project is licensed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file contour_depth-0.0.tar.gz
.
File metadata
- Download URL: contour_depth-0.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61d75f7cdd2c9ca8c350fdcbd46eb13d4c6f55fca19a1920399cde4da826ff60 |
|
MD5 | 2acbebe093f8e8ab0152aa63a1afcd56 |
|
BLAKE2b-256 | 75646d37f33723e0bf69074a38a6248847c0418177e602a75cb82b1fd47e1612 |
File details
Details for the file contour_depth-0.0-py3-none-any.whl
.
File metadata
- Download URL: contour_depth-0.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c88f0169ef7f1fea707499b8d47084768f7bb1a5e0e943ebab6d0d343ba4dce0 |
|
MD5 | 999d4f0a7b9422f0be6783a5f49b172c |
|
BLAKE2b-256 | d4431c2dec09b725eefd353878075d3ad561af79998fc8e1d2b27d34be5ebf65 |