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.

Rust crates

The Rust side is a cargo workspace with two members. mortie-core holds the packed-word codec — the bit layout, encode/decode, the order arithmetic, the decimal-string grammar, and the (depth, nested-ipix) ↔ packed-word pivot — and carries no dependencies at all, so a Rust project can take the codec without inheriting pyo3, numpy, rayon or a HEALPix crate. The root package mortie (library mortie_rustie) is the pyo3 extension this Python package compiles to; it depends on mortie-core and re-exports it, so every Rust path is unchanged. See BUILDING.md for the layout.

Neither crate is published to crates.io yet, so cargo add mortie-core finds nothing today; the crate is only available from this repository. Publishing mortie-core is tracked separately in issue #201.

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).  The coverer is batch-native (one MOC per ring); one polygon is a
# one-group call.
moc, _ = mortie.polygons_to_morton_mocs(lats, lons, [0, len(lats)], order=10)

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

The coverers handle concave polygons, antimeridian-crossing polygons, and polar regions. Multipart polygons and holes are supported by passing a list of rings (even-odd fill) to morton_coverage, or through from_geometry / from_wkb / from_wkt with moc=True (and the Moc object below) for the compact form: disjoint parts are unioned and a nested ring carves a hole, so a donut is [outer, hole]. Of those compact routes only from_wkb (bytes in) and Moc are backend-free, and Moc has no order knob — it covers at the coverer's default finest order. 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.

The Moc object

mortie.moc(...) wraps the same cover as an object, so coverage geometry reads as geometry:

from mortie import moc

cali = moc(cali_geojson)      # multi-order coverage; no order argument
q    = moc(aoi_geojson)       # GeoJSON dicts, ring arrays, or a uint64 word array
assert cali.contains(q)
shards = q.to_order(9)        # fixed-order cast when a consumer's grid wants one

