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

A Live Pointing Run

Fitting after the night is over tells you whether the run was any good when it’s too late to take more stars. A live run refits after every star. You see the model settle as the stars come in, you see how far each new star landed from where the current model predicted, and you can stop when the predictions are good enough. PointingRun does this in a mount driver: you give it each star and the mount’s encoder reading, and it hands back the refitted model.

Simulate a run

The example below runs ten stars through a simulated mount. The mount’s errors are a known six-term model, and each “observation” is the encoder reading that puts the star in the middle of the field, plus a couple of arcseconds of centering error. That lets you compare what the run fits with the truth. At a real telescope, the encoder reading comes from the mount after you’ve centered the star or plate solved the frame.

use celestial_coords::frames::icrs::ICRSPosition;
use celestial_core::angle::Angle;
use celestial_core::constants::ARCSEC_TO_RAD;
use celestial_core::location::Location;
use celestial_pointing::astrometry::{RefractionModelKind, RunRefraction};
use celestial_pointing::frames::{MountReading, PierSide};
use celestial_pointing::model::{model_from_names, Model};
use celestial_pointing::observation::ObsId;
use celestial_pointing::pointer::Pointer;
use celestial_pointing::pointing_run::PointingRun;
use celestial_pointing::run_params::RunWeather;
use celestial_time::scales::utc::utc_from_calendar;

// (name, RA hours, Dec degrees), ICRS
const STARS: [(&str, f64, f64); 10] = [
    ("Regulus", 10.1395, 11.9672),
    ("Dubhe", 11.0621, 61.7510),
    ("Pollux", 7.7553, 28.0262),
    ("Spica", 13.4199, -11.1613),
    ("Alphard", 9.4598, -8.6586),
    ("Alkaid", 13.7923, 49.3133),
    ("Procyon", 7.6550, 5.2250),
    ("Arcturus", 14.2610, 19.1824),
    ("Kochab", 14.8451, 74.1555),
    ("Denebola", 11.8177, 14.5721),
];

// Centering errors in arcseconds, standing in for the observer's.
const NOISE: [(f64, f64); 10] = [
    (1.2, -0.8), (-2.1, 0.4), (0.3, 1.9), (-0.7, -1.5), (1.8, 0.2),
    (-0.4, -2.2), (2.3, 1.1), (-1.6, 0.9), (0.5, -0.3), (-1.1, 1.4),
];

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let weather = RunWeather {
        temperature_c: Some(8.0),
        pressure_hpa: Some(812.0),
        ..RunWeather::default()
    };
    let mut run = PointingRun::new(
        Location::from_degrees(39.0072, -104.881, 1840.0)?,
        Some((2026, 4, 22)),
        weather,
        RunRefraction::FromWeather(RefractionModelKind::Ciddor),
    )?;

    // The errors of the simulated mount, in arcseconds.
    let mut truth = model_from_names(&["IH", "ID", "NP", "CH", "ME", "MA"]);
    for (term, value) in truth.iter_mut().zip([300.0, -200.0, 20.0, 100.0, -80.0, 45.0]) {
        term.value = value;
    }
    let mount = Pointer { model: Model::new(truth)?, ..run.pointer(None) };

    for (n, ((name, ra, dec), (nx, nd))) in STARS.iter().zip(NOISE).enumerate() {
        let star = ICRSPosition::new(Angle::from_hours(*ra), Angle::from_degrees(*dec))?;
        let utc = utc_from_calendar(2026, 4, 22, 4, 2 * n as u8, 0.0)?;
        // East of the meridian the telescope is beyond the pole.
        let east = mount.mount_for(&star, &utc, PierSide::Normal)?.h() < 0.0;
        let side = if east { PierSide::BeyondPole } else { PierSide::Normal };
        let exact = mount.mount_for(&star, &utc, side)?;
        let encoder = MountReading::new(
            exact.h() + nx * ARCSEC_TO_RAD,
            exact.d() + nd * ARCSEC_TO_RAD,
        )?;

        let observation = run.observation(ObsId(n + 1), &star, &utc, None, encoder)?;
        let step = run.add(observation)?;
        let miss = match step.predicted_miss {
            Some(miss) => format!("{miss:7.1}\""),
            None => "      -".to_string(),
        };
        let names: Vec<&str> = step.refit.model.terms().iter().map(|t| t.name.as_str()).collect();
        let rms = step.refit.fit.as_ref().map_or(0.0, |fit| fit.rms);
        println!("{:2} {name:9} miss {miss}  rms {rms:5.2}  {}", n + 1, names.join(" "));
        for line in &step.refit.log {
            println!("     {line}");
        }
    }

    for term in run.model().terms() {
        println!("{:3} {:+8.2} +- {:.2}", term.name, term.value, term.sigma.unwrap_or(0.0));
    }
    std::fs::write("run.dat", run.to_indat()?)?;
    Ok(())
}
 1 Regulus   miss       -  rms  0.00  IH ID
 2 Dubhe     miss   247.9"  rms 146.68  IH ID
 3 Pollux    miss    61.8"  rms 62.38  IH ID CH
 4 Spica     miss   127.4"  rms  5.30  IH ID CH ME MA
 5 Alphard   miss    16.2"  rms  7.36  IH ID CH ME MA
 6 Alkaid    miss     7.7"  rms  1.28  IH ID NP CH ME MA
 7 Procyon   miss     1.3"  rms  1.25  IH ID NP CH ME MA
 8 Arcturus  miss     1.6"  rms  1.27  IH ID NP CH ME MA
 9 Kochab    miss     0.9"  rms  1.23  IH ID NP CH ME MA
