rslearn.vis.render_raster¶
render_raster ¶
Functions for reading and rendering raster layers for visualization.
read_raster_layer ¶
read_raster_layer(window: Window, layer_name: str, layer_config: LayerConfig, band_names: list[str], group_idx: int = 0, bounds: PixelBounds | None = None) -> ndarray
Read a raster layer for visualization.
This reads bands from potentially multiple band sets to get the requested bands. Uses read_raster_layer_groups_for_data_input from rslearn.train.dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
Window
|
The window to read from |
required |
layer_name
|
str
|
The layer name |
required |
layer_config
|
LayerConfig
|
The layer configuration |
required |
band_names
|
list[str]
|
List of band names to read (e.g., ["B04", "B03", "B02"]) |
required |
group_idx
|
int
|
The item group index (default 0) |
0
|
bounds
|
PixelBounds | None
|
Optional bounds to read. If None, uses window.bounds |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array with shape (bands, height, width) as float32 |
Source code in rslearn/vis/render_raster.py
render_sentinel2_rgb ¶
render_sentinel2_rgb(array: ndarray, layer_config: LayerConfig, label_colors: dict[str, tuple[int, int, int]] | None = None) -> ndarray
Render by dividing by 10 and clipping (for Sentinel-2 B04/B03/B02 bands).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Input array with shape (channels, height, width) |
required |
layer_config
|
LayerConfig
|
LayerConfig (unused) |
required |
label_colors
|
dict[str, tuple[int, int, int]] | None
|
Label colors (unused) |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array with shape (height, width, channels) as uint8 |
Source code in rslearn/vis/render_raster.py
render_percentile ¶
render_percentile(array: ndarray, layer_config: LayerConfig, label_colors: dict[str, tuple[int, int, int]] | None = None) -> ndarray
Render using 2-98 percentile clipping per band.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Input array with shape (channels, height, width) |
required |
layer_config
|
LayerConfig
|
LayerConfig (unused) |
required |
label_colors
|
dict[str, tuple[int, int, int]] | None
|
Label colors (unused) |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array with shape (height, width, channels) as uint8 |
Source code in rslearn/vis/render_raster.py
render_minmax ¶
render_minmax(array: ndarray, layer_config: LayerConfig, label_colors: dict[str, tuple[int, int, int]] | None = None) -> ndarray
Render using min-max stretch per band.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Input array with shape (channels, height, width) |
required |
layer_config
|
LayerConfig
|
LayerConfig (unused) |
required |
label_colors
|
dict[str, tuple[int, int, int]] | None
|
Label colors (unused) |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array with shape (height, width, channels) as uint8 |
Source code in rslearn/vis/render_raster.py
render_linear ¶
render_linear(array: ndarray, layer_config: LayerConfig, label_colors: dict[str, tuple[int, int, int]] | None = None, vmin: float = 0, vmax: float = 1) -> ndarray
Render using user-specified min/max range per band.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Input array with shape (channels, height, width) |
required |
layer_config
|
LayerConfig
|
LayerConfig (unused) |
required |
label_colors
|
dict[str, tuple[int, int, int]] | None
|
Label colors (unused) |
None
|
vmin
|
float
|
Minimum value of the range |
0
|
vmax
|
float
|
Maximum value of the range |
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array with shape (height, width, channels) as uint8 |
Source code in rslearn/vis/render_raster.py
render_classes ¶
render_classes(array: ndarray, layer_config: LayerConfig, label_colors: dict[str, tuple[int, int, int]] | None = None) -> ndarray
Render a raster as a colored class map.
Maps integer pixel values to colors. Uses label_colors when provided, otherwise falls back to DEFAULT_COLORS by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Raster array with shape (bands, height, width) -- uses band 0 |
required |
layer_config
|
LayerConfig
|
LayerConfig with optional class_names |
required |
label_colors
|
dict[str, tuple[int, int, int]] | None
|
Optional pre-computed mapping of class name -> RGB color |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array with shape (height, width, 3) as uint8 |
Source code in rslearn/vis/render_raster.py
render_raster ¶
render_raster(array: ndarray, layer_config: LayerConfig, render_spec: dict[str, Any], label_colors: dict[str, tuple[int, int, int]] | None = None) -> ndarray
Dispatch to the appropriate raster render function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
(C, H, W) float32 input from read_raster_layer |
required |
layer_config
|
LayerConfig
|
LayerConfig for this layer |
required |
render_spec
|
dict[str, Any]
|
Dict with "name" key and optional "args" dict, e.g. {"name": "linear", "args": {"vmin": 0, "vmax": 3000}} |
required |
label_colors
|
dict[str, tuple[int, int, int]] | None
|
Optional pre-computed label colors to pass to render functions |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Rendered array as uint8 (H, W, C) |