rslearn.data_sources.utils¶
utils ¶
Utilities shared by data sources.
MOSAIC_MIN_ITEM_COVERAGE
module-attribute
¶
Minimum fraction of area that item should cover when adding it to a mosaic group.
MOSAIC_REMAINDER_EPSILON
module-attribute
¶
Fraction of original geometry area below which mosaic is considered to contain the entire geometry.
MatchedItemGroup
dataclass
¶
Bases: Generic[ItemType]
A matched item group carrying the request time range used to build it.
Source code in rslearn/data_sources/utils.py
PendingMosaic
dataclass
¶
A mosaic being created by match_candidate_items_to_window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
list
|
the list of items in the mosaic. |
required |
remainder
|
Polygon
|
the remainder of the geometry that is not covered by any of the items. |
required |
completed
|
bool
|
whether the mosaic is done (sufficient coverage of the geometry). |
False
|
Source code in rslearn/data_sources/utils.py
match_with_space_mode_contains ¶
match_with_space_mode_contains(geometry: STGeometry, items: list[ItemType], item_shps: list[Geometry], query_config: QueryConfig) -> list[list[ItemType]]
Match items that fully contain the window geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
STGeometry
|
the window's geometry. |
required |
items
|
list[ItemType]
|
list of items. |
required |
item_shps
|
list[Geometry]
|
the item shapes projected to the window's projection. |
required |
query_config
|
QueryConfig
|
the query configuration. |
required |
Returns:
| Type | Description |
|---|---|
list[list[ItemType]]
|
list of matched item groups, where each group contains a single item. |
Source code in rslearn/data_sources/utils.py
match_with_space_mode_intersects ¶
match_with_space_mode_intersects(geometry: STGeometry, items: list[ItemType], item_shps: list[Geometry], query_config: QueryConfig) -> list[list[ItemType]]
Match items that intersect any portion of the window geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
STGeometry
|
the window's geometry. |
required |
items
|
list[ItemType]
|
list of items. |
required |
item_shps
|
list[Geometry]
|
the item shapes projected to the window's projection. |
required |
query_config
|
QueryConfig
|
the query configuration. |
required |
Returns:
| Type | Description |
|---|---|
list[list[ItemType]]
|
list of matched item groups, where each group contains a single item. |
Source code in rslearn/data_sources/utils.py
match_with_space_mode_mosaic ¶
match_with_space_mode_mosaic(geometry: STGeometry, items: list[ItemType], item_shps: list[Geometry], query_config: QueryConfig) -> list[list[ItemType]]
Match items into mosaic groups that cover the window geometry.
Creates groups of items that together cover the window geometry. The number of overlapping coverages in each group is controlled by mosaic_compositing_overlaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
STGeometry
|
the window's geometry. |
required |
items
|
list[ItemType]
|
list of items. |
required |
item_shps
|
list[Geometry]
|
the item shapes projected to the window's projection. |
required |
query_config
|
QueryConfig
|
the query configuration. |
required |
Returns:
| Type | Description |
|---|---|
list[list[ItemType]]
|
list of matched item groups, where each group forms a mosaic covering the |
list[list[ItemType]]
|
window. |
Source code in rslearn/data_sources/utils.py
match_with_space_mode_single_composite ¶
match_with_space_mode_single_composite(geometry: STGeometry, items: list[ItemType], item_shps: list[Geometry], query_config: QueryConfig) -> list[list[ItemType]]
Match items for SINGLE_COMPOSITE.
All spatially-intersecting items go into a single group so that one composite can be created from all matching items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
STGeometry
|
the window's geometry. |
required |
items
|
list[ItemType]
|
list of items. |
required |
item_shps
|
list[Geometry]
|
the item shapes projected to the window's projection. |
required |
query_config
|
QueryConfig
|
the query configuration. |
required |
Returns:
| Type | Description |
|---|---|
list[list[ItemType]]
|
list containing a single item group of all spatially-intersecting items, |
list[list[ItemType]]
|
or empty list if no items intersect. |
Source code in rslearn/data_sources/utils.py
match_candidate_items_to_window ¶
match_candidate_items_to_window(geometry: STGeometry, items: list[ItemType], query_config: QueryConfig) -> list[MatchedItemGroup[ItemType]]
Match candidate items to a window based on the query configuration.
If period_duration is set, the window time range is split into sub-periods
and the handler is applied per-period with effective max_matches=1.
When period_duration is set and per_period_mosaic_reverse_time_order
is True (the current default), the resulting groups are reversed so that the
most recent period comes first. This default will change to False after
2026-04-01.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
STGeometry
|
the window's geometry |
required |
items
|
list[ItemType]
|
all items from the data source that intersect spatially with the geometry |
required |
query_config
|
QueryConfig
|
the query configuration to use for matching |
required |
Returns:
| Type | Description |
|---|---|
list[MatchedItemGroup[ItemType]]
|
list of matched item groups. |
Source code in rslearn/data_sources/utils.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 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 | |