Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Solve Your First Image

You have a frame from last night and you want to know exactly where it points: the sky position of every pixel, the plate scale and the field rotation. Finding that out from the stars in the image is called plate solving, and the answer is a WCS (World Coordinate System), the mapping from pixel coordinates to sky coordinates that FITS headers store.

celestial-solver is a plate solver. It detects the stars in your image, matches them against a Gaia DR3 and Hipparcos star catalog, and fits a WCS with lens distortion terms. This page solves one image from the command line and then from Rust.

What you need

  • An image in FITS or XISF, straight from your capture program. Most capture programs write the rough pointing, the time and the optics into the header, and the solver reads them. Hints and Image Metadata covers images without them.
  • A star catalog file. Download one from the catalog folder. The examples use catalog-standard.bin, 2.2 GB. The Star Catalog explains the three sizes and how to choose.
  • The image-solver binary, built with the cli feature:
cargo install --path celestial-solver --features cli

Solve from the command line

The example image is a 2328 x 1760 frame of M106 taken through a 14-inch SCT. Point image-solver at the image and the catalog:

image-solver --image m106.fit --catalog catalog-standard.bin
================================================================================
Creation time ............ 2026-11-29 17:42:41 UTC
Creation software ........ Celestial Image Solver v0.1.1-alpha.2
Reference catalog ........ Gaia DR3 - Celestial Catalog v0.1.1-alpha.2
Linear transformation matrix (sky = matrix * pixel):
 -1.17033237e-5  +1.59491498e-4  -1.26803744e-1
 -1.59558955e-4  -1.18413163e-5  +1.96232683e-1
Projection ............... Gnomonic (TAN-SIP)
Projection origin ........ [1164.500000 880.500000] px -> [RA: 12 18 54.266  Dec: +47 18 38.81]
Resolution ............... 0.575 arcsec/px (linear approximation)
Rotation ................. -85.785 deg (linear approximation)
Reference system ......... ICRS
Observation start time ... 2023-03-20 04:17:45 UTC
Focal distance ........... 2725.60 mm
Pixel size ............... 7.60 um
Field of view ............ 22' 18.6" x 16' 52.5"
Image dimensions ......... 2328 x 1760 px
Image center ............. RA: 12 18 54.240  Dec: +47 18 39.12  ex: -0.026787 px  ey: -0.025739 px
Image bounds:
   top-left          RA: 12 18 09.389  Dec: +47 30 21.12  ex: +0.011043 px  ey: +0.014759 px
   top-right         RA: 12 17 59.911  Dec: +47 08 08.03  ex: -0.019714 px  ey: +0.026397 px
   bottom-left       RA: 12 19 48.782  Dec: +47 29 06.58  ex: +0.016245 px  ey: -0.003358 px
   bottom-right      RA: 12 19 38.740  Dec: +47 06 55.42  ex: +0.002875 px  ey: -0.030406 px
SIP distortion order ..... A=3, B=3
  A_2_0  +7.960367e-7
  A_1_1  -6.321852e-7
  A_0_2  +1.379057e-7
  A_3_0  -1.541029e-9
  A_2_1  -4.614312e-10
  A_1_2  -2.109124e-9
  A_0_3  -7.964577e-10
  B_2_0  -1.469285e-7
  B_1_1  +4.951556e-7
  B_0_2  -5.844659e-7
  B_3_0  -5.513422e-10
  B_2_1  -1.434648e-9
  B_1_2  -5.377468e-10
  B_0_3  -8.729534e-10
Control points ........... 24
Linear RMS ............... 0.5607 px
SIP RMS .................. 0.2055 px
Weighted SIP RMS ......... 0.2056 px
Improvement .............. 63.3%
================================================================================
--- timings ---
  open file:   2.5ms
  solve:       50.6ms
  save files:  2.4us
  total:       53.0ms

The lines to read first:

  • Image center is where the middle of the frame points. The header said 12 18 48.035 +47 15 45.90, so the mount was off by about 3 arcminutes.
  • Resolution and Rotation are the plate scale and the angle from image up to north. “Linear approximation” means they describe the linear part of the fit, before the distortion terms.
  • Focal distance is the effective focal length that the fitted scale implies for the header’s pixel size. The header said 2737 mm.
  • Control points is the number of image stars the final fit used. SIP RMS is the RMS distance between those stars and the places where the solution puts their catalog positions: 0.21 px here.

The report goes to standard output and the timings to standard error, so image-solver ... > m106.txt saves the report alone. The image-solver Command describes every line of the report.

Save the solution

Add --output to write a copy of the image with the WCS in its header:

image-solver --image m106.fit --catalog catalog-standard.bin --output m106.solved.fits

The extension picks the format: .fits, .fit or .fts for FITS, or .xisf. The input file isn’t touched. The new header has the standard FITS WCS cards, with SIP distortion cards when the solver fitted them, so any program that reads a FITS WCS can place the image on the sky. The solver also reads that WCS back, so solving the solved file works and starts from the WCS it holds.

Solve from Rust

The library call is solve(&image, &catalog).run(). It reads the same header values as the command does and returns a SolveResult:

use celestial_catalog::query::catalog::Catalog;
use celestial_images::formats::image::Image;
use celestial_solver::solve::solve;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let img = Image::open("m106.fit")?;
    let catalog = Catalog::open("catalog-standard.bin")?;

    let result = solve(&img, &catalog).run()?;

    let (ra, dec) = result.pixel_to_sky(1163.5, 879.5)?;
    println!("center: RA {ra:.4}°, Dec {dec:.4}°");
    let (sx, sy) = result.wcs.scale_arcsec();
    println!("scale: {sx:.3} x {sy:.3} arcsec/px, rotation {:.2}°", result.wcs.rotation_deg());
    println!("{} stars matched, log-odds {:.1}", result.pairs.len(), result.log_odds);
    match &result.sip {
        Some(sip) => println!("RMS {:.3} px with SIP order {}", sip.rms_px, sip.a_order),
        None => println!("RMS {:.3} px", result.wcs.rms_px),
    }

    result.save_with(&img, "m106.solved.fits")?;
    Ok(())
}
center: RA 184.7260°, Dec 47.3109°
scale: 0.575 x 0.575 arcsec/px, rotation -85.79°
24 stars matched, log-odds 202.3
RMS 0.206 px with SIP order 3

pixel_to_sky and sky_to_pixel apply the full solution, distortion included. They count pixels from 0 at the center of the first pixel, so the center of this 2328 x 1760 frame is (1163.5, 879.5). The FITS header counts from 1 at the same point, and the text report counts from 0 at the outer corner of the first pixel. Those are the same position in three conventions.

result.wcs is the linear fit alone, and result.wcs.rms_px is its RMS, 0.56 px here. When the solver fitted distortion terms, result.sip holds them with their own RMS. log_odds measures how sure the solver is that the match is real. How Solving Works explains it.

save_with writes a solved copy as --output does. To add the WCS to an image you already hold, call result.write_into(&mut img).

The library API is likely to change shape in a later release. The steps and ideas in these pages will stay the same.

Next steps