CDSE
s3lst_ds.utilities.cdse_utils
Classes:
| Name | Description |
|---|---|
CDSEAuthState |
A class for holding CDSE's authentication state (credentials, refresh token, and |
Functions:
| Name | Description |
|---|---|
download_cdse |
Download products from CDSE (Copernicus Data Space Ecosystem) using the OData API, |
get_access_and_refresh_tokens |
Get CDSE's access and refresh tokens for downloading data. |
query_cdse |
Query CDSE (Copernicus Data Space Ecosystem) using the OData API for data and return |
CDSEAuthState
dataclass
A class for holding CDSE's authentication state (credentials, refresh token, and time of last access token generation) and obtaining a valid access token (through generation, refresh or regeneration).
Attributes:
| Name | Type | Description |
|---|---|---|
username |
str
|
User mail for accessing CDSE (only required for access token generation). |
password |
str
|
User password for accessing CDSE (only required for access token generation). |
refresh_token |
str or None, default=None
|
The refresh token that had been previously returned in the former access token generation request (only required for access token refresh). |
time_last_access_token_generation |
datetime.time or None, default=None
|
Time of the last access token generation. If |
Methods:
| Name | Description |
|---|---|
__init__ |
|
get_access_token |
Get a valid CDSE access token (generated, refreshed or regenerated). |
Source code in src/s3lst_ds/utilities/cdse_utils.py
time_last_access_token_generation
class-attribute
instance-attribute
__init__
__init__(
username: str,
password: str,
refresh_token: str | None = None,
time_last_access_token_generation: Timestamp | None = None,
) -> None
get_access_token
Get a valid CDSE access token (generated, refreshed or regenerated).
According to CDSE's Quotas and Limitations page (https://documentation.dataspace.copernicus.eu/Quotas.html#copernicus-general-users), in the case of the OData API, the token remains active only for 10 minutes. However, it may be refreshed as many times as wanted within the first 60 minutes through a refresh request using the refresh token previously issued as response to the former access token generation request (https://documentation.dataspace.copernicus.eu/APIs/OData.html#product-download). After those 60 min, a new access token would need to be generated.
The access token generation request requires login credentials (username and
password) while the access token refresh solely requires the refresh_token.
Note that refreshing solely re-activates the access token. The request returns
the same access and refresh tokens.
The number of active access tokens is limited to 100. The current value may be known from CDSE's Device Activity page (https://identity.dataspace.copernicus.eu/auth/realms/CDSE/account/account-security/device-activity).
Returns:
| Name | Type | Description |
|---|---|---|
access_token |
str
|
A valid CDSE access token. |
Source code in src/s3lst_ds/utilities/cdse_utils.py
download_cdse
download_cdse(
products_info: DataFrame,
path_out_dir: Path,
access_token: str,
max_workers: int = 4,
show_progress: bool = True,
logger: RichLogger | None = None,
) -> None
Download products from CDSE (Copernicus Data Space Ecosystem) using the OData API, as described in the documentation (https://documentation.dataspace.copernicus.eu/APIs/OData.html#product-download).
Parallel requesting is done for efficiency. Note that downloading files may by slow due to waiting for the external system, not because of CPU processing. Parallel request would increase the number of files downloaded per time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
products_info
|
DataFrame
|
DataFrame with products info previously obtained in a query to CDSE search endpoint. |
required |
path_out_dir
|
Path
|
Path to directory where to save downloaded products. The respective files would
have the same name as the one issued in the |
required |
access_token
|
str
|
The CDSE access token for downloading the data. |
required |
max_workers
|
int
|
Maximum number of processes to run in parallel. This value cannot be higher than
4 or error |
4
|
show_progress
|
bool
|
|
True
|
logger
|
RichLogger or None
|
A rich logger for stating progress. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/s3lst_ds/utilities/cdse_utils.py
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 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 618 619 620 621 622 623 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 | |
get_access_and_refresh_tokens
get_access_and_refresh_tokens(
username: str | None = None,
password: str | None = None,
refresh_token: str | None = None,
time_last_access_token_generation: Timestamp | None = None,
logger: RichLogger | None = None,
) -> dict[str, Any]
Get CDSE's access and refresh tokens for downloading data.
According to CDSE's Quotas and Limitations page (https://documentation.dataspace.copernicus.eu/Quotas.html#copernicus-general-users), in the case of the OData API, the token remains active only for 10 minutes. However, it may be refreshed as many times as wanted within the first 60 minutes through a refresh request using the refresh token previously issued as response to the former access token generation request (https://documentation.dataspace.copernicus.eu/APIs/OData.html#product-download). After those 60 min, a new access token would need to be generated.
The access token generation request requires login credentials (username and
password) while the access token refresh solely requires the refresh_token. Note
that refreshing solely re-activates the access token. The request returns the same
access and refresh tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
User mail for accessing CDSE (only required for access token generation). |
None
|
password
|
str
|
User password for accessing CDSE (only required for access token generation). |
None
|
refresh_token
|
str
|
The refresh token that had been previously returned in the former access token generation request (only required for access token refresh). |
None
|
time_last_access_token_generation
|
time or None
|
Time of the last access token generation. If |
None
|
logger
|
RichLogger or None
|
A rich logger for stating progress. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tokens_and_time_last_gen |
dict[str, str]
|
Dictionary with access and refresh tokens as well as the time of the last access
token generation. These are keyed by "access_token", "refresh_token" and
"time_last_access_token_generation". If the request is such that no new access
token was generated, the value for the latter is set as the one of the argument
|
Source code in src/s3lst_ds/utilities/cdse_utils.py
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 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 | |
query_cdse
query_cdse(
collection: str,
includes: str | list[str] | tuple[str] | None = None,
excludes: str | list[str] | tuple[str] | None = None,
start_sensing_time: str | None = None,
end_sensing_time: str | None = None,
geometry: str | None = None,
orderby_start_sensing_time: Literal["desc", "asc"] | None = "asc",
max_query_items: int | None = None,
logger: RichLogger | None = None,
) -> dict
Query CDSE (Copernicus Data Space Ecosystem) using the OData API for data and return the response as a JSON object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
str
|
The name of the data collection, which as listed in the CDSE documentation
(https://documentation.dataspace.copernicus.eu/APIs/OData.html#query-collection-of-products)
may take the values:
- |
required |
includes
|
str or list[str] or tuple[str]
|
Including file name substring(s) to consider. |
None
|
excludes
|
str or list[str] or tuple[str]
|
Excluding file name substring(s) to consider. |
None
|
start_sensing_time
|
str
|
Oldest start sensing datetime to consider. |
None
|
end_sensing_time
|
str
|
Newest end sensing datetime to consider. |
None
|
geometry
|
str
|
Geometry to intersect the data with (note that an intersection includes its boundary). This parameter needs to be a WKT string describing a polygon with same start and end vertices. Furthermore, its coordinates need to be expressed in EPSG:4326. |
None
|
orderby_start_sensing_time
|
(desc, asc)
|
Order of the returned querying items with respect to start sensing time. It may
take the values:
- |
"desc"
|
max_query_items
|
int
|
Maximum number of items that may be returned by the query. It must be an integer between 0 and 1000 (inclusive). If not defined, 20 is considered. Check CDSE documentation for more details (https://documentation.dataspace.copernicus.eu/APIs/OData.html#top-option). |
20
|
logger
|
RichLogger or None
|
A rich logger for stating progress. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
response_json |
dict
|
The response of the query as a JSON object. |
Source code in src/s3lst_ds/utilities/cdse_utils.py
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 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 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 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 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |