Skip to content

Encode GZIP_1 and RICE_1 tiles with fitsio-pure - #1

Open
meawoppl wants to merge 1 commit into
sunipkm:masterfrom
meawoppl:meawoppl/fitsio-pure
Open

meawoppl wants to merge 1 commit into
sunipkm:masterfrom
meawoppl:meawoppl/fitsio-pure

Conversation

@meawoppl

@meawoppl meawoppl commented Oct 9, 2026

Copy link
Copy Markdown

Hello nerdy friend.

I maintain fitsio-pure, a pure-Rust FITS library. Its new compress module (0.21.0) writes RICE_1 and GZIP_1 tiles. It's a no_std, wasm-capable port of cfitsio's encoders, checked against cfitsio in CI, and your encoders here were its cross-check (credited in its docs). This PR swaps refimage's rice.rs / gzip.rs for it so you don't have to maintain those codecs. It's a net −452 lines and drops miniz_oxide.

Nothing user-visible changes. HCOMPRESS, the tile grid and your global f32 quantization step all stay in refimage, and every builder setting behaves as before.

Tested against 1.0.0-pre6 on 17 codec/type/tiling cases, at 57×23 and at 26 MP:

  • Every file is the same size, and astropy decodes it identically.
  • The one difference: quantized f32 pixels on a rounding boundary can land one step apart, with the same error bound.
  • Write speed is within about 10% either way.
  • All tests pass, including the cfitsio and astropy round-trips, and it builds for wasm32.
  • One test now checks for ZQUANTIZ = 'NONE' on lossless GZIP floats, which is how cfitsio marks them.

Happy to adjust, or to close it if you'd rather keep the encoders in-tree.

As an aside, OrbitalCommons is doing grants for astronomy maintainers that want to work in the Rust ecosystem, let me know if that is something of interest to you.

fitsio-pure's compress module is a pure-Rust (no_std, wasm32) port of
cfitsio's Rice encoder and tile quantization, checked against cfitsio in its
CI. rice.rs and gzip.rs (461 lines) and the miniz_oxide dependency go.
HCOMPRESS_1, the tile grid and the global f32 quantization step stay here
and are passed through exactly, so every builder setting behaves as before.

Checked against 1.0.0-pre6 on 17 codec x type x tiling cases, at 57x23 and
at 26 MP:
- Every file is the same size, and astropy decodes every case, quantized
  f32 included, to identical values. Metadata cards are unchanged.
- Write time is within about 10% either way; u8 is faster.

Lossless GZIP_1 floats now carry ZQUANTIZ = 'NONE', as cfitsio writes
them, so the float_compresses_both_ways test checks for that.
@sunipkm

sunipkm commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Hey, I was actually looking at your crate and wondering about this myself. Thank you for doing the pull request! I will review and merge when I get a second. I would also really appreciate if you can go over the API surface and give some feedback.

OrbitalCommons sounds interesting, thanks for the lead!

@sunipkm

sunipkm commented Oct 12, 2026

Copy link
Copy Markdown
Owner

I think my current issue is - I have to maintain a FITS writer inside refimage at all. I would love it if we could replace that entirely with fitsio-pure. Replacing just the encoders is not a huge win in my book.

I am more than happy to contribute refimage to OrbitalCommons if it would be interesting to that audience.

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.

2 participants