Skip to main content

Morton numbering and indexing for healpix grids

Project description

mortie

Tests CodSpeed codecov PyPI version Python 3.10+ CodSpeed Badge

Morty using mortie

Mortie is a library for applying morton indexing to healpix grids. Morton numbering (also called z-ordering) facilitates several geospatial operators such as buffering and neighborhood look-ups, and can generally be thought of as a type of geohashing.

This particular implementation focuses on hierarchical healpix maps, and is mostly inspired from this paper.

Performance

Mortie uses Rust-accelerated morton indexing functions for high performance. The Rust implementation provides dramatic speedups:

Dataset Size Rust Python (reference) Speedup
1,000 values 1.93 ms 4.14 ms 2.1x
100,000 values 1.85 ms 410.59 ms 222x
1.2M coordinates 102.51 ms 5.1 sec 50x

Pre-built wheels are available for Linux, macOS, and Windows. The Rust extension is required and is included in all pip-installed wheels.

Installation

pip install mortie

For development builds with Rust, see BUILDING.md.

Spatial Buffer

Mortie provides a morton_buffer function for expanding a set of morton cells by a configurable border ring. This is useful for... well, buffering.

import numpy as np
import mortie

# Convert coordinates to morton cells at order 6
cells = np.unique(mortie.geo2mort(lats, lons, order=6))

# Expand by 1-cell ring (8-connected neighbors)
border = mortie.morton_buffer(cells, k=1)
expanded = np.union1d(cells, border)

All input indices must be at the same order. The function returns only the new border cells, not the input cells themselves.

Polygon Coverage

morton_coverage computes the set of morton indices that cover a polygon defined by lat/lon vertices. It uses a top-down hierarchical descent over the HEALPix tree: starting from the 12 base cells it keeps cells inside the polygon, prunes cells outside, and refines cells the boundary passes through down to the requested order. Cost scales with the polygon's boundary, not its area or vertex count, so it stays fast on very large, high-vertex polygons.

import mortie

# Define polygon vertices (lat, lon in degrees)
lats = [40.0, 40.0, 50.0, 50.0]
lons = [-125.0, -115.0, -115.0, -125.0]

# Flat cover — every cell at order 6
cells = mortie.morton_coverage(lats, lons, order=6)

# Compact Multi-Order Coverage — coarse interior, fine boundary (usually far smaller)
moc = mortie.morton_coverage_moc(lats, lons, order=10)

# Adaptive boundary: stop at an angular tolerance, or cap the cell count
moc_tol = mortie.morton_coverage_moc(lats, lons, order=10, tolerance=0.5)   # degrees
moc_bud = mortie.morton_coverage_moc(lats, lons, order=10, max_cells=500)

The function handles concave polygons, antimeridian-crossing polygons, and polar regions. Multipart polygons and holes are supported by passing a list of rings (even-odd fill): disjoint parts are unioned and a nested ring carves a hole, so a donut is [outer, hole]. Helpers compress_moc (merge 4-sibling groups) and moc_to_order (densify a MOC to a flat order) round out the API. See docs/coverage_methods.md for the full method/precision/runtime trade-offs and a benchmark matrix.

Dependencies

numpy. All HEALPix operations use the Rust-native healpix crate bundled in the compiled extension — no external HEALPix library is needed.

Funding

Initial funding of this work was supported by the ICESat-2 project science office, at the Laboratory for Cryospheric Sciences (NASA Goddard, Section 615).

References

[1] Youngren, Robert W., and Mikel D. Petty. "A multi-resolution HEALPix data structure for spherically mapped point data." Heliyon 3.6 (2017): e00332. doi: 10.1016/j.heliyon.2017.e00332

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

mortie-0.7.0.tar.gz (17.9 MB view details)

Uploaded Source

Built Distributions

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

mortie-0.7.0-cp310-abi3-win_amd64.whl (15.1 MB view details)

Uploaded CPython 3.10+Windows x86-64

mortie-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

mortie-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (15.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

mortie-0.7.0-cp310-abi3-macosx_11_0_arm64.whl (15.1 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

mortie-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file mortie-0.7.0.tar.gz.

File metadata

  • Download URL: mortie-0.7.0.tar.gz
  • Upload date:
  • Size: 17.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mortie-0.7.0.tar.gz
Algorithm Hash digest
SHA256 1beeb1c6f26d34eb6deb9a518c92c1b7fe7db4ffca437b15e1984fb4b046b2e6
MD5 1984179f3d7335bd686878a94a36192a
BLAKE2b-256 2676eab1b1166208b12694d6f4863c22e6950bae892495817ab686379d0288b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.7.0.tar.gz:

Publisher: build-wheels.yml on espg/mortie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mortie-0.7.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: mortie-0.7.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 15.1 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mortie-0.7.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6da25819fec2b38d59a8647a5874d9b2e2d00e2708af8fd1d99483b64d02b453
MD5 337e3c7e2979cfbe371803af85bc66ed
BLAKE2b-256 d9c5aee3c98b653ec5bbb7baa19d82298b84bf2df81c71f6f36f1b20d8b2fd77

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.7.0-cp310-abi3-win_amd64.whl:

Publisher: build-wheels.yml on espg/mortie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mortie-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mortie-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 56065a06dde0f2083500e1916d537d3874a54196fb27cb8c85dbd1b7accf501e
MD5 30357fb9e128fba4b01e606ca57fecbf
BLAKE2b-256 656cfb5ee71e8a3bb87a0d0bb7bb5a89b1927c0e2051febc3cb87f8dc28b6cf5

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on espg/mortie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mortie-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mortie-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e3fdc2c9edd22a7a0bb2ea3d92e3aa9476b6f8e4389c7bad32c3ada318bc74d7
MD5 18f895d356e490a029946c5752aff79e
BLAKE2b-256 0652dec507c81d71e9b124ef6d4f216f4f7dfe896eb705b9c5cf0fb771df69ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build-wheels.yml on espg/mortie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mortie-0.7.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mortie-0.7.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 23ad8f03136be0c02dad0f57ab1b841e203bfa02ac70dd2c3e894bb12836a47d
MD5 fa11c54da1d84308f17f1624f89758b5
BLAKE2b-256 0a9a61facf7fc02ae3aa0a73be088679b56370cfca8a342f9d3d63d2df8ccfe2

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.7.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on espg/mortie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mortie-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for mortie-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 891cf6a022456d95fc938b8a68c57c14ee2628e3f791d2b080f7eceda278dd57
MD5 42bc2ea206731b98f4aba8f72424d759
BLAKE2b-256 43272cfebc446759b29f0a3dfea545bbc4ac71c644605b1bce102b65ce216073

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: build-wheels.yml on espg/mortie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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