stac
copernicus #
Copernicus Data Space Ecosystem (CDSE) tools and constants.
CopernicusS2Band #
Bases: StrEnum
Copernicus Sentinel-2 Bands for Level-2A.
The value of each member corresponds to the asset key for the band. Base band names (e.g., 'B02') default to their native resolution. Explicit resolution members (e.g., 'B02_20m') are also provided.
native_res
property
#
native_res: int
Returns the native resolution of the band in meters.
Defaults to 10m if band base name is not recognized.
at_res #
at_res(resolution: int | CopernicusS2Resolution) -> str
Returns the asset key for this band at the specified resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
int | CopernicusS2Resolution
|
The resolution to get the key for (e.g., 20 or CopernicusS2Resolution.R20M). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The asset key string (e.g., 'B02_20m'). |
Source code in src/geospatial_tools/stac/copernicus/constants.py
184 185 186 187 188 189 190 191 192 193 194 195 | |
CopernicusS2Collection #
Bases: StrEnum
Copernicus Sentinel-2 Collections.
CopernicusS2Property #
Bases: StrEnum
Copernicus Sentinel-2 STAC query properties.
These are standard STAC properties shared across catalogs. The sortby_field
property returns the full JSON path required by the STAC API sortby object.
sortby_field
property
#
sortby_field: str
Returns the full JSON path prefix required by the STAC API sortby object.
CopernicusS2Resolution #
Bases: int, Enum
Copernicus Sentinel-2 Resolutions in meters.
__str__ #
__str__() -> str
Returns the resolution as a string with 'm' suffix.
Source code in src/geospatial_tools/stac/copernicus/constants.py
65 66 67 | |
__repr__ #
__repr__() -> str
Returns the band name as a string.
Source code in src/geospatial_tools/stac/copernicus/constants.py
69 70 71 | |
auth #
This module contains authentication-related functions.
get_copernicus_credentials #
get_copernicus_credentials(logger: Logger = LOGGER) -> tuple[str, str] | None
Retrieves Copernicus credentials from environment variables or prompts the user.
This function first checks for COPERNICUS_USERNAME and COPERNICUS_PASSWORD
environment variables. If they are not set, it interactively prompts the user
for their username and password.
Using environment variables is recommended for security and to comply with the 12-factor app methodology, which separates configuration from code. This prevents hardcoding sensitive information and makes the application more portable across different environments (development, testing, production).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
Logger instance. |
LOGGER
|
Returns:
| Type | Description |
|---|---|
tuple[str, str] | None
|
A tuple containing the username and password, or None if they could not be |
tuple[str, str] | None
|
obtained. |
Source code in src/geospatial_tools/stac/copernicus/auth.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
get_copernicus_token #
get_copernicus_token(logger: Logger = LOGGER) -> str | None
Retrieves an access token from the Copernicus Data Space Ecosystem.
This function uses the credentials obtained from get_copernicus_credentials
to request an access token from the authentication endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
Logger instance. |
LOGGER
|
Returns:
| Type | Description |
|---|---|
str | None
|
The access token as a string, or None if authentication fails. |
Source code in src/geospatial_tools/stac/copernicus/auth.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 | |
constants #
This module contains Enums for Sentinel-2 on Copernicus Data Space Ecosystem (CDSE).
CopernicusS2Collection #
Bases: StrEnum
Copernicus Sentinel-2 Collections.
CopernicusS2Property #
Bases: StrEnum
Copernicus Sentinel-2 STAC query properties.
These are standard STAC properties shared across catalogs. The sortby_field
property returns the full JSON path required by the STAC API sortby object.
sortby_field
property
#
sortby_field: str
Returns the full JSON path prefix required by the STAC API sortby object.
CopernicusS2Resolution #
Bases: int, Enum
Copernicus Sentinel-2 Resolutions in meters.
__str__ #
__str__() -> str
Returns the resolution as a string with 'm' suffix.
Source code in src/geospatial_tools/stac/copernicus/constants.py
65 66 67 | |
__repr__ #
__repr__() -> str
Returns the band name as a string.
Source code in src/geospatial_tools/stac/copernicus/constants.py
69 70 71 | |
CopernicusS2Band #
Bases: StrEnum
Copernicus Sentinel-2 Bands for Level-2A.
The value of each member corresponds to the asset key for the band. Base band names (e.g., 'B02') default to their native resolution. Explicit resolution members (e.g., 'B02_20m') are also provided.
native_res
property
#
native_res: int
Returns the native resolution of the band in meters.
Defaults to 10m if band base name is not recognized.
at_res #
at_res(resolution: int | CopernicusS2Resolution) -> str
Returns the asset key for this band at the specified resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
int | CopernicusS2Resolution
|
The resolution to get the key for (e.g., 20 or CopernicusS2Resolution.R20M). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The asset key string (e.g., 'B02_20m'). |
Source code in src/geospatial_tools/stac/copernicus/constants.py
184 185 186 187 188 189 190 191 192 193 194 195 | |
core #
This module contains functions that are related to STAC API.
AssetSubItem #
AssetSubItem(asset: Item, item_id: str, band: str, filename: str | Path)
Class that represent a STAC asset sub item.
Generally represents a single satellite image band.
Initializes an AssetSubItem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset
|
Item
|
The pystac Item this asset belongs to. |
required |
item_id
|
str
|
The ID of the item. |
required |
band
|
str
|
The band name of this sub-item. |
required |
filename
|
str | Path
|
The local filename of the downloaded asset. |
required |
Source code in src/geospatial_tools/stac/core.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
Asset #
Asset(
asset_id: str,
bands: list[str] | None = None,
asset_item_list: list[AssetSubItem] | None = None,
merged_asset_path: str | Path | None = None,
reprojected_asset: str | Path | None = None,
logger: Logger = LOGGER,
)
Represents a STAC asset, potentially composed of multiple bands/sub-items.
Initializes an Asset object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_id
|
str
|
Unique ID for the asset (usually the item ID). |
required |
bands
|
list[str] | None
|
List of bands this asset contains. |
None
|
asset_item_list
|
list[AssetSubItem] | None
|
List of AssetSubItem objects belonging to this asset. |
None
|
merged_asset_path
|
str | Path | None
|
Path to the merged multi-band raster file. |
None
|
reprojected_asset
|
str | Path | None
|
Path to the reprojected raster file. |
None
|
logger
|
Logger
|
Logger instance. |
LOGGER
|
Source code in src/geospatial_tools/stac/core.py
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 | |
__iter__ #
__iter__() -> Iterator[AssetSubItem]
Allows direct iteration: for item in asset:
Source code in src/geospatial_tools/stac/core.py
194 195 196 | |
__len__ #
__len__() -> int
Allows checking size: len(asset)
Source code in src/geospatial_tools/stac/core.py
198 199 200 | |
__contains__ #
__contains__(band_name: str) -> bool
Allows checking for band existence: "B04" in asset
Source code in src/geospatial_tools/stac/core.py
202 203 204 | |
__getitem__ #
__getitem__(index: int) -> AssetSubItem
__getitem__(band_name: str) -> AssetSubItem
__getitem__(key: int | str) -> AssetSubItem
Allows indexing by position or band name:
asset[0] or asset["B04"]
Source code in src/geospatial_tools/stac/core.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
add_asset_item #
add_asset_item(asset: AssetSubItem) -> None
Adds an AssetSubItem to the asset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset
|
AssetSubItem
|
The AssetSubItem to add. |
required |
Source code in src/geospatial_tools/stac/core.py
228 229 230 231 232 233 234 235 236 237 | |
show_asset_items #
show_asset_items() -> None
Show items that belong to this asset.
Source code in src/geospatial_tools/stac/core.py
239 240 241 242 243 244 | |
merge_asset #
merge_asset(
base_directory: str | Path | None = None, delete_sub_items: bool = False
) -> Path | None
Merges individual band rasters into a single multi-band raster file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_directory
|
str | Path | None
|
Directory where the merged file will be saved. |
None
|
delete_sub_items
|
bool
|
If True, delete individual band files after merging. |
False
|
Returns:
| Type | Description |
|---|---|
Path | None
|
The Path to the merged file if successful, else None. |
Source code in src/geospatial_tools/stac/core.py
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 | |
reproject_merged_asset #
reproject_merged_asset(
target_projection: str | int,
base_directory: str | Path | None = None,
delete_merged_asset: bool = False,
) -> Path | None
Reprojects the merged multi-band raster to a target projection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_projection
|
str | int
|
The target CRS (EPSG code or string). |
required |
base_directory
|
str | Path | None
|
Directory where the reprojected file will be saved. |
None
|
delete_merged_asset
|
bool
|
If True, delete the merged file after reprojection. |
False
|
Returns:
| Type | Description |
|---|---|
Path | None
|
The Path to the reprojected file if successful, else None. |
Source code in src/geospatial_tools/stac/core.py
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 | |
delete_asset_sub_items #
delete_asset_sub_items() -> None
Delete all asset sub items that belong to this asset.
Source code in src/geospatial_tools/stac/core.py
332 333 334 335 336 337 | |
delete_merged_asset #
delete_merged_asset() -> None
Delete merged asset.
Source code in src/geospatial_tools/stac/core.py
339 340 341 342 343 | |
delete_reprojected_asset #
delete_reprojected_asset() -> None
Delete reprojected asset.
Source code in src/geospatial_tools/stac/core.py
345 346 347 348 349 | |
StacSearch #
StacSearch(catalog_name: str, logger: Logger = LOGGER)
Utility class to help facilitate and automate STAC API searches through the use of pystac_client.Client.
Initializes a StacSearch instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_name
|
str
|
Name of the STAC catalog (e.g., 'planetary_computer', 'copernicus'). |
required |
logger
|
Logger
|
Logger instance. |
LOGGER
|
Source code in src/geospatial_tools/stac/core.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
search #
search(
date_range: DateLike = None,
max_items: int | None = None,
limit: int | None = None,
ids: list[str] | None = None,
collections: str | list[str] | None = None,
bbox: BBoxLike | None = None,
intersects: IntersectsLike | None = None,
query: dict[str, Any] | None = None,
sortby: list[dict[str, str]] | str | list[str] | None = None,
max_retries: int = 3,
delay: int = 5,
) -> list[Item]
STAC API search that will use search query and parameters. Essentially a wrapper on pystac_client.Client.
Parameter descriptions taken from pystac docs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_range
|
DateLike
|
Either a single datetime or datetime range used to filter results.
You may express a single datetime using a :class: |
None
|
max_items
|
int | None
|
The maximum number of items to return from the search, even if there are more matching results. |
None
|
limit
|
int | None
|
A recommendation to the service as to the number of items to return per page of results. |
None
|
ids
|
list[str] | None
|
List of one or more Item ids to filter on. |
None
|
collections
|
str | list[str] | None
|
List of one or more Collection IDs or pystac. Collection instances. Only Items in one of the provided Collections will be searched |
None
|
bbox
|
BBoxLike | None
|
A list, tuple, or iterator representing a bounding box of 2D or 3D coordinates. Results will be filtered to only those intersecting the bounding box. |
None
|
intersects
|
IntersectsLike | None
|
A string or dictionary representing a GeoJSON geometry, or an object that implements a geo_interface property, as supported by several libraries including Shapely, ArcPy, PySAL, and geojson. Results filtered to only those intersecting the geometry. |
None
|
query
|
dict[str, Any] | None
|
List or JSON of query parameters as per the STAC API query extension. |
None
|
sortby
|
list[dict[str, str]] | str | list[str] | None
|
A single field or list of fields to sort the response by |
None
|
max_retries
|
int
|
|
3
|
delay
|
int
|
|
5
|
Returns:
| Type | Description |
|---|---|
list[Item]
|
A list of pystac.Item objects matching the search criteria. |
Source code in src/geospatial_tools/stac/core.py
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 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 | |
search_for_date_ranges #
search_for_date_ranges(
date_ranges: Sequence[DateLike],
max_items: int | None = None,
limit: int | None = None,
collections: str | list[str] | None = None,
bbox: BBoxLike | None = None,
intersects: IntersectsLike | None = None,
query: dict[str, Any] | None = None,
sortby: list[dict[str, str]] | str | list[str] | None = None,
max_retries: int = 3,
delay: int = 5,
) -> list[Item]
STAC API search that will use search query and parameters for each date range in given list of date_ranges.
Date ranges can be generated with the help of the geospatial_tools.utils.create_date_range_for_specific_period
function for more complex ranges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_ranges
|
Sequence[DateLike]
|
List containing datetime date ranges |
required |
max_items
|
int | None
|
The maximum number of items to return from the search, even if there are more matching results |
None
|
limit
|
int | None
|
A recommendation to the service as to the number of items to return per page of results. |
None
|
collections
|
str | list[str] | None
|
List of one or more Collection IDs or pystac. Collection instances. Only Items in one of the provided Collections will be searched |
None
|
bbox
|
BBoxLike | None
|
A list, tuple, or iterator representing a bounding box of 2D or 3D coordinates. Results will be filtered to only those intersecting the bounding box. |
None
|
intersects
|
IntersectsLike | None
|
A string or dictionary representing a GeoJSON geometry, or an object that implements a geo_interface property, as supported by several libraries including Shapely, ArcPy, PySAL, and geojson. Results filtered to only those intersecting the geometry. |
None
|
query
|
dict[str, Any] | None
|
List or JSON of query parameters as per the STAC API query extension. |
None
|
sortby
|
list[dict[str, str]] | str | list[str] | None
|
A single field or list of fields to sort the response by |
None
|
max_retries
|
int
|
|
3
|
delay
|
int
|
|
5
|
Returns:
| Type | Description |
|---|---|
list[Item]
|
A list of pystac.Item objects. |
Source code in src/geospatial_tools/stac/core.py
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 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 | |
sort_results_by_cloud_coverage #
sort_results_by_cloud_coverage() -> list[Item] | None
Sorts the search results by cloud coverage (ascending).
Returns:
| Type | Description |
|---|---|
list[Item] | None
|
A list of sorted pystac.Item objects, or None if no results exist. |
Source code in src/geospatial_tools/stac/core.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | |
filter_no_data #
filter_no_data(property_name: str, max_no_data_value: int = 5) -> list[Item] | None
Filter results that are above a nodata value threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name
|
str
|
Name of the property containing nodata percentage. |
required |
max_no_data_value
|
int
|
Max allowed percentage of nodata. (Default value = 5) |
5
|
Returns:
| Type | Description |
|---|---|
list[Item] | None
|
Filtered list of pystac.Item objects. |
Source code in src/geospatial_tools/stac/core.py
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | |
download_search_results #
download_search_results(bands: list[str], base_directory: str | Path) -> list[Asset]
Downloads assets for all search results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bands
|
list[str]
|
List of bands to download. |
required |
base_directory
|
str | Path
|
The base directory for downloads. |
required |
Returns:
| Type | Description |
|---|---|
list[Asset]
|
A list of Asset objects for the downloaded search results. |
Source code in src/geospatial_tools/stac/core.py
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
download_sorted_by_cloud_cover_search_results #
download_sorted_by_cloud_cover_search_results(
bands: list[str],
base_directory: str | Path,
first_x_num_of_items: int | None = None,
) -> list[Asset]
Downloads sorted results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bands
|
list[str]
|
List of bands to download. |
required |
base_directory
|
str | Path
|
The base directory for downloads. |
required |
first_x_num_of_items
|
int | None
|
Optional number of top items to download. |
None
|
Returns:
| Type | Description |
|---|---|
list[Asset]
|
A list of Asset objects for the downloaded items. |
Source code in src/geospatial_tools/stac/core.py
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 | |
download_best_cloud_cover_result #
download_best_cloud_cover_result(
bands: list[str], base_directory: str | Path
) -> Asset | None
Downloads the single best result based on cloud cover.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bands
|
list[str]
|
List of bands to download. |
required |
base_directory
|
str | Path
|
The base directory for downloads. |
required |
Returns:
| Type | Description |
|---|---|
Asset | None
|
The Asset object for the best result, or None if no results available. |
Source code in src/geospatial_tools/stac/core.py
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 | |
AbstractStacWrapper #
AbstractStacWrapper(
collection: str | None = None,
date_range: DateLike = None,
bbox: BBoxLike | None = None,
intersects: IntersectsLike | None = None,
logger: Logger = LOGGER,
)
Bases: ABC
Abstract base class for STAC search wrappers using a Facade + Proxy pattern.
This class provides a common interface and shared logic for different STAC collections
(e.g., Sentinel-1, Sentinel-2). It delegates actual STAC operations to an underlying
StacSearch client and exposes results via proxy properties.
Initialize the STAC wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
str | None
|
The STAC collection ID to search. |
None
|
date_range
|
DateLike
|
Temporal filter for the search. |
None
|
bbox
|
BBoxLike | None
|
Spatial bounding box filter. |
None
|
intersects
|
IntersectsLike | None
|
Spatial GeoJSON geometry filter. |
None
|
logger
|
Logger
|
Logger instance. |
LOGGER
|
Source code in src/geospatial_tools/stac/core.py
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 | |
search_results
property
#
search_results: list[Item] | None
Proxy property for STAC search results from the underlying client.
downloaded_assets
property
#
downloaded_assets: list[Asset] | None
Proxy property for downloaded assets from the underlying client.
with_custom_query #
with_custom_query(query_params: dict[str, Any]) -> Self
Merge custom STAC query parameters and invalidate current state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_params
|
dict[str, Any]
|
Dictionary of custom STAC query parameters. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The instance itself (Self) for fluent chaining. |
Source code in src/geospatial_tools/stac/core.py
939 940 941 942 943 944 945 946 947 948 949 950 951 | |
search #
search() -> list[Item] | None
Execute the STAC search using the built query and parameters.
Returns:
| Type | Description |
|---|---|
list[Item] | None
|
List of matched pystac Items, or None if no results. |
Source code in src/geospatial_tools/stac/core.py
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
download #
download(bands: list[str], base_directory: str | Path) -> list[Asset] | None
Download assets for the matched search results.
Triggers a search if no results are currently available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bands
|
list[str]
|
List of asset keys (bands) to download. |
required |
base_directory
|
str | Path
|
Local directory where assets will be saved. |
required |
Returns:
| Type | Description |
|---|---|
list[Asset] | None
|
List of downloaded Asset objects. |
Source code in src/geospatial_tools/stac/core.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
create_planetary_computer_catalog #
create_planetary_computer_catalog(
max_retries: int = 3, delay: int = 5, logger: Logger = LOGGER
) -> Client | None
Creates a Planetary Computer Catalog Client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_retries
|
int
|
The maximum number of retries for the API connection. (Default value = 3) |
3
|
delay
|
int
|
The delay between retry attempts in seconds. (Default value = 5) |
5
|
logger
|
Logger
|
The logger instance to use. (Default value = LOGGER) |
LOGGER
|
Returns:
| Type | Description |
|---|---|
Client | None
|
A pystac_client.Client instance if successful, else None. |
Source code in src/geospatial_tools/stac/core.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
create_copernicus_catalog #
create_copernicus_catalog(
max_retries: int = 3, delay: int = 5, logger: Logger = LOGGER
) -> Client | None
Creates a Copernicus Data Space Ecosystem Catalog Client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_retries
|
int
|
The maximum number of retries for the API connection. (Default value = 3) |
3
|
delay
|
int
|
The delay between retry attempts in seconds. (Default value = 5) |
5
|
logger
|
Logger
|
The logger instance to use. (Default value = LOGGER) |
LOGGER
|
Returns:
| Type | Description |
|---|---|
Client | None
|
A pystac_client.Client instance if successful, else None. |
Source code in src/geospatial_tools/stac/core.py
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 | |
catalog_generator #
catalog_generator(catalog_name: str, logger: Logger = LOGGER) -> Client | None
Generates a STAC Client for the specified catalog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_name
|
str
|
The name of the catalog (e.g., 'planetary_computer', 'copernicus'). |
required |
logger
|
Logger
|
The logger instance to use. |
LOGGER
|
Returns:
| Type | Description |
|---|---|
Client | None
|
A pystac_client.Client instance for the requested catalog if supported, else None. |
Source code in src/geospatial_tools/stac/core.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
list_available_catalogs #
list_available_catalogs(logger: Logger = LOGGER) -> frozenset[str]
Lists all available STAC catalogs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
The logger instance to use. |
LOGGER
|
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
A frozenset of available catalog names. |
Source code in src/geospatial_tools/stac/core.py
122 123 124 125 126 127 128 129 130 131 132 133 | |
download_stac_asset #
download_stac_asset(
asset_url: str,
destination: Path,
method: str = "http",
headers: dict[str, str] | None = None,
s3_client: Any | None = None,
logger: Logger = LOGGER,
) -> Path | None
Generic dispatcher for downloading STAC assets via HTTP or S3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_url
|
str
|
URL/HREF of the asset to download. |
required |
destination
|
Path
|
Path where the file will be saved. |
required |
method
|
str
|
Download method ('http' or 's3'). |
'http'
|
headers
|
dict[str, str] | None
|
Headers for HTTP request. |
None
|
s3_client
|
Any | None
|
Boto3 S3 client (required for 's3' method). |
None
|
logger
|
Logger
|
Logger instance. |
LOGGER
|
Returns:
| Type | Description |
|---|---|
Path | None
|
The Path to the downloaded file if successful, else None. |
Source code in src/geospatial_tools/stac/core.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
planetary_computer #
PlanetaryComputerS1Band #
Bases: StrEnum
Planetary Computer Sentinel-1 asset band keys.
Used to fetch assets from the STAC item.
PlanetaryComputerS1Collection #
Bases: StrEnum
Planetary Computer Sentinel-1 Collections.
PlanetaryComputerS1InstrumentMode #
Bases: StrEnum
Planetary Computer Sentinel-1 instrument modes.
Used for STAC queries.
PlanetaryComputerS1OrbitState #
Bases: StrEnum
Planetary Computer Sentinel-1 orbit states.
Used for STAC queries.
PlanetaryComputerS1Polarization #
Bases: StrEnum
Planetary Computer Sentinel-1 polarizations.
Used for STAC queries.
PlanetaryComputerS1Property #
Bases: StrEnum
Planetary Computer Sentinel-1 STAC query properties.
PlanetaryComputerS2Band #
Bases: StrEnum
Planetary Computer Sentinel-2 asset band keys.
Planetary Computer uses plain base names (e.g., "B02") as asset keys, unlike Copernicus which appends resolution suffixes.
PlanetaryComputerS2Collection #
Bases: StrEnum
Planetary Computer Sentinel-2 Collections.
PlanetaryComputerS2Property #
Bases: StrEnum
Planetary Computer Sentinel-2 STAC query properties.
sortby_field
property
#
sortby_field: str
Returns the full JSON path prefix required by the STAC API sortby object.
PlanetaryComputerS3Band #
Bases: StrEnum
Planetary Computer Sentinel-3 asset band keys.
PlanetaryComputerS3Collection #
Bases: StrEnum
Planetary Computer Sentinel-3 Collections.
PlanetaryComputerS3Property #
Bases: StrEnum
Planetary Computer Sentinel-3 STAC query properties.
constants #
Constants for Planetary Computer Sentinel-2 STAC catalog.
PlanetaryComputerS2Collection #
Bases: StrEnum
Planetary Computer Sentinel-2 Collections.
PlanetaryComputerS2Property #
Bases: StrEnum
Planetary Computer Sentinel-2 STAC query properties.
sortby_field
property
#
sortby_field: str
Returns the full JSON path prefix required by the STAC API sortby object.
PlanetaryComputerS2Band #
Bases: StrEnum
Planetary Computer Sentinel-2 asset band keys.
Planetary Computer uses plain base names (e.g., "B02") as asset keys, unlike Copernicus which appends resolution suffixes.
PlanetaryComputerS1Collection #
Bases: StrEnum
Planetary Computer Sentinel-1 Collections.
PlanetaryComputerS1Property #
Bases: StrEnum
Planetary Computer Sentinel-1 STAC query properties.
PlanetaryComputerS1Band #
Bases: StrEnum
Planetary Computer Sentinel-1 asset band keys.
Used to fetch assets from the STAC item.
PlanetaryComputerS1InstrumentMode #
Bases: StrEnum
Planetary Computer Sentinel-1 instrument modes.
Used for STAC queries.
PlanetaryComputerS1Polarization #
Bases: StrEnum
Planetary Computer Sentinel-1 polarizations.
Used for STAC queries.
PlanetaryComputerS1OrbitState #
Bases: StrEnum
Planetary Computer Sentinel-1 orbit states.
Used for STAC queries.
PlanetaryComputerS3Collection #
Bases: StrEnum
Planetary Computer Sentinel-3 Collections.
PlanetaryComputerS3Property #
Bases: StrEnum
Planetary Computer Sentinel-3 STAC query properties.
PlanetaryComputerS3OrbitState #
Bases: StrEnum
Planetary Computer Sentinel-3 orbit states.
Used for STAC queries.
PlanetaryComputerS3Band #
Bases: StrEnum
Planetary Computer Sentinel-3 asset band keys.
sentinel_1 #
Sentinel1Search #
Sentinel1Search(
collection: PlanetaryComputerS1Collection | str = GRD,
date_range: DateLike = None,
bbox: BBoxLike | None = None,
intersects: IntersectsLike | None = None,
logger: Logger = LOGGER,
)
Bases: AbstractStacWrapper
Executable wrapper for Sentinel-1 GRD data on Planetary Computer.
Implements a fluent builder pattern to construct STAC queries for SAR data.
Execution and result storage are delegated to an underlying StacSearch client
via proxy properties.
Initialize Sentinel1Search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
PlanetaryComputerS1Collection | str
|
The Sentinel-1 STAC collection (default: sentinel-1-grd). |
GRD
|
date_range
|
DateLike
|
Temporal filter, native pystac DateLike. |
None
|
bbox
|
BBoxLike | None
|
Spatial bounding box filter. |
None
|
intersects
|
IntersectsLike | None
|
Spatial GeoJSON geometry filter. |
None
|
logger
|
Logger
|
Custom logger instance. |
LOGGER
|
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_1.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
search_results
property
#
search_results: list[Item] | None
Proxy property for STAC search results from the underlying client.
downloaded_assets
property
#
downloaded_assets: list[Asset] | None
Proxy property for downloaded assets from the underlying client.
filter_by_instrument_mode #
filter_by_instrument_mode(
modes: list[PlanetaryComputerS1InstrumentMode] | PlanetaryComputerS1InstrumentMode,
) -> Self
Filter SAR products by instrument mode (e.g., IW, EW).
Invalidates current search results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modes
|
list[PlanetaryComputerS1InstrumentMode] | PlanetaryComputerS1InstrumentMode
|
Single mode or list of |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The instance itself (Self) for fluent chaining. |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_1.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
filter_by_polarization #
filter_by_polarization(
polarizations: (
list[PlanetaryComputerS1Polarization] | PlanetaryComputerS1Polarization
),
) -> Self
Filter SAR products by polarization (e.g., VV, VH).
Invalidates current search results. Note: PC STAC requires an exact array match
for sar:polarizations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polarizations
|
list[PlanetaryComputerS1Polarization] | PlanetaryComputerS1Polarization
|
Single polarization or list of |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The instance itself (Self) for fluent chaining. |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_1.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
filter_by_orbit_state #
filter_by_orbit_state(
states: list[PlanetaryComputerS1OrbitState] | PlanetaryComputerS1OrbitState,
) -> Self
Filter SAR products by orbit state (ascending or descending).
Invalidates current search results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
states
|
list[PlanetaryComputerS1OrbitState] | PlanetaryComputerS1OrbitState
|
Single state or list of |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The instance itself (Self) for fluent chaining. |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_1.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
download #
download(
bands: list[PlanetaryComputerS1Band | str], base_directory: str | Path
) -> list[Asset] | None
Download Sentinel-1 assets with lowercase band key normalization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bands
|
list[PlanetaryComputerS1Band | str]
|
List of bands to download. |
required |
base_directory
|
str | Path
|
Local directory where assets will be saved. |
required |
Returns:
| Type | Description |
|---|---|
list[Asset] | None
|
List of downloaded Asset objects. |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_1.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
with_custom_query #
with_custom_query(query_params: dict[str, Any]) -> Self
Merge custom STAC query parameters and invalidate current state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_params
|
dict[str, Any]
|
Dictionary of custom STAC query parameters. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The instance itself (Self) for fluent chaining. |
Source code in src/geospatial_tools/stac/core.py
939 940 941 942 943 944 945 946 947 948 949 950 951 | |
search #
search() -> list[Item] | None
Execute the STAC search using the built query and parameters.
Returns:
| Type | Description |
|---|---|
list[Item] | None
|
List of matched pystac Items, or None if no results. |
Source code in src/geospatial_tools/stac/core.py
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
sentinel_2 #
Sentinel2Search #
Sentinel2Search(
collection: PlanetaryComputerS2Collection | str = L2A,
date_range: DateLike = None,
bbox: BBoxLike | None = None,
intersects: IntersectsLike | None = None,
logger: Logger = LOGGER,
)
Bases: AbstractStacWrapper
Executable wrapper for Sentinel-2 L2A data on Planetary Computer.
Implements a fluent builder pattern to construct STAC queries for optical data.
Execution and result storage are delegated to an underlying StacSearch client
via proxy properties.
Initialize Sentinel2Search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
PlanetaryComputerS2Collection | str
|
Collection used to search for Sentinel 2 products. |
L2A
|
date_range
|
DateLike
|
Temporal filter, native pystac DateLike. |
None
|
bbox
|
BBoxLike | None
|
Spatial bounding box filter. |
None
|
intersects
|
IntersectsLike | None
|
Spatial GeoJSON geometry filter. |
None
|
logger
|
Logger
|
Custom logger instance. |
LOGGER
|
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
search_results
property
#
search_results: list[Item] | None
Proxy property for STAC search results from the underlying client.
downloaded_assets
property
#
downloaded_assets: list[Asset] | None
Proxy property for downloaded assets from the underlying client.
filter_by_cloud_cover #
filter_by_cloud_cover(max_cloud_cover: int) -> Self
Filter by maximum cloud cover percentage.
Invalidates current search results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_cloud_cover
|
int
|
Maximum percentage of cloud cover allowed. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The instance itself (Self) for fluent chaining. |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
filter_by_nodata_pixel_percentage #
filter_by_nodata_pixel_percentage(max_no_data_value: int) -> Self
Filter by maximum no-data pixel percentage.
Invalidates current search results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_no_data_value
|
int
|
Maximum percentage of no-data pixels allowed. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The instance itself (Self) for fluent chaining. |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
filter_by_mgrs_tile #
filter_by_mgrs_tile(mgrs_tiles: list[str] | str) -> Self
Filter by MGRS tile ID(s).
Invalidates current search results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mgrs_tiles
|
list[str] | str
|
Single MGRS tile ID or list of IDs. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The instance itself (Self) for fluent chaining. |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
with_custom_query #
with_custom_query(query_params: dict[str, Any]) -> Self
Merge custom STAC query parameters and invalidate current state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_params
|
dict[str, Any]
|
Dictionary of custom STAC query parameters. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The instance itself (Self) for fluent chaining. |
Source code in src/geospatial_tools/stac/core.py
939 940 941 942 943 944 945 946 947 948 949 950 951 | |
search #
search() -> list[Item] | None
Execute the STAC search using the built query and parameters.
Returns:
| Type | Description |
|---|---|
list[Item] | None
|
List of matched pystac Items, or None if no results. |
Source code in src/geospatial_tools/stac/core.py
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
download #
download(bands: list[str], base_directory: str | Path) -> list[Asset] | None
Download assets for the matched search results.
Triggers a search if no results are currently available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bands
|
list[str]
|
List of asset keys (bands) to download. |
required |
base_directory
|
str | Path
|
Local directory where assets will be saved. |
required |
Returns:
| Type | Description |
|---|---|
list[Asset] | None
|
List of downloaded Asset objects. |
Source code in src/geospatial_tools/stac/core.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
BestProductsForFeatures #
BestProductsForFeatures(
sentinel2_tiling_grid: GeoDataFrame,
sentinel2_tiling_grid_column: str,
vector_features: GeoDataFrame,
vector_features_column: str,
collection: PlanetaryComputerS2Collection | str = L2A,
date_ranges: list[str] | None = None,
max_cloud_cover: int = 5,
max_no_data_value: int = 5,
logger: Logger = LOGGER,
)
Class made to facilitate and automate searching for Sentinel 2 products using the Sentinel 2 tiling grid as a reference.
Current limitation is that vector features used must fit, or be completely contained inside a single Sentinel 2 tiling grid.
For larger features, a mosaic of products will be necessary.
This class was conceived first and foremost to be used for numerous smaller vector
features, like polygon grids created from
geospatial_tools.vector.create_vector_grid
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sentinel2_tiling_grid
|
GeoDataFrame
|
GeoDataFrame containing Sentinel 2 tiling grid |
required |
sentinel2_tiling_grid_column
|
str
|
Name of the column in |
required |
vector_features
|
GeoDataFrame
|
GeoDataFrame containing the vector features for which the best Sentinel 2 products will be chosen for. |
required |
vector_features_column
|
str
|
Name of the column in |
required |
date_ranges
|
list[str] | None
|
Date range used to search for Sentinel 2 products. should be created using
|
None
|
max_cloud_cover
|
int
|
Maximum cloud cover used to search for Sentinel 2 products. |
5
|
logger
|
Logger
|
Logger instance |
LOGGER
|
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
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 | |
create_date_ranges #
create_date_ranges(
start_year: int, end_year: int, start_month: int, end_month: int
) -> list[str] | None
This function create a list of date ranges.
For example, I want to create date ranges for 2020 and 2021, but only for the months from March to May. I therefore expect to have 2 ranges: [2020-03-01 to 2020-05-30, 2021-03-01 to 2021-05-30].
Handles the automatic definition of the last day for the end month, as well as periods that cross over years
For example, I want to create date ranges for 2020 and 2022, but only for the months from November to January. I therefore expect to have 2 ranges: [2020-11-01 to 2021-01-31, 2021-11-01 to 2022-01-31].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_year
|
int
|
Start year for ranges |
required |
end_year
|
int
|
End year for ranges |
required |
start_month
|
int
|
Starting month for each period |
required |
end_month
|
int
|
End month for each period (inclusively) |
required |
Returns:
| Type | Description |
|---|---|
list[str] | None
|
List of date ranges |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
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 | |
find_best_complete_products #
find_best_complete_products(
max_cloud_cover: int | None = None, max_no_data_value: int = 5
) -> dict
Finds the best complete products for each Sentinel 2 tiles. This function will filter out all products that have more than 5% of nodata values.
Filtered out tiles will be stored in self.incomplete and tiles for which
the search has found no results will be stored in self.error_list
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_cloud_cover
|
int | None
|
Max percentage of cloud cover allowed used for the search (Default value = None) |
None
|
max_no_data_value
|
int
|
Max percentage of no-data coverage by individual Sentinel 2 product (Default value = 5) |
5
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary of product IDs and their corresponding Sentinel 2 tile names. |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
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 | |
select_best_products_per_feature #
select_best_products_per_feature() -> GeoDataFrame
Return a GeoDataFrame containing the best products for each Sentinel 2 tile.
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
to_file #
to_file(output_dir: str | Path) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str | Path
|
Output directory used to write to file |
required |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
295 296 297 298 299 300 301 302 303 304 305 306 307 | |
sentinel_2_complete_tile_search #
sentinel_2_complete_tile_search(
tile_id: int,
collection: str,
date_ranges: list[str],
max_cloud_cover: int,
max_no_data_value: int = 5,
) -> tuple[int, str, float | None, float | None] | None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
str
|
|
required |
tile_id
|
int
|
|
required |
date_ranges
|
list[str]
|
|
required |
max_cloud_cover
|
int
|
|
required |
max_no_data_value
|
int
|
(Default value = 5) |
5
|
Returns:
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
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 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
find_best_product_per_s2_tile #
find_best_product_per_s2_tile(
collection: str,
date_ranges: list[str],
max_cloud_cover: int,
s2_tile_grid_list: list,
max_no_data_value: int = 5,
num_of_workers: int = 4,
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
str
|
|
required |
date_ranges
|
list[str]
|
|
required |
max_cloud_cover
|
int
|
|
required |
s2_tile_grid_list
|
list
|
|
required |
max_no_data_value
|
int
|
(Default value = 5) |
5
|
num_of_workers
|
int
|
(Default value = 4) |
4
|
Returns:
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 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 | |
write_best_product_ids_to_dataframe #
write_best_product_ids_to_dataframe(
spatial_join_results: GeoDataFrame,
tile_dictionary: dict,
best_product_column: str = "best_s2_product_id",
s2_tiles_column: str = "s2_tiles",
logger: Logger = LOGGER,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spatial_join_results
|
GeoDataFrame
|
|
required |
tile_dictionary
|
dict
|
|
required |
best_product_column
|
str
|
|
'best_s2_product_id'
|
s2_tiles_column
|
str
|
|
's2_tiles'
|
logger
|
Logger
|
|
LOGGER
|
Returns:
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
write_results_to_file #
write_results_to_file(
cloud_cover: int,
successful_results: dict,
incomplete_results: list | None = None,
error_results: list | None = None,
output_dir: str | Path = DATA_DIR,
logger: Logger = LOGGER,
) -> dict
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cloud_cover
|
int
|
|
required |
successful_results
|
dict
|
|
required |
incomplete_results
|
list | None
|
|
None
|
error_results
|
list | None
|
|
None
|
output_dir
|
str | Path
|
|
DATA_DIR
|
logger
|
Logger
|
|
LOGGER
|
Returns:
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
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 | |
download_and_process_sentinel2_asset #
download_and_process_sentinel2_asset(
product_id: str,
product_bands: list[str],
collections: PlanetaryComputerS2Collection | str = L2A,
target_projection: int | str | None = None,
base_directory: str | Path = DATA_DIR,
delete_intermediate_files: bool = False,
logger: Logger = LOGGER,
) -> Asset
This function downloads a Sentinel 2 product based on the product ID provided.
It will download the individual asset bands provided in the bands argument,
merge then all in a single tif and then reproject them to the input CRS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product_id
|
str
|
ID of the Sentinel 2 product to be downloaded |
required |
product_bands
|
list[str]
|
List of the product bands to be downloaded |
required |
collections
|
PlanetaryComputerS2Collection | str
|
Collections to be downloaded from. Defaults to |
L2A
|
target_projection
|
int | str | None
|
The CRS project for the end product. If |
None
|
stac_client
|
StacSearch client to used. A new one will be created if not provided |
required | |
base_directory
|
str | Path
|
The base directory path where the downloaded files will be stored |
DATA_DIR
|
delete_intermediate_files
|
bool
|
Flag to determine if intermediate files should be deleted. Defaults to False |
False
|
logger
|
Logger
|
Logger instance |
LOGGER
|
Returns:
| Type | Description |
|---|---|
Asset
|
Asset instance |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_2.py
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 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
sentinel_3 #
Sentinel3Search #
Sentinel3Search(
collection: PlanetaryComputerS3Collection | str = OLCI_WFR,
date_range: DateLike = None,
bbox: BBoxLike | None = None,
intersects: IntersectsLike | None = None,
logger: Logger = LOGGER,
)
Bases: AbstractStacWrapper
Executable wrapper for Sentinel-3 OLCI data on Planetary Computer.
Implements a fluent builder pattern to construct STAC queries.
Execution and result storage are delegated to an underlying StacSearch client
via proxy properties.
Initialize Sentinel3Search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
PlanetaryComputerS3Collection | str
|
The Sentinel-3 STAC collection (default: sentinel-3-olci-wfr-l2-netcdf). |
OLCI_WFR
|
date_range
|
DateLike
|
Temporal filter, native pystac DateLike. |
None
|
bbox
|
BBoxLike | None
|
Spatial bounding box filter. |
None
|
intersects
|
IntersectsLike | None
|
Spatial GeoJSON geometry filter. |
None
|
logger
|
Logger
|
Custom logger instance. |
LOGGER
|
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_3.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
search_results
property
#
search_results: list[Item] | None
Proxy property for STAC search results from the underlying client.
downloaded_assets
property
#
downloaded_assets: list[Asset] | None
Proxy property for downloaded assets from the underlying client.
filter_by_orbit_state #
filter_by_orbit_state(
states: list[PlanetaryComputerS3OrbitState] | PlanetaryComputerS3OrbitState,
) -> Self
Filter products by orbit state (ascending or descending).
Invalidates current search results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
states
|
list[PlanetaryComputerS3OrbitState] | PlanetaryComputerS3OrbitState
|
Single state or list of |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The instance itself (Self) for fluent chaining. |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_3.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
download #
download(
bands: list[PlanetaryComputerS3Band | str], base_directory: str | Path
) -> list[Asset] | None
Download Sentinel-3 assets with lowercase band key normalization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bands
|
list[PlanetaryComputerS3Band | str]
|
List of bands to download. |
required |
base_directory
|
str | Path
|
Local directory where assets will be saved. |
required |
Returns:
| Type | Description |
|---|---|
list[Asset] | None
|
List of downloaded Asset objects. |
Source code in src/geospatial_tools/stac/planetary_computer/sentinel_3.py
90 91 92 93 94 95 96 97 98 99 100 101 102 | |
with_custom_query #
with_custom_query(query_params: dict[str, Any]) -> Self
Merge custom STAC query parameters and invalidate current state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_params
|
dict[str, Any]
|
Dictionary of custom STAC query parameters. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The instance itself (Self) for fluent chaining. |
Source code in src/geospatial_tools/stac/core.py
939 940 941 942 943 944 945 946 947 948 949 950 951 | |
search #
search() -> list[Item] | None
Execute the STAC search using the built query and parameters.
Returns:
| Type | Description |
|---|---|
list[Item] | None
|
List of matched pystac Items, or None if no results. |
Source code in src/geospatial_tools/stac/core.py
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
utils #
create_date_range_for_specific_period #
create_date_range_for_specific_period(
start_year: int, end_year: int, start_month_range: int, end_month_range: int
) -> list[str]
This function create a list of date ranges.
For example, I want to create date ranges for 2020 and 2021, but only for the months from March to May. I therefore expect to have 2 ranges: [2020-03-01 to 2020-05-30, 2021-03-01 to 2021-05-30].
Handles the automatic definition of the last day for the end month, as well as periods that cross over years
For example, I want to create date ranges for 2020 and 2022, but only for the months from November to January. I therefore expect to have 2 ranges: [2020-11-01 to 2021-01-31, 2021-11-01 to 2022-01-31].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_year
|
int
|
Start year for ranges |
required |
end_year
|
int
|
End year for ranges |
required |
start_month_range
|
int
|
Starting month for each period |
required |
end_month_range
|
int
|
End month for each period (inclusively) |
required |
Returns:
Source code in src/geospatial_tools/stac/utils.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
get_s3_client #
get_s3_client(endpoint_url: str | None = None) -> client
Creates and returns a boto3 S3 client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint_url
|
str | None
|
The S3 endpoint URL. If None, it attempts to use the COPERNICUS_S3_ENDPOINT environment variable. |
None
|
Returns:
| Type | Description |
|---|---|
client
|
A boto3 S3 client. |
Source code in src/geospatial_tools/stac/utils.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
parse_s3_url #
parse_s3_url(url: str) -> tuple[str, str]
Parses an S3 URL or a CDSE STAC href to extract the bucket and key.
Expected formats: - s3://bucket/key - https://eodata.dataspace.copernicus.eu/bucket/key - https://zipper.dataspace.copernicus.eu/download/uuid (this might not be a direct S3 key)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to parse. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
A tuple of (bucket, key). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the URL cannot be parsed into a bucket and key. |
Source code in src/geospatial_tools/stac/utils.py
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 | |