rumi

C

make submodules
make build                       # core/build/librumi
make install PREFIX=/usr/local   # the library and its headers

Include rumi/rumi.h, which pulls in dlpack/dlpack.h, and link librumi. The library exports only the rumi_* symbols, and make install installs it with rumi.h, rumi_dtypes.def and dlpack/dlpack.h. GPU reads need a build configured with -DRUMI_BUILD_GPU=ON, such as make configure CMAKE_FLAGS=-DRUMI_BUILD_GPU=ON before make build.

Version and errors

Calls that can fail return a rumi_status, and rumi_last_error then describes the failure for the calling thread. The C API and ABI are not stable before 1.0. RUMI_API_VERSION and the library's SONAME stay at 1 until then, so recompile after every update, as Compatibility sets out.

typedef enum {
    RUMI_OK              = 0,
    RUMI_ERR_INVALID     = 1,
    RUMI_ERR_IO          = 2,
    RUMI_ERR_PARSE       = 3,
    RUMI_ERR_FORMAT      = 4,
    RUMI_ERR_DECODE      = 5,
    RUMI_ERR_OOM         = 6,
    RUMI_ERR_UNSUPPORTED = 7,
    RUMI_ERR_STATE       = 8,
    RUMI_ERR_INTERNAL    = 99
} rumi_status;
RUMI_OKSuccess.
RUMI_ERR_INVALIDA bad argument, selection, pattern or buffer size, or an external header that does not match its source.
RUMI_ERR_IOA source could not be opened or read.
RUMI_ERR_PARSEAn external header blob is malformed.
RUMI_ERR_FORMATThe file is malformed, such as frame data that runs past the end of the source.
RUMI_ERR_DECODEA frame did not decode or decoded to an unexpected size, or a GPU call failed.
RUMI_ERR_OOMAn allocation failed or its size cannot be represented.
RUMI_ERR_UNSUPPORTEDThe build or the machine lacks something the call needs, such as GPU support or a codec the file uses.
RUMI_ERR_STATEA process-wide setting is already pinned to another value.
RUMI_ERR_INTERNALAn unexpected internal error.

rumi_api_version

#define RUMI_API_VERSION 1
int rumi_api_version(void);

Returns the C API version the library was built with, to compare with RUMI_API_VERSION in the header you compiled against.

rumi_version_string

const char* rumi_version_string(void);

Returns the library version as a static string, such as "0.32.0".

rumi_openzl_format_version

int rumi_openzl_format_version(void);

Returns the newest OpenZL frame format version the linked decoder accepts.

rumi_last_error, rumi_clear_error

const char* rumi_last_error(void);
void        rumi_clear_error(void);

Returns the message from the last status-returning call on this thread, or NULL. Each such call clears the previous message first. The pointer stays valid until the next one or until rumi_clear_error clears it.

rumi_free

void rumi_free(void* ptr);

Releases a buffer returned by rumi_plan_ranges, rumi_geozl_compress, rumi_write or rumi_geokeys. Accepts NULL.

Process settings

These settings apply to the whole process. The thread count and checksum verification are pinned once reads start, so set them before the first read.

rumi_set_max_frame_bytes, rumi_get_max_frame_bytes

uint64_t rumi_set_max_frame_bytes(uint64_t n);
uint64_t rumi_get_max_frame_bytes(void);

Set and read the safety limit for a decoded frame and other allocations sized from the input. 0 restores the default of one gibibyte. Both return the limit in effect.

rumi_set_num_threads, rumi_get_num_threads

rumi_status rumi_set_num_threads(int n);
rumi_status rumi_get_num_threads(int* out);

Set and read the read thread count, from 1 to 1024. Without a call it comes from RUMI_NUM_THREADS, an integer in that range or ALL_CPUS, and is 1 when that is unset. The first parallel read fixes the pool size, and a different count after that returns RUMI_ERR_STATE. A forked child starts with its own setting.

Returns RUMI_ERR_INVALID for a count out of range, and rumi_get_num_threads does the same when RUMI_NUM_THREADS holds any other value.

rumi_set_checksum_verification, rumi_get_checksum_verification

rumi_status rumi_set_checksum_verification(int on);
rumi_status rumi_get_checksum_verification(int* out);

Turn OpenZL checksum verification on or off. on must be 0 or 1. Without a call the setting comes from RUMI_VERIFY, which takes 0 or 1, false or true, off or on, and no or yes, and is off when that is unset. The first decoded frame pins it, and a different value after that returns RUMI_ERR_STATE.

rumi_get_checksum_verification returns RUMI_ERR_INVALID when RUMI_VERIFY holds any other value. GPU contexts cannot be created while verification is on.

Dtypes

A rumi_dtype is the sample type of a file. The values are generated from rumi_dtypes.def, and the codes missing from the list are reserved and never reused.

typedef enum {
    RUMI_DT_UNKNOWN         = 0,
    RUMI_DT_UINT8           = 1,  RUMI_DT_INT8            = 2,
    RUMI_DT_UINT16          = 3,  RUMI_DT_INT16           = 4,
    RUMI_DT_UINT32          = 5,  RUMI_DT_INT32           = 6,
    RUMI_DT_UINT64          = 7,  RUMI_DT_INT64           = 8,
    RUMI_DT_FLOAT16         = 9,  RUMI_DT_FLOAT32         = 10,
    RUMI_DT_FLOAT64         = 11, RUMI_DT_COMPLEX32       = 14,
    RUMI_DT_COMPLEX64       = 15, RUMI_DT_COMPLEX128      = 16,
    RUMI_DT_FLOAT8_E4M3FN   = 17, RUMI_DT_FLOAT8_E5M2     = 18,
    RUMI_DT_BFLOAT16        = 19, RUMI_DT_BOOL            = 24,
    RUMI_DT_FLOAT8_E8M0FNU  = 25, RUMI_DT_FLOAT8_E4M3FNUZ = 29,
    RUMI_DT_FLOAT8_E5M2FNUZ = 30
} rumi_dtype;

typedef struct {
    uint8_t     code;
    uint8_t     sample_format;
    uint8_t     bits;
    uint8_t     storage_bytes;
    uint8_t     component_bytes;
    uint8_t     dl_code;
    uint8_t     dl_bits;
    uint16_t    dl_lanes;
    const char* name;
    const char* numpy;
} rumi_dtype_info;

In a registry row sample_format and bits are the file encoding, and storage_bytes is the size of one decoded sample, which output buffers are sized by. component_bytes is smaller only for complex types, which OpenZL may decode as a stream of components. dl_code, dl_bits and dl_lanes give the DLPack type, and numpy is NULL when NumPy has no exact scalar for it.

rumi_dtype_registry

size_t rumi_dtype_registry(const rumi_dtype_info** out);

Returns the number of rows in the dtype registry and, when out is not NULL, points it at the rows. The registry lives as long as the process and the caller does not own it. RUMI_DT_UNKNOWN has no row.

rumi_dtype_info_size

size_t rumi_dtype_info_size(void);

Returns the size of one registry row as the library was built, so a binding can check its copy of rumi_dtype_info.

rumi_check_samples

rumi_status rumi_check_samples(const void* data, size_t n_bytes,
                               rumi_dtype dtype);

Checks that dtype is a known type. For RUMI_DT_BOOL it also checks that each of the n_bytes bytes is 0 or 1. Returns RUMI_ERR_INVALID otherwise, naming the first bad sample.

Read patterns

A read pattern sets the axis order of a read's output. It names n for the item, t for time, b for band, and y and x for the window, with the rightmost axis changing fastest. Parentheses merge axes into one dimension, as in y x b or n (t b) y x. A pattern must name y and x, and an axis it leaves out must have extent 1.

#define RUMI_OUT_N 0
#define RUMI_OUT_T 1
#define RUMI_OUT_B 2
#define RUMI_OUT_Y 3
#define RUMI_OUT_X 4
#define RUMI_OUT_NDIM 5

typedef struct {
    int64_t shape[5];
    int     ndim;
    int64_t stride[5];
    int     native;
} rumi_layout;

shape[0..ndim) follows the pattern, with each merged group as one dimension, and the remaining entries are zero. stride is indexed by RUMI_OUT_* and counts elements. native is nonzero when the axes come in n t b y x order, ignoring the ones left out.

rumi_default_pattern

const char* rumi_default_pattern(size_t n_items, uint32_t times);

Returns the static pattern a read uses when pattern is NULL. That is b y x for an Image and t b y x for a Cube, with a leading n when n_items is above 1. times is the file's time_count, not the number of selected steps.

rumi_compile_layout

rumi_status rumi_compile_layout(const char* pattern,
                                int64_t n, int64_t t, int64_t b,
                                int64_t y, int64_t x, rumi_layout* out);

Compiles a pattern for the selected extents and writes its shape and strides to out. Every extent must be positive. NULL uses the default pattern for n and t. Returns RUMI_ERR_INVALID for an unknown, repeated or missing axis, or a left-out axis with an extent above 1.

Frame patterns and units

These helpers cut an array into frames without passing the array to C. A frame pattern such as b (row h) (col w) -> row col (b h w) splits the image axes into a tile grid and names what one frame holds. It resolves to a frame_unit, the layout number the file stores, which the specification lists.

