Skip to content

DAMIT Asteroid Models

DAMIT asteroid shape model download, parsing, spin computation, and mesh export.

See the DAMIT User Guide for concepts and usage.

Download

Download and extract the DAMIT complete export archive.

Provides helpers to stream-download the large (~1.3 GB) DAMIT complete export tar.gz file and extract it to a directory for fast per-file access. Uses streaming with 1 MB chunks to avoid holding the entire file in memory, and writes to a temporary file with atomic rename on completion.

DAMIT_URL = 'https://damit.cuni.cz/projects/damit/exports/complete/latest' module-attribute

Default URL for the DAMIT complete export (tar.gz).

download_damit_file(filepath, *, url=DAMIT_URL, timeout=_DEFAULT_TIMEOUT)

Stream-download the DAMIT complete export to filepath.

Creates parent directories if they do not exist. The file is first written to a .tmp sibling and atomically renamed on successful completion, preventing partial downloads from corrupting the cache.

Parameters:

Name Type Description Default
filepath str | Path

Destination path for the downloaded archive.

required
url str

URL to fetch. Defaults to :data:DAMIT_URL.

DAMIT_URL
timeout float

HTTP timeout in seconds. Defaults to 600 (10 minutes).

_DEFAULT_TIMEOUT

Returns:

Name Type Description
Resolved Path

class:~pathlib.Path to the written file.

Raises:

Type Description
HTTPStatusError

If the server returns a non-2xx status.

TransportError

On network-level failures (DNS, timeout, etc.).

extract_damit_archive(tar_path, extract_dir)

Extract the DAMIT tar.gz archive to extract_dir.

Uses tarfile.extractall with the data filter on Python 3.12+ for safety, falling back to manual member filtering on older versions. A .extracted marker file is written on success so callers can detect whether the extraction is up-to-date relative to the archive.

Parameters:

Name Type Description Default
tar_path str | Path

Path to the DAMIT tar.gz archive file.

required
extract_dir str | Path

Directory to extract into. Created if it does not exist.

required

Returns:

Name Type Description
Resolved Path

class:~pathlib.Path to extract_dir.

Raises:

Type Description
FileNotFoundError

If tar_path does not exist.

TarError

On archive corruption or read errors.

Parsers

Parsing utilities for the DAMIT asteroid shape model dataset.

Extracts CSV tables and shape files from the DAMIT complete export tar.gz archive. The archive contains tables/ with CSV metadata and files/ with per-asteroid shape models.

The canonical data source is asteroid_models.csv which contains all spin parameters (lambda, beta, period, etc.) alongside physical properties, eliminating the need to parse individual spin.txt files.

build_shape_index(files_dir)

Build a mapping from model ID to relative shape file path.

Walks the files/ directory tree looking for directories matching model_<N> that contain a shape.txt file.

Parameters:

Name Type Description Default
files_dir Path

The files/ directory inside the extracted DAMIT archive.

required

Returns:

Type Description
dict[int, str]

Dictionary mapping model ID (int) to the relative path from

dict[int, str]

files_dir to the shape.txt file (e.g.

dict[int, str]

"asteroid_1/model_42/shape.txt").

load_shape_for_model(filepath, model_id, *, extracted_dir=None)

Load the shape mesh for a specific DAMIT model.

When extracted_dir is provided, looks for the shape file directly on disk (fast O(1) read). Otherwise falls back to scanning the tar.gz archive.

Parameters:

Name Type Description Default
filepath str | Path

Path to the DAMIT tar.gz archive file.

required
model_id int

DAMIT model ID (from the id column of asteroid_models.csv).

required
extracted_dir str | Path | None

Optional path to the extracted archive directory. When provided, the shape file is read directly from disk.

None

Returns:

Type Description
tuple[Array, Array]

Tuple of (vertices, facets) as JAX arrays.

Raises:

Type Description
FileNotFoundError

If filepath does not exist.

KeyError

If no shape file is found for the given model_id.

parse_damit_asteroids_table(filepath, *, extracted_dir=None)

Parse the asteroids.csv table from a DAMIT tar.gz archive.

Reads tables/asteroids.csv from the compressed archive and returns a Polars DataFrame with asteroid identity information. The created and modified timestamp columns are dropped.

When extracted_dir is provided and contains the expected CSV file, it is read directly from disk (fast path) instead of decompressing the tar.gz archive.

Parameters:

Name Type Description Default
filepath str | Path

Path to the DAMIT tar.gz archive file.

required
extracted_dir str | Path | None

Optional path to the extracted archive directory. When provided, the CSV is read directly from disk.

None

Returns:

Type Description
DataFrame

Polars DataFrame with columns: id (Int64), number

DataFrame

(Int64), name (Utf8), designation (Utf8), comment

DataFrame

(Utf8).

Raises:

Type Description
FileNotFoundError

