Skip to main content

earthframe-codec

earthframe-codec is a zero-runtime-dependency Python library for bounded, incremental inspection of environmental binary frames. It is designed for telemetry gateways and archive readers that cannot load multi-gigabyte products into memory just to validate a header.

The package exposes one status contract for every input buffer:

  • SCIENCE_VALID_FRAME: structural checks passed.
  • SCIENCE_INCOMPLETE_STREAM: more bytes are required.
  • SCIENCE_CORRUPTED_FRAME: the bytes cannot satisfy the selected format rules.

Scope

The current release provides production-safe structural decoders for GRIB2, BUFR, HDF5 signatures/superblocks, and NEXRAD archive messages. GRIB2 simple packing, BUFR descriptor words, and legacy one-byte radar bins have reusable bitwise primitives. HDF5 object trees and vendor-specific radar message payloads intentionally remain exposed as bounded raw offsets because their layouts depend on version, templates, filters, and local tables.

This is not a claim that one decoder can infer every vendor template or every NetCDF convention. NetCDF4 data is HDF5 storage with NetCDF metadata conventions; callers should use the returned HDF5 superblock information to schedule dataset-specific block reads.

Installation

python -m pip install earthframe-codec

No NumPy, HDF5 C library, or network service is required at runtime. Python 3.10+ is supported.

Streaming integration

from earthframe_codec import FrameDecoder, FrameStatus

reader = FrameDecoder(max_frame_size=256 * 1024 * 1024)
with open("telemetry.bin", "rb", buffering=0) as source:
    while block := source.read(1024 * 1024):
        for result in reader.feed(block):
            if result.status is FrameStatus.SCIENCE_VALID_FRAME:
                print(result.protocol, result.consumed, result.data.keys())
            elif result.status is FrameStatus.SCIENCE_CORRUPTED_FRAME:
                raise ValueError(result.errors)
    for result in reader.feed(b"", final=True):
        print(result.status, result.errors)

FrameDecoder retains a bytearray only for the current incomplete record. decode_frame(memoryview(...)) accepts a caller-owned buffer and does not copy section payloads while validating them. Results copy only small metadata fields; raw payloads are included as bytes where a protocol has no safe universal template.

Protocol fields

GRIB2

The decoder verifies GRIB, edition 2, the 8-byte total length, section lengths, section ordering boundaries, and the 7777 end marker. Section summaries expose raw section bytes plus common fields:

from earthframe_codec.grib2 import unpack_simple_packing
values = unpack_simple_packing(payload, count=nx * ny, bits_per_value=12,
                               reference=reference_value,
                               binary_scale=binary_scale,
                               decimal_scale=decimal_scale)

Grid schemas are returned as metadata rather than guessed coordinates. Common section 3 fields include grid_template, ni, and nj; use the template-specific Earth model and scan-mode flags to reconstruct longitude/latitude arrays.

BUFR

BUFR section boundaries and edition are checked. Section 3 descriptor words are decoded into (F, X, Y) using F=(word >> 14) & 3, X=(word >> 8) & 63, and Y=word & 255. Table B/C/D interpretation is intentionally supplied by the application or station profile because descriptors and local tables evolve independently of the wire framing.

HDF5 / NetCDF4

The HDF5 signature and superblock version/address sizes are checked without reading the full file. root_object_offset, when present in superblock v0, is an absolute file offset suitable for a block scheduler. Dataset filters, fractal heaps, B-trees, and NetCDF attributes must be interpreted against the file's exact HDF5 version and are not safely interchangeable.

NEXRAD

The archive signature, message length, type, and channel are checked. decode_legacy_bins turns byte-valued REF/VEL/SW bins into scaled values while preserving the configured missing sentinel. Vendor message 1/31/packet-structure templates should be decoded by a product-specific adapter using the returned payload.

Development

python -m pip install -e ".[test]"
python -m pytest

The GitHub Actions workflow builds and publishes distributions for version tags matching v*.*.*. Configure PyPI trusted publishing for the repository before pushing a tag.

Release files for earthframe-codec 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for earthframe-codec 0.1.0
File Size Uploaded
earthframe_codec-0.1.0.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for earthframe-codec 0.1.0
File Interpreter ABI Platform
earthframe_codec-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.9 kB

Release files / earthframe_codec-0.1.0.tar.gz

Download URL earthframe_codec-0.1.0.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
518c992f38feb4aa33641d2fc66559520e2df81515b19a364abab12aa217e5ce
BLAKE2b-256 checksum
How to use checksums
dc133cc0c51f514e83afc789bb6f55fcb45eb77933bf89e7aa98a85fa9ae7e08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / earthframe_codec-0.1.0-py3-none-any.whl

Download URL earthframe_codec-0.1.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c36706c0f36c8a85bc2660111c203306de9ccc2b58b0b3b4d7fea4a2b9bc0ed
BLAKE2b-256 checksum
How to use checksums
076f2e99efb59afb7096af5a009964031892ee14efdc56b4af8e44e7f2e28f96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page