Newer
Older
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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
{
"cells": [
{
"cell_type": "markdown",
"id": "1a70970d",
"metadata": {},
"source": [
"# <center> Tree Classification Demo </center>"
]
},
{
"cell_type": "markdown",
"id": "bf3c2a51",
"metadata": {},
"source": [
"<center>Tests for geopandas and gdal<center>"
]
},
{
"cell_type": "markdown",
"id": "c55216cb",
"metadata": {},
"source": [
"## Import Packages"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "4d9291fa",
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime\n",
"import json\n",
"import time\n",
"import configparser\n",
"import requests\n",
"# On NASA , install with pip install geopandas\n",
"# On ESA; use a PolinSAR stack ( geopandas already embedded) \n",
"import geopandas as gpd\n",
"import pandas as pd\n",
"from creodias_finder import query\n",
"from shapely.geometry import Polygon,shape\n"
]
},
{
"cell_type": "markdown",
"id": "711e5ecd",
"metadata": {},
"source": [
"## Define Functions"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "2b694047",
"metadata": {},
"outputs": [],
"source": [
"def __get_result_S1( geometry_search, str_plateformeS1, str_product_type, str_sensor_mode, start_date, end_date):\n",
" '''\n",
" Recupere dans un dataframe les produits S1 qui intersectent la zone de recherche\n",
"\n",
" :geometry_search: geometrie de la zone de recherche\n",
" :str_plateformeS1: nom de la plateforme\n",
" :str_product_type: nom du product type\n",
" :str_sensor_mode: nom du sensor mode\n",
" :start_date: date debut interval recherche au format datetime\n",
" :end_date: date fin interval recherche au format datetime\n",
"\n",
"\n",
" return: df_groupby\n",
" :rtype: dataframe\n",
" '''\n",
"\n",
" # liste des produits de l'api creodias\n",
" results = query.query(\n",
" str_plateformeS1,\n",
" start_date=start_date,\n",
" end_date=end_date,\n",
" productType=str_product_type,\n",
" sensorMode=str_sensor_mode,\n",
" status=\"ONLINE\",\n",
" geometry=geometry_search\n",
" )\n",
"\n",
" # init des listes des parametres a conserver \n",
" list_title = []\n",
" list_date = []\n",
" list_orbit = []\n",
" list_orbitDirection = []\n",
" list_geom = []\n",
" list_url = []\n",
"\n",
" # remplissage des listes avec les parametres des produits du results de l'api\n",
" for idproduct, dict_product in results.items():\n",
" list_title.append(dict_product['properties']['title'])\n",
" list_orbit.append(dict_product['properties']['relativeOrbitNumber'])\n",
" list_orbitDirection.append(dict_product['properties']['orbitDirection'])\n",
" list_geom.append(shape(dict_product['geometry']))\n",
" list_url.append(dict_product['properties']['productIdentifier'])\n",
" list_date.append(dict_product['properties']['title'][17:25])\n",
"\n",
" # genere le gdf avec les produits s1\n",
" gdf_product = gpd.GeoDataFrame({'title' : list_title, 'date' : list_date, 'orbit' : list_orbit, 'direction' : list_orbitDirection,'geometry' : list_geom, 'url' : list_url}, crs = \"4326\")\n",
" # regroupe les produits qui ont les memes parametres de date, orbit et direction\n",
" df_groupby = gdf_product.groupby(['date', 'orbit', 'direction']).agg({'title' : list, 'url' : list, 'geometry' : list}).reset_index()\n",
"\n",
" return df_groupby\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "2573ab84",
"metadata": {},
"source": [
"## Define the study area or list of tile"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "7e14efe8",
"metadata": {},
"outputs": [],
"source": [
"search_zone = [[4.751930185604931,45.37522170186796],[4.468812157001305,45.24092464324643],[4.018935832120382,44.88158298080388],[3.852035966569818,44.75014456444579],[3.898047329546759,44.56923769773521],[4.038870891160542,44.31329708744024],[4.241954580160842,44.26894961414283],[4.674279531570155,44.26246269728098],[4.882500597010154,44.8652889083827],[4.905098845459158,45.06277528749476],[4.782524828980907,45.368587240900965],[4.751930185604931,45.37522170186796]]\n",
"search_poly = Polygon(search_zone)\n"
]
},
{
"cell_type": "markdown",
"id": "9b8ee178",
"metadata": {},
"source": [
"## Search S1 products"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "f7fd2a1c",
"metadata": {},
"outputs": [],
"source": [
"# parametres de recherche\n",
"str_plateformeS1 = 'Sentinel1'\n",
"str_product_type = 'GRD'\n",
"str_sensor_mode = 'IW'\n",
"start_date = datetime(2022, 6, 3)\n",
"end_date = datetime(2023, 1, 31)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "3cb6aa8f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"query_url http://datahub.creodias.eu/resto/api/collections/Sentinel1/search.json?maxRecords=1000&startDate=2022-06-03T00%3A00%3A00&completionDate=2023-01-31T23%3A59%3A59&geometry=POLYGON+%28%284.751930185604931+45.37522170186796%2C+4.468812157001305+45.24092464324643%2C+4.018935832120382+44.88158298080388%2C+3.852035966569818+44.75014456444579%2C+3.898047329546759+44.56923769773521%2C+4.038870891160542+44.31329708744024%2C+4.241954580160842+44.26894961414283%2C+4.674279531570155+44.26246269728098%2C+4.882500597010154+44.8652889083827%2C+4.905098845459158+45.06277528749476%2C+4.782524828980907+45.368587240900965%2C+4.751930185604931+45.37522170186796%29%29&status=ONLINE&productType=GRD&sensorMode=IW\n",
"<Response [200]>\n"
]
}
],
"source": [
"\n",
"df_product = __get_result_S1( search_poly, str_plateformeS1, str_product_type, str_sensor_mode, start_date, end_date)\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "568856bd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20\n"
]
}
],
"source": [
"df_product\n",
"df_product = df_product[df_product['orbit']==37]\n",
"df_product\n",
"print(len(df_product))"
]
},
{
"cell_type": "markdown",
"id": "f85d0273",
"metadata": {},
"source": [
"## Extract list of URL "
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "6cfbf9c7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\"Sentinel-1/SAR/GRD/2022/06/04/S1A_IW_GRDH_1SDV_20220604T055236_20220604T055301_043509_0531E5_DC1B.SAFE,\"Sentinel-1/SAR/GRD/2022/06/16/S1A_IW_GRDH_1SDV_20220616T055236_20220616T055301_043684_05371A_E51A.SAFE,\"Sentinel-1/SAR/GRD/2022/06/28/S1A_IW_GRDH_1SDV_20220628T055237_20220628T055302_043859_053C5F_3096.SAFE,\"Sentinel-1/SAR/GRD/2022/07/22/S1A_IW_GRDH_1SDV_20220722T055238_20220722T055303_044209_0546C9_677E.SAFE,\"Sentinel-1/SAR/GRD/2022/08/03/S1A_IW_GRDH_1SDV_20220803T055239_20220803T055304_044384_054BF3_4ACD.SAFE,\"Sentinel-1/SAR/GRD/2022/08/15/S1A_IW_GRDH_1SDV_20220815T055240_20220815T055305_044559_05516B_B0D3.SAFE,\"Sentinel-1/SAR/GRD/2022/08/27/S1A_IW_GRDH_1SDV_20220827T055240_20220827T055305_044734_055755_77D7.SAFE,\"Sentinel-1/SAR/GRD/2022/09/08/S1A_IW_GRDH_1SDV_20220908T055241_20220908T055306_044909_055D33_8C27.SAFE,\"Sentinel-1/SAR/GRD/2022/09/20/S1A_IW_GRDH_1SDV_20220920T055241_20220920T055306_045084_056320_8ED8.SAFE,\"Sentinel-1/SAR/GRD/2022/10/02/S1A_IW_GRDH_1SDV_20221002T055242_20221002T055307_045259_0568FD_84DA.SAFE,\"Sentinel-1/SAR/GRD/2022/10/14/S1A_IW_GRDH_1SDV_20221014T055242_20221014T055307_045434_056EDB_346E.SAFE,\"Sentinel-1/SAR/GRD/2022/10/26/S1A_IW_GRDH_1SDV_20221026T055242_20221026T055307_045609_05740C_5826.SAFE,\"Sentinel-1/SAR/GRD/2022/11/07/S1A_IW_GRDH_1SDV_20221107T055241_20221107T055306_045784_0579F9_649C.SAFE,\"Sentinel-1/SAR/GRD/2022/11/19/S1A_IW_GRDH_1SDV_20221119T055241_20221119T055306_045959_057FDC_E997.SAFE,\"Sentinel-1/SAR/GRD/2022/12/01/S1A_IW_GRDH_1SDV_20221201T055240_20221201T055305_046134_0585CE_836F.SAFE,\"Sentinel-1/SAR/GRD/2022/12/13/S1A_IW_GRDH_1SDV_20221213T055240_20221213T055305_046309_058BCE_F90F.SAFE,\"Sentinel-1/SAR/GRD/2022/12/25/S1A_IW_GRDH_1SDV_20221225T055239_20221225T055304_046484_0591C3_7C2C.SAFE,\"Sentinel-1/SAR/GRD/2023/01/06/S1A_IW_GRDH_1SDV_20230106T055239_20230106T055304_046659_0597A7_7ED7.SAFE,\"Sentinel-1/SAR/GRD/2023/01/18/S1A_IW_GRDH_1SDV_20230118T055238_20230118T055303_046834_059D93_5C5F.SAFE,\"Sentinel-1/SAR/GRD/2023/01/30/S1A_IW_GRDH_1SDV_20230130T055238_20230130T055303_047009_05A37A_61B6.SAFE\"]\n"
]
}
],
"source": [
"tmp_list_product_path = []\n",
"for prd in df_product['url']:\n",
" hour_1 = int(prd[0].split('/')[-1].split('_')[4].split('T')[1])\n",
" hour_2 = int(prd[1].split('/')[-1].split('_')[4].split('T')[1])\n",
" \n",
" if hour_1 > hour_2:\n",
" tmp_list_product_path.append(prd[0])\n",
" else:\n",
" tmp_list_product_path.append(prd[1])\n",
"\n",
"list_product_path = []\n",
"for path_url in tmp_list_product_path:\n",
" list_product_path.append(path_url[8:])\n",
"\n",
"prod_payload = \"[\\\"\"+\",\\\"\".join(list_product_path)+\"\\\"]\"\n",
"print(prod_payload)\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "0142ecbc",
"metadata": {},
"outputs": [],
"source": [
"## Test Gdal"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "ae1c9c71",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Creating output file that is 4680P x 5400L.\n",
"0...10...20...30...40...50...60...70...80...90...100 - done.\n",
"\n",
"[02/28 16:51:44] [INFO dem.py] Bounds: -156.0 18.8 -154.7 20.3\n",
"[02/28 16:51:44] [INFO cop_dem.py] Creating /projects/treeclassificationdemo/driver/L1_MSI_pixel_value_Composite_123.tif\n",
"[02/28 16:51:44] [INFO cop_dem.py] Fetching remote tiles...\n",
"[02/28 16:51:44] [INFO cop_dem.py] Running GDAL command:\n",
"[02/28 16:51:44] [INFO cop_dem.py] gdalwarp /vsicurl/https://raw.githubusercontent.com/scottstanie/sardem/master/sardem/data/cop_global.vrt /projects/treeclassificationdemo/driver/L1_MSI_pixel_value_Composite_123.tif -of GTiff -ot Int16 -te -156 18.8000000000000007 -154.699999999999989 20.3000000000000007 -tr 0.000277777777777777778 0.000277777777777777778 -s_srs \"epsg:4326+3855\" -t_srs \"epsg:4326\" -wo NUM_THREADS=4 -r nearest -wm 5000 -multi\n",
"\n"
]
}
],
"source": [
"!conda run -n maap sardem --bbox -156 18.8 -154.7 20.3 --data-source COP -o \"/projects/treeclassificationdemo/driver/maap_utils/L1_MSI_pixel_value_Composite_123.tif\" --output-format GTiff\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Maap",
"language": "python",
"name": "maap"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}