typedef enum {
    RUMI_AXIS_BAND = 0,
    RUMI_AXIS_Y    = 1,
    RUMI_AXIS_X    = 2,
    RUMI_AXIS_H    = 3,
    RUMI_AXIS_W    = 4,
    RUMI_AXIS_TIME = 5
} rumi_axis;

#define RUMI_MAX_AXES 4

typedef struct {
    uint8_t input[RUMI_MAX_AXES];
    int     input_ndim;
    uint8_t frame[RUMI_MAX_AXES];
    int     frame_ndim;
    uint8_t index[2];
    int     index_ndim;
} rumi_frame_pattern;

Y and X are the full image axes, and H and W are their tile-local parts after the split. In a compiled pattern input is the source array's axis order, frame is the decoded frame's axis order, and index lists the band and time axes outside the frame, outermost first.

rumi_compile_frame_pattern

rumi_status rumi_compile_frame_pattern(const char* pattern,
                                       rumi_frame_pattern* out);

Compiles a frame pattern. Spatial splits use ceiling division, so edge frames may be smaller than the tile. Returns RUMI_ERR_INVALID for a pattern that names no frame layout rumi defines.

rumi_frame_unit

rumi_status rumi_frame_unit(const rumi_frame_pattern* pattern,
                            uint16_t bands, uint32_t times,
                            uint8_t* out);

Resolves a compiled pattern to the frame_unit for these band and time counts. A band or time axis of size 1 is dropped here. Returns RUMI_ERR_INVALID when no unit fits.

rumi_unit_from_name

rumi_status rumi_unit_from_name(const char* name, uint16_t bands,
                                uint32_t times, uint8_t* out);

Resolves frame axes written as text, such as "b h w", to the frame_unit for these band and time counts.

rumi_unit_name

rumi_status rumi_unit_name(uint8_t unit, uint16_t bands, uint32_t times,
                           char* out, size_t out_size);

Writes the unit's frame axes, such as "b h w", to out as a NUL-terminated string. Eight bytes hold every valid result. Returns RUMI_ERR_INVALID when the unit does not fit the counts or out_size is too small.

rumi_unit_index_axes

rumi_status rumi_unit_index_axes(uint8_t unit, uint16_t bands,
                                 uint32_t times, uint8_t* out,
                                 int* out_ndim);

Writes the band and time axes outside the frame as rumi_axis values, outermost first. out must hold two, *out_ndim says how many were written, and axes of size 1 are left out.

rumi_axis_name

const char* rumi_axis_name(uint8_t axis);

Returns the static pattern name of an axis, "b", "t", "y", "x", "h" or "w", or NULL for an invalid one.

rumi_frame_count

rumi_status rumi_frame_count(uint8_t unit, uint32_t width,
                             uint32_t length, uint16_t tile,
                             uint16_t bands, uint32_t times,
                             uint32_t* out_across, uint32_t* out_down,
                             uint64_t* out_frames);

Returns the tile grid and the total frame count of a raster. Any output pointer may be NULL.

unitA frame_unit valid for bands and times.
width, lengthImage size in pixels.
tileHeight and width of a square tile, at least 1.
bands, timesBand and time step counts, at least 1.

Returns RUMI_ERR_INVALID when an argument is out of range or the count overflows.

rumi_frame_locate

typedef struct {
    uint32_t row, col, band, time, h, w;
    int64_t  dims[RUMI_MAX_AXES];
    uint8_t  perm[RUMI_MAX_AXES];
    int      ndim;
} rumi_frame_at;
rumi_status rumi_frame_locate(uint8_t unit, uint32_t width,
                              uint32_t length, uint16_t tile,
                              uint16_t bands, uint32_t times,
                              uint64_t index, rumi_frame_at* out);

Resolves a zero-based frame index to its place in the raster and its decoded shape. The arguments before index follow rumi_frame_count. row, col, band and time are zero-based, and h and w are the frame's size after clipping at the edge.

dims holds the decoded frame shape in its first ndim entries. perm reorders a cut taken as held band, held time, h and w into dims order, as a transpose would. Returns RUMI_ERR_INVALID for an index past the last frame.

External headers

The external header is the small blob rumi_write returns. It holds the raster fields and the frame byte counts, so a reader can locate any frame without parsing the file. A rumi_spec is a parsed copy, independent of any source and reusable across reads.

typedef struct rumi_spec rumi_spec;

typedef struct {
    uint32_t   image_width;
    uint32_t   image_length;
    uint32_t   time_count;
    uint16_t   tile_width;
    uint16_t   tile_length;
    uint16_t   samples_per_pixel;
    uint8_t    bits_per_sample;
    uint8_t    sample_format;
    uint8_t    frame_unit;
    uint32_t   tiles_across;
    uint32_t   tiles_down;
    uint64_t   base_frame_offset;
    rumi_dtype dtype;
} rumi_header;

