Python
- Package
rumi-eoon PyPI, with wheels for Linux x86-64 and macOS arm64 on Python 3.11 or newer.
pip install rumi-eo
The package imports as rumi and carries GeoZL inside it, as rumi.geozl, to compress the frames before a write. The Linux wheels decode on CUDA and the macOS wheels on Metal, and both read on the CPU when no GPU is present.
Writing
A file is written in three steps. frames cuts an array into tiles, you compress each tile with rumi.geozl, and write stores the payloads with the index and returns the external header.
frames
rumi.frames(x, pattern, tile_size=512) -> FrameTable
Splits an array into frames and returns them in file order. Frames at the right and bottom edges are clipped.
| x | Anything np.asarray accepts. Its axes can come in any order the pattern names. |
|---|---|
| pattern | An einops-style pattern. The left side names every input axis, and a pair such as (row h) splits an image axis into a grid coordinate and a frame axis. The group on the right lists the axes stored together in one frame. Only b and t are reserved. |
| tile_size | Height and width of a square tile, from 1 to 65535. |
"b (row h) (col w) -> row col (b h w)" # every band in one frame, band by band
"b (row h) (col w) -> row col (h w b)" # every band in one frame, interleaved
"b (row h) (col w) -> row col b (h w)" # one band per frame
Each frame is C-contiguous and follows the axis order on the right. The guide shows when each layout pays off.
FrameTable
The table frames returns. len gives the frame count, iteration and integer indexing give live Frame views, and assigning frame.compressed stores a payload in the table.
| tiles_across, tiles_down | The tile grid. |
|---|---|
| cells | Grid labels such as "0.1", row by row. |
| layout | The axis order of a decoded frame. |
| dims | The columns that identify each frame. |
| done, nbytes | How many frames have a payload, and their total size in bytes. |
| attach(name, values) | Adds a column with one value per frame or per grid cell. It stays in memory and is not written to the file. Returns the table, so calls chain. |
| to_pandas() | The frame metadata as a pandas DataFrame, without the payloads. Needs pandas. |
Frame
One frame of a FrameTable. data is the tile to compress and shape its shape. index, row, col and cell place it in the grid, and band and time are set when the pattern stores one band or one time step per frame. compressed holds the payload once you assign it.
for frame in frames:
g = rumi.geozl.graph(frame.data, "planar>zigzag>lanes")
frame.compressed = rumi.geozl.compress(frame.data, g)
Each frame can use its own recipe, so a land tile and an ocean tile in one file can compress differently.
geozl
rumi.geozl.graph(raster, method, *, width=None, planes=None, error=None,
nodata=None) -> rumi.geozl.Graph
rumi.geozl.compress(tile, graph) -> bytes
Compress frames with the GeoZL linked into Rumi, and write stores the resulting bytes. rumi.geozl covers graph and compress only. decompress, profile and coeffs live in the geozl package.
| raster | The samples the graph is built from. For a bounded error they also fix the domain later tiles must fall in, so use data spanning the product. |
|---|---|
| method | A recipe such as "planar>zigzag>lanes". |
| width, planes | Row width in samples and the number of stacked images, whole numbers from 1 to 4294967295. They default to the last axis and, for three or more axes, the first. Row predictors restart at each plane. |
| error | None or zero 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. Integers and 16, 32 and 64-bit floats take a bound. |
| nodata | A sentinel number that marks missing samples. It must fit the dtype, and an integer raster takes a whole number, not NaN. NaN holes in a float raster are kept without one. |
A Graph keeps method, width, planes, dtype, itemsize in bytes per sample, error as the full recipe, and nodata. It prints as <rumi.geozl.Graph planar>zigzag>pfor, uint16, row width 48, 1 plane, lossless>. A graph is reusable for tiles of its dtype, and threads that share one take turns. It cannot be pickled or copied. compress takes it by position or by name. It refuses a tile of another dtype, and a bounded tile outside the graph's domain.
A bad argument raises the same exception with the same text as in the geozl package, with rumi.geozl. in place of geozl.. A recipe GeoZL refuses raises ValueError in both, and other library refusals raise a RumiError.
write
rumi.write(path, frames, *, bands, time, transform=None, crs=None,
pixel_is_point=False) -> bytes
Writes a FrameTable to a local file. The payloads are stored as they are, without decoding or recompressing them.
| path | A local path, as text or a path-like object. A leading ~ is expanded. |
|---|---|
| frames | A FrameTable with a non-empty payload on every frame. |
| bands | One unique, non-empty label per band, in band order, such as "B4, Red, 665nm". |
| time | One entry per time step. An instant is a date, a datetime, an ISO string or a numpy.datetime64, and an interval is a (start, end) pair of them. ISO text is YYYY-MM-DD, or a date and HH:MM joined by T or a space, with optional seconds and an optional Z, +HH, +HHMM or +HH:MM offset. A fraction of a second must be all zeros, so "20240825" and "2024-08-25T14" are refused, as in R and Julia. Every coordinate falls in the years 1 to 9999 UTC. |
| transform | Six affine coefficients in rasterio order, (x_res, row_rot, x_origin, col_rot, y_res, y_origin). Give it together with crs. |
| crs | An EPSG code from 1 to 4294967295 as an integer, a string such as "EPSG:32718", or an object with to_epsg(). |
| pixel_is_point | A bool or numpy.bool_ that says whether coordinates refer to pixel centres. The default refers to pixel corners. |
Returns the external header as bytes, which read and read_many need beside the file. A failure after the file is opened removes the partial file.
frame_start
rumi.frame_start(shape, pattern, tile_size=512) -> int
Returns the byte offset of the first frame, without building any frames. shape follows the axis order the pattern names. Everything before that offset is fixed by the shape, so it is known before anything is compressed.
Reading
A source is a local path, a remote URI or the file's bytes. Remote reads go through Karu, which covers HTTP, S3, GCS, Azure, Hugging Face, Source Cooperative and /vsisubfile/. Indices and window origins count from 0. time and bands take one index, a list of indices, a range or a 1-D integer NumPy array, and None selects them all. A tuple or a bool is refused, so a range is written range(start, stop).
read
rumi.read(source, header, *, time=None, bands=None, window=None,
pattern=None, framework="numpy", device=None, decode_backend="auto")
Reads one raster, or the part of it you select. Only the frames under the selection are fetched and decoded.
| source | A path, a URI or the file's bytes. |
|---|---|
| header | The header write returned. For an existing file, info(source=...).header rebuilds it. |
| time, bands | The time steps and bands to read. |
| window | Four integers (row, column, height, width) in pixels, as a tuple, a list or a 1-D array. |
| pattern | The output axis order. The default is (T, B, Y, X), without the time axis for an Image. |
| framework | "numpy", "torch", "jax", "tensorflow" or "dlpack". The last returns a RumiArray. |
| device | "cuda:N" or "mps" decodes into GPU memory and hands it to the framework through DLPack, so it needs a framework other than "numpy". A CUDA read makes the framework's current stream wait for it on the device. |
| decode_backend | "auto" decodes supported frames on the GPU and the rest on the CPU, never splitting a frame. "cpu" decodes every frame on the CPU and only places the samples on the GPU. |
chip = rumi.read(path, header, bands=[2, 3], window=(0, 0, 256, 256),
framework="torch", device="cuda:0")
GeoZL decodes on the GPU the frames that end in PFOR or PivCo, such as planar>zigzag>lanes or planar>zigzag>pfor. Other frames decode on the CPU and are copied over. What a GPU wants explains why.
read_many
rumi.read_many(sources, headers, *, windows=None, time=None, bands=None,
pattern=None, framework="numpy", device=None, decode_backend="auto")
Reads one window from each source as a single plan and stacks the results along a leading n axis, in the order given. This is the call a training data loader makes.
| headers | One header per source. |
|---|---|
| windows | One window per source, as in read, or None for that source's whole image. An (n, 4) integer array gives one window per row. All windows must be the same size, only their positions differ. Without windows, every whole image is read, and the images must share a size. |
| other arguments | As in read, applied to every item. |
The sources must agree on tile size, band count, dtype, time step count and frame layout. Their image sizes may differ when windows is given. To read one window from one file several times, repeat it once per item.
info
rumi.info(source=None, *, header=None) -> Metadata
Inspects a source, a header, or both. From a source, Rumi reads the index, georeferencing, band labels and time, and rebuilds the external header. A header alone opens nothing and gives only what a reader needs. With both, Rumi checks that they match.
The returned Metadata has header, shape as (B, Y, X) or (T, B, Y, X), time_count, dtype, tile as (height, width), frame_layout, index_order, frames, bands, time, time_kind, transform, crs and pixel_is_point. The last six are None without a source.
header = rumi.info(source="s3://bucket/scene.rumi").header
Output
RumiArray
What framework="dlpack" returns. It holds the decoded samples once and hands them over a single time, through __dlpack__ or one of numpy(), torch(), jax() and tensorflow(). Each keeps the exact dtype and consumes the array, so a second export raises RuntimeError. shape stays readable.
For a CUDA array, __dlpack__(stream=...) makes that stream wait on the device, and the memory returns to Rumi in that stream's order, so keep the stream alive while the tensor lives. JAX needs 64-bit types enabled for 64-bit samples.
DType
The sample type of a file, in Metadata.dtype. It compares equal to its name, so meta.dtype == "uint16", and hashes as its name. It has name, bits, itemsize, component_size, the DLPack type code and the matching numpy_dtype, which is None for types NumPy lacks, such as bfloat16 and float8. Those still reach PyTorch and JAX through DLPack.
Errors
RumiError
class rumi.RumiError(Exception):
kind: str
An invalid request raises ValueError or TypeError, whether the binding or librumi refuses it. Every other failure raises a RumiError whose kind names it. The raised class also derives from the built-in exception named here, so except OSError still catches a missing file.
| "io" | A source could not be opened, read or written. An OSError. |
|---|---|
| "parse" | An external header is malformed. A ValueError. |
| "format" | The file is malformed, such as frame data that runs past the end of the source. A ValueError. |
| "decode" | A frame did not decode or decoded to an unexpected size, or a GPU call failed. An OSError. |
| "oom" | An allocation failed or its size cannot be represented. A MemoryError. |
| "unsupported" | The build or the machine lacks something the call needs, such as GPU support. A NotImplementedError. |
| "state" | A process-wide setting is already pinned to another value. A RuntimeError. |
| "internal" | An unexpected internal error. A RuntimeError. |
try:
chip = rumi.read(url, header, window=(0, 0, 256, 256))
except rumi.RumiError as error:
if error.kind != "io":
raise
chip = None
Settings
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, decodes and plans GPU work, from 1 to 1024. Set it before the first parallel read. Once the pool or a GPU context exists, changing it raises a RumiError of kind "state", which is also a RuntimeError. RUMI_NUM_THREADS gives the starting value and also accepts ALL_CPUS. Without it, each process starts with one thread, and so does each DDP rank and each forked worker.
set_checksum_verification, get_checksum_verification
rumi.set_checksum_verification(on) -> bool
rumi.get_checksum_verification() -> bool
Whether OpenZL checks frame checksums while decoding. Set it before the first decoded frame, after which changing it raises a 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.
__version__
The installed version of rumi-eo.