Skip to main content

Toolbox for generating alpha shapes (fork of alphashape).

Project description

Contributors Forks Stargazers Issues MIT License


ashp

Fast alpha shapes (concave hulls) for Python — a maintained, numba-accelerated fork of alphashape.
Explore the docs »

Interactive Dashboard · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Performance
  5. Interactive Dashboard
  6. Roadmap
  7. Contributing
  8. License
  9. Contact
  10. Acknowledgments

About The Project

Effect of the alpha parameter

An alpha shape generalises the convex hull of a point cloud: as alpha increases, the hull is carved inward to follow the actual shape of the data — useful for concave hulls, boundary extraction, and footprint generation in 2-D and 3-D.

ashp is a maintained fork of Kenneth E. Bellock's excellent alphashape library. It keeps the original API while adding:

  • A numba-accelerated circumradius core (JIT-compiled, disk-cached, parallel for large meshes) — see Performance.
  • Modern uv packaging with the uv_build backend.
  • An interactive Streamlit + Plotly dashboard for exploring alpha shapes.

Two moons alpha shape Spiral alpha shape

It also works in 3-D, returning a surface mesh:

3-D alpha-shape surface meshes

(back to top)

Built With

  • Python
  • NumPy
  • SciPy
  • Numba
  • Shapely
  • Streamlit
  • Plotly

(back to top)

Getting Started

Prerequisites

  • Python 3.13+
  • uv (recommended) or pip

Installation

Add it to your project:

uv add ashp            # or: pip install ashp

Optional geopandas support:

uv add "ashp[geo]"

Or work on the project itself:

git clone https://github.com/arunoruto/ashp.git
cd ashp
uv sync                # project + test group
uv run pytest          # 13 tests

(back to top)

Usage

from ashp import alphashape, optimizealpha, select_alpha

points = [(0., 0.), (0., 1.), (1., 1.), (1., 0.),
          (0.5, 0.25), (0.5, 0.75), (0.25, 0.5), (0.75, 0.5)]

# Fixed alpha (larger = tighter / more concave; 0 = convex hull):
shape = alphashape(points, alpha=2.0)        # -> shapely geometry

# Pick alpha from the circumradius distribution — fast, outlier-robust, and the
# resulting shape stays stable as the point count changes. Works in 2-D and 3-D:
shape = alphashape(points, select_alpha(points, q=0.9))     # keep 90% of simplices
shape = alphashape(points, select_alpha(points, method="knee"))  # auto cutoff

# 'knee' finds the cutoff automatically at the knee of the sorted circumradius
# curve (the DBSCAN-eps heuristic): it drops the long edges that bridge gaps /
# holes and keeps the homogeneous local connections. alpha_knee() also returns
# the diagnostic curve.
shape = alphashape(points, select_alpha(points, method="band"))
# 'band' targets the centre of the usable alpha range — past the blob, before
# the shape fragments — and is the most point-count-stable of the selectors;
# alpha_sweep() / usable_band() expose the underlying curves and band.

# Or solve for the tightest alpha that keeps every point in one polygon.
# Note: this is a bottleneck statistic — sensitive to outliers and density:
best = optimizealpha(points)
shape = alphashape(points, best)

alphashape accepts 2-D points (returns a shapely Polygon / LineString / Point), 3-D points (returns a trimesh.Trimesh), a MultiPoint, or a geopandas.GeoDataFrame.

A small CLI is included too:

ashp input_points.geojson output_shape.geojson --alpha 2.0

(back to top)

Performance

Two hot paths were optimised relative to the original implementation:

  • The per-simplex circumradius computation is JIT-compiled with numba and cached to disk, parallelising across cores for large meshes. If numba is not installed, it transparently falls back to numpy.
  • The boundary reconstruction is fully vectorised for every dimension (numpy set logic for the perimeter facets in place of a per-simplex Python loop), plus bulk shapely geometry construction in 2-D instead of building shapely objects one edge at a time. Biggest effect in 2-D; 3-D/N-D get a smaller speed-up with byte-identical output.

Together these take a single 4000-point alphashape call from ~1031 ms (the original pure-Python / np.matrix implementation) to ~72 ms — roughly 14×, with bit-identical output. The first call in a fresh environment pays a one-time numba compilation cost before the cache is warm.

(back to top)

Interactive Dashboard

A Streamlit app (using Plotly) lives in apps/dashboard for exploring how alpha and the input distribution shape the result:

uv run --group dashboard streamlit run apps/dashboard/app.py

The gallery images above are produced by assets/generate_images.py (written to assets/img/):

uv run --group dashboard python assets/generate_images.py

(back to top)

Roadmap

  • numba-accelerated circumradius core
  • Interactive Streamlit + Plotly dashboard
  • Documentation gallery image generator
  • True 2-D holes (interior rings) in the reconstruction
  • Interactive 3-D mesh viewer in the dashboard
  • Published documentation site

See the open issues for a full list of proposed features and known issues.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/amazing-feature)
  3. Commit your Changes (git commit -m 'Add some amazing feature')
  4. Push to the Branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please run uv run pytest before opening a PR.

(back to top)

License

Distributed under the MIT License. See LICENSE for more information. Original work © Kenneth E. Bellock.

(back to top)

Contact

Mirza Arnaut - mirza.arnaut45@gmail.com

Project Link: https://github.com/arunoruto/ashp

(back to top)

Acknowledgments

(back to top)

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

ashp-1.4.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ashp-1.4.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file ashp-1.4.0.tar.gz.

File metadata

  • Download URL: ashp-1.4.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ashp-1.4.0.tar.gz
Algorithm Hash digest
SHA256 cc63458b2926d0b28b6ff02d6e0238050d51dfdebd01463bb7b6171b49840a36
MD5 390586f316dafb42213550e8d05e1deb
BLAKE2b-256 4619df2b814463e8c2f31fd3750ff30a8daa3708347234bdf0726eaed339d105

See more details on using hashes here.

File details

Details for the file ashp-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: ashp-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ashp-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71a29e4bc5278faf2fd4a2ef36d4ae4a903307699fc79402ce0ba9e3f9d2b0f3
MD5 4c76fc5225369338092a75ad9bb9407a
BLAKE2b-256 a616033d9a723fa25b596c0d23945f6a84229e184c27c044fadc24e8a6b7f22c

See more details on using hashes here.

Supported by

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