If filepath does not exist.

ValueError

If the archive does not contain asteroids.csv.

parse_damit_models_table(filepath, *, extracted_dir=None)

Parse the asteroid_models.csv table from a DAMIT tar.gz archive.

This table is the canonical source for spin parameters (lambda, beta, period, yorp, jd0, phi0) as well as physical properties (diameter, albedo, thermal inertia) and model quality flags.

When extracted_dir is provided and contains the expected CSV file, it is read directly from disk (fast path) instead of decompressing the tar.gz archive.

Parameters:

Name Type Description Default
filepath str | Path

Path to the DAMIT tar.gz archive file.

required
extracted_dir str | Path | None

Optional path to the extracted archive directory. When provided, the CSV is read directly from disk.

None

Returns:

Type Description
DataFrame

Polars DataFrame with spin and physical property columns.

Raises:

Type Description
FileNotFoundError

If filepath does not exist.

ValueError

If the archive does not contain asteroid_models.csv.

parse_shape_file(shape_text)

Parse a DAMIT shape.txt file into vertices and facets.

The file format is:

  • Line 1: N_vertices N_facets
  • Next N_vertices lines: x y z whitespace-separated coordinates
  • Next N_facets lines: v1 v2 v3 whitespace-separated 1-indexed vertex indices

Facet indices are converted from 1-indexed to 0-indexed.

Parameters:

Name Type Description Default
shape_text str

Raw text content of a shape.txt file.

required

Returns:

Type Description
Array

Tuple of (vertices, facets) where vertices is a

Array

(N, 3) float32 JAX array and facets is a (M, 3)

tuple[Array, Array]

int32 JAX array with 0-indexed vertex references.

Raises:

Type Description
ValueError

If the file format is invalid.

write_shape_index(extracted_dir)

Build and persist the shape index JSON file.

Locates the files/ directory inside extracted_dir, builds the model-ID-to-path mapping, and writes it as extracted_dir/shape_index.json.

Parameters:

Name Type Description Default
extracted_dir Path

Root of the extracted archive.

required

Returns:

Type Description
Path

Path to the written shape_index.json file.

Providers

Factory functions for loading the DAMIT asteroid shape model dataset.

Provides convenience functions for loading DAMIT data as Polars DataFrames and JAX arrays:

  • :func:load_damit_asteroids: Load asteroid identity table from cache.
  • :func:load_damit_models: Load model/spin parameter table from cache.
  • :func:get_damit_spin: Look up spin parameters for a specific asteroid.
  • :func:get_damit_shape: Load shape mesh for a specific model.

get_damit_shape(filepath=None, *, model_id, max_age_days=_DEFAULT_MAX_AGE_DAYS)

Load the shape mesh for a specific DAMIT model.

Downloads the DAMIT archive if needed, extracts it, then reads model_{model_id}/shape.txt directly from disk.

Parameters:

Name Type Description Default
filepath str | Path | None

Path to the cached tar.gz file. When None, uses the default cache location.

None
model_id int

DAMIT model ID (from the id column of the models table).

required
max_age_days float

Maximum acceptable age of the cached file in days. Defaults to 30.

_DEFAULT_MAX_AGE_DAYS

Returns:

Type Description
Array

Tuple of (vertices, facets) where vertices is a

Array

(N, 3) float32 JAX array and facets is a (M, 3)

tuple[Array, Array]

int32 JAX array with 0-indexed vertex references.

Raises:

Type Description
RuntimeError

If the download fails and no cached file exists.

KeyError

If no shape file exists for model_id.

Examples:

from astrojax.datasets import get_damit_shape
vertices, facets = get_damit_shape(model_id=42)
print(vertices.shape, facets.shape)

get_damit_spin(models_df, asteroid_id, *, model_index=0)

Look up spin parameters for an asteroid from a pre-loaded models DataFrame.

Filters the models table by asteroid_id and returns the row at model_index as a dictionary. Multiple models may exist for a single asteroid; use model_index to select among them.

Parameters:

Name Type Description Default
models_df DataFrame

Polars DataFrame as returned by :func:load_damit_models.

required
asteroid_id int

DAMIT asteroid ID (from the asteroid_id column).

required
model_index int

Zero-based index among models for this asteroid. Defaults to 0 (first/best model).

0

Returns:

Type Description
dict

Dictionary with all columns from the matched row, including

dict

spin parameters lambda, beta, period, yorp,

dict

jd0, phi0.

Raises:

Type Description
KeyError

If no models exist for asteroid_id or model_index is out of range.

Examples:

from astrojax.datasets import load_damit_models, get_damit_spin
models = load_damit_models()
spin = get_damit_spin(models, asteroid_id=1)
print(spin["lambda"], spin["beta"], spin["period"])

load_damit_asteroids(filepath=None, *, max_age_days=_DEFAULT_MAX_AGE_DAYS)

Load the DAMIT asteroids table from a local cache, downloading when stale.

Checks whether the cached tar.gz at filepath exists and is younger than max_age_days. If the file is missing or stale, a fresh copy is downloaded from the DAMIT server.

Parameters:

Name Type Description Default
filepath str | Path | None

Path to the cached tar.gz file. When None (the default), uses <cache_dir>/datasets/damit/damit_complete.tar.gz.

None
max_age_days float

Maximum acceptable age of the cached file in days. Defaults to 30.

_DEFAULT_MAX_AGE_DAYS

Returns:

Type Description
DataFrame

Polars DataFrame with columns: id, number, name,

DataFrame

designation, comment.

Raises:

Type Description
RuntimeError

If the download fails and no cached file exists.

Examples:

from astrojax.datasets import load_damit_asteroids
df = load_damit_asteroids()
print(df.shape)

load_damit_models(filepath=None, *, max_age_days=_DEFAULT_MAX_AGE_DAYS)

Load the DAMIT asteroid models table from a local cache, downloading when stale.

The models table contains spin parameters (lambda, beta, period, yorp, jd0, phi0) and physical properties (diameter, albedo, thermal inertia) for all principal-axis rotator models in DAMIT.

Parameters:

Name Type Description Default
filepath str | Path | None

Path to the cached tar.gz file. When None (the default), uses <cache_dir>/datasets/damit/damit_complete.tar.gz.

None
max_age_days float

Maximum acceptable age of the cached file in days. Defaults to 30.

_DEFAULT_MAX_AGE_DAYS

Returns:

Type Description
DataFrame

Polars DataFrame with spin parameter and physical property

DataFrame

columns for all DAMIT models.

Raises:

Type Description
RuntimeError

If the download fails and no cached file exists.

Examples:

from astrojax.datasets import load_damit_models
df = load_damit_models()
print(df.columns)

Spin Computation

JAX rotation and shape operations for DAMIT spin parameters.

Computes body-fixed-to-ecliptic rotation matrices from DAMIT spin parameters, and provides utilities for scaling and rotating asteroid shape vertices. All functions use JAX primitives and are compatible with jax.jit, jax.vmap, and jax.grad.

The rotation model for principal-axis rotators is:

.. math::

R = R_z(\lambda) \cdot R_y(90^\circ - \beta) \cdot R_z(\phi_0 + \frac{360}{P} (t - t_0) \cdot 24 + \frac{1}{2} \dot{\omega} (t - t_0)^2)

where :math:(t - t_0) is in days, :math:P is in hours, and :math:\dot{\omega} (YORP) is in deg/day².

damit_spin_to_rotation(spin_params, target_jd)

Compute the body-to-ecliptic rotation matrix from DAMIT spin parameters.

Implements the principal-axis rotation model used by DAMIT:

R = Rz(lambda) @ Ry(90 - beta) @ Rz(phi0 + 360/P * (t-t0) * 24 + 0.5 * yorp * (t-t0)^2)

where time differences are in days, period P is in hours, and YORP acceleration is in deg/day^2.

Parameters:

Name Type Description Default
spin_params ArrayLike

6-element array [lambda_deg, beta_deg, P_hours, t0_jd, phi0_deg, yorp]. Set yorp=0.0 when absent.

required
target_jd ArrayLike

Julian date at which to evaluate the rotation.

required

Returns:

Type Description
Array

3x3 rotation matrix (body-fixed to ecliptic).

Examples:

import jax.numpy as jnp
from astrojax.datasets import damit_spin_to_rotation

spin = jnp.array([30.0, 60.0, 5.0, 2460000.5, 0.0, 0.0])
R = damit_spin_to_rotation(spin, 2460001.5)
print(R.shape)  # (3, 3)

rotate_shape_points(spin_params, target_jd, vertices)

Rotate shape vertices from body-fixed to ecliptic frame.

Computes the rotation matrix via :func:damit_spin_to_rotation and applies it to all vertex positions: (R @ vertices.T).T.

Parameters:

Name Type Description Default
spin_params ArrayLike

6-element spin parameter array (see :func:damit_spin_to_rotation).

required
target_jd ArrayLike

Julian date at which to evaluate the rotation.

required
vertices ArrayLike

(N, 3) array of body-fixed vertex coordinates.

required

Returns:

Type Description
Array

(N, 3) array of ecliptic-frame vertex coordinates.

Examples:

import jax.numpy as jnp
from astrojax.datasets import rotate_shape_points

spin = jnp.array([30.0, 60.0, 5.0, 2460000.5, 0.0, 0.0])
verts = jnp.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
rotated = rotate_shape_points(spin, 2460001.5, verts)

scale_shape_vertices(vertices, max_extent_m)

Rescale shape vertices so the furthest vertex is at a given distance.

