Asteroid Masses¶
SBN Archive asteroid masses download, parsing, and loading.
See the Asteroid Masses User Guide for concepts and usage.
Download¶
Download the SBN Archive asteroid masses compilation dataset.
Provides a helper to fetch the compil.ast.masses.zip file from the
SBN Archive. Network errors are propagated to the caller so that
higher-level code (e.g. :func:load_asteroid_masses) can decide on
fallback behaviour.
ASTMASS_URL = 'https://sbnarchive.psi.edu/pds4/non_mission/compil.ast.masses.zip'
module-attribute
¶
Default URL for the SBN Archive asteroid masses compilation (ZIP).
download_astmass_file(filepath, *, url=ASTMASS_URL, timeout=_DEFAULT_TIMEOUT)
¶
Download the SBN Archive asteroid masses dataset to filepath.
Creates parent directories if they do not exist. On success the downloaded binary data is written to filepath and the resolved path is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str | Path
|
Destination path for the downloaded file. |
required |
url
|
str
|
URL to fetch. Defaults to :data: |
ASTMASS_URL
|
timeout
|
float
|
HTTP timeout in seconds. Defaults to 120. |
_DEFAULT_TIMEOUT
|
Returns:
| Name | Type | Description |
|---|---|---|
Resolved |
Path
|
class: |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the server returns a non-2xx status. |
TransportError
|
On network-level failures (DNS, timeout, etc.). |
Parsers¶
Parsing utilities for the SBN Archive asteroid masses dataset.
Extracts the fixed-width astmass12.tab table from the downloaded ZIP
archive and converts it into a Polars DataFrame with typed columns for
mass, density, shape, and reference information.
load_astmass_tab_to_dataframe(filepath)
¶
Load the asteroid masses .tab file from a ZIP into a Polars DataFrame.
Opens the ZIP at filepath, searches for an entry whose name ends with
astmass12.tab (to handle subdirectory paths inside the archive),
and parses each line of the fixed-width table by byte-offset slicing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str | Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with 15 typed columns. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If filepath does not exist. |
ValueError
|
If the ZIP does not contain a |
Providers¶
Factory functions for loading the SBN Archive asteroid masses dataset.
Provides convenience functions for loading the asteroid masses compilation as a Polars DataFrame:
- :func:
load_asteroid_masses: Load from cache, downloading fresh data when stale. - :func:
load_astmass_from_file: Load from an arbitrary file path.
load_asteroid_masses(filepath=None, *, max_age_days=_DEFAULT_MAX_AGE_DAYS)
¶
Load asteroid masses from a local cache, downloading when stale.
Checks whether the cached file at filepath exists and is younger than
max_age_days. If the file is missing or stale, a fresh copy of
compil.ast.masses.zip is downloaded from the SBN Archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str | Path | None
|
Path to the cached ZIP file. When |
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 asteroid mass, density, and shape data. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the download fails and no cached file exists. |
Examples:
load_astmass_from_file(filepath)
¶
Load asteroid masses data from a local file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str | Path
|
Path to a |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with asteroid mass, density, and shape data. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist. |
ValueError
|
If the ZIP does not contain |
Examples: