Skip to content

Add initial FitsChan write support - #5

Open
timj wants to merge 22 commits into
u/timj/phase2-simplifyfrom
u/timj/phase3-fitschan-write
Open

timj wants to merge 22 commits into
u/timj/phase2-simplifyfrom
u/timj/phase3-fitschan-write

Conversation

@timj

@timj timj commented Nov 16, 2026

Copy link
Copy Markdown
Member

No description provided.

timj and others added 22 commits November 15, 2026 10:11
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
FitsSipIntWorld ports C's SIPIntWorld, which MakeIntWorld now calls when
SipOK is set and the WCS Frame has a celestial longitude axis, using its
CRPIX and CD values for the celestial axes. AnalysePoly and
ScalePolyInputs port the fitschan.c helpers, and PolyMap.mergeShift
ports astMergeShift, which AnalysePoly uses. SIP coefficients go into
the store's existing A, B, AP and BP tables through a port of SetItem.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
C's CelestialAxes, SplitMap and SplitMap2 (FitsCelestialAxes), SkySys and
IsSkyOff (FitsSkySys, dates converted through TimeFrame by TDBConv), SkyPole
(FitsSkyPole, with WcsMap.isZenithal) and GetFiducialWCS (FitsFiducial, which
now also holds GetFiducialPPC). WcsNative is shared with the read side. The
-TAB branch throws UnsupportedOperationException ending "needs LutMap".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
fixup! Port the celestial axes of FitsChan writing

Port IsMapTab1D, IsMapTab2D, AdaptLut and ChangePermSplit (FitsMapTab) so the
-TAB branch of CelestialAxes decides as C does, throwing needs FitsTable only
where C creates or uses one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
FitsFsetToStore ports C's FsetToStore, AddVersion, MakeFitsFrameSet,
FitsAxisOrder, ReadCrval and SpectralAxes (no SpecFrame in this
library); FitsOtherAxes ports OtherAxes, LogAxis, AddUnitMaps and
SetAlgCode; FitsPlaneStores holds the descriptions by version letter,
as C's store does. FitsChan.writeForeign now makes the descriptions,
with the method and class names in C's swapped order, and still
returns false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
Port C's FitsFromStore and WcsFromStore (FitsWcsWrite) and wire them
into FitsChan.writeForeign for the FITS-WCS encoding: each version is
written in letter order after the last card describing WCS, with the
SIP coefficients and their orders inside the version loop, a version
missing a required keyword removed, and alternates dropped when the
primary fails. The cards are stored with C's SetValue and SetFits
comment rules (FitsCardList.setValueAsWriter, Similar); FindWcs now
matches C's keyword templates. DATE-OBS is formatted from MJD-OBS with
palDjcal, palDjcl and palDd2tf as C does.

Thirteen fits-wcs rows of wcsconv now match C; the rest give the class
they need. FitsChanWriteTest covers failed and Strict writes, where the
cards go, round trips of the in-scope headers and writes in threads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
Convert the Rust repository's sipok, splitmap, alt_naxes, alt_epoch and
encodings probe cases to JSON and translate their tests, and add the
write test of SkyPoleOracleTest. Only FITS-WCS runs: the cases of the
other encodings are pinned by number, the headers whose read needs
SpecFrame and the cases that need MathMap are listed. Cards are
compared to 4 ULP; the few numbers that a difference of java.lang.Math
from C's libm reaches (a cosine in the CAR rotation, atan2 after an
offset SkyRef), amplified by FitLine's least-squares fit, are compared
within libm rounding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
LogAxis now builds C's test: a package-private FitsLogMap computes what
C's MathMap logs=log(s) / s=exp(logs) computes, is put after the axis
Mapping and the result tested with IsMapLinear. Only when the logarithm
is linear, where C builds the -LOG Mapping holding that MathMap, does the
write throw "needs MathMap"; otherwise the axis goes on to -TAB or the
linear description, as in C. A slightly non-linear axis is now written
linearly within FitsTol as C writes it.

lsst, offset-sky and offset-sky-pole leave the wcsconv deferred list;
the offset SkyFrame headers round-trip as C's do; the cursor oracle's
sky_offset_system_rw is compared within libm rounding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
FitsChan.write's Javadoc now says that only NATIVE writes in front of
the current card, the other encodings after the last card describing
WCS or at the end, and that a failed write leaves the cards as they
were except for a card it replaced before failing, which is lost as in
C. A test pins C's behaviour for that case (C probe: a FITS-PC write
of a TPN FrameSet replaces CRVAL1, then returns 0), and the C quirk is
recorded in docs/rust-c-differences.md.

cardsAreWrittenBeforeTheCurrentCard is renamed cardsGoAfterTheLastWcsCard
to say what it asserts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
Update the report for the final review fixes: the wcsconv and test
counts, the LogAxis gap measured with the review's fuzz, the failed
write that loses a replaced card, and the new tolerances.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
The libm licence of the cursor-oracle cases is 1e-14 relative, five
times the largest difference (2e-15, PC2_1 of sky_offset_system_rw).
The stored poles are compared to 1e-12, C's 15 significant digits of
a value of at most 180.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
C's SpecTrans writes its translations into a FitsChan of their own,
which WcsToStore reads after every card of the header. The
translations are now kept apart from the header's cards and follow
them, so a translation outranks every card with its keyword (a zero
CDELT followed by another CDELT, several CDELTs before a CD matrix),
and a repeated translation keeps its comment by SetFits's rules.
A CTYPE card without a comment no longer clears the comment an
earlier one gave, as C's SetItemC ignores it.

DistortMaps reads NAXIS1 to NAXISn with astGetFitsF, so a NAXISn of a
described axis that is not a number fails the read with AST__FTCNV.

Expected values come from a C probe on the pinned library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
fixup! Report phase 3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DidLSPfwbAELCxqtcAbPhR
@timj
timj added this pull request to stack #4 November 16, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant