rumi

Read and write

  • Python examples that write Images and Cubes, then read them back from local or remote storage.

These examples write an Image and a Cube, read part of a file back, run the same read against local and remote storage, and build training batches. The first four sections create data. If a catalog already gives you a source and its header, start at bands, times and windows. Each example comes in Python, R and Julia, except frameworks and devices, which only Python has.

Installation

Use rumi.geozl in Python, rumi_geozl_graph and rumi_geozl_compress in R, or Rumi.GeoZL in Julia. All three use the GeoZL linked into Rumi.

python -m pip install rumi-eo
install.packages("rumi", repos = "https://asterisk-labs.r-universe.dev")
using Pkg
Pkg.Registry.add(url = "https://github.com/asterisk-labs/AsteriskRegistry")
Pkg.add("Rumi")
import numpy as np
import rumi
library(rumi)
using Random, Rumi
using Rumi: GeoZL

Shapes and positions. In Python an Image is (B, Y, X) and a temporal Cube is (T, B, Y, X). Selections count from zero, and a window is (row, column, height, width). R and Julia count from one and return Images as (X, Y, Band) and Cubes as (X, Y, Band, Time). They write arrays in that order too, with the same patterns as Python.

One Image

This round trip stores a four-band Image in 256 × 256 spatial cells. Each frame holds all four bands of one cell.

image = np.random.default_rng(0).integers(
    0, 4096,
    size=(4, 1024, 1024),
    dtype=np.uint16,
)

frames = rumi.frames(
    image,
    "b (row h) (col w) -> row col (b h w)",
    tile_size=256,
)

for frame in frames:
    graph = rumi.geozl.graph(frame.data, "planar>zigzag>zstd")
    frame.compressed = rumi.geozl.compress(frame.data, graph)

image_header = rumi.write(
    "image.rumi",
    frames,
    bands=[
        "B2, Blue, 496.6nm (S2A) / 492.1nm (S2B)",
        "B3, Green, 560nm (S2A) / 559nm (S2B)",
        "B4, Red, 664.5nm (S2A) / 665nm (S2B)",
        "B8, NIR, 835.1nm (S2A) / 833nm (S2B)",
    ],
    time=["2026-01-01"],
)
image_again = rumi.read("image.rumi", image_header)
set.seed(0)
image <- array(
  sample(0:4095, 1024 * 1024 * 4, replace = TRUE),
  c(1024, 1024, 4)
)

frames <- rumi_frames(
  image,
  "b (row h) (col w) -> row col (b h w)",
  tile_size = 256,
  dtype = "uint16"
)

for (i in seq_along(frames$data)) {
  tile <- frames$data[[i]]
  graph <- rumi_geozl_graph(tile, "planar>zigzag>zstd", dtype = "uint16")
  frames$compressed[[i]] <- rumi_geozl_compress(tile, graph)
}

image_header <- rumi_write(
  "image.rumi",
  frames,
  bands = c(
    "B2, Blue, 496.6nm (S2A) / 492.1nm (S2B)",
    "B3, Green, 560nm (S2A) / 559nm (S2B)",
    "B4, Red, 664.5nm (S2A) / 665nm (S2B)",
    "B8, NIR, 835.1nm (S2A) / 833nm (S2B)"
  ),
  time = "2026-01-01"
)
image_again <- rumi_read("image.rumi", image_header)
image = rand(Xoshiro(0), UInt16(0):UInt16(4095), 1024, 1024, 4)

frames = Rumi.frames(
    image,
    "b (row h) (col w) -> row col (b h w)";
    tile_size = 256,
)

for (i, tile) in enumerate(frames.data)
    graph = GeoZL.graph(tile, "planar>zigzag>zstd")
    frames.compressed[i] = GeoZL.compress(tile, graph)
end

image_header = Rumi.write(
    "image.rumi",
    frames;
    bands = [
        "B2, Blue, 496.6nm (S2A) / 492.1nm (S2B)",
        "B3, Green, 560nm (S2A) / 559nm (S2B)",
        "B4, Red, 664.5nm (S2A) / 665nm (S2B)",
        "B8, NIR, 835.1nm (S2A) / 833nm (S2B)",
    ],
    time = ["2026-01-01"],
)
image_again = Rumi.read("image.rumi", image_header)

image_header is the small external index to keep with the file, in a catalog or a dataset manifest.

Every file names each band and dates each time step. bands takes one text per band, in band order. A good text gives the band name, a short description and the wavelength.

Every frame is explicit. rumi.frames, rumi_frames and Rumi.frames return the decoded frames. The loop builds a GeoZL graph for each frame and assigns its compressed payload. A write refuses a table in which any frame has no payload.

Frame layouts

The logical Image does not change. Only the right side of the pattern changes, and with it how many samples are fetched and decoded together.

# One independently addressable frame per band and spatial tile.
tile_frames = rumi.frames(
    image,
    "b (row h) (col w) -> row col b (h w)",
    tile_size=256,
)

# One band-planar cell frame at each spatial position.
planar_cells = rumi.frames(
    image,
    "b (row h) (col w) -> row col (b h w)",
    tile_size=256,
)

# One pixel-interleaved cell frame at each spatial position.
chunky_cells = rumi.frames(
    image,
    "b (row h) (col w) -> row col (h w b)",
    tile_size=256,
)
# One independently addressable frame per band and spatial tile.
tile_frames <- rumi_frames(
  image,
  "b (row h) (col w) -> row col b (h w)",
  tile_size = 256,
  dtype = "uint16"
)

# One band-planar cell frame at each spatial position.
planar_cells <- rumi_frames(
  image,
  "b (row h) (col w) -> row col (b h w)",
  tile_size = 256,
  dtype = "uint16"
)

# One pixel-interleaved cell frame at each spatial position.
chunky_cells <- rumi_frames(
  image,
  "b (row h) (col w) -> row col (h w b)",
  tile_size = 256,
  dtype = "uint16"
)
# One independently addressable frame per band and spatial tile.
tile_frames = Rumi.frames(
    image,
    "b (row h) (col w) -> row col b (h w)";
    tile_size = 256,
)

# One band-planar cell frame at each spatial position.
planar_cells = Rumi.frames(
    image,
    "b (row h) (col w) -> row col (b h w)";
    tile_size = 256,
)

# One pixel-interleaved cell frame at each spatial position.
chunky_cells = Rumi.frames(
    image,
    "b (row h) (col w) -> row col (h w b)";
    tile_size = 256,
)
frameselective readscompression
h wbands you skip are never fetched or decodeda frame holds one band, so the graph cannot use correlation between bands
b h wreading one band decodes its whole cellthe band planes share one graph
h w breading one band decodes its whole cellthe interleaved pixels share one graph

R and Julia take the same pattern text. Their image is (x, y, band), and each frame keeps the reverse of its stored axes, so a b h w frame is (w, h, band). That is the order GeoZL reads in both languages, with the row width first and the planes last.

A temporal Cube

This Cube has three time steps and four bands. Band and time sit outside each frame, so any one band at one step can be read without decoding the others.

cube = np.random.default_rng(1).integers(
    0, 4096,
    size=(3, 4, 1024, 1024),
    dtype=np.uint16,
)

cube_frames = rumi.frames(
    cube,
    "t b (row h) (col w) -> row col b t (h w)",
    tile_size=256,
)

for frame in cube_frames:
    graph = rumi.geozl.graph(frame.data, "planar>zigzag>zstd")
    frame.compressed = rumi.geozl.compress(frame.data, graph)

cube_header = rumi.write(
    "cube.rumi",
    cube_frames,
    bands=[
        "B2, Blue, 496.6nm (S2A) / 492.1nm (S2B)",
        "B3, Green, 560nm (S2A) / 559nm (S2B)",
        "B4, Red, 664.5nm (S2A) / 665nm (S2B)",
        "B8, NIR, 835.1nm (S2A) / 833nm (S2B)",
    ],
    time=["2026-01-01", "2026-02-01", "2026-03-01"],
)
set.seed(1)
cube <- array(
  sample(0:4095, 1024 * 1024 * 4 * 3, replace = TRUE),
  c(1024, 1024, 4, 3)
)

cube_frames <- rumi_frames(
  cube,
  "t b (row h) (col w) -> row col b t (h w)",
  tile_size = 256,
  dtype = "uint16"
)

for (i in seq_along(cube_frames$data)) {
  tile <- cube_frames$data[[i]]
  graph <- rumi_geozl_graph(tile, "planar>zigzag>zstd", dtype = "uint16")
  cube_frames$compressed[[i]] <- rumi_geozl_compress(tile, graph)
}

cube_header <- rumi_write(
  "cube.rumi",
  cube_frames,
  bands = c(
    "B2, Blue, 496.6nm (S2A) / 492.1nm (S2B)",
    "B3, Green, 560nm (S2A) / 559nm (S2B)",
    "B4, Red, 664.5nm (S2A) / 665nm (S2B)",
    "B8, NIR, 835.1nm (S2A) / 833nm (S2B)"
  ),
  time = c("2026-01-01", "2026-02-01", "2026-03-01")
)
cube = rand(Xoshiro(1), UInt16(0):UInt16(4095), 1024, 1024, 4, 3)

cube_frames = Rumi.frames(
    cube,
    "t b (row h) (col w) -> row col b t (h w)";
    tile_size = 256,
)

for (i, tile) in enumerate(cube_frames.data)
    graph = GeoZL.graph(tile, "planar>zigzag>zstd")
    cube_frames.compressed[i] = GeoZL.compress(tile, graph)
end

cube_header = Rumi.write(
    "cube.rumi",
    cube_frames;
    bands = [
        "B2, Blue, 496.6nm (S2A) / 492.1nm (S2B)",
        "B3, Green, 560nm (S2A) / 559nm (S2B)",
        "B4, Red, 664.5nm (S2A) / 665nm (S2B)",
        "B8, NIR, 835.1nm (S2A) / 833nm (S2B)",
    ],
    time = ["2026-01-01", "2026-02-01", "2026-03-01"],
)
tile framesrow col b t (h w) or row col t b (h w) keeps band and time separately addressable.
cell framesrow col (b t h w) lets one graph model the whole band and time block at each spatial position.

time takes dates, datetimes, ISO strings or NumPy datetime64 values, or one (start, end) interval per step. Its length must equal T. R takes Date, POSIXct or ISO strings, with intervals as a two-column matrix or a list of pairs. Julia takes Date, DateTime or ISO strings, with intervals as (start, end) tuples. An ISO string is a date such as 2026-01-01, or a date and time such as 2026-01-01T10:30:00Z, and all three read the same strings.

Bands, times and windows

A list picks exact positions and may reorder them. A range picks consecutive positions. The optional output pattern changes the order of the returned axes, not what is stored.

# Exact positions, time 2 and bands 3 then 1.
picked = rumi.read(
    "cube.rumi",
    cube_header,
    time=[2],
    bands=[3, 1],
    window=(100, 200, 128, 128),
)

# Ranges and a model-specific output order.
reordered = rumi.read(
    "cube.rumi",
    cube_header,
    time=range(0, 2),
    bands=range(1, 4),
    window=(100, 200, 128, 128),
    pattern="t y x b",
)
# Exact positions, time 3 and bands 4 then 2.
picked <- rumi_read(
  "cube.rumi",
  cube_header,
  time = 3,
  bands = c(4, 2),
  window = c(101, 201, 128, 128)
)

# Ranges and a model-specific output order.
reordered <- rumi_read(
  "cube.rumi",
  cube_header,
  time = 1:2,
  bands = 2:4,
  window = c(101, 201, 128, 128),
  pattern = "t y x b"
)
# Exact positions, time 3 and bands 4 then 2.
picked = Rumi.read(
    "cube.rumi",
    cube_header;
    time = [3],
    bands = [4, 2],
    window = (101, 201, 128, 128),
)

# Ranges and a model-specific output order.
reordered = Rumi.read(
    "cube.rumi",
    cube_header;
    time = 1:2,
    bands = 2:4,
    window = (101, 201, 128, 128),
    pattern = "t y x b",
)

time=[2] keeps exactly one step and keeps its time axis, so picked is (1, 2, 128, 128). bands=[3, 1] keeps two bands, in that order. window=(100, 200, 128, 128) returns 128 rows and 128 columns starting at row 100, column 200. With pattern="t y x b", reordered comes back as (2, 128, 128, 3).

R and Julia count from one, so the same read asks for time 3, bands 4 and 2 and a window at row 101, column 201. Their ranges include both ends, so 2:4 is the three bands Python's range(1, 4) picks. picked comes back as (128, 128, 2, 1). A pattern gives R and Julia the axes in reverse, so reordered is (3, 128, 128, 2).

Local and remote sources

This example runs as it is against the public Rumi fixtures. It reads the same bands and window from Source Cooperative, Hugging Face, the S3-compatible endpoint of Source Cooperative and a downloaded local file, then checks that all four results are identical.

import os
from pathlib import Path
from urllib.request import Request, urlopen

import numpy as np
import rumi

PRODUCT = "asterisk-labs/rumi-api-fixtures"
NAME = "s2-00-tile"
SOURCE_BASE = f"https://data.source.coop/{PRODUCT}"

def fetch(url):
    request = Request(url, headers={"User-Agent": "rumi-example"})
    with urlopen(request) as response:
        return response.read()

header = fetch(f"{SOURCE_BASE}/headers/{NAME}.header")
selection = dict(
    bands=[3, 0],
    window=(237, 233, 91, 107),
)

# Source Cooperative also serves an S3-compatible public endpoint.
os.environ["AWS_ENDPOINT_URL"] = "https://data.source.coop"
os.environ["AWS_NO_SIGN_REQUEST"] = "YES"
os.environ["AWS_VIRTUAL_HOSTING"] = "NO"

sources = {
    "Source Cooperative": f"source://{PRODUCT}/data/{NAME}.rumi",
    "Hugging Face": f"hf://datasets/{PRODUCT}@main/data/{NAME}.rumi",
    "S3": f"s3://asterisk-labs/rumi-api-fixtures/data/{NAME}.rumi",
}
chips = {
    label: np.asarray(rumi.read(uri, header, **selection))
    for label, uri in sources.items()
}

# Download once to run the same read from a local path.
local_dir = Path("rumi-api-fixtures")
local_dir.mkdir(exist_ok=True)
local_file = local_dir / f"{NAME}.rumi"
local_file.write_bytes(fetch(f"{SOURCE_BASE}/data/{NAME}.rumi"))
chips["Local"] = np.asarray(
    rumi.read(local_file, header, **selection)
)

reference = chips["Source Cooperative"]
assert reference.shape == (2, 91, 107)
assert all(np.array_equal(reference, chip) for chip in chips.values())

print({label: chip.shape for label, chip in chips.items()})
library(rumi)

product <- "asterisk-labs/rumi-api-fixtures"
name <- "s2-00-tile"
source_base <- paste0("https://data.source.coop/", product)

fetch <- function(url) {
  path <- tempfile()
  download.file(url, path, mode = "wb", quiet = TRUE)
  readBin(path, "raw", file.info(path)$size)
}

header <- fetch(sprintf("%s/headers/%s.header", source_base, name))
bands <- c(4, 1)
window <- c(238, 234, 91, 107)

# Source Cooperative also serves an S3-compatible public endpoint.
Sys.setenv(
  AWS_ENDPOINT_URL = "https://data.source.coop",
  AWS_NO_SIGN_REQUEST = "YES",
  AWS_VIRTUAL_HOSTING = "NO"
)

sources <- c(
  "Source Cooperative" = sprintf("source://%s/data/%s.rumi", product, name),
  "Hugging Face" = sprintf("hf://datasets/%s@main/data/%s.rumi", product, name),
  "S3" = sprintf("s3://asterisk-labs/rumi-api-fixtures/data/%s.rumi", name)
)
chips <- lapply(sources, rumi_read, header = header, bands = bands,
                window = window)

# Download once to run the same read from a local path.
dir.create("rumi-api-fixtures", showWarnings = FALSE)
local_file <- file.path("rumi-api-fixtures", paste0(name, ".rumi"))
download.file(sprintf("%s/data/%s.rumi", source_base, name), local_file,
              mode = "wb", quiet = TRUE)
chips$Local <- rumi_read(local_file, header, bands = bands, window = window)

reference <- chips[["Source Cooperative"]]
stopifnot(identical(dim(reference), c(107L, 91L, 2L)))
stopifnot(all(vapply(chips, identical, logical(1), reference)))

str(lapply(chips, dim))
using Downloads, Rumi

product = "asterisk-labs/rumi-api-fixtures"
name = "s2-00-tile"
source_base = "https://data.source.coop/$product"

fetch(url) = take!(Downloads.download(url, IOBuffer()))

header = fetch("$source_base/headers/$name.header")
selection = (bands = [4, 1], window = (238, 234, 91, 107))

# Source Cooperative also serves an S3-compatible public endpoint.
ENV["AWS_ENDPOINT_URL"] = "https://data.source.coop"
ENV["AWS_NO_SIGN_REQUEST"] = "YES"
ENV["AWS_VIRTUAL_HOSTING"] = "NO"

sources = Dict(
    "Source Cooperative" => "source://$product/data/$name.rumi",
    "Hugging Face" => "hf://datasets/$product@main/data/$name.rumi",
    "S3" => "s3://asterisk-labs/rumi-api-fixtures/data/$name.rumi",
)
chips = Dict(label => Rumi.read(uri, header; selection...) for (label, uri) in sources)

# Download once to run the same read from a local path.
mkpath("rumi-api-fixtures")
local_file = joinpath("rumi-api-fixtures", "$name.rumi")
Downloads.download("$source_base/data/$name.rumi", local_file)
chips["Local"] = Rumi.read(local_file, header; selection...)

reference = chips["Source Cooperative"]
@assert size(reference) == (107, 91, 2)
@assert all(chip == reference for chip in values(chips))

println(Dict(label => size(chip) for (label, chip) in chips))
sourceaddressconfiguration
Source Cooperativesource://asterisk-labs/rumi-api-fixtures/…none for public data
Hugging Facehf://datasets/asterisk-labs/rumi-api-fixtures@main/…none for this public dataset
S3-compatibles3://asterisk-labs/rumi-api-fixtures/…the Source endpoint and unsigned requests
localrumi-api-fixtures/s2-00-tile.rumidownloaded by the example

One object, four transports. The two mirrors hold byte-identical Rumi objects and headers. The S3 URI names the same Source Cooperative object as the source:// URI, and only the backend configuration changes. Remote reads send range requests, and the local read uses positional file reads.

Training batches

read_many plans all the items together and returns them along a leading n axis. Positions may differ, but every window must have the same height and width.

# Continue from the previous example.
names = ["s2-00-tile", "s2-01-tile", "s2-02-tile"]
headers = [
    fetch(f"{SOURCE_BASE}/headers/{name}.header")
    for name in names
]
sources = [
    f"source://{PRODUCT}/data/{names[0]}.rumi",
    f"hf://datasets/{PRODUCT}@main/data/{names[1]}.rumi",
    f"s3://asterisk-labs/rumi-api-fixtures/data/{names[2]}.rumi",
]
windows = [
    (0, 0, 128, 128),
    (128, 192, 128, 128),
    (320, 256, 128, 128),
]

batch = rumi.read_many(
    sources,
    headers,
    windows=windows,
    bands=[0, 1, 2, 3],
)

assert batch.shape == (3, 4, 128, 128)
# Continue from the previous example.
names <- c("s2-00-tile", "s2-01-tile", "s2-02-tile")
headers <- lapply(sprintf("%s/headers/%s.header", source_base, names), fetch)
sources <- c(
  sprintf("source://%s/data/%s.rumi", product, names[1]),
  sprintf("hf://datasets/%s@main/data/%s.rumi", product, names[2]),
  sprintf("s3://asterisk-labs/rumi-api-fixtures/data/%s.rumi", names[3])
)
windows <- list(
  c(1, 1, 128, 128),
  c(129, 193, 128, 128),
  c(321, 257, 128, 128)
)

batch <- rumi_read_many(
  sources,
  headers,
  windows = windows,
  bands = 1:4
)

stopifnot(identical(dim(batch), c(128L, 128L, 4L, 3L)))
# Continue from the previous example.
names = ["s2-00-tile", "s2-01-tile", "s2-02-tile"]
headers = [fetch("$source_base/headers/$name.header") for name in names]
sources = [
    "source://$product/data/$(names[1]).rumi",
    "hf://datasets/$product@main/data/$(names[2]).rumi",
    "s3://asterisk-labs/rumi-api-fixtures/data/$(names[3]).rumi",
]
windows = [
    (1, 1, 128, 128),
    (129, 193, 128, 128),
    (321, 257, 128, 128),
]

