rumi

JavaScript

  • Package @asterisk-labs/rumi on npm, for browsers and Node.js 24 or newer.

The JavaScript package reads Rumi Image and Cube files in browsers and Node.js. It opens the complete .rumi file, requests only the byte ranges a read needs, and decodes each frame with the GeoZL WebAssembly package. Indices are zero-based and a Cube reads as (Time, Band, Y, X), as in Python.

Install

npm install @asterisk-labs/rumi

The package is an ES module and installs @asterisk-labs/geozl as its decoder. GeoZL uses wasm64, so decoding needs WebAssembly Memory64. Use Node.js 24 or newer, or a browser with Memory64 support. TypeScript declarations ship in index.d.ts.

import {openRumi} from '@asterisk-labs/rumi';

const dataset = await openRumi('https://example.com/cube.rumi');
const chip = await dataset.read({
  time: [3], bands: [4, 2, 1], window: [1024, 2048, 256, 256],
});
chip.shape;            // [1, 3, 256, 256]
dataset.info().bands;  // band descriptions from the trailer
dataset.info().time;   // POSIX seconds as bigint

Opening a file

Calls that fail throw, or reject their promise, with an Error, TypeError or RangeError. Errors from the decoder pass through unchanged.

openRumi

openRumi(source: RumiSource, options?: OpenOptions): Promise<RumiDataset>

Reads and checks the file header, the directory and the trailer, then resolves to a RumiDataset. It takes three reads and fetches no frame. Anything but a complete .rumi file is refused. GeoZL loads on the first read, and a failed load is tried again on the next one. Datasets opened without geozl options share one GeoZL module.

decoderA Decoder to use instead of GeoZL.
geozlOptions for GeoZL's createGeoZL, such as wasmUrl and locateFile.
maxFrameBytesRefuse a file whose largest decoded frame is bigger than this. Defaults to 1 GiB.
maxMetadataBytesRefuse a directory, frame index or trailer bigger than this. Defaults to 64 MiB.
maxOutputBytesRefuse a read whose result is bigger than this. Defaults to 1 GiB.
maxTimeCoordinatesRefuse a file with more time coordinates than this, counting an interval as two. Defaults to one million.
fetchThe fetch for URL sources. Defaults to globalThis.fetch.
signalAn AbortSignal passed to every range request of a URL source.

Each limit must be a positive safe integer.

const dataset = await openRumi(file, {geozl: {wasmUrl: '/static/geozl.wasm'}});

RumiSource

type RumiSource = ArrayBuffer | SharedArrayBuffer | ArrayBufferView | Blob | string | URL | {
  read(offset: bigint, length: number): Promise<Uint8Array>;
  size(): bigint | Promise<bigint>;
};

Bytes are read from memory and a Blob is sliced per range. A string or URL is fetched with HTTP range requests. Any other object needs read, which returns exactly length bytes as a Uint8Array, and size, which returns the size of the complete file as a bigint.

A server that ignores the range or answers with the wrong Content-Range is refused. Cross-origin responses must expose Content-Range. If they also expose a strong ETag, CORS must allow the If-Match request header, which pins later reads to that object version. An object that changes while it is read fails the read.

Decoder and GeoZLDecoder

interface GeoZLDecoder {
  decompress(frame: Uint8Array, options: {verify: boolean; maxOutputSize: number}):
    ArrayBufferView | ArrayBuffer | SharedArrayBuffer
    | Promise<ArrayBufferView | ArrayBuffer | SharedArrayBuffer>;
}
type Decoder = GeoZLDecoder | ((frame: Uint8Array, options: {verify: boolean; maxOutputSize: number})
  => ArrayBufferView | ArrayBuffer | SharedArrayBuffer
  | Promise<ArrayBufferView | ArrayBuffer | SharedArrayBuffer>);

A decoder replaces GeoZL. It is an object with decompress, such as the one createGeoZL returns, or a bare function. Rumi calls it once per compressed frame, with verify from the read and maxOutputSize set to the frame's decoded size, and refuses a result of any other length.

Reading

RumiDataset

class RumiDataset {
  readonly header: ParsedHeader;
  info(): RumiInfo;
  planRanges(options?: ReadOptions): FrameRange[];
  read(options?: ReadOptions): Promise<ReadResult>;
}

An open file, made only by openRumi. It holds the frame index and no frame data. header is the external header that openRumi rebuilds from the file's directory, described under ParsedHeader.

info

dataset.info(): RumiInfo

Returns a frozen description of the array without reading the file. RumiInfo extends RumiMetadata, which adds the band and time fields to RumiGeoreferencing.

shape[bands, height, width] for an Image and [time, bands, height, width] for a Cube.
axes["band", "y", "x"] or ["time", "band", "y", "x"].
dtypeThe sample type, a DType.
tileShapeTile height and width.
gridShapeTiles down and across.
frameUnitThe frame_unit code, 0 to 9.
frameLayoutThe axes of one decoded frame, such as "h w t b".
frameCountNumber of frames in the file.
transformThe affine coefficients [x_res, row_rot, x_origin, col_rot, y_res, y_origin], or null when the file has no CRS.
epsgThe EPSG code, or null.
crsThe code as a string such as "EPSG:4326", or null.
pixelIsPointtrue for PixelIsPoint and false for PixelIsArea.
bandsOne description per band, from the trailer.
timeOne RumiTime per time step.
timeKind"instant" or "interval".