A time_count of 1 is an Image and more is a Cube. samples_per_pixel is the band count. bits_per_sample and sample_format are the on-disk encoding of dtype, and rumi_unit_name resolves frame_unit to its axes. base_frame_offset is the byte offset of the first frame.

rumi_spec_parse, rumi_spec_destroy

rumi_status rumi_spec_parse(const unsigned char* blob, size_t blob_size,
                            rumi_spec** out);
void        rumi_spec_destroy(rumi_spec* spec);

Parses and copies a header blob, which may be released after the call. *out is unchanged on error. Release the spec with rumi_spec_destroy. Returns RUMI_ERR_INVALID for a NULL or empty argument and RUMI_ERR_PARSE for a malformed blob.

rumi_spec_header

rumi_status rumi_spec_header(const rumi_spec* spec, rumi_header* out);

Copies the parsed fields into out.

rumi_plan_ranges

typedef struct { uint64_t offset; uint64_t length; } rumi_range;

rumi_status rumi_plan_ranges(const rumi_spec* spec,
                             const int* times, size_t n_times,
                             const int* bands, size_t n_bands,
                             int y_off, int y_size,
                             int x_off, int x_size,
                             rumi_range** out, size_t* out_count);

Returns the unique byte ranges of the frames a read needs, in frame-index order, without any I/O. The selection and window follow rumi_read. Release *out with rumi_free.

Sources and metadata

A rumi_source is the byte source of one file, and concurrent reads may share it.

typedef struct rumi_source rumi_source;

rumi_source_file

rumi_status rumi_source_file(const char* path, rumi_source** out);

Opens a local path or a remote URI through Karu, rumi's internal transport. A remote read normally takes its external header from a manifest. Returns RUMI_ERR_IO when the source cannot be opened.

rumi_source_memory

rumi_status rumi_source_memory(const void* data, size_t size,
                               rumi_source** out);

Wraps a buffer the caller owns. Keep it alive for the life of the source.

rumi_source_free

void rumi_source_free(rumi_source* src);

Releases a source. Accepts NULL.

rumi_info

typedef struct {
    rumi_header    fields;
    unsigned char* blob;
    size_t         blob_size;
    int            has_source;
    double         transform[6];
    uint32_t       epsg;
    int            pixel_is_point;
    char**         band_texts;
    size_t         band_text_count;
    uint8_t        time_type;
    int64_t*       time;
    size_t         time_coords;
} rumi_metadata;
rumi_status rumi_info(rumi_source* source,
                      const unsigned char* header, size_t header_size,
                      rumi_metadata* out);

Inspects a source, parses an external header, or both. With both, the header must exactly match the canonical header rebuilt from the source. That checks the index, not the payloads, so sources with the same structure and compressed frame sizes share a header. At least one input is required, and out is unchanged on error.

fieldsThe parsed rumi_header.
blob, blob_sizeThe canonical external header.
has_sourceNonzero when the georeferencing, band texts and time were read from a source. An external header alone does not hold them, and they stay zero or NULL without one.
transform, epsgThe six affine coefficients, in the order rumi_write_desc uses, and the EPSG code.
pixel_is_pointNonzero for PixelIsPoint.
band_texts, band_text_countOne NUL-terminated UTF-8 text per band, in band order.
time_type1 for intervals and 2 for instants.
time, time_coordsThe time coordinates in POSIX seconds, one per step for instants and two for intervals.

Returns RUMI_ERR_INVALID when neither input is given or the header does not match the source, and RUMI_ERR_PARSE for a malformed header. A source that cannot be read returns RUMI_ERR_IO or RUMI_ERR_FORMAT.

rumi_metadata_free

void rumi_metadata_free(rumi_metadata* metadata);

Releases the blob, band texts and time a rumi_metadata owns and zeroes it, so a second call is safe. Accepts NULL.

Reading on the CPU

Every read entry point may be called concurrently. Parsed specs and sources may be shared between calls, destination buffers must not overlap, and a borrowed source buffer must stay alive. Reads decode on the process-wide thread pool, so set its size before the first one. The read functions share these parameters.

times, n_times1-based time steps in output order. NULL and 0 select every step in file order.
bands, n_bands1-based bands in output order. NULL and 0 select every band in file order.
y_off, y_size, x_off, x_sizeA zero-based window, which must lie inside the image.
patternA read pattern, or NULL for the default Image or Cube layout.
dst, dst_sizeThe output buffer. It must hold every selected sample at the dtype's storage_bytes.

