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
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import json\n",
"import sys\n",
"import os\n",
"import xml.etree.ElementTree as ET\n",
"import time\n",
"import sys\n",
"\n",
"sys.path.insert(0, '/projects/owslib')\n",
"from owslib.wps import WebProcessingService\n",
"\n",
"oauth_token = '4e911402-fb22-4e3c-aa25-8d96caf96768'\n",
"copa_backend_url = \"https://gravitee-gateway.val.esa-maap.org/\"\n",
"\n",
"user_id='37275'"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--- GET CAPABILITIES---\n",
"--- Service identification ---\n",
"title: WPS COPA layer\n",
"type: WPS 2.0.0\n"
]
}
],
"source": [
"wps = WebProcessingService(copa_backend_url + 'wps/capabilities', \\\n",
" headers = {'Authorization': 'Bearer ' + oauth_token}, version =\"2.0.0\")\n",
"\n",
"print(\"--- GET CAPABILITIES---\")\n",
"print(\"--- Service identification ---\")\n",
"print('title: ',wps.identification.title)\n",
"print('type: ',wps.identification.type, wps.identification.version)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--- Service Provider ---\n",
"provider: COPA Application caroline.ball@capgemini.com https://copa-backend-val.biomass-maap.com/\n"
]
}
],
"source": [
"print(\"--- Service Provider ---\")\n",
"print('provider: ',wps.provider.name,wps.provider.contact.email,wps.provider.url) "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--- Service Operations ---\n",
"getCapabilities\n",
"execute\n",
"getResult\n"
]
}
],
"source": [
"print(\"--- Service Operations ---\")\n",
"for operation in wps.operations:\n",
" print(operation.name)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--- Service Processes ---\n",
"there are 11 processes available for execution\n",
"5fe1c9ca6d8d6d0001b0e230 readl2 None\n",
"5ff3301e91db790001274258 read This is a project description\n",
"5fff1388493f610001f5178d read-s2 Read Sentinel 2 data\n",
"5fff1388493f610001f5178b geocoding Geocodes an image using georeferencing information from a reference image\n",
"5fff1388493f610001f5178a classification-mask Classify image using a vegetation, water and urban mask\n",
"5fff1388493f610001f5178c s2index Compute Sentinel 2 index\n",
"5fff1388493f610001f5178e resample Resample image\n",
"600e8ca13d255d0001aef7c5 reads2 None\n",
"600ef3b64f4c6300018f2c54 readstwo Read the tile\n",
"6011904643325f0001558fa5 classificationmask Classify image using a vegetation, water and urban mask\n",
"6011904643325f0001558fa6 indexstwo Compute Sentinel 2 index (NDVI, NDWI, NDBI, ...)\n"
]
}
],
"source": [
"print(\"--- Service Processes ---\")\n",
"print(\"there are \"+str(len(wps.processes))+\" processes available for execution\")\n",
"for process in wps.processes:\n",
" print(process.identifier, process.title, process.abstract)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--- EXECUTE---\n",
"--- EXECUTE---\n",
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n",
"<StatusInfo xmlns:xlin=\"http://www.w3.org/1999/xlink\" xmlns:se=\"http://www.opengis.net/se/2.0/core\" xmlns:fes=\"http://www.opengis.net/fes/2.1\" xmlns:ows=\"http://www.opengis.net/ows/2.0\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:wps=\"http://www.opengis.net/wps/2.0\" xmlns:ns2=\"http://www.w3.org/2005/Atom\" xmlns:wms=\"http://www.opengis.net/wms\" xmlns:ns3=\"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0\">\n",
" <wps:JobID>601d7a173d255d000167b452</wps:JobID>\n",
" <wps:Status>ACCEPTED</wps:Status>\n",
"</StatusInfo>\n",
"\n",
"\n",
"--- EXECUTE---\n",
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n",
"<StatusInfo xmlns:xlin=\"http://www.w3.org/1999/xlink\" xmlns:se=\"http://www.opengis.net/se/2.0/core\" xmlns:fes=\"http://www.opengis.net/fes/2.1\" xmlns:ows=\"http://www.opengis.net/ows/2.0\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:wps=\"http://www.opengis.net/wps/2.0\" xmlns:ns2=\"http://www.w3.org/2005/Atom\" xmlns:wms=\"http://www.opengis.net/wms\" xmlns:ns3=\"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0\">\n",
" <wps:JobID>601d7a183d255d000167b454</wps:JobID>\n",
" <wps:Status>ACCEPTED</wps:Status>\n",
"</StatusInfo>\n",
"\n",
"\n",
"--- EXECUTE---\n",
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n",
"<StatusInfo xmlns:xlin=\"http://www.w3.org/1999/xlink\" xmlns:se=\"http://www.opengis.net/se/2.0/core\" xmlns:fes=\"http://www.opengis.net/fes/2.1\" xmlns:ows=\"http://www.opengis.net/ows/2.0\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:wps=\"http://www.opengis.net/wps/2.0\" xmlns:ns2=\"http://www.w3.org/2005/Atom\" xmlns:wms=\"http://www.opengis.net/wms\" xmlns:ns3=\"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0\">\n",
" <wps:JobID>601d7a1a3d255d000167b456</wps:JobID>\n",
" <wps:Status>ACCEPTED</wps:Status>\n",
"</StatusInfo>\n",
"\n",
"\n",
"--- EXECUTE---\n",
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n",
"<StatusInfo xmlns:xlin=\"http://www.w3.org/1999/xlink\" xmlns:se=\"http://www.opengis.net/se/2.0/core\" xmlns:fes=\"http://www.opengis.net/fes/2.1\" xmlns:ows=\"http://www.opengis.net/ows/2.0\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:wps=\"http://www.opengis.net/wps/2.0\" xmlns:ns2=\"http://www.w3.org/2005/Atom\" xmlns:wms=\"http://www.opengis.net/wms\" xmlns:ns3=\"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0\">\n",
" <wps:JobID>601d7a1c3d255d000167b458</wps:JobID>\n",
" <wps:Status>ACCEPTED</wps:Status>\n",
"</StatusInfo>\n",
"\n",
"\n",
"--- EXECUTE---\n",
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n",
"<StatusInfo xmlns:xlin=\"http://www.w3.org/1999/xlink\" xmlns:se=\"http://www.opengis.net/se/2.0/core\" xmlns:fes=\"http://www.opengis.net/fes/2.1\" xmlns:ows=\"http://www.opengis.net/ows/2.0\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:wps=\"http://www.opengis.net/wps/2.0\" xmlns:ns2=\"http://www.w3.org/2005/Atom\" xmlns:wms=\"http://www.opengis.net/wms\" xmlns:ns3=\"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0\">\n",
" <wps:JobID>601d7a1d3d255d000167b45a</wps:JobID>\n",
" <wps:Status>ACCEPTED</wps:Status>\n",
"</StatusInfo>\n",
"\n",
"\n",
"--- EXECUTE---\n",
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n",
"<StatusInfo xmlns:xlin=\"http://www.w3.org/1999/xlink\" xmlns:se=\"http://www.opengis.net/se/2.0/core\" xmlns:fes=\"http://www.opengis.net/fes/2.1\" xmlns:ows=\"http://www.opengis.net/ows/2.0\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:wps=\"http://www.opengis.net/wps/2.0\" xmlns:ns2=\"http://www.w3.org/2005/Atom\" xmlns:wms=\"http://www.opengis.net/wms\" xmlns:ns3=\"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0\">\n",
" <wps:JobID>601d7a1f3d255d000167b45c</wps:JobID>\n",
" <wps:Status>ACCEPTED</wps:Status>\n",
"</StatusInfo>\n",
"\n",
"\n"
]
}
],
"source": [
"def wps_execute(user_id, algo_wps_xml):\n",
" \n",
" print(\"--- EXECUTE---\")\n",
" \n",
" url = copa_backend_url + 'wps?userId=' + user_id\n",
" tree = ET.parse(algo_wps_xml)\n",
" \n",
" response = requests.post(url, headers = \\\n",
" {'Authorization': 'Bearer '+oauth_token, 'Content-Type': 'application/xml'}, \\\n",
" data=ET.tostring(tree.getroot()))\n",
" print(response.text)\n",
" tree = ET.fromstring(response.text)\n",
" \n",
" return tree.find('{http://www.opengis.net/wps/2.0}JobID').text\n",
"\n",
"\n",
"read_xml = '/projects/scalability-s2-jupyter/wps_readstwo.xml'\n",
"\n",
"print(\"--- EXECUTE---\")\n",
"\n",
"i = 0\n",
"b = 6\n",
"\n",
"time1 = time.time()\n",
"job = []\n",
"\n",
"################read##############\n",
"\n",
"while i < b:\n",
" jobId = wps_execute(user_id, read_xml)\n",
" job.append(jobId)\n",
" time.sleep(1)\n",
" i += 1\n",
"i = 0\n",
"\n",
"while len(job) != 0:\n",
" \n",
" for Id in job:\n",
" \n",
" url = copa_backend_url + 'wps/getStatus?userId=' + user_id\n",
" body = { \"jobID\": Id }\n",
" response = requests.post(url, headers = {'Authorization': 'Bearer '+oauth_token}, json = body)\n",
" parsed = json.loads(response.text)\n",
" if parsed[\"status\"] == \"SUCCEEDED\":\n",
" job.remove(Id)\n",
" \n",
" \n",
" time.sleep(2)\n",
" \n",
"time2 = time.time()\n",
"final_time = (time2 - time1)\n",
"print('execution time was', final_time)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}