planetary_computer
sentinel_2 #
BestProductsForFeatures #
BestProductsForFeatures(
sentinel2_tiling_grid: GeoDataFrame,
sentinel2_tiling_grid_column: str,
vector_features: GeoDataFrame,
vector_features_column: str,
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 geospatial_tools/planetary_computer/sentinel_2.py
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 62 63 64 65 66 67 68 69 70 71 |
|
max_cloud_cover
property
writable
#
max_cloud_cover
Max % of cloud cover used for Sentinel 2 product search.
create_date_ranges #
create_date_ranges(
start_year: int, end_year: int, start_month: int, end_month: 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
|
int
|
Starting month for each period |
required |
end_month
|
int
|
End month for each period (inclusively) |
required |
Returns:
Type | Description |
---|---|
list[str]
|
List of date ranges |
Source code in geospatial_tools/planetary_computer/sentinel_2.py
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 |
|
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 geospatial_tools/planetary_computer/sentinel_2.py
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 |
|
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 geospatial_tools/planetary_computer/sentinel_2.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
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 geospatial_tools/planetary_computer/sentinel_2.py
198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
sentinel_2_complete_tile_search #
sentinel_2_complete_tile_search(
tile_id: int,
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 |
---|---|---|---|
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 geospatial_tools/planetary_computer/sentinel_2.py
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 |
|
find_best_product_per_s2_tile #
find_best_product_per_s2_tile(
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 |
---|---|---|---|
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 geospatial_tools/planetary_computer/sentinel_2.py
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 |
|
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,
)
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 geospatial_tools/planetary_computer/sentinel_2.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
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 geospatial_tools/planetary_computer/sentinel_2.py
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 |
|
download_and_process_sentinel2_asset #
download_and_process_sentinel2_asset(
product_id: str,
product_bands: list[str],
collections: str = "sentinel-2-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
|
str
|
Collections to be downloaded from. Defaults to |
'sentinel-2-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 geospatial_tools/planetary_computer/sentinel_2.py
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 |
|