CCSDS 121.0-B-3 Lossless Data Compression (Rice/Golomb coding)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

OCaml 84.3%
C 9.0%
Shell 1.4%
Dune 1.3%
Other 4.0%
39 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-rice https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-rice
git@git.recoil.org:gazagnaire.org/ocaml-rice git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-rice

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

rice#

Pure OCaml implementation of CCSDS 121.0-B-3 Lossless Data Compression.

Overview#

Rice/Golomb adaptive entropy coding for science instrument data. Used by missions including Mars rovers, JWST, and Earth observation satellites for lossless compression of image and science data.

The codec implements the full CCSDS 121.0-B-3 bitstream format: configurable block size, sample bit depth, reference sample interval, and two prediction modes (unit delay and neighborhood).

Installation#

Install with opam:

$ opam install rice

If opam cannot find the package, it may not yet be released in the public opam-repository. Add the overlay repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install rice

Usage#

(* Configure: 16 samples per block, 16-bit samples. *)
let cfg = Rice.config ~block_size:16 ~bits_per_sample:16 ()

(* Compress + decompress 512 16-bit samples. *)
let data = Bytes.make 1024 '\x00'
let compressed = Rice.compress cfg data

let () =
  match Rice.decompress ~sample_count:512 cfg compressed with
  | Ok original -> assert (Bytes.length original = 1024)
  | Error msg -> Fmt.failwith "decompression failed: %s" msg

(* Use neighborhood predictor for 2D image data. *)
let cfg_2d = Rice.config_with_predictor Neighborhood cfg

API Overview#

  • config -- Create compression configuration: block_size (8-64), bits_per_sample (1-32), rsi
  • compress -- Compress data to CCSDS 121.0-B-3 compliant bitstream
  • decompress -- Decompress with explicit sample count
  • config_with_predictor -- Set prediction mode: Unit_delay or Neighborhood

References#

  • CCSDS 121.0-B-3 -- Lossless Data Compression. Consultative Committee for Space Data Systems, 2020.

Licence#

ISC License. See LICENSE.md for details.