Skip to main content

Python wrapper for the libtinyhtm library.

Project description

PynyHTM

PynyHTM is a Cython based Python wrapper for libtinyhtm, the minimalistic hierarchal triangular mesh library. libtinyhtm, developed by Serge Monkewitz and Walter Landry is based on prior work from Alex Szalay, Gyorgy Fekete and Jim Gray in Searchable Sky Coverage of Astronomical Observations: Footprints and Exposures and Indexing the Sphere with the Hierarchical Triangular Mesh.

Hierarchal triangular meshes(HTM) use the sub-division of triangles, which are projected onto a sphere, to elegantly and efficiently partition the earth or the sky into regions with different identifiers.

Usage sample

The code snippets below are available in this example file. Classes SphericalCoordinate and V3 cover basic functionality for expressing points in 3D space.

from pynyhtm import HTM, SphericalCoordinate, Triangle, V3

# Retrieve HTM ID for a spherical coordinate
sc_1 = SphericalCoordinate(10.1234, -20.1234)
id = sc_1.get_htm_id(level=14)
print(f"HTM-ID for sc_1: {id} at level 14")
# >>> HTM-ID for sc_1: 3278525534 at level 14

# Convert spherical coordinate to vector
v_1 = sc_1.to_v3()

# Retrieve HTM ID for a V3 vector
v_2 = V3(0.1,0.2,0.3)
id = v_2.get_htm_id(level=3)
print(f"HTM-ID for v_2: {id} at level 3")
# >>> HTM-ID for v_2: 986 at level 3

# Conversion from vector to spherical coordinate
sc_2 = v_2.to_sc()

diff = sc_1.angle_separation(sc_2)
print(f"Angle between sc_1 and sc_2 (v2): {diff}")
# >>> Angle between sc_1 and sc_2 (v2): 78.05738774142326

Triangles, instantiated from the Triangle class provide additional information about a trixel within the HTM. They contain the three vertices which make up a Trixel as well as the center and more additional information.

# Retrieve additional information about a triangle within the HTM
triangle = Triangle.from_id(id)
print(f"This triangle is in level {triangle.level}")
# >>> This triangle is in level 3

sc_center = triangle.center.to_sc()
print(f"The center is located at {sc_center}")
# >>> The center is located at SphericalCoordinate({'_latitude': 57.03662706265828, '_longitude': 59.20954536171413})

The HTM class contains more helpers to manage HTM identifiers.

print(f"The Triangle with id {id} is located at level {HTM.get_level(id)}")
# >>> The Triangle with id 986 is located at level 3

print(f"The ID can also be expressed in it's subdivision form: {HTM.id_to_dec(id)}")
# >>> The ID can also be expressed in it's subdivision form: 23122

# Determine the children of a given triangle
children = HTM.children(id)
print(f"Children of {id}: {children}")
# >>> Children of 986: [3944, 3945, 3946, 3947]

# Determine the parent of a given id
parent = HTM.parent(id)
print(f"Parent of {id}: {parent}")
# >>> Parent of 986: 246

# Determine neighbors of a given triangle
neighbors = HTM.neighbors(id)
print(f"The neighbors of {id} are: {neighbors}")
# >>> The neighbors of 986 are: [987, 988, 1017]

# Search IDs within a circle around a given point
ids = HTM.circle_search(center=v_1, radius=0.5, level=7)
print(f"{ids} are located near center with radius 0.5")
# >>> [200104, 200105, 200106, 200107, 200108, 200134] are located near center with radius 0.5

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

pynyhtm-0.1.0.tar.gz (496.8 kB view hashes)

Uploaded Source

Built Distributions

pynyhtm-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

pynyhtm-0.1.0-cp312-cp312-musllinux_1_2_aarch64.whl (1.8 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ ARM64

pynyhtm-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (912.4 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pynyhtm-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (875.1 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

pynyhtm-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

pynyhtm-0.1.0-cp311-cp311-musllinux_1_2_aarch64.whl (1.8 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ ARM64

pynyhtm-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (927.7 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pynyhtm-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (901.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pynyhtm-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

pynyhtm-0.1.0-cp310-cp310-musllinux_1_2_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ ARM64

pynyhtm-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (847.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pynyhtm-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (818.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pynyhtm-0.1.0-cp39-cp39-musllinux_1_2_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

pynyhtm-0.1.0-cp39-cp39-musllinux_1_2_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ ARM64

pynyhtm-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (847.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pynyhtm-0.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (817.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pynyhtm-0.1.0-cp38-cp38-musllinux_1_2_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

pynyhtm-0.1.0-cp38-cp38-musllinux_1_2_aarch64.whl (1.8 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ ARM64

pynyhtm-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (866.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pynyhtm-0.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (835.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

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