Two layers, and they stay separate. The free moc_* functions above are the kernel / batch layer — words in, words out, no wrapping cost — and they are unchanged and un-deprecated; the batch forms (the keyword-only offsets= spellings of the kernels, plus the batch-native polygons_to_morton_mocs — one polymorphic name per operation since issue #187) stay function-shaped permanently. Moc is ergonomics only: a thin view over the canonical uint64 word array, where every method is a single delegation to one of those kernels. The array stays the interchange format — Moc.__morton_moc__() hands the words back, and any object exposing that dunder is accepted wherever a Moc is.

Vocabulary mirrors MOCpy where it applies, so the crosswalk is short:

MOCpy mortie object mortie kernel
MOC.from_polygon(lon, lat, max_depth=…) Moc.from_polygon(lats, lons), or moc(geojson) polygons_to_morton_mocs(lats, lons, offsets, order=…)
a.union(b), a | b a.union(b), a | b moc_or(a, b)
a.intersection(b), a & b a.intersection(b), a & b moc_and(a, b)
a.difference(b), a - b a.difference(b), a - b moc_minus(a, b)
a.symmetric_difference(b) a.symmetric_difference(b), a ^ b moc_xor(a, b)
b.difference(a).empty() a.contains(b), b.within(a) moc_minus(b, a).size == 0
a.contains_lonlat(lon, lat) — (kernel only) moc_intersects(a, geo2mort(lat, lon, order))
— a.intersects(b) moc_intersects(a, b)
a.degrade_to_order(n).flatten() a.to_order(n) moc_to_order(a, n)
a.complement() — (kernel only) moc_not(a, domain)

Mind the two places where the vocabulary matches but the meaning does not. MOCpy's from_polygon(lon, lat, …) takes its coordinates in the opposite order to Moc.from_polygon(lats, lons, …); and MOCpy's MOC.contains is a point-in-MOC mask (deprecated there in favour of contains_lonlat), not the MOC-in-MOC test a.contains(b) is. a.to_order(n) also densifies when n is finer than the cover, which degrade_to_order(n).flatten() does not.

The predicates are cover algebra, not polygon algebra — both sides dilate their polygons to cell boundaries, so intersects can over-report near a boundary while a False stays decisive. docs/api/moc_object.md carries the conservative-direction table and the full constructor matrix.

mortie.moc is no longer a submodule. It is the constructor as of issue #196; import mortie.moc and from mortie.moc import x break. The flat package names (mortie.moc_to_order, mortie.compress_moc, …) are unchanged and are the supported spelling — see the CHANGELOG.

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

Metadata

Release files for mortie 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mortie 1.0.0
File Size Uploaded
mortie-1.0.0.tar.gz 17.3 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for mortie 1.0.0
File
mortie-1.0.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
mortie-1.0.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
mortie-1.0.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
mortie-1.0.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
mortie-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 92.2 MB

Release files / mortie-1.0.0.tar.gz

Download URL mortie-1.0.0.tar.gz
Size 17.3 MB
Tags Source
SHA-256 checksum
How to use checksums
6bf2cafe25eb34b67e5e662070af558f4b009e1b693dc20a7d0d4b1b9a16a835
BLAKE2b-256 checksum
How to use checksums
07ad5c5402cacddd6fc1aeeb5bb78c354ac06c2e969eff935a8a5652fdbb8b52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / mortie-1.0.0-cp310-abi3-win_amd64.whl

Download URL mortie-1.0.0-cp310-abi3-win_amd64.whl
Size 15.0 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fafee2cd754b4cb6b3d9f219934a64294fdfb9bcdbe1c617b65be809d82c61a3
BLAKE2b-256 checksum
How to use checksums
44f19376382b0dc6a55c63f38a7853a76145692f0ba8cdce3e2247275eea1d29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / mortie-1.0.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mortie-1.0.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 15.0 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
88c52f184020d1be9c2ec58e2dc94c76b0c8dd24ba1e116e358f6e1e1c5bd328
BLAKE2b-256 checksum
How to use checksums
d3fed9a42abd192ebbe79bc62a426aadd7a310b5884407f28ab415e2d1ab670f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / mortie-1.0.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL mortie-1.0.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 15.0 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
fce06afc899fa214735380c5454e7793e3422aaae23e0c093a6f090d4be0ea34
BLAKE2b-256 checksum
How to use checksums
372430e46eda96d74d86366ca27f95ef5882335eaea5cc43c7aec4c9597fab6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / mortie-1.0.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL mortie-1.0.0-cp310-abi3-macosx_11_0_arm64.whl
Size 14.9 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
28e470ca8046ba64a9ec11d76997604582a5d5b52b07111ace5f637b2160621a
BLAKE2b-256 checksum
How to use checksums
0d4dc89fa70da257530586963d369eb26ad7fd4714ad54945698e70fef521687
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / mortie-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL mortie-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 15.0 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
542c2c545e40057befd4c61660fdd095e5ee6e94b1600eaa20e71e02d0d95a24
BLAKE2b-256 checksum
How to use checksums
dec9de91706912ce96553caee79541f9d8e9ee3d1acd357d5ac1eccfc7854b80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

6 release files

0.9.11

6 release files

0.9.10

6 release files

0.9.9

6 release files

0.9.8

6 release files

0.9.7

6 release files

0.9.6

6 release files

0.9.5

6 release files

0.9.4

6 release files

0.9.3

6 release files

0.9.2

6 release files

0.9.1

6 release files

0.9.0

6 release files

0.8.5

6 release files

0.8.4

6 release files

0.8.3

6 release files

0.8.2

6 release files

0.8.1

6 release files

0.8.0

6 release files

0.7.2

6 release files

0.7.1

6 release files

0.7.0

6 release files

0.6.6

6 release files

0.6.5

6 release files

0.6.4

6 release files

0.6.3

6 release files

0.6.2

6 release files

0.6.1

6 release files

0.5.2

6 release files

0.5.1

5 release files

0.5.0

5 release files

0.4.10

5 release files

0.4.8

5 release files

0.4.7

5 release files

0.4.6

5 release files

0.4.5

5 release files

0.4.4

5 release files

0.4.3

5 release files

0.4.0

5 release files

0.3.1

2 release files

0.2.0

2 release files

0.1.0

1 release file

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page