Search the Catalog from Rust
Use this when your program needs the stars around a position: a target list, a finder chart, a check on a mount’s pointing, or your own matching code. The library needs no solver and no network, only a catalog file from Get a Catalog File.
Add the crate
[dependencies]
celestial-catalog = { git = "https://github.com/gaker/celestial" }
# Only for the proper-motion example, to turn a UTC time into TT.
celestial-time = { git = "https://github.com/gaker/celestial" }
The library doesn’t need the cli feature.
Open a file and run a cone search
use celestial_catalog::query::catalog::Catalog;
use celestial_catalog::query::cone::{cone_search, ConeSearchParams};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let catalog = Catalog::open("catalog-small.bin")?;
// The Pleiades: every star brighter than magnitude 4 within 1 degree.
let stars = cone_search(&catalog, &ConeSearchParams {
ra_deg: 56.75,
dec_deg: 24.1167,
radius_deg: 1.0,
max_mag: Some(4.0),
max_results: None,
epoch: None,
})?;
for s in &stars {
println!(
"{:>20} RA {:9.5}° Dec {:+9.5}° mag {:5.2} {:.3}° away",
s.star.source_id, s.ra_deg, s.dec_deg, s.star.mag, s.distance_deg
);
}
Ok(())
}
66714384142368256 RA 56.87125° Dec +24.10494° mag 2.85 0.111° away
65283232316451328 RA 56.45680° Dec +24.36754° mag 3.86 0.367° away
65271996684817280 RA 56.21900° Dec +24.11313° mag 3.70 0.485° away
66526127137440128 RA 57.29069° Dec +24.05321° mag 3.62 0.498° away
Catalog::open maps the file and checks its header and index, so a bad
file fails here instead of partway through a search. It reads no star
records. Keep one Catalog for the life of your program: every search
borrows it, and searches from several threads can share it.
cone_search returns a Vec<ConeSearchResult>, nearest first. Each
result has:
star, theStarRecordas stored in the file.ra_deganddec_deg, the position the search matched on. Without an epoch they’re the stored position.distance_deg, the distance from the search center.
max_mag drops fainter stars before sorting, and max_results keeps the
nearest ones after sorting. Leave both None to get every star in the
cone.
Read a star’s fields
A StarRecord holds the Gaia DR3 source ID, the position and proper
motion at the catalog epoch, the parallax, one magnitude and a set of
flags. The flags say which of the other fields you can trust:
use celestial_catalog::query::catalog::{
Catalog, StarRecord, FLAG_HAS_PARALLAX, FLAG_HAS_PROPER_MOTION, FLAG_RUWE_SUSPECT,
FLAG_SOURCE_HIPPARCOS,
};
use celestial_catalog::query::cone::{cone_search, ConeSearchParams};
fn describe(star: &StarRecord) -> String {
let id = if star.flags & FLAG_SOURCE_HIPPARCOS == 0 {
format!("Gaia DR3 {}", star.source_id)
} else if star.source_id < 0 {
format!("HIP {}", -star.source_id)
} else {
format!("Hipparcos, Gaia DR3 {}", star.source_id)
};
let motion = if star.flags & FLAG_HAS_PROPER_MOTION != 0 {
format!("pm {:+.1}, {:+.1} mas/yr", star.pmra, star.pmdec)
} else {
"no proper motion".to_string()
};
let parallax = if star.flags & FLAG_HAS_PARALLAX != 0 {
format!("parallax {:.2} mas", star.parallax)
} else {
"no parallax".to_string()
};
let ruwe = if star.flags & FLAG_RUWE_SUSPECT != 0 { ", RUWE > 1.4" } else { "" };
format!("{id}: mag {:.2}, {motion}, {parallax}{ruwe}", star.mag)
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let catalog = Catalog::open("catalog-small.bin")?;
let stars = cone_search(&catalog, &ConeSearchParams {
ra_deg: 56.75,
dec_deg: 24.1167,
radius_deg: 1.0,
max_mag: Some(4.5),
max_results: None,
epoch: None,
})?;
for s in &stars {
println!("{}", describe(&s.star));
}
Ok(())
}
Hipparcos, Gaia DR3 66714384142368256: mag 2.85, pm +19.3, -43.7 mas/yr, parallax 8.09 mas
Gaia DR3 65205373152172032: mag 4.17, pm +13.1, -48.4 mas/yr, parallax 7.07 mas, RUWE > 1.4
Gaia DR3 65283232316451328: mag 3.86, pm +19.5, -45.5 mas/yr, parallax 7.67 mas, RUWE > 1.4
Gaia DR3 65271996684817280: mag 3.70, pm +20.5, -46.1 mas/yr, parallax 8.35 mas, RUWE > 1.4
Gaia DR3 66526127137440128: mag 3.62, pm +19.1, -46.2 mas/yr, parallax 8.12 mas, RUWE > 1.4
Gaia DR3 65296907494549120: mag 4.26, pm +16.3, -47.2 mas/yr, parallax 9.54 mas, RUWE > 1.4
Raising the limit to 4.5 brings in Merope and Taygeta, and shows three things about the records:
- Source IDs. A Gaia record has its Gaia DR3 source ID. A Hipparcos record has the Gaia ID of its cross-match when there is one, and its HIP number negated when there isn’t. Alcyone, the first line, is a Hipparcos record because Gaia has no proper motion or parallax for it.
- Stars without a cross-match. Gaia’s Hipparcos cross-match table has
no entry for Merope,
Gaia DR3 65205373152172032, or Taygeta,Gaia DR3 65296907494549120.forge mergepaired each Hipparcos record with the Gaia record 0.07″ or 0.13″ from it, and kept the Gaia record because each has a 5- or 6-parameter solution. A negative-ID record is a Hipparcos star that nothing paired, or one whose Gaia record has no proper motion. - Gaia’s bright stars are often flagged. All five Gaia records here have RUWE above 1.4, which says Gaia’s astrometric solution for them fits poorly. Check the flag before you use a bright Gaia star as a reference position.
pmra includes the cos(Dec) factor, as Gaia gives it, so it’s the motion
across the sky. A record without FLAG_HAS_PROPER_MOTION or
FLAG_HAS_PARALLAX stores zero in that field, which leaves the star in
place when you move it to an epoch.
These are all the flags, as constants in query::catalog:
| Flag | Set when |
|---|---|
FLAG_HAS_PROPER_MOTION | pmra and pmdec are measured |
FLAG_HAS_PARALLAX | parallax is measured |
FLAG_RUWE_SUSPECT | Gaia RUWE is above 1.4, so the astrometric solution may be poor |
FLAG_NO_5PARAM | Gaia has no 5-parameter solution: a 6-parameter one, or position only |
FLAG_BP_RP_EXCESS_SUSPECT | Gaia’s BP/RP flux excess is high, a sign of a blend or an extended source |
FLAG_SOURCE_HIPPARCOS | the record came from Hipparcos, and mag is Hp |
FLAG_5_OR_6_PARAM | Gaia has a 5- or 6-parameter solution |
FLAG_DUPLICATED_SOURCE | Gaia flagged the source as duplicated during its processing |
Move stars to your date
Every position in the file is at the catalog epoch, J2016.0 for the
pre-built files. Set epoch to a TT Julian Date and the search moves each
star to that date, using its proper motion and parallax, before it
measures distances:
use celestial_catalog::query::catalog::Catalog;
use celestial_catalog::query::cone::{cone_search, ConeSearchParams};
use celestial_time::scales::conversions::{ToTAI, ToTT};
use celestial_time::scales::utc::UTC;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let catalog = Catalog::open("catalog-small.bin")?;
// cone_search reads the epoch as TT.
let utc: UTC = "2026-04-10T14:00:00Z".parse()?;
let epoch = utc.to_tai()?.to_tt()?.to_julian_date();
// Barnard's Star, searched at its J2016.0 catalog position.
let stars = cone_search(&catalog, &ConeSearchParams {
ra_deg: 269.4485,
dec_deg: 4.7394,
radius_deg: 0.1,
max_mag: Some(9.0),
max_results: None,
epoch: Some(epoch),
})?;
for s in &stars {
println!("catalog: RA {:.6}° Dec {:+.6}°", s.star.ra, s.star.dec);
println!("2026: RA {:.6}° Dec {:+.6}°", s.ra_deg, s.dec_deg);
println!("{:.1}\" from the search center", s.distance_deg * 3600.0);
}
Ok(())
}
catalog: RA 269.448503° Dec +4.739420°
2026: RA 269.446207° Dec +4.768989°
106.8" from the search center
s.star keeps the stored J2016.0 place, and s.ra_deg and s.dec_deg
hold the moved one. The search matches on the moved place, so a star that
has moved out of the cone isn’t returned.
The catalog has no radial velocities, so the motion uses zero for them.
For Barnard’s Star, which has the largest proper motion of any star, that
leaves out about 0.07″ over these ten years. The
moved place is still an ICRS catalog place. To get where the star appears
from your site, pass it to celestial-coords, as Find the Altitude and
Azimuth of a Star does.
Moving a star costs more than reading it. A 1° search around the Trapezium returns 7,668 stars from the full file, and once the file’s pages were in memory it took 0.6 ms without an epoch and 3.6 ms with one.
Read a cell directly
A cone search is built on two lower-level calls. ang2pix_nest gives the
HEALPix cell that holds a position, and Catalog::stars_in_pixel returns
that cell’s stars as a slice into the file, brightest first:
use celestial_catalog::query::catalog::Catalog;
use celestial_catalog::query::healpix::ang2pix_nest;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let catalog = Catalog::open("catalog-small.bin")?;
let order = catalog.header().order;
// The pixel that holds the center of the Pleiades.
let pixel = ang2pix_nest(order, 56.75, 24.1167)?;
let stars = catalog.stars_in_pixel(pixel);
println!("pixel {pixel}: {} stars", stars.len());
if let (Some(first), Some(last)) = (stars.first(), stars.last()) {
println!("brightest mag {:.2}, faintest mag {:.2}", first.mag, last.mag);
}
Ok(())
}
pixel 463: 100 stars
brightest mag 3.70, faintest mag 12.65
This is the small file’s cap at work: the cell is 55′ across, and it keeps its 100 brightest stars, down to magnitude 12.65. Use the order from the file’s header, because the cell numbers depend on it. A pixel number past the end of the grid returns an empty slice.
Reading cells is useful when you want to walk the whole sky, such as
counting stars or building your own index. For anything shaped like a
circle, use cone_search, which works out the cells for you.
Read the header
Catalog::header returns the values forge wrote:
use celestial_catalog::query::catalog::Catalog;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let catalog = Catalog::open("catalog-small.bin")?;
let header = catalog.header();
println!("order {}, {} pixels", header.order, header.npix);
println!("{} stars to magnitude {}", header.total_stars, header.mag_limit);
println!("positions at J{:.1}", header.epoch);
println!("{} bytes", catalog.file_size());
Ok(())
}
order 6, 49152 pixels
4915200 stars to magnitude 18.5
positions at J2016.0
276037696 bytes
epoch is a Julian year. CatalogHeader also implements Display, which
prints the block that query-catalog info shows.
Handle errors
Every fallible call returns a CatalogError. Opening a file that isn’t
there gives an Io error with the path, and a search with an impossible
center gives InvalidInput:
use celestial_catalog::error::CatalogError;
use celestial_catalog::query::catalog::Catalog;
use celestial_catalog::query::cone::{cone_search, ConeSearchParams};
fn main() -> Result<(), Box<dyn std::error::Error>> {
match Catalog::open("missing.bin") {
Err(CatalogError::Io { context, source }) => println!("{context}: {source}"),
Err(e) => println!("{e}"),
Ok(_) => println!("opened"),
}
let catalog = Catalog::open("catalog-small.bin")?;
let result = cone_search(&catalog, &ConeSearchParams {
ra_deg: 10.0,
dec_deg: 95.0,
radius_deg: 1.0,
max_mag: None,
max_results: None,
epoch: None,
});
if let Err(e) = result {
println!("{e}");
}
Ok(())
}
Failed to open catalog file "missing.bin": No such file or directory (os error 2)
Invalid input: cone search: Dec 95 is outside [-90, 90] degrees
Catalog::open returns InvalidHeader for a file that isn’t a catalog,
is a version 1 file, or has the wrong length, and CorruptTable for a
damaged index. A search rejects a center or radius
that isn’t finite, a negative radius and an epoch that isn’t finite. Any
RA is accepted and reduced to [0°, 360°), and a radius over 180° searches
the whole sky.
Next steps
- To understand what the order and the cap mean for your searches, read How the Catalog File Works.
- To turn catalog places into altitude and azimuth, read From Catalog to Horizon.
- To plate-solve images against the catalog, start with Solve Your First Image.