Skip to content

Fit navigation minimisation from GCPs as pixels - #265

Draft
mraspaud wants to merge 15 commits into
pytroll:mainfrom
mraspaud:fit-as-pixels
Draft

mraspaud wants to merge 15 commits into
pytroll:mainfrom
mraspaud:fit-as-pixels

Conversation

@mraspaud

Copy link
Copy Markdown
Member

The minimisation from GCP displacements to rectify the navigation of a satellite pass is done todays using metres, which biases the fit towards the edges of the swath.
This PR replaces it with displacements express in pixel units.

Moreover, outliers are now weighted down in the minimisation thanks to the soft_loss parameter.

  • Tests added
  • Fully documented

mraspaud and others added 10 commits November 23, 2026 15:21
The matching measures displacements in swath pixels, at a precision that is
roughly the same fraction of a pixel wherever it looks. A miss in metres
mixes that with the size of the footprint, which grows several times from
nadir to the swath edge.

A fixed local conversion is taken from a one-line and one-sample step at
each gcp, so it can be computed once and reused across a fit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
The geodetic latitude iterates until every point has settled, and a NaN
never compares close to itself, so one control point without a position
held the whole geolocation in an endless loop. It now settles as NaN, and
a gcp that cannot be placed keeps its row among the misses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
The matching is about equally precise, in pixels, anywhere in the swath,
while a pixel at the edge covers several times the ground it does at nadir.
Fitted in metres, the edge outweighs the centre for no better reason than
its footprint; fitted in pixels, each point counts for what it measured.

The fit returns what is left of each gcp's miss alongside the time offset
and attitude, one row per gcp, so how well every displacement was matched
can be kept with the result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
Squared misses let each control point pull in proportion to how far out it
is. On a synthetic pass, two matches fifteen samples out among sixty moved
the time offset by 0.17 s and left every good point half a pixel off.

The fit now uses a soft L1 loss scaled to one pixel by default: misses
within a pixel count as squares, larger ones roughly linearly. It stays
convex, so it cannot settle in a wrong minimum the way a redescending loss
can; cauchy or arctan remove the pull of gross outliers more completely and
can be asked for, as can plain least squares.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
The covariance of the fitted time offset and attitude is taken from the
solver's Jacobian, scaled by the spread of the misses read from their median
absolute deviation, so the bad matches the loss already discounted do not
inflate it again. Over forty synthetic passes with a third of a pixel of
matching noise, the reported standard deviations come within 5 to 20 per
cent of the scatter the fits actually show.

A held parameter keeps zeros: it was asserted, not measured. The
correlation is reported too; time and pitch come out at 0.998 on a pass of
twelve hundred lines, which is what decides whether the split between them
means anything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
A pass refitted later with a richer model, an attitude that drifts along
the track say, is only comparable with the first fit if every choice that
fit made can be reproduced. The conventions are resolved once, up front,
and recorded as the values actually used, so one left to the config is not
written down as nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
Products already quote the leftover distance on the ground, and moving the
fit to swath pixels should not take that figure away from them. It is kept
one value per gcp, NaN where a point could not be placed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
Before the fit in metres can go, what its tests guarded has to be guarded
for its successor: a time found beyond the search when the fit is told
where to look, a time resting on its bound refused, a trusted clock held, a
pitch pinned, a steered swath fitted by a model that turns with it, and
the nadir it is given honoured. The pixel fit already does all of it
through the helpers the two share; these tests keep it so once the old
ones are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
estimate_time_and_attitude_deviations weighs each miss by the footprint it
landed in and lets a few bad matches drag every point that agreed.
fit_navigation judges misses in swath pixels under a robust loss, returns
what it left of each, and says how far its answer can be trusted. The old
fit now says so and points there; its own tests stay until it is removed,
and the behaviour they guard is held by the new fit's tests too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
@mraspaud mraspaud self-assigned this Nov 23, 2026
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.29245% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.52%. Comparing base (9c63846) to head (0e60acc).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pyorbital/geoloc_avhrr.py 98.12% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #265      +/-   ##
==========================================
+ Coverage   93.03%   93.52%   +0.48%     
==========================================
  Files          22       22              
  Lines        4911     5327     +416     
==========================================
+ Hits         4569     4982     +413     
- Misses        342      345       +3     
Flag Coverage Δ
unittests 93.52% <99.29%> (+0.48%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

mraspaud and others added 5 commits November 24, 2026 11:42
The fit in metres logged the distances it left behind; its successor said
nothing, so a run log could not show how well a pass was navigated. It now
logs, at debug level, how many control points it stood on, the time offset
and attitude it found, and the root mean square of what it left, in the
swath lines and samples it fits in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
…s navigation

A root mean square over every control point mixes three things: mismatches,
the matcher's own noise, and navigation the fit did not remove. Only the
last says how good the corrected navigation is.

Mismatches are set aside first, by how far each miss strays from the rest
in robust standard deviations of its two axes; at the 99.9 % radius one
good point in a thousand is lost. What remains is quoted as the trusted
root mean square, and its smooth part across the swath -- a constant,
slopes along and across, and their product -- as the navigation left
wrong. Matching noise differs from point to point and barely reaches it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
…is navigation

The fit's log line now separates what it left: how many points it took for
mismatches, the spread of the rest, and the part of that spread which varies
smoothly across the swath, the navigation still left wrong.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
A reference stands at its true place, but the swath shows it where the line
of sight to it meets the ellipsoid, further from nadir the higher it is. A
fit that compares on the ellipsoid alone takes that for navigation error:
on a NOAA-14 pass over the Andes it tilted the whole pass by 0.1 degrees of
roll to meet the mountains, misplacing the ellipsoid geolocation everywhere,
clouds and sea included.

Given the references' heights, the fit first moves each to where the
satellite sees it, from the satellite's direction at that gcp's own scan
time, and fits as before. The fitted geometry stays that of the ellipsoid,
so the geolocation it yields is still the line of sight meeting the
ellipsoid, as parallax corrections downstream expect. Against an exact
construction of the line of sight, the shortcut used leaves 0.001 pixel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
The trusted root mean square of the control points' misses after a fit
mixes two things: the matcher's own noise, which differs from point to
point, and what the navigation still gets wrong, which is the same for
points close together. Only the second says how far the product is off.

Two trustworthy points between the matcher's window and 150 swath pixels
apart see the same navigation error, so the difference of their misses is
noise alone; its spread, read from the median absolute deviation, is one
point's noise times the square root of two. Pairs closer than the window
share pixels and would share noise, so they are left out. What the noise
leaves of the root mean square is the navigation error, zero when the
noise accounts for all of it, and NaN when too few pairs can be formed.

Mismatches are set aside by the same rule as when the fit is judged, now
shared between the two.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv4ScWgmkP6dNwjQKY7NL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant