rslearn.utils.array¶
array ¶
Array util functions.
nodata_eq ¶
NaN-aware element-wise equality between array and a nodata sentinel.
Equivalent to array == nodata_value but also matches NaN positions when
the nodata sentinel is NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArray[generic]
|
the data array (any shape). |
required |
nodata_value
|
int | float
|
scalar nodata sentinel. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[bool_]
|
Boolean mask with the same shape as array; True where the value |
NDArray[bool_]
|
equals (or is NaN-matching) the nodata sentinel. |
Source code in rslearn/utils/array.py
unique_nodata_value ¶
Return the single unique value from values, or None if empty.
NaN-aware: all NaN entries are treated as equal.
Raises:
| Type | Description |
|---|---|
ValueError
|
if values contains more than one distinct value. |
Source code in rslearn/utils/array.py
copy_spatial_array ¶
copy_spatial_array(src: Tensor | NDArray[Any], dst: Tensor | NDArray[Any], src_offset: tuple[int, int], dst_offset: tuple[int, int]) -> None
Copy image content from a source array onto a destination array.
The source and destination might be in the same coordinate system. Only the portion of the source array that overlaps in the coordinate system with the destination array will be copied, and other parts of the destination array will not be overwritten.
Supports arrays with any number of dimensions >= 2. The last two dimensions are treated as (H, W); any leading dimensions (e.g. C, or C and T) are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Tensor | NDArray[Any]
|
the source array ( |
required |
dst
|
Tensor | NDArray[Any]
|
the destination array ( |
required |
src_offset
|
tuple[int, int]
|
the (col, row) position of the top-left pixel of src in the coordinate system. |
required |
dst_offset
|
tuple[int, int]
|
the (col, row) position of the top-left pixel of dst in the coordinate system. |
required |