Skip to main content

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

License PyPI version

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:

  1. Install a conda (we recommend using miniconda)
  2. Create environment: conda create --name=test-env python=3.9
  3. Activate environment: conda activate test-env
  4. Install dependencies with pip: pip install contour-depth and pip install matplotlib. Other dependencies should be already available.
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

contour_depth-0.0.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

contour_depth-0.0.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file contour_depth-0.0.1.tar.gz.

File metadata

  • Download URL: contour_depth-0.0.1.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

Hashes for contour_depth-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3597a1d7631a7c6c079f020c63e397d0f5940b0cb64dd274bfbe1285343e69ea
MD5 bf7413e397d034e695f8b70210c1e84b
BLAKE2b-256 d29e039f85f415d0133d796dbe4fa104bcbeea09f6f142f4ae49e42ae81f26d3

See more details on using hashes here.

File details

Details for the file contour_depth-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for contour_depth-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 75b9e39e99e41b85b16288ca72634522abc46a0e39279ff59a81c26551ad9957
MD5 69f8c221211e226b55e71f660f44f2c8
BLAKE2b-256 08c1a0616a9fd1fde136cc5d26549e01f51cad8c04127074ef95b3a975b07c3a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page