Normalizes the vertex cloud by its current maximum extent (distance from origin to furthest vertex), then scales to max_extent_m.

Parameters:

Name Type Description Default
vertices ArrayLike

(N, 3) array of vertex coordinates.

required
max_extent_m ArrayLike

Desired maximum extent in meters (distance from origin to the furthest vertex after scaling).

required

Returns:

Type Description
Array

(N, 3) array of rescaled vertex coordinates.

Examples:

import jax.numpy as jnp
from astrojax.datasets import scale_shape_vertices

verts = jnp.array([[1.0, 0.0, 0.0], [0.0, 2.0, 0.0]])
scaled = scale_shape_vertices(verts, 100.0)
# Furthest vertex is now at distance 100.0

Mesh Export

Mesh export utilities for DAMIT asteroid shape models.

Provides functions to convert DAMIT shape data (vertices and facets) into standard 3D mesh formats (GLB, STL) via the optional trimesh library. Functions raise :class:ImportError with install instructions if trimesh is not available.

compute_spherical_uvs(vertices)

Compute spherical-projection UV coordinates for mesh vertices.

Projects each vertex onto a unit sphere centred at the mesh centroid and maps the resulting spherical coordinates to the [0, 1] UV range.

Parameters:

Name Type Description Default
vertices ArrayLike

(N, 3) array of vertex coordinates.

required

Returns:

Type Description
ndarray

(N, 2) float32 array of UV coordinates with u in [0, 1]

ndarray

(azimuth) and v in [0, 1] (elevation).

Examples:

from astrojax.datasets import get_damit_shape, compute_spherical_uvs
verts, faces = get_damit_shape(model_id=42)
uvs = compute_spherical_uvs(verts)
print(uvs.shape)  # (N, 2)

export_shape_glb(vertices, facets, filepath)

Export DAMIT shape data to a GLB (binary glTF) file.

Parameters:

Name Type Description Default
vertices ArrayLike

(N, 3) array of vertex coordinates.

required
facets ArrayLike

(M, 3) array of 0-indexed face vertex indices.

required
filepath str | Path

Destination path for the GLB file.

required

Returns:

Name Type Description
Resolved Path

class:~pathlib.Path to the written file.

Raises:

Type Description
ImportError

If trimesh is not installed.

Examples:

from astrojax.datasets import get_damit_shape, export_shape_glb
verts, faces = get_damit_shape(model_id=42)
export_shape_glb(verts, faces, "asteroid.glb")

export_shape_glb_textured(vertices, facets, filepath, texture_image)

Export DAMIT shape data to a textured GLB (binary glTF) file.

Applies a texture to the mesh using spherical UV projection. The texture is embedded as a PBR base-color map in the exported GLB.

Parameters:

Name Type Description Default
vertices ArrayLike

(N, 3) array of vertex coordinates.

required
facets ArrayLike

(M, 3) array of 0-indexed face vertex indices.

required
filepath str | Path

Destination path for the GLB file.

required
texture_image Image

PIL Image to use as the base-color texture.

required

Returns:

Name Type Description
Resolved Path

class:~pathlib.Path to the written file.

Raises:

Type Description
ImportError

If trimesh is not installed.

Examples:

from PIL import Image
from astrojax.datasets import get_damit_shape, export_shape_glb_textured
verts, faces = get_damit_shape(model_id=42)
tex = Image.open("texture.tif")
export_shape_glb_textured(verts, faces, "asteroid.glb", tex)

export_shape_stl(vertices, facets, filepath)

Export DAMIT shape data to an STL file.

Parameters:

Name Type Description Default
vertices ArrayLike

(N, 3) array of vertex coordinates.

required
facets ArrayLike

(M, 3) array of 0-indexed face vertex indices.

required
filepath str | Path

Destination path for the STL file.

required

Returns:

Name Type Description
Resolved Path

class:~pathlib.Path to the written file.

Raises:

Type Description
ImportError

If trimesh is not installed.

Examples:

from astrojax.datasets import get_damit_shape, export_shape_stl
verts, faces = get_damit_shape(model_id=42)
export_shape_stl(verts, faces, "asteroid.stl")

shape_to_trimesh(vertices, facets)

Convert DAMIT shape arrays to a trimesh Trimesh object.

Parameters:

Name Type Description Default
vertices ArrayLike

(N, 3) array of vertex coordinates.

required
facets ArrayLike

(M, 3) array of 0-indexed face vertex indices.

required

Returns:

Name Type Description
A Trimesh

class:trimesh.Trimesh instance.

Raises:

Type Description
ImportError

If trimesh is not installed.

Examples:

from astrojax.datasets import get_damit_shape, shape_to_trimesh
verts, faces = get_damit_shape(model_id=42)
mesh = shape_to_trimesh(verts, faces)
print(mesh.is_watertight)