10 Denebola  miss     2.4"  rms  1.33  IH ID NP CH ME MA
IH   +299.75 +- 0.54
ID   -199.89 +- 0.74
NP    +21.48 +- 1.36
CH    +98.61 +- 0.58
ME    -80.24 +- 0.52
MA    +44.49 +- 1.18

Each line is one star: the miss the model had predicted before that star was added, the Sky RMS after the refit, and the terms in the model. After one star the Sky RMS is zero, because two terms fit its two residuals exactly. The fitted terms end up within about 1.5 arcseconds of the simulated mount’s errors, which is the size of the centering errors.

How the model grows

A model with six terms can’t be fitted to two stars, so the run grows the model with the number of stars kept:

Stars keptTerms tried
1, 2IH ID
3IH ID CH
4, 5IH ID CH ME MA
6 or moreIH ID NP CH ME MA

From the third star on, each refit vets the model: a term below 2 sigma, or whose removal doesn’t raise the PSD, is dropped. If vetting drops ID, ID is added back for the last fit, because a declination zero point is always there. step.refit.log lists each decision, and was empty in this run because every term was strong enough to keep.

A star below 10° elevation, or within 0.2° of the zenith or a celestial pole, is kept in the run but not fitted: step.rejected is true and the model stays as it was.

The schedule only grows through the six basic terms, which suit a German equatorial mount. To add flexure or harmonics once enough stars are in, call run.automodel(&AutomodelOptions::default()). It searches as FAUTO does and makes the result the run’s model. The stars it masks join the run’s mask.

Read the predicted miss

step.predicted_miss is the distance in arcseconds between where the star really was and where the model before this star said the mount was pointing. It’s the miss you would have seen if you had slewed to the star with that model. It’s None for the first star, when there’s no model yet.

In the run above the miss falls from 248 arcseconds at the second star to 1 or 2 arcseconds from the seventh on, once NP is in the model. That’s the signal to stop: more stars won’t make the pointing better than the centering errors.

A large miss on one star, when the stars around it were predicted well, usually means a bad observation: a misidentified star or a mount that hadn’t settled. run.mask(ObsId(n)) leaves it out and refits, and run.unmask puts it back.

Use the model during the run

run.pointer(eop) returns a Pointer with the run’s current model, site and refraction, so the driver can slew to the next star with the best model so far. The encoder reading you record for that star must still be the raw one. The run measures the mount’s errors from scratch, so a reading with the model applied would measure only what the model missed.

Save the run

run.to_indat() returns the run as INDAT text, and the example writes it to run.dat. The pointing shell reads it like any other INDAT file, so you can look at the plots, try other terms or run FAUTO after the night is over:

*INDAT run.dat
...
*USE IH ID NP CH ME MA
*FIT

       coeff       change     value    sigma

  1     IH       +299.755   +299.75    0.539
  2     ID       -199.892   -199.89    0.741
  3     NP        +21.483    +21.48    1.356
  4     CH        +98.611    +98.61    0.581
  5     ME        -80.243    -80.24    0.516
  6     MA        +44.485    +44.49    1.177

Sky RMS =   1.33
Popn SD =   2.10

Observation #6 is a very weak outlier candidate.

The INDAT file stores the run’s observations, not its mask. Mask the same stars again in the shell.

Next steps