rslearn.dataset.tile_utils¶
tile_utils ¶
Low-level helpers for reading raster data from tile stores.
get_needed_band_sets_and_indexes ¶
get_needed_band_sets_and_indexes(item: ItemType, bands: list[str], tile_store: TileStoreWithLayer) -> list[tuple[list[str], list[int], list[int]]]
Identify indexes of required bands in tile store.
Returns:
| Type | Description |
|---|---|
list[tuple[list[str], list[int], list[int]]]
|
A list for each tile-store layer that contains at least |
list[tuple[list[str], list[int], list[int]]]
|
one requested band, a tuple: (src_bands, src_idx, dst_idx) where |
list[tuple[list[str], list[int], list[int]]]
|
|
list[tuple[list[str], list[int], list[int]]]
|
|
list[tuple[list[str], list[int], list[int]]]
|
|
Source code in rslearn/dataset/tile_utils.py
read_raster_window_from_tiles ¶
read_raster_window_from_tiles(tile_store: TileStoreWithLayer, item: ItemType, bands: list[str], projection: Projection, bounds: PixelBounds, nodata_val: int | float | None, band_dtype: DTypeLike, remapper: Remapper | None = None, resampling: Resampling = bilinear, dst: RasterArray | None = None) -> RasterArray | None
Read an item's raster data from tiles into a window-aligned RasterArray.
Handles band mapping and spatial intersection internally. Uses first-valid nodata logic: only overwrites pixels where all bands equal the nodata value.
When nodata_val is None, every source pixel unconditionally overwrites the destination, and the destination is initialized as zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_store
|
TileStoreWithLayer
|
the TileStore to read from. |
required |
item
|
ItemType
|
the item to read. |
required |
bands
|
list[str]
|
the requested band names (determines dst band order). |
required |
projection
|
Projection
|
the projection of the window. |
required |
bounds
|
PixelBounds
|
the pixel bounds of the window. |
required |
nodata_val
|
int | float | None
|
the scalar nodata value for the band set, or |
required |
band_dtype
|
DTypeLike
|
data type for the output array. |
required |
remapper
|
Remapper | None
|
optional remapper to apply on the source pixel values. |
None
|
resampling
|
Resampling
|
how to resample pixels if re-projection is needed. |
bilinear
|
dst
|
RasterArray | None
|
optional pre-allocated RasterArray to write into. If None, a new one is allocated with T from the item's tile store data and H/W from the given bounds. |
None
|
Returns:
| Type | Description |
|---|---|
RasterArray | None
|
The dst RasterArray (allocated or provided), or None if the item has no |
RasterArray | None
|
matching bands and dst was not provided. |
Source code in rslearn/dataset/tile_utils.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
read_raster_windows ¶
read_raster_windows(group: list[ItemType], bands: list[str], tile_store: TileStoreWithLayer, projection: Projection, bounds: PixelBounds, nodata_val: int | float | None, band_dtype: DTypeLike, remapper: Remapper | None = None, resampling_method: Resampling = bilinear) -> list[RasterArray]
Read each item in the group into a window-aligned RasterArray.
Each returned RasterArray has shape (C, T, H, W) where C = len(bands), T is determined by the item's data in the tile store, and H/W match the window bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
list[ItemType]
|
items to read. We create one RasterArray per item. |
required |
bands
|
list[str]
|
requested band names. The bands in the RasterArrays will appear in this order. |
required |
tile_store
|
TileStoreWithLayer
|
tile store containing raster data. |
required |
projection
|
Projection
|
target projection. |
required |
bounds
|
PixelBounds
|
target pixel bounds. |
required |
nodata_val
|
int | float | None
|
scalar nodata value for the band set, or |
required |
band_dtype
|
DTypeLike
|
output data type. |
required |
remapper
|
Remapper | None
|
optional remapper. |
None
|
resampling_method
|
Resampling
|
resampling method. |
bilinear
|
Returns:
| Type | Description |
|---|---|
list[RasterArray]
|
A list of RasterArrays, one per item that had matching bands. |
Source code in rslearn/dataset/tile_utils.py
mask_stacked_rasters ¶
Mask stacked rasters where pixels equal the nodata value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stacked_rasters
|
NDArray[generic]
|
numpy array of shape (num_items, num_bands, T, height, width) containing raster values for each item in the group. |
required |
nodata_val
|
int | float
|
scalar nodata value used to identify invalid pixels. |
required |
Returns:
| Type | Description |
|---|---|
MaskedArray
|
np.ma.MaskedArray with the same shape as |
MaskedArray
|
pixels equal to the nodata value are masked. |