read

dataset.read(options?: ReadOptions): Promise<ReadResult>

Fetches and decodes the frames a selection touches and copies the window out of them. Each frame is fetched once, and up to eight are read and decoded at a time. Selections keep their order and repeats, so bands: [2, 0, 2] returns three planes. An option left out selects the whole axis.

timeTime indices. An Image accepts only one.
bandsBand indices.
window[y, x, height, width] in pixels. It must be non-empty and inside the image.
verifyHave GeoZL check the frame checksums. Defaults to true.

An index list is an array or a typed array, the IndexArray type, and cannot be empty. The result is a frozen ReadResult.

dataThe samples as a dtype.ArrayType over the same buffer as bytes.
bytesThe samples as raw little-endian bytes.
shape[bands, height, width] for an Image and [time, bands, height, width] for a Cube, sized by the selection.
axesAs in info.
dtypeThe sample type.

It rejects an index out of range, a result bigger than maxOutputBytes, a short read from the source and a decoded frame of the wrong size.

const rgb = await dataset.read({bands: [3, 2, 1], window: [0, 0, 256, 256]});
rgb.shape;  // [3, 256, 256] for an Image

planRanges

dataset.planRanges(options?: ReadOptions): FrameRange[]

Returns the compressed frames that read would fetch for the same options, without fetching or decoding them. Each frame appears once, in file order.

frameIndexThe frame's position in the frame index.
offsetIts byte offset in the file, as a bigint.
lengthIts compressed size in bytes.

Types

DType

interface DType {
  readonly code: number;
  readonly name: string;
  readonly sampleFormat: number;
  readonly bits: number;
  readonly bytes: number;
  readonly componentBytes: number;
  readonly ArrayType: TypedArrayConstructor;
}

A frozen sample type, one of the 21 in the spec. code is the rumi_dtype value of the C API and name its name, such as "uint16" or "bfloat16". sampleFormat and bits are the SampleFormat and BitsPerSample values stored in the file. bytes is the size of one decoded sample and componentBytes the size of one element of ArrayType, the typed array behind data.

nativeThe eight integer types, float32 and float64 use their own typed array, with BigUint64Array and BigInt64Array for 64-bit integers.
float16, bfloat16Uint16Array of the raw bits.
float8, boolUint8Array for the five float8 types and bool. A bool read refuses a byte other than 0 or 1.
complexThe component array, two elements per sample with the real part first. Uint16Array for complex32, Float32Array for complex64 and Float64Array for complex128.

TypedArray is the union of the ten typed arrays data can be, and TypedArrayConstructor the type of ArrayType. data needs a little-endian host.

RumiTime

type RumiTime = bigint | readonly [start: bigint, end: bigint];

A time coordinate in exact POSIX seconds. A file of instants holds one bigint per time step, and a file of intervals holds a [start, end] pair.

ParsedHeader

header.frameOffset(index: number): bigint
header.frameByteCount(index: number): number
header.frameIndex(spatial: number, band: number, time: number): number

The frozen header behind dataset.header. The methods give a frame's byte offset in the file, its compressed size, and the frame that holds a tile, band and time, where spatial is row * tilesAcross + column. The first two refuse an index out of range.

width, heightImage size in pixels.
bands, timeCountNumber of bands and time steps. An Image has one time step.
dtypeThe sample type.
tileWidth, tileHeightTile size in pixels.
tilesAcross, tilesDownThe tile grid.
frameUnitThe frame_unit code.
frameAxes, frameLayoutThe axes of one decoded frame, as names such as ["y", "x", "band"] and as letters such as "h w b".
timeFirsttrue for frame_unit 9, whose index walks time before band.
frameCountNumber of frames.
maxDecodedFrameBytes in the largest decoded frame.
baseFrameOffsetByte offset of the first frame, as a bigint.
countMin, countBitsThe smallest frame byte count and the bit width of the packed residuals.

Playground

The package has a small MapLibre viewer in bindings/javascript/playground. Paste a public .rumi URL or drop a local file, choose bands and render it over the map. The viewer reads band descriptions, time coordinates, frame layout, tile grid and georeferencing from the file.

cd bindings/javascript
npm install
npm run playground

Then open http://127.0.0.1:4321/. From the repository root, make playground starts it too. To view a local file, start the server with node playground/server.mjs --sample /path/to/image.rumi and open http://127.0.0.1:4321/?url=/sample.rumi. GEOZL_WASM_DIR points the server at a local GeoZL build holding geozl_api.js, geozl.js and geozl.wasm.

What it covers

The JavaScript package reads complete .rumi files only. It exposes the array shape, dtype, tile grid, frame index, affine transform, EPSG CRS, band descriptions and time coordinates. It does not write files, and it does not open a source with a separate external LOVE header as Python, R and Julia do. It has no read_many and no GPU reads.