Skip to content

Fetch and stream grid data

You are viewing in-progress documentation for v2 (Beta). Switch to the stable version for the current production release.

A grid’s raster values are read back per band, per chunk. Large grids are tiled into chunks so you can stream them without pulling the whole array at once; you fetch each chunk and place it into the full array using the chunk’s offset. This guide walks that loop.

  1. An API key: my-api-key.

  2. A domain and a completed grid: your-domain-id and your-grid-id — e.g. the fuel-load grid from Build a surface fuel grid from LANDFIRE.

GET the grid. Two fields drive the rest: georeference.shape (the full (height, width)) and chunks.count (how many chunks to fetch per band).

GET grid
curl -X 'GET' \
'https://api-v2-prod-nyvjyh5ywa-uw.a.run.app/domains/your-domain-id/grids/your-grid-id' \
-H 'accept: application/json' \
-H 'api-key: my-api-key'

bands lists the band keys you can request. chunks.count here is 1 (this grid fits in a single tile); a larger grid reports more, laid out count_by_axis.

GET /grids/{{GRID_ID}}/data/{band}/{chunk_index}. The response carries the chunk’s own shape, an offset into the full array, the chunk’s affine transform, and the values.

GET data/fuel_load.1hr/0
curl -X 'GET' \
'https://api-v2-prod-nyvjyh5ywa-uw.a.run.app/domains/your-domain-id/grids/your-grid-id/data/fuel_load.1hr/0' \
-H 'accept: application/json' \
-H 'api-key: my-api-key'

data.values is the real chunk data — a flat array of shape[0] × shape[1] values in order ("C", row-major). It’s shown abridged above; the full chunk here is 30 × 45 = 1350 floats. Two formats:

  • dense (the default) — values holds every cell, in order.
  • sparse — request it with ?array_format=sparse. values holds only the cells that differ from fill_value, paired with indices; reconstruct by filling with fill_value then scattering values into indices. This is worth requesting for chunks that are mostly one value (e.g. a masked grid that’s largely zero) — it also lets an oversized chunk fit under the response size limit.

The SDK does the per-chunk loop for you. grid.to_numpy(band) fetches every chunk, handles dense vs sparse, and places each at its offset — returning the full (height, width) array ((z, y, x) for a voxel grid). grid.to_xarray() returns every band as a georeferenced xarray.Dataset, with x/y coordinates derived from the grid’s affine transform.

Read every band into an xarray.Dataset
import fastfuels_sdk.v2 as ff
ff.set_api_key("my-api-key")
grid = ff.get_grid("your-domain-id", "your-grid-id")
# Every band at once as a georeferenced xarray.Dataset, with x / y coordinate
# vectors derived from the grid's affine transform and the CRS on the dataset.
dataset = grid.to_xarray()

Working over raw HTTP with curl instead? Loop chunk_index from 0 to chunks.count - 1 and position each chunk by its metadata.offset, exactly as the responses above show.

These apply when you fetch over raw HTTP (the curl path); the SDK’s to_numpy() / to_xarray() handle band iteration, chunk offsets, and the dense/sparse formats for you.

  • Forgetting it’s per band. Each data/{band}/{chunk_index} call returns one band. Loop over bands (from step 1) as well as over chunks.
  • Ignoring offset. Concatenating chunks in fetch order mis-places them. Always position a chunk with its metadata.offset — that’s what makes the reassembled array correct for multi-chunk grids.
  • Assuming a format. The response format follows the array_format you request (dense by default), and every chunk comes back in that format. Branch on data.format if your code requests sparse anywhere, so the reassembly handles both shapes.
  • Grid not completed. Data is only readable once the grid finishes; chunks is null and there’s nothing to fetch while it’s pending.