rslearn.config.dataset¶
dataset ¶
Classes for storing configuration of a dataset.
DType ¶
Bases: StrEnum
Data type of a raster.
Source code in rslearn/config/dataset.py
get_numpy_dtype ¶
Returns numpy dtype object corresponding to this DType.
Source code in rslearn/config/dataset.py
ResamplingMethod ¶
Bases: StrEnum
An enum representing the rasterio Resampling.
Source code in rslearn/config/dataset.py
get_rasterio_resampling ¶
BandSetConfig ¶
Bases: BaseModel
A configuration for a band set in a raster layer.
Each band set specifies one or more bands that should be stored together. It also specifies the storage format and dtype, the zoom offset, etc. for these bands.
Source code in rslearn/config/dataset.py
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
after_validator ¶
after_validator() -> BandSetConfig
Ensure the BandSetConfig is valid, and handle the num_bands field.
Source code in rslearn/config/dataset.py
get_final_projection_and_bounds ¶
get_final_projection_and_bounds(projection: Projection, bounds: PixelBounds) -> tuple[Projection, PixelBounds]
Gets the final projection/bounds based on band set config.
The band set config may apply a non-zero zoom offset or a fixed spatial_size that modifies the window's projection and bounds.
When spatial_size is set, the projection resolution is scaled so that the
window's geographic extent maps to exactly spatial_size pixels. The returned
bounds will have width = spatial_size[1] and height = spatial_size[0].
Note: the spatial_size path uses round() to compute the new pixel-space
origin, which can shift the geographic origin by up to half of the new
(coarser) pixel size. This is the same rounding behaviour used by
ResolutionFactor.multiply_bounds and is negligible for coarse-resolution
layers (e.g. ERA5 at 0.1 deg) where sub-pixel shifts are irrelevant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projection
|
Projection
|
the window's projection |
required |
bounds
|
PixelBounds
|
the window's bounds |
required |
Returns:
| Type | Description |
|---|---|
tuple[Projection, PixelBounds]
|
tuple of updated projection and bounds |
Source code in rslearn/config/dataset.py
convert_format_from_legacy
classmethod
¶
Support legacy format of the RasterFormat.
The legacy format sets 'name' instead of 'class_path', and uses custom parsing for the init_args.
Source code in rslearn/config/dataset.py
instantiate_raster_format ¶
instantiate_raster_format() -> RasterFormat
Instantiate the RasterFormat specified by this BandSetConfig.
Source code in rslearn/config/dataset.py
SpaceMode ¶
Bases: StrEnum
Spatial matching mode when looking up items corresponding to a window.
Source code in rslearn/config/dataset.py
CONTAINS
class-attribute
instance-attribute
¶
Items must contain the entire window.
INTERSECTS
class-attribute
instance-attribute
¶
Items must overlap any portion of the window.
MOSAIC
class-attribute
instance-attribute
¶
Groups of items should be computed that cover the entire window.
During materialization, items in each group are merged to form a mosaic in the dataset.
PER_PERIOD_MOSAIC
class-attribute
instance-attribute
¶
Deprecated: use MOSAIC with period_duration instead. Will be removed after 2026-05-01.
SINGLE_COMPOSITE
class-attribute
instance-attribute
¶
Put all intersecting items into a single group.
This can be used together with compositing method to create one composite for the layer.
TimeMode ¶
Bases: StrEnum
Temporal matching mode when looking up items corresponding to a window.
Note: setting this is deprecated. It should always be set to TimeMode.WITHIN, and TimeMode will be removed in a future release.
Source code in rslearn/config/dataset.py
WITHIN
class-attribute
instance-attribute
¶
Items must be within the window time range.
NEAREST
class-attribute
instance-attribute
¶
Deprecated: Select items closest to the window time range, up to max_matches.
BEFORE
class-attribute
instance-attribute
¶
Deprecated: Select items before the end of the window time range, up to max_matches.
AFTER
class-attribute
instance-attribute
¶
Deprecated: Select items after the start of the window time range, up to max_matches.
QueryConfig ¶
Bases: BaseModel
A configuration for querying items in a data source.
Source code in rslearn/config/dataset.py
DataSourceConfig ¶
Bases: BaseModel
Configuration for a DataSource in a dataset layer.
Source code in rslearn/config/dataset.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 | |
get_request_time_range ¶
get_request_time_range(window_time_range: tuple[datetime, datetime] | None) -> tuple[datetime, datetime] | None
Apply time_offset and duration to a window time range.
This converts a window's time range into the request time range that should be used during prepare and materialize.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window_time_range
|
tuple[datetime, datetime] | None
|
the window's original time range, or None. |
required |
Returns:
| Type | Description |
|---|---|
tuple[datetime, datetime] | None
|
The adjusted time range, or None if the input was None. |
Source code in rslearn/config/dataset.py
convert_from_legacy
classmethod
¶
Support legacy format of the DataSourceConfig.
The legacy format sets 'name' instead of 'class_path', and mixes the arguments for the DataSource in with the DataSourceConfig keys.
Source code in rslearn/config/dataset.py
LayerType ¶
CompositingMethod ¶
Bases: StrEnum
Method how to select pixels for the composite from corresponding items of a window.
For MEAN and MEDIAN modes, mosaic_compositing_overlaps (in the QueryConfig) should be set higher than 1 so that rslearn creates item groups during prepare that cover the window with multiple overlaps. At each pixel/band, the mean and median can then be computed across items in each group that cover that pixel.
Source code in rslearn/config/dataset.py
FIRST_VALID
class-attribute
instance-attribute
¶
Select first valid pixel in order of corresponding items (might be sorted)
MEAN
class-attribute
instance-attribute
¶
Select per-pixel mean value of corresponding items of a window
MEDIAN
class-attribute
instance-attribute
¶
Select per-pixel median value of corresponding items of a window
SPATIAL_MOSAIC_TEMPORAL_STACK
class-attribute
instance-attribute
¶
Spatial first-valid compositing per timestep, stacked along T.
Items, which can contain multi-temporal rasters, are spatially composited using first-valid logic within each timestep, but timesteps are stacked. The result is a (C, T, H, W) RasterArray whose T dimension spans the union of all item timesteps, clipped to the window time range.
TEMPORAL_MEAN
class-attribute
instance-attribute
¶
Reduce a multi-temporal raster stack to one timestep via temporal mean.
TEMPORAL_MAX
class-attribute
instance-attribute
¶
Reduce a multi-temporal raster stack to one timestep via temporal max.
TEMPORAL_MIN
class-attribute
instance-attribute
¶
Reduce a multi-temporal raster stack to one timestep via temporal min.
LayerConfig ¶
Bases: BaseModel
Configuration of a layer in a dataset.
Source code in rslearn/config/dataset.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | |
after_validator ¶
after_validator() -> LayerConfig
Ensure the LayerConfig is valid.
Source code in rslearn/config/dataset.py
instantiate_data_source
cached
¶
instantiate_data_source(ds_path: UPath | None = None) -> DataSource
Instantiate the data source specified by this config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds_path
|
UPath | None
|
optional dataset path to include in the DataSourceContext. |
None
|
Returns:
| Type | Description |
|---|---|
DataSource
|
the DataSource object. |
Source code in rslearn/config/dataset.py
instantiate_vector_format ¶
instantiate_vector_format() -> VectorFormat
Instantiate the vector format specified by this config.
Source code in rslearn/config/dataset.py
instantiate_compositor ¶
instantiate_compositor() -> Compositor
Instantiate the Compositor for this layer's compositing_method.
Returns:
| Type | Description |
|---|---|
Compositor
|
A Compositor instance -- either a built-in one resolved from the |
Compositor
|
CompositingMethod enum, or a custom one instantiated via jsonargparse |
Compositor
|
from a class_path/init_args dict. |
Source code in rslearn/config/dataset.py
StorageConfig ¶
Bases: BaseModel
Configuration for the WindowStorageFactory (window metadata storage backend).
Source code in rslearn/config/dataset.py
instantiate_window_storage_factory ¶
instantiate_window_storage_factory() -> WindowStorageFactory
Instantiate the WindowStorageFactory specified by this config.
Source code in rslearn/config/dataset.py
WindowDataStorageConfig ¶
Bases: BaseModel
Configuration for the WindowDataStorage of the dataset.
The WindowDataStorage controls the on-disk layout of materialized raster and vector data within each window.
Source code in rslearn/config/dataset.py
instantiate_factory ¶
instantiate_factory() -> WindowDataStorageFactory
Instantiate the WindowDataStorageFactory specified by this config.
Source code in rslearn/config/dataset.py
DatasetConfig ¶
Bases: BaseModel
Overall dataset configuration.
Source code in rslearn/config/dataset.py
layer_names_validator
classmethod
¶
layer_names_validator(v: dict[str, LayerConfig]) -> dict[str, LayerConfig]
Ensure layer names don't contain periods, since we use periods to distinguish different materialized groups within a layer.
Source code in rslearn/config/dataset.py
ensure_timedelta ¶
Ensure the value is a timedelta.
If the value is a string, we try to parse it with pytimeparse.
This function is meant to be used like Annotated[timedelta, BeforeValidator(ensure_timedelta)].
Source code in rslearn/config/dataset.py
ensure_optional_timedelta ¶
Like ensure_timedelta, but allows None as a value.
Source code in rslearn/config/dataset.py
serialize_optional_timedelta ¶
Serialize an optional timedelta for compatibility with pytimeparse.