rslearn.vis.utils¶
utils ¶
Utility functions and constants for visualization.
read_vector_layer ¶
read_vector_layer(window: Window, layer_name: str, layer_config: LayerConfig, group_idx: int = 0) -> list[Any]
Read a vector layer for visualization.
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 |
group_idx
|
int
|
The item group index (default 0) |
0
|
Returns:
| Type | Description |
|---|---|
list[Any]
|
List of Feature objects |
Source code in rslearn/vis/utils.py
generate_label_colors_for_layer ¶
generate_label_colors_for_layer(layer_config: LayerConfig) -> dict[str, tuple[int, int, int]] | None
Generate label colors from a layer config's class_names.
Returns None if class_names is not set, signaling that the caller should fall back to DEFAULT_COLORS by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_config
|
LayerConfig
|
LayerConfig to read class_names from |
required |
Returns:
| Type | Description |
|---|---|
dict[str, tuple[int, int, int]] | None
|
Dictionary mapping label class names to RGB color tuples, or None |
Source code in rslearn/vis/utils.py
format_window_info ¶
format_window_info(window: Window) -> tuple[tuple[datetime, datetime] | None, float | None, float | None]
Extract window metadata for display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
Window
|
Window object |
required |
Returns:
| Type | Description |
|---|---|
tuple[tuple[datetime, datetime] | None, float | None, float | None]
|
Tuple of (time_range, lat, lon) where time_range is a tuple of (start, end) datetime objects |
Source code in rslearn/vis/utils.py
array_to_bytes ¶
Convert a numpy array to PNG bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Array with shape (height, width, channels) or (height, width) as uint8 |
required |
resampling
|
Resampling
|
PIL Image resampling method (default NEAREST) |
NEAREST
|
Returns:
| Type | Description |
|---|---|
bytes
|
PNG image bytes |