A NULL pointer needs a count of 0; a non-NULL selection must contain at least one index. Selections, windows and layouts are checked before decoding. A read returns RUMI_ERR_INVALID for a bad selection, window or pattern or a buffer that is too small, RUMI_ERR_IO when a frame cannot be fetched, and RUMI_ERR_DECODE or RUMI_ERR_UNSUPPORTED when one cannot be decoded.

rumi_read

rumi_status rumi_read(rumi_source* src, const rumi_spec* spec,
                      const int* times, size_t n_times,
                      const int* bands, size_t n_bands,
                      int y_off, int y_size, int x_off, int x_size,
                      const char* pattern, void* dst, size_t dst_size);

Reads one window from one source into dst, fetching only the frames it covers.

rumi_spec* spec = NULL;
rumi_source* src = NULL;
int bands[] = {2, 3};
uint16_t chip[2 * 256 * 256];       /* bands 2 and 3, uint16 Image */

if (rumi_spec_parse(blob, blob_size, &spec) != RUMI_OK
    || rumi_source_file("scene.rumi", &src) != RUMI_OK
    || rumi_read(src, spec, NULL, 0, bands, 2, 0, 256, 0, 256,
                 NULL, chip, sizeof chip) != RUMI_OK) {
    fprintf(stderr, "%s\n", rumi_last_error());
}
rumi_source_free(src);
rumi_spec_destroy(spec);

rumi_read_many

typedef struct {
    rumi_source*     source;
    const rumi_spec* spec;
    int              y_off;
    int              x_off;
} rumi_read_item;
rumi_status rumi_read_many(const rumi_read_item* items, size_t n_items,
                           const int* times, size_t n_times,
                           const int* bands, size_t n_bands,
                           int y_size, int x_size, const char* pattern,
                           void* dst, size_t dst_size);

Reads one window per item into dst, in n order. Each item names a source, its parsed header and the zero-based window origin, and the caller keeps them alive for the call. Every window shares y_size and x_size, and times and bands apply to every item.

The headers must agree on tile size, band count, dtype, time step count, and which of band and time a frame holds. Image sizes may differ, so one batch can draw from scenes of different extents. The default pattern keeps n even for one item, and a custom pattern must include n for more than one.

rumi_read_layout, rumi_read_many_layout

rumi_status rumi_read_layout(const rumi_spec* spec,
                             const int* times, size_t n_times,
                             const int* bands, size_t n_bands,
                             int y_off, int y_size, int x_off, int x_size,
                             const char* pattern,
                             rumi_layout* out, size_t* out_bytes);
rumi_status rumi_read_many_layout(const rumi_read_item* items, size_t n_items,
                                  const int* times, size_t n_times,
                                  const int* bands, size_t n_bands,
                                  int y_size, int x_size, const char* pattern,
                                  rumi_layout* out, size_t* out_bytes);

Check the selection, window and layout without fetching data. The functions return the output layout and, when out_bytes is not NULL, the required dst_size. Call them before allocating a caller-owned output buffer.

Reading on the GPU

A GPU read plans the frames and the window on the CPU, then GeoZL writes the decoded samples into device memory. It needs a build with RUMI_BUILD_GPU, which drives CUDA on Linux and Metal on macOS. The device types follow DLPack.

#define RUMI_DEVICE_CUDA 2
#define RUMI_DEVICE_METAL 8
#define RUMI_GPU_DECODE_AUTO 0
#define RUMI_GPU_DECODE_CPU 1

typedef struct rumi_gpu rumi_gpu;

rumi_gpu_available

int rumi_gpu_available(int device_type);

Returns nonzero when this build can drive device_type.

rumi_gpu_create, rumi_gpu_destroy

rumi_status rumi_gpu_create(int device_type, int device, size_t threads,
                            size_t max_decoded_bytes, rumi_gpu** out);
void        rumi_gpu_destroy(rumi_gpu* gpu);

Creates a context on one device. A context is not safe for concurrent calls.

device_typeRUMI_DEVICE_CUDA or RUMI_DEVICE_METAL.
deviceThe device index.
threadsSets and pins the process-wide read thread count, up to 1024. 0 uses the current count.
max_decoded_bytesBounds the decoded frame bytes staged per batch. It must be nonzero.

Returns RUMI_ERR_STATE when threads differs from a count already pinned, and RUMI_ERR_UNSUPPORTED when the build has no GPU support, the device is unavailable or checksum verification is on.

rumi_gpu_synchronize

rumi_status rumi_gpu_synchronize(rumi_gpu* gpu);

Waits for queued work and releases any target the context retains. Returns RUMI_ERR_DECODE when that work failed.

rumi_gpu_current_device

rumi_status rumi_gpu_current_device(int device_type, int* out);

