Skip to main content

mortie

Documentation Tests Docs CodSpeed codecov PyPI version Python 3.10+ CodSpeed Badge Binder

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.

Documentation

The full documentation — the generated API reference alongside the specification, interchange and coverage guides — is published at espg.github.io/mortie. Every page below is rendered there; the in-tree markdown links are the same content at the revision you are reading.

The normative encoding and conventions — the packed-word bit layout, the decimal string grammar, the order 0–29 resolution table, the morton-hive store layout, and the coverage-MOC serializations, all frozen for the 1.x series — are documented in docs/specification.md. Moving a packed word to and from the wider HEALPix ecosystem (cdshealpix / healpy (order, nested-pixel) pairs) is covered in docs/healpix_interchange.md.

Example notebooks

Runnable walkthroughs live in examples/; each opens on Binder from the badge in its first cell. Two of them need no downloads at all — morton_set_algebra.ipynb for the MOC boolean verbs, and toc_temporal_coverage.ipynb for the toc word (temporal order coverage: encoding, the conservative merge, the comparator-free sort, window predicates, and the UTC/GPS boundary).

Performance

Mortie's morton core is a Rust extension and the sole runtime path — there is no Python implementation to fall back on — so performance is reported as absolute throughput rather than a speedup ratio. Encoding (geo2mort) and decoding (mort2geo) run at tens of millions of morton indices per second on one core, staying within roughly 2× across orders 4–29.

See docs/benchmarks.md for the full cross-order table (raw encode / decode throughput and coverage timing at orders 4 / 12 / 18 / 29), regenerated in place by a committed script. Cell counts there are deterministic; timings are machine/run dependent.

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)

Latitude convention. Since 0.10 geo2mort and the coverage kernels take WGS84 geodetic latitude and map it to the authalic sphere, so cells are equal-area on the ellipsoid. Cell ids therefore differ from pre-0.10 mortie and from raw-spherical HEALPix libraries; pass latitude="geodetic-spherical" for the old behaviour. See docs/specification.md §9.

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 — interior regions collapse to a few coarse cells, so a large but simple polygon is cheap. Vertex count still matters (a one-time O(V) edge/seed setup, plus per-boundary-cell work that grows with local edge density), but far more gently than the old O(cells × vertices) approach — a 1M-vertex polygon covers in ~1 s, roughly 40× faster than before.

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

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.9.9.tar.gz (17.1 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.9.9-cp310-abi3-win_amd64.whl (14.9 MB view details)

Uploaded CPython 3.10+Windows x86-64

mortie-0.9.9-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.9 MB view details)

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

mortie-0.9.9-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (14.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

mortie-0.9.9-cp310-abi3-macosx_11_0_arm64.whl (14.8 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

mortie-0.9.9-cp310-abi3-macosx_10_12_x86_64.whl (14.9 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: mortie-0.9.9.tar.gz
  • Upload date:
  • Size: 17.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mortie-0.9.9.tar.gz
Algorithm Hash digest
SHA256 7e93cfde818e894b7c10028793dc29446eefa134390e33bb889e9f7819b11402
MD5 875f2f08799e46378790a812c1c0ac6b
BLAKE2b-256 8a8471a86d13080823b22e8991fdcc055723b23a7c9662fde105fc84a1b5854b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.9.9.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.9.9-cp310-abi3-win_amd64.whl.

File metadata

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

File hashes

Hashes for mortie-0.9.9-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6c7830dc7def3539111b3320b24d72de1edc496ba61cebcc7b1f0c8b07415e22
MD5 4ae3b756bef641aba43e8e4d944f9cbc
BLAKE2b-256 610c72a8eddbaa52f84327f2ff0a40ec134c8580a19e515103d3ad0709c39331

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.9.9-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.9.9-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mortie-0.9.9-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 651c131c3af9c2f2e161185e134c9463af8dcbdd1c277fb451ee36504097d46a
MD5 ec470f0005e92cd741b5091ba085198b
BLAKE2b-256 1c290f1596b8940104b40cb7258b54b9f9e5a8031c6de0b5e99142b02ee269c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.9.9-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.9.9-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mortie-0.9.9-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ca4797669cf5e09db8a09a4c620e50e1d77e807bd08abb9374674083b73658eb
MD5 5111f0d0e66cd2bee6554a3c71005bf5
BLAKE2b-256 8317db493960dcd444515c8b719611e386f5f2a095fcc0615b6d628d39300713

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.9.9-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.9.9-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mortie-0.9.9-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 68c428338681968ecd9bd3a119d68ec95e2fccb933ae90c5535370a2c83f4890
MD5 c719805b95e40a82a45d210535507b33
BLAKE2b-256 ad917a07e62d5b2ce4abfaa7a3f21e9dbb575cb864557ad08b55d74e397ef10e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.9.9-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.9.9-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for mortie-0.9.9-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 712e5e98d8db1fa4bf5f601b12eb4f30e8f5a920d2a4aae64be3fa2b21666359
MD5 09a52905c7a0416767530bc18f5bd592
BLAKE2b-256 bd171d77ce3c5918dadb8b4b22988c6099e7b81b25c4f584a4e283029f0609ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for mortie-0.9.9-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.

Release history Release notifications | RSS feed

0.9.11

6 files

0.9.10

6 files

This release

0.9.9 This release

6 files

0.9.8

6 files

0.9.7

6 files

0.9.6

6 files

0.9.5

6 files

0.9.4

6 files

0.9.3

6 files

0.9.2

6 files

0.9.1

6 files

0.9.0

6 files

0.8.5

6 files

0.8.4

6 files

0.8.3

6 files

0.8.2

6 files

0.8.1

6 files

0.8.0

6 files

0.7.2

6 files

0.7.1

6 files

0.7.0

6 files

0.6.6

6 files

0.6.5

6 files

0.6.4

6 files

0.6.3

6 files

0.6.2

6 files

0.6.1

6 files

0.5.2

6 files

0.5.1

5 files

0.5.0

5 files

0.4.10

5 files

0.4.8

5 files

0.4.7

5 files

0.4.6

5 files

0.4.5

5 files

0.4.4

5 files

0.4.3

5 files

0.4.0

5 files

0.3.1

2 files

0.2.0

2 files

0.1.0

1 file

0.0.0

2 files

Supported by

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