-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_download_data_creodias.py
98 lines (79 loc) · 2.82 KB
/
01_download_data_creodias.py
1
2
3
4
5
6
7
8
9
10
11
12
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
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
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
#!/usr/bin/python
"""
This script shows how to download Sentinel-2 data from Creodias for a given
region of interest, date range, cloud coverage and processing level.
It requires an account at Creodias (https://creodias.eu/) and the account's
username and password set in the environmental variables as
SET CREODIAS_USER=<your-username>
SET CREODIAS_PASSWORD0<your-password>
It is the FIRST script in the uncertainty processing chain
"""
import geopandas as gpd
from datetime import date
from pathlib import Path
from typing import Optional
from eodal.downloader.sentinel2.creodias import query_creodias
from eodal.downloader.sentinel2.creodias import download_datasets
from eodal.downloader.sentinel2.utils import unzip_datasets
from eodal.utils.constants import ProcessingLevels
def main(
start_date: date,
end_date: date,
processing_level: ProcessingLevels,
cloud_cover_threshold: int,
aoi_file: Path,
download_dir: Path,
max_records: Optional[int]=200
) -> None:
"""
the main executable function that calls all the required
processing steps
"""
bbox_data = gpd.read_file(aoi_file)
# project to geographic coordinates (required for API query)
bbox_data.to_crs(4326, inplace=True)
# use the first feature (all others are ignored)
bounding_box = bbox_data.geometry.iloc[0]
# check for available datasets
datasets = query_creodias(
start_date=start_date,
end_date=end_date,
max_records=max_records,
processing_level=processing_level,
bounding_box=bounding_box,
cloud_cover_threshold=cloud_cover_threshold
)
try:
download_datasets(datasets, download_dir)
except Exception as e:
print(e)
# unzip files
unzip_datasets(download_dir=download_dir)
if __name__ == '__main__':
### user inputs
# processing level
processing_level = ProcessingLevels.L1C
# date range (1st March to 15th October)
start_date = date(2019,1,1)
end_date = date(2019,10,15)
# max_records defines the maximum number of datasets to download, increase if
# necessary; however, CREODIAS might impose a limitation...
max_records = 200
# filter by cloud cover (all scenes with a cloud cover lower than the threshold
# will be downloaded)
cloud_cover_threshold = 20
# shapefile defining the bounds of your region of interest
aoi_file = Path(
'../../shp/AOI_Esch_EPSG32632.shp'
)
download_dir = Path('../../S2_MSIL1C_orig')
if not download_dir.exists():
download_dir.mkdir()
main(
start_date=start_date,
end_date=end_date,
processing_level=processing_level,
cloud_cover_threshold=cloud_cover_threshold,
aoi_file=aoi_file,
download_dir=download_dir
)