batch = Rumi.read_many(
    sources,
    headers;
    windows = windows,
    bands = 1:4,
)

@assert size(batch) == (128, 128, 4, 3)

R and Julia put the items on the last axis instead, so batch is (128, 128, 4, 3) there.

Sources may mix local and remote storage. They must agree on tile size, dtype, band and time counts, and which axes their frames hold. The result keeps the input order even when ranges arrive in another order.

Why not a Python loop? A batch exposes the independent work of every item at once. Remote waits, local reads and OpenZL decoding then overlap while Rumi assembles one tensor of a known shape.

Frameworks and devices

This section is Python only. R and Julia return their own arrays, in host memory.

Choose the destination in the read call. Results pass through DLPack with no NumPy copy in between. A device such as "cuda:0" or "mps" decodes straight into CUDA or Metal memory, for any framework but NumPy.

numpy_chip = rumi.read("cube.rumi", cube_header)
torch_chip = rumi.read(
    "cube.rumi", cube_header, framework="torch"
)
jax_chip = rumi.read(
    "cube.rumi", cube_header, framework="jax"
)
tensorflow_chip = rumi.read(
    "cube.rumi", cube_header, framework="tensorflow"
)
dlpack_chip = rumi.read(
    "cube.rumi", cube_header, framework="dlpack"
)
cuda_chip = rumi.read(
    "cube.rumi", cube_header,
    framework="torch", device="cuda:0"
)
jax_cuda_chip = rumi.read(
    "cube.rumi", cube_header,
    framework="jax", device="cuda:0"
)
mps_chip = rumi.read(
    "cube.rumi", cube_header,
    framework="torch", device="mps"
)

framework sets what comes back.

"numpy"a NumPy array, the default
"torch"a PyTorch tensor
"jax"a JAX array. 64-bit dtypes need jax_enable_x64.
"tensorflow"a TensorFlow tensor
"dlpack"a RumiArray, a DLPack producer that exports once

Every Rumi dtype maps exactly to a CPU dtype that PyTorch accepts. NumPy, JAX and TensorFlow accept exact subsets. Rumi checks the dtype before it reads a frame, and it never casts or returns a byte view.

CUDA reads run on a stream Rumi owns. Importing the result makes the framework's current stream wait for the read on the device, without blocking the host. When the array is released, its memory returns to Rumi in that stream's order. Metal reads finish before they return.

Metadata and headers

A Rumi file describes itself. If the external header is missing, info rebuilds the canonical header, and it also returns the band texts, time and georeferencing stored in the file.

metadata = rumi.info(source="cube.rumi")
recovered_header = metadata.header

print(metadata.shape)         # (3, 4, 1024, 1024)
print(metadata.tile)          # (256, 256)
print(metadata.frame_layout)  # h w for the tile-frame Cube
print(metadata.bands)         # the four band texts
print(metadata.time)          # the three recorded dates

# Supplying both checks the header against the source.
checked = rumi.info(
    source="cube.rumi",
    header=recovered_header,
)
metadata <- rumi_info("cube.rumi")
recovered_header <- metadata$header

print(metadata$shape)         # 3 4 1024 1024
print(metadata$tile)          # 256 256
print(metadata$frame_layout)  # h w for the tile-frame Cube
print(metadata$bands)         # the four band texts
print(metadata$time)          # the three recorded dates

# Supplying both checks the header against the source.
checked <- rumi_info("cube.rumi", header = recovered_header)
metadata = Rumi.info("cube.rumi")
recovered_header = metadata.header

println(metadata.shape)         # (3, 4, 1024, 1024)
println(metadata.tile)          # (256, 256)
println(metadata.frame_layout)  # h w for the tile-frame Cube
println(metadata.bands)         # the four band texts
println(metadata.time)          # the three recorded dates

# Supplying both checks the header against the source.
checked = Rumi.info("cube.rumi"; header = recovered_header)

rumi_info and Rumi.info take the same three forms and return the same fields.

header onlyrumi.info(header=...), rumi_info(header = ...) and Rumi.info(; header) describe the read index without opening the source.
with a sourceA source also gives band texts, time coordinates, transform, CRS and a rebuilt header.

How Rumi reads follows a read from the request to the tensor, and the specification defines the file format.