Writes the device of the CUDA context current on the calling thread, as a framework's set-device call leaves it, or 0 when none is current. Metal reports 0.

rumi_read_gpu

rumi_status rumi_read_gpu(rumi_gpu* gpu, rumi_source* src,
                          const rumi_spec* spec,
                          const int* times, size_t n_times,
                          const int* bands, size_t n_bands,
                          int y_off, int y_size, int x_off, int x_size,
                          const char* pattern,
                          void* dst, size_t dst_size,
                          void* stream, int decode_backend);

The GPU form of rumi_read, with the same selection.

dst, dst_sizeThe backend's native destination, a CUDA device pointer or a Metal MTLBuffer object, and its size in bytes.
streamThe native CUDA stream. NULL for Metal.
decode_backendRUMI_GPU_DECODE_AUTO decodes supported complete frames on the GPU and the rest on the host. RUMI_GPU_DECODE_CPU decodes every frame on the host, then places the samples on dst. Either way dst stays on the GPU.

On CUDA the work may still be pending when the call returns. Consume dst on stream, or make another stream wait on an event recorded after the read, and keep dst alive until the consumer finishes. On Metal, finish earlier work that touches dst before the call. The call finishes its own Metal work before it returns and retains dst until rumi_gpu_synchronize, the next read or rumi_gpu_destroy.

Boolean samples return RUMI_ERR_UNSUPPORTED.

rumi_read_many_gpu

rumi_status rumi_read_many_gpu(rumi_gpu* gpu,
                               const rumi_read_item* items,
                               size_t n_items,
                               const int* times, size_t n_times,
                               const int* bands, size_t n_bands,
                               int y_size, int x_size,
                               const char* pattern,
                               void* dst, size_t dst_size,
                               void* stream, int decode_backend);

The GPU form of rumi_read_many. dst, stream and decode_backend follow rumi_read_gpu.

DLPack

These forms allocate the output and return it as a DLManagedTensorVersioned, shaped by the pattern with C-contiguous strides. Release a tensor with its deleter or rumi_dlpack_free.

rumi_read_dlpack

rumi_status rumi_read_dlpack(rumi_source* src, const rumi_spec* spec,
                             const int* times, size_t n_times,
                             const int* bands, size_t n_bands,
                             int y_off, int y_size,
                             int x_off, int x_size,
                             const char* pattern,
                             DLManagedTensorVersioned** out);

The DLPack form of rumi_read. It returns a CPU tensor whose data is 256-byte aligned.

rumi_read_many_dlpack

rumi_status rumi_read_many_dlpack(const rumi_read_item* items,
                                  size_t n_items,
                                  const int* times, size_t n_times,
                                  const int* bands, size_t n_bands,
                                  int y_size, int x_size,
                                  const char* pattern,
                                  DLManagedTensorVersioned** out);

The DLPack form of rumi_read_many.

rumi_read_gpu_dlpack

rumi_status rumi_read_gpu_dlpack(rumi_gpu* gpu, rumi_source* src,
                                 const rumi_spec* spec,
                                 const int* times, size_t n_times,
                                 const int* bands, size_t n_bands,
                                 int y_off, int y_size,
                                 int x_off, int x_size,
                                 const char* pattern, int decode_backend,
                                 DLManagedTensorVersioned** out);

The DLPack form of rumi_read_gpu. It allocates the output on the context's device and returns a kDLCUDA or kDLMetal tensor. On CUDA the work is queued on a stream the context owns and may still be pending, so call rumi_dlpack_wait before using the tensor on another stream. Metal work has finished.

rumi_read_many_gpu_dlpack

rumi_status rumi_read_many_gpu_dlpack(rumi_gpu* gpu,
                                      const rumi_read_item* items,
                                      size_t n_items,
                                      const int* times, size_t n_times,
                                      const int* bands, size_t n_bands,
                                      int y_size, int x_size,
                                      const char* pattern,
                                      int decode_backend,
                                      DLManagedTensorVersioned** out);

The DLPack form of rumi_read_many_gpu, following rumi_read_gpu_dlpack.

rumi_dlpack_wait

rumi_status rumi_dlpack_wait(DLManagedTensorVersioned* t, void* stream);

Hands a GPU tensor to the CUDA stream that will use it, as DLPack's __dlpack__(stream=...) does. The stream waits on the device for the read, and the tensor's memory returns to rumi's pool in stream order when it is released, so keep the stream alive until then. NULL waits on the host now and for the whole device at release. Call it once, before the first use. CPU and Metal tensors are ready and need no call.

rumi_dlpack_free

void rumi_dlpack_free(DLManagedTensorVersioned* t);

Releases a tensor rumi returned, with its data. Accepts NULL.

rumi_dlpack_legacy, rumi_dlpack_legacy_free

DLManagedTensor* rumi_dlpack_legacy(DLManagedTensorVersioned* t);
void             rumi_dlpack_legacy_free(DLManagedTensor* t);

Wraps a versioned tensor for a DLPack 0.x consumer. On success the wrapper owns t, and rumi_dlpack_legacy_free releases both. On failure it returns NULL and the caller still owns t. rumi_dlpack_legacy_free accepts NULL.

rumi_dlpack_capsule_api, rumi_dlpack_capsule_destructor

typedef int   (*rumi_capsule_is_valid_fn)(void* capsule,
                                         const char* name);
typedef void* (*rumi_capsule_pointer_fn)(void* capsule,
                                         const char* name);

void rumi_dlpack_capsule_api(rumi_capsule_is_valid_fn is_valid,
                             rumi_capsule_pointer_fn  pointer);
void rumi_dlpack_capsule_destructor(void* capsule);

For bindings that do not include Python.h. Register PyCapsule_IsValid and PyCapsule_GetPointer once, then pass rumi_dlpack_capsule_destructor to PyCapsule_New. The destructor releases a capsule no consumer claimed, and it can do so only after the registration. A renamed capsule belongs to the consumer.

Compression

These functions compress with the GeoZL linked into Rumi. Python, R and Julia call them; rumi_write stores the bytes it receives without compressing them.

rumi_geozl_graph_open, rumi_geozl_graph_close

rumi_status rumi_geozl_graph_open(const char* method, rumi_dtype dtype,
                                  const void* raster, size_t n_bytes,
                                  uint32_t width, uint32_t planes,
                                  const char* error, const void* nodata,
                                  rumi_geozl_graph** out);
void rumi_geozl_graph_close(rumi_geozl_graph* graph);

Builds a reusable graph for method, such as "planar>zigzag>pfor", from n_bytes of native dtype samples. Release it with rumi_geozl_graph_close, which accepts NULL. A graph owns a compression context, so threads that share one take turns on it.

dtypeAny sample type of 1, 2, 4 or 8 bytes. Integers and float16, float32 and float64 take a bound and a sentinel. The others compress losslessly.
width, planesThe row in samples and the number of stacked images, whose row predictors restart. Both are positive, and more than one plane must split the raster into whole rows.
errorNULL or "" for lossless, a decimal bound such as "0.5" (LINEAR), a percentage such as "1%" (LOG), or a full LINEAR, LOG or SQRT recipe. A zero bound is lossless. The raster fixes the domain a bounded graph accepts later tiles from.
nodataOne dtype sample that marks missing data, or NULL. A NaN sample, or NULL with a NaN in a float raster, keeps every NaN as a hole.

Returns RUMI_ERR_INVALID for a recipe, geometry, sample width, sentinel or bound GeoZL refuses, RUMI_ERR_OOM when memory runs out, and RUMI_ERR_INTERNAL for any other GeoZL failure. A GeoZL failure names the method and ends with its ZL error code. The texts match the geozl packages.

rumi_geozl_compress

rumi_status rumi_geozl_compress(rumi_geozl_graph* graph, rumi_dtype dtype,
                                const void* tile, size_t n_bytes,
                                unsigned char** out_frame, size_t* out_size);

Compresses one tile of the graph's dtype, aligned to its samples. Its shape is not checked against the graph, but a row predictor refuses a tile longer than one row that is not whole rows of the graph's width. A bounded tile outside the graph's domain is refused, and so is a bool tile holding a byte other than 0 or 1, which a read would refuse. *out_frame holds *out_size bytes the caller releases with rumi_free.

rumi_geozl_graph* graph = NULL;
if (rumi_geozl_graph_open("planar>zigzag>pfor", RUMI_DT_UINT16, tile, tile_bytes,
                          256, 4, NULL, NULL, &graph) != RUMI_OK) {
    fprintf(stderr, "%s\n", rumi_last_error());
    return 1;
}
unsigned char* frame = NULL;
size_t frame_size = 0;
rumi_status status = rumi_geozl_compress(graph, RUMI_DT_UINT16, tile, tile_bytes,
                                         &frame, &frame_size);
rumi_geozl_graph_close(graph);

rumi_geozl_graph_error

const char* rumi_geozl_graph_error(const rumi_geozl_graph* graph);

Returns the normalized error recipe, such as "LINEAR:MAX_ERROR=0.5" for a bound of "0.5", or NULL for a lossless graph. A full recipe comes back as given, without the parameters GeoZL fits from the raster, such as the A and B of a SQRT recipe. The text lives as long as the graph.

Writing

A file is written in three steps. The frame helpers give the frames in frame-index order with their decoded shapes, you compress each one with rumi_geozl_compress, and rumi_write stores the payloads and returns the external header.

typedef struct {
    uint32_t           image_width;
    uint32_t           image_length;
    uint32_t           time_count;
    uint16_t           tile_size;
    uint16_t           samples_per_pixel;
    rumi_dtype         dtype;
    const double*      transform;
    uint32_t           epsg;
    int                pixel_is_point;
    uint8_t            frame_unit;
    const char* const* band_texts;
    uint64_t           band_text_count;
    uint8_t            time_type;
    const int64_t*     time;
    uint64_t           time_coords;
} rumi_write_desc;
image_width, image_lengthImage size in pixels.
time_countTime steps. 1 is an Image and more is a Cube.
tile_sizeHeight and width of a square tile.
samples_per_pixelThe band count.
transform, epsgSix affine coefficients in the order (x_res, row_rotation, x_origin, column_rotation, y_res, y_origin), and an EPSG code. Give both, or NULL and 0 for no CRS.
pixel_is_pointNonzero for PixelIsPoint, 0 for PixelIsArea.
frame_unitNormally from rumi_frame_unit.
band_texts, band_text_countOne NUL-terminated UTF-8 text per band, in band order. Each text is non-empty and differs from the others.
time_type1 for intervals and 2 for instants.
time, time_coordsPOSIX seconds, time_count values for instants and twice that for intervals. rumi derives the storage scale.

rumi_write

rumi_status rumi_write(const char* path, const rumi_write_desc* desc,
                       const unsigned char* const* frames,
                       const size_t* sizes, size_t frame_count,
                       unsigned char** out_blob, size_t* out_size);

Writes the compressed frames to a local file and returns the external header. frames[i] points at the sizes[i] bytes of frame i, in frame-index order. *out_blob holds *out_size bytes the caller releases with rumi_free. On failure the partial file is removed and the outputs are unchanged.

Returns RUMI_ERR_INVALID when the frame count does not match the grid, a frame is empty, or the band texts or time coordinates do not match desc.

const char* names[] = {"B2", "B3", "B4", "B8"};
int64_t when = 1724544000;                  /* 2024-08-25, an instant */
const unsigned char* frames[4];
size_t sizes[4];
rumi_frame_pattern fp;
uint8_t unit;
uint64_t n;

rumi_compile_frame_pattern("b (row h) (col w) -> row col (b h w)", &fp);
rumi_frame_unit(&fp, 4, 1, &unit);
rumi_frame_count(unit, 1024, 1024, 512, 4, 1, NULL, NULL, &n);   /* 4 */
for (uint64_t i = 0; i < n; i++) {
    rumi_frame_at at;
    rumi_frame_locate(unit, 1024, 1024, 512, 4, 1, i, &at);
    /* cut tile (at.row, at.col) to at.dims, compress it with GeoZL,
       and store the payload in frames[i] and sizes[i] */
}

rumi_write_desc desc = {
    .image_width = 1024, .image_length = 1024, .time_count = 1,
    .tile_size = 512, .samples_per_pixel = 4, .dtype = RUMI_DT_UINT16,
    .frame_unit = unit, .band_texts = names, .band_text_count = 4,
    .time_type = 2, .time = &when, .time_coords = 1,
};
unsigned char* header = NULL;
size_t header_size = 0;
if (rumi_write("scene.rumi", &desc, frames, sizes, n,
               &header, &header_size) == RUMI_OK) {
    /* keep header with the file, then */
    rumi_free(header);
}

rumi_write_base_offset

rumi_status rumi_write_base_offset(const rumi_write_desc* desc,
                                   uint64_t* out);

Validates the layout in desc and writes the offset of the first frame, without writing a file. Band texts and time coordinates are not read.

rumi_frame_start

rumi_status rumi_frame_start(uint32_t samples_per_pixel,
                             uint64_t frame_count, uint64_t* out);

Returns the byte offset of the first frame, which is also the size of everything before it. No frame payloads are needed. samples_per_pixel must be 1 to 65535 and frame_count 1 to 4294967295.

rumi_geokeys

rumi_status rumi_geokeys(uint32_t epsg, int pixel_is_point,
                         unsigned char** out_dir, size_t* out_dir_size,
                         unsigned char** out_dbl, size_t* out_dbl_size,
                         unsigned char** out_ascii,
                         size_t* out_ascii_size);

Builds the fixed GeoKeyDirectory rumi writes for an EPSG code. pixel_is_point selects PixelIsArea (0) or PixelIsPoint (nonzero). Release *out_dir with rumi_free. *out_dbl and *out_ascii come back NULL with size 0. Every output pointer is required and unchanged on error.