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 | |