rumi

Julia

Write Rumi files from Julia arrays, or read selected windows, bands and time steps. The reader pairs each file with its external header.

Install

using Pkg
Pkg.Registry.add(url = "https://github.com/asterisk-labs/AsteriskRegistry")
Pkg.add("Rumi")

The package calls librumi directly, and compresses frames with the GeoZL inside it. It loads the library named by RUMI_LIB, then the one make build writes to core/build in a checkout, then the artifact a release publishes for Linux x86-64 and macOS arm64, downloaded on first use and kept in the Julia depot. Loading fails with a librumi built for another C API version.

using Rumi

header = Base.read("scene.header")
chip = Rumi.read("scene.rumi", header; bands = [4, 8], time = 1:3, window = (1, 1, 256, 256))
size(chip)                                   # (256, 256, 2, 3)
meta = Rumi.info("scene.rumi"; header)

Functions

Call every function with the module prefix, such as Rumi.read or Rumi.info. The package exports only the types FrameTable, Metadata and RumiError. Invalid requests throw ArgumentError, and other library failures throw a RumiError that names its kind.

read

Rumi.read(source, header; time=nothing, bands=nothing, window=nothing,
    pattern=nothing) -> Array

Reads a selection into a new array of the file's element type. Every read is stateless and uses the header alone, so it fetches only the frames the selection needs. It does not check that the header belongs to the file, which Rumi.info(source; header) does.

sourceA local path, a remote URI, or the file's bytes as an AbstractVector{UInt8}. A leading ~ in a path is expanded, and bytes are read in place for the call, without a copy.
headerThe external header bytes, any AbstractVector{UInt8}.
timeOne-based time steps, as an integer, a vector of integers or a range such as 2:5, kept in the order given. nothing reads every step. A tuple is refused, so (1, 3) never stands for a range, and so is a Bool.
bandsOne-based bands, in the same form.
window(row, column, height, width) with a one-based origin, as a tuple or a vector of four integers. It must lie inside the image, and nothing reads the whole image.
patternThe output axes, as in Arrays. nothing uses "t b y x" when the file has more than one time step, otherwise "b y x".

An empty selection, an index outside the file, a tuple selection, or a window past the image throws ArgumentError.

chip = Rumi.read("scene.rumi", header; time = [2, 1], bands = [3, 1], window = (2, 3, 3, 4))
size(chip)                                   # (4, 3, 2, 2)
size(Rumi.read("scene.rumi", header; time = 2, bands = 1:3))   # (8, 6, 3, 1)

read_many

Rumi.read_many(sources, headers; windows=nothing, time=nothing,
    bands=nothing, pattern=nothing) -> Array

Reads one window from each source into one array, as a training batch needs. Every file takes the same time steps and bands, checked against the first file, and every window must have the same height and width. Each source is read with its header alone, as in read.

sources, headersOne source and one external header per item, as in read.
windowsA vector with one window per source, as in read, or a Matrix of integers with one (row, column, height, width) window per row. An entry of nothing reads that whole image, and nothing alone reads every whole image.
time, bandsAs in read.
patternAs in read. nothing uses "n t b y x" or "n b y x", which puts the n axis last in Julia. The n axis stays for one source.

An empty list, a windows list of the wrong length, windows of different sizes, or sources and headers of different lengths throw ArgumentError.

batch = Rumi.read_many(["scene.rumi", "scene.rumi"], [header, header];
                       windows = [1 1 2 3; 3 4 2 3], bands = [2])
size(batch)                                  # (3, 2, 1, 2, 2)

info

Rumi.info(source; header=nothing) -> Metadata
Rumi.info(; header) -> Metadata

Inspects a source, an external header, or both. A source alone is read, and its canonical external header is rebuilt. A header alone opens nothing. Given both, the header must match the source, or ArgumentError is thrown.

sourceA local path, a remote URI or the file's bytes.
headerThe external header bytes, any AbstractVector{UInt8}.

Returns a Metadata with these fields. Without a source, bands, time, time_kind, transform, crs and pixel_is_point are nothing.

headerThe canonical external header bytes. For a file without its header, Rumi.info(source).header rebuilds it.
shape(band, y, x), or (time, band, y, x) when the file has more than one time step.
time_countTime steps in the file.
dtypeThe element type name, such as "uint16".
tileThe tile (height, width).
frame_layoutThe axes inside one frame, such as "b h w".
index_orderThe band and time axes outside the frame, outermost first, as the symbols :t and :b. Axes of length one are left out.
framesFrames in the file.
bandsBand descriptions, in band order.
timeDate values when every coordinate is a whole UTC day, and UTC DateTime values otherwise, or (start, stop) pairs of them. A file from another writer with a time outside the years 1 to 9999 throws RumiError of kind :format.
time_kind:instant or :interval.
transformSix affine coefficients (x_res, row_rotation, x_origin, column_rotation, y_res, y_origin), or nothing without a CRS.
crsThe EPSG code, or nothing.
pixel_is_pointtrue for PixelIsPoint, false for PixelIsArea.
meta = Rumi.info("scene.rumi")
meta.shape                                   # (2, 3, 6, 8)
meta.bands                                   # ["B02", "B03", "B04"]
Rumi.info(; header = meta.header).bands      # nothing

frames

Rumi.frames(x::AbstractArray, pattern, tile_size=512) -> FrameTable
Rumi.frames(x::AbstractArray, pattern; tile_size=512) -> FrameTable

Cuts an array into frames in file order, clipping edge tiles. Compress each frame with Rumi.GeoZL before writing.

xAn array of samples. Its element type is the file's sample type, and it holds the pattern's input axes in reverse, so "b (row h) (col w)" takes (x, y, band), the shape Rumi.read returns. A view works and is copied frame by frame.
patternThe frame pattern Python takes, in C order, such as "b (row h) (col w) -> row col b (h w)".
tile_sizeHeight and width of a square tile, from 1 to 65535, given by position or by name.

Returns a FrameTable, whose row, col, band and time say where each frame belongs. A b h w frame is a Julia array shaped (w, h, band).

using Rumi: GeoZL

table = Rumi.frames(image, "b (row h) (col w) -> row col b (h w)"; tile_size = 256)
for (i, tile) in enumerate(table.data)
    table.compressed[i] = GeoZL.compress(tile, GeoZL.graph(tile, "planar>zigzag>pfor"))
end

GeoZL

Rumi.GeoZL.graph(x, method; width=nothing, planes=nothing, error=nothing,
    nodata=nothing) -> Rumi.GeoZL.Graph{T}
Rumi.GeoZL.compress(x, graph::Rumi.GeoZL.Graph) -> Vector{UInt8}
Rumi.GeoZL.compress(x; graph::Rumi.GeoZL.Graph) -> Vector{UInt8}

Compress frames with the GeoZL linked into librumi. Rumi.GeoZL covers graph and compress only, and Rumi.write stores the resulting bytes. decompress, profile and coeffs live in GeoZL.jl. Argument errors read as in the GeoZL packages. librumi makes every check it can see, and the binding only those that need a Julia value, such as a Bool width or a NaN sentinel on an integer array.

xAn array of a Rumi sample type. missing values take nodata, or NaN in a float array. For a bounded error the graph's x also fixes the domain later tiles must fall in.
methodA recipe such as "planar>zigzag>pfor".
width, planesRow width in samples and the number of stacked images, each an integer from 1 to 4294967295. They default to size(x, 1) and, for three or more dimensions, the last one, which is the planes of a b h w frame.
errornothing or 0 for lossless, a positive number for an absolute bound, a percentage such as "1%" for a relative one, or a full LINEAR, LOG or SQRT recipe.
nodataA sentinel value that marks missing samples, a real number or NaN on an integer or float array. NaN holes in a float array are kept without one.
graphThe Graph to compress with, by position or by name.

graph returns a Graph{T} for samples of type T, and eltype(g) returns T. Its fields method, width, planes, error and nodata repeat the arguments, with error as the full recipe. dtype holds the Rumi name of T, such as "uint16", and itemsize its bytes per sample. It prints as GeoZL.jl prints its graphs, with the module in front. compress refuses a tile of another element type, and a bounded tile outside the graph's domain. A Graph holds native state, so tasks that share it take turns; build one per task to compress in parallel.

g = Rumi.GeoZL.graph(tile, "planar>zigzag>pfor")
# Rumi.GeoZL.Graph(planar>zigzag>pfor, uint16, row width 48, 1 plane, lossless)
frame = Rumi.GeoZL.compress(tile; graph = g)

write

Rumi.write(path, frames::FrameTable; bands, time, transform=nothing, crs=nothing,
    pixel_is_point=false) -> Vector{UInt8}

Writes the compressed frames to a local file.

pathA local path. A leading ~ is expanded, and an existing file is replaced.
framesA FrameTable with a non-empty payload in every compressed entry. A missing payload throws ArgumentError naming the first one.
bandsA vector or tuple with one unique, non-empty text per band, in band order, such as "B4, Red, 665nm".
timeA vector with one entry per time step. An instant is a Date, a DateTime or an ISO string such as "2025-08-08", and an interval is a (start, end) tuple of them. A Date marks midnight UTC and a DateTime is read as UTC. Every time falls in the years 1 to 9999, the range every binding's date type holds.
transformSix affine coefficients in rasterio order, (x_res, row_rot, x_origin, col_rot, y_res, y_origin). Give it together with crs.
crsAn EPSG code, such as 32631 or "EPSG:32631".
pixel_is_pointA Bool, true when coordinates refer to pixel centres. The default refers to pixel corners.

Returns the external header. Keep it with the path, for example with Base.write. A failed write removes the partial file.

using Dates

header = Rumi.write("scene.rumi", table; bands = ["B02", "B03", "B04", "B08"],
                    time = [Date(2025, 8, 8)],
                    transform = (10, 0, 500000, 0, -10, 8000000), crs = 32618)
Base.write("scene.header", header)

frame_start

Rumi.frame_start(shape, pattern, tile_size=512) -> Int
Rumi.frame_start(shape, pattern; tile_size=512) -> Int

Returns the byte offset of the first frame that Rumi.write would give an array of size shape, without cutting any frames. Everything before that offset is fixed by the shape, so it is known before anything is compressed.

shapeThe array's size, a tuple or vector of integers in the reverse of the pattern's input axes, as Rumi.frames takes the array.
pattern, tile_sizeAs in Rumi.frames.
Rumi.frame_start(size(image), "b (row h) (col w) -> row col b (h w)", 256)

set_num_threads, get_num_threads

Rumi.set_num_threads(n) -> Int
Rumi.get_num_threads() -> Int

The size of the process-wide pool that reads and decodes, a whole number from 1 to 1024. Set it before the first parallel read. Once the pool exists, a different count throws RumiError of kind :state. RUMI_NUM_THREADS gives the starting value and also accepts ALL_CPUS. Without it, each process starts with one thread. The setter returns n.

set_checksum_verification, get_checksum_verification

Rumi.set_checksum_verification(on::Bool) -> Bool
Rumi.get_checksum_verification() -> Bool

Whether OpenZL checks frame checksums while decoding. Set it before the first decoded frame. Afterwards a different value throws RumiError of kind :state. RUMI_VERIFY gives the starting value and accepts 0 or 1, false or true, off or on, and no or yes. The setter returns on.

Types

MetadataWhat Rumi.info returns, with the fields above.
FrameTableWhat Rumi.frames returns. data holds one array per frame and compressed one payload per frame, nothing until it is set. layout names the axes of one frame, such as "h w", dtype the sample type and pattern the pattern text. tiles_across and tiles_down give the grid. row and col hold each frame's one-based grid cell, and band and time its one-based band and time step when frames are split by that axis, or nothing otherwise. length(table) is the frame count.
RumiErrorA library failure other than an invalid request, with the fields kind and message, as in Errors.

Errors

An invalid request, from the binding or from librumi, throws ArgumentError. Every other failure throws RumiError(kind, message), whose message comes from librumi and whose kind is one of these symbols. RumiError(message) has kind :internal and marks a failed check inside the binding.

:ioA source could not be opened or read.
:parseAn external header is malformed.
:formatThe file is malformed, such as frame data that runs past the end of the source.
:decodeA frame did not decode or decoded to an unexpected size.
:oomAn allocation failed or its size cannot be represented.
:unsupportedThe build lacks something the call needs, such as a codec the file uses.
:stateA process-wide setting is already pinned to another value.
:internalAn unexpected internal error.
chip = try
    Rumi.read(url, header; window = (1, 1, 256, 256))
catch err
    err isa RumiError && err.kind === :io || rethrow()
    nothing                                  # retry later
end

Arrays

Selections and window origins are one-based. Arrays use Julia's own memory order, so an Image reads as (x, y, band) and a Cube as (x, y, band, time), and Rumi.read_many adds the n axis last. A Cube read keeps its time axis when one step is selected. Metadata.shape keeps Rumi's (band, y, x) or (time, band, y, x).

A pattern names the output axes from n, t, b, y and x, outermost first. Grouped axes become one dimension, and an axis may be left out only when its extent is one. The Julia array has the dimensions in reverse, so pattern = "t y x b" gives an array shaped (b, x, y, t).

A frame pattern in Rumi.frames reads the same way. "b (row h) (col w)" takes an (x, y, band) array, the order Rasters.jl holds a raster in.

Integer, Float16, Float32, Float64, complex and Bool files read into Julia's own types. bfloat16 reads into Core.BFloat16 where Julia defines it and Rumi.RumiBFloat16 otherwise. The five float8 dtypes read into the 8-bit types Rumi.Float8E4M3FN, Rumi.Float8E5M2, Rumi.Float8E8M0FNU, Rumi.Float8E4M3FNUZ and Rumi.Float8E5M2FNUZ.

What it covers

The Julia binding writes and reads on the CPU. GPU reads and the framework, device and decode_backend arguments are Python only.