summaryrefslogtreecommitdiff
path: root/python-wasdi.spec
blob: 49edfd2e33e557054cdd5ba0365466c463fa0073 (plain)
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
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
523
524
525
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
%global _empty_manifest_terminate_build 0
Name:		python-wasdi
Version:	0.8.0.2
Release:	1
Summary:	The WASDI Python library
License:	GNU General Public License v3 (GPLv3)
URL:		https://www.wasdi.net
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/3e/d2/6e90269162e7bd43e8f8e2f75c3496bf9cdf591924ac8aea8755e042b9f0/wasdi-0.8.0.2.tar.gz
BuildArch:	noarch

Requires:	python3-requests

%description
## Python tutorial
WASPY is the **WAS**DI **Py**thon Library. 
**GET UPDATED DOCUMENTATION, TUTORIALS AND MORE [here](https://wasdi.readthedocs.io/en/latest/index.html)**
### Prerequisites:
mandatory:
- a [WASDI](http://www.wasdi.net) registered user (with a username/password, google users are not supported yet)
- at least one workspace
- some EO products in your workspace
### Installation
To start working with WASPY, just install the library using:
```bash
pip install wasdi
```
To quickly check if the installation worked correctly, try running the following code:
```python
import wasdi
print(wasdi.hello())
```
You should see this kind of output:
```json
{"boolValue":null,"doubleValue":null,"intValue":null,"stringValue":"Hello Wasdi!!"}
```
### Configuration
Create a `config.json` file. It is a standard json file, which is used to store the credentials of the user and some other settings. The syntax is:
```json
“VARIABLE_NAME”: value
```
Hint: exploit an editor which can check the syntax (there are many which can be accessed online for free)
The minimal configuration to begin working with WASPY is:
```json
{
  "USER": "yourUser@wasdi.net",
  "PASSWORD": "yourPasswordHere",
  "WORKSPACE": "nameOfTheWorkspaceYouWantToUse"
}
```
For the other available parameters please refer to the Documentation.
### Start WASPY
To start WASPY and check if everything is working, run the following code:
```python
wasdi.init('./config.json')
```
(Adapt the path if the file is not located in your working directory)
The Lib will read the configuration file, load the user and password, log the user in, and then open the workspace specified in the configuration file. To check if everything is working, try to get the list of workspaces available for the user:
```python
wasdi.getWorkspaces()
```
You should be able to see a result similar to the following one:
```python
[{u'ownerUserId': u'yourUser@wasdi.net',
  u'sharedUsers': [],
  u'workspaceId': u'23ab54f3-b453-2b3e-284a-b6a4243f0f2c',
  u'workspaceName': u'nameOfTheWorkspaceYouWantToUse'},
 {u'ownerUserId': u'yourUser@wasdi.net',
  u'sharedUsers': [],
  u'workspaceId': u'103fbf01-2e68-22d3-bd45-2cf95665dac2',
  u'workspaceName': u'theNameOfAnotherWorkspace'}]
```
The configured Workspace is already opened.  The use can open another workspace using:
```python
wasdi.openWorkspace('theNameOfAnotherWorkspace')
```
and the lib replies showing the workspace unique id:
```python
u'9ce787d4-1d59-4146-8df7-3fc9516d4eb3'
```
To get the list of the products available in the workspace, call
```python
wasdi.getProductsByWorkspace('nameOfTheWorkspaceYouWantToUse')
```
and the lib returns a list of the products in the given workspace:
```python
[u'S1A_IW_GRDH_1SDV_20190517T053543_20190517T053608_027263_0312F1_F071.zip',
u'S1B_IW_RAW__0SDV_20190506T052631_20190506T052703_016119_01E53A_D2AD.zip', u'S1A_IW_GRDH_1SDV_20190517T053608_20190517T053633_027263_0312F1_3382.zip']
```
Now try something more, let's search for some Sentinel 1 images. Let's assume we are interested in images taken from "2018-09-01" to "2018-09-02". Also, we'd better specify a bounding box. Assume we're interested in images with *latitude* in `[43, 44]` and *longitude* in `[11, 12]`. We can think of these coordinates as a rectangle limited by the upper left corner `(44, 11)` and the lower right corner`(43, 12)`. 
 The corresponding code is:
```python
wasdi.wasdiLog('Let\'s search some images')
aoImages = wasdi.searchEOImages("S1", "2018-09-01", "2018-09-02", 44, 11, 43, 12, None, None, None, None)
wasdi.wasdiLog('Found ' + str(len(aoImages)))
```
The output should be similar to this:
```
 Let's search some images
[INFO] waspy.searchEOImages: search results:
[{
		'footprint': 'POLYGON ((8.8724 45.3272, 8.4505 43.3746, 11.4656 43.0981, 11.9901 45.0472, 8.8724 45.3272, 8.8724 45.3272))',
		'id': 'cba6c104-3006-4af7-a2d1-cbd55f58b939',
		'link': 'https://catalogue.onda-dias.eu/dias-catalogue/Products(cba6c104-3006-4af7-a2d1-cbd55f58b939)/$value',
		'preview': None,
		'properties': {
			'offline': 'false',
			'downloadable': '',
			'filename': 'S1A_IW_RAW__0SDV_20180902T052727_20180902T052759_023515_028F75_7325.zip',
			'size': '1.54 GB',
			'pseudopath': 'RADAR/LEVEL-0/2018/09/02, S1/1A/SAR-C/LEVEL-0/IW_RAW__0S/2018/09/02, S1/1A/LEVEL-0/IW_RAW__0S/2018/09/02, S1/SAR-C/LEVEL-0/IW_RAW__0S/2018/09/02, S1/LEVEL-0/IW_RAW__0S/2018/09/02, 2014-016A/SAR-C/LEVEL-0/IW_RAW__0S/2018/09/02, 2014-016A/LEVEL-0/IW_RAW__0S/2018/09/02',
			'link': 'https://catalogue.onda-dias.eu/dias-catalogue/Products(cba6c104-3006-4af7-a2d1-cbd55f58b939)/$value',
			'format': 'application/zip',
			'creationDate': '2018-09-03T05:12:37.000Z'
		},
		'provider': 'ONDA',
		'summary': 'Date: 2018-09-03T05:12:37.000Z, Instrument: null, Mode: null, Satellite: null, Size: 1.54 GB',
		'title': 'S1A_IW_RAW__0SDV_20180902T052727_20180902T052759_023515_028F75_7325'
},
{'(...7 more results similar to this one, omitted for brevity)'}]
Found 8
```
Now we can import one of those products in WASDI: let's download the first one:
```python
sImportWithDict = wasdi.importProduct(None, None, aoImages[0])
```
We can see a list of the products in the workspace as follows:
```python
asProducts = wasdi.getProductsByActiveWorkspace()
wasdi.wasdiLog(asProducts)
```
The second line logs the list of products
### Running an existing workflow
If you wish to run an existing SNAP workflow you can use `wasdi.executeWorkflow`. For example, if you wish to execute a workflow that calibrates and corrects the georeference of a Sentinel 1 image, you may use the workflow called `LISTSinglePreproc` in this way:
```python
asProducts = wasdi.getProductsByActiveWorkspace()
sStatus = wasdi.executeWorkflow([asProducts[0]], ['lovelyOutput'], 'LISTSinglePreproc')
```
Here the first line gets the list of products and the second calls the workflow `LISTSinglePreproc` on the first product of the workspace and creates another product called `lovelyOutput`.
### A more complete example
Now put everything back together. Create a file called [`myProcessor.py`](https://github.com/fadeoutsoftware/WASDI/blob/develop/libraries/waspy/examples/myProcessor.py) (follow the link to download the file) with the following content:
```python
import wasdi
def run(parameters, processId):
    wasdi.wasdiLog('Here\'s the list of your workspaces:')
    aoWorkspaces = wasdi.getWorkspaces()
    wasdi.wasdiLog(aoWorkspaces)
    wasdi.wasdiLog('The ID of currently selected workspace is:')
    sActiveWorkspace = wasdi.getActiveWorkspaceId()
    wasdi.wasdiLog(sActiveWorkspace)
    wasdi.wasdiLog('Let\'s search some images...')
    aoImages = wasdi.searchEOImages("S1", "2018-09-01", "2018-09-02", 44, 11, 43, 12, sProductType='GRD')
    wasdi.wasdiLog('Found ' + str(len(aoImages)) + ' images')
    wasdi.wasdiLog('Download the first one passing the dictionary...')
    sImportWithDict = wasdi.importProduct(None, None, aoImages[0])
    wasdi.wasdiLog('Import with dict returned: ' + sImportWithDict)
    wasdi.wasdiLog('Now, these are the products in your workspace: ')
    asProducts = wasdi.getProductsByActiveWorkspace()
    wasdi.wasdiLog(asProducts)
    wasdi.wasdiLog('Let\'s run a workflow on the first image to rectify its georeference...')
    sStatus = wasdi.executeWorkflow([asProducts[0]], ['lovelyOutput'], 'LISTSinglePreproc')
    if sStatus == 'DONE':
        wasdi.wasdiLog('The product is now in your workspace, look at it on the website')
    wasdi.wasdiLog('It\'s over!')
def WasdiHelp():
    sHelp = "Wasdi Tutorial"
    return sHelp
```
Then create another file to start the processor. Let's call it [`tutorial.py`](https://github.com/fadeoutsoftware/WASDI/blob/develop/libraries/waspy/examples/tutorial.py) (follow the link to download the file), with the following content:
```python
import myProcessor
import wasdi
bInitResult = wasdi.init('config.json')
if bInitResult:
    myProcessor.run(wasdi.getParametersDict(), '')
```
Now, if you run `tutorial.py`, it will call `myProcessor.py`, which will go through the instructions we saw above. Pro tip: keep the browser open in wasdi.net (make sure you are logged in) and open the workspace you are using, to see the evolution of the script in real time.
### Deploy your processor on WASDI
Finally, to deply our processor on WASDI, you need first to create a text file called [`pip.txt`](https://github.com/fadeoutsoftware/WASDI/blob/develop/libraries/waspy/examples/pip.txt) (follow the link to download the file) containg the packages we imported in `myProcessor.py`, one per line. Since we just imported `wasdi`, it should look like this:
```
wasdi
```
Now, create a zip file containing these two files:
- `myProcessor.py`
- `pip.txt`
You can now upload the zip file on wasdi.net from *Edit* -> *Processor* -> *New WASDI App* by giving it a name and completing the other details. You will need to do this just once.

%package -n python3-wasdi
Summary:	The WASDI Python library
Provides:	python-wasdi
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-wasdi
## Python tutorial
WASPY is the **WAS**DI **Py**thon Library. 
**GET UPDATED DOCUMENTATION, TUTORIALS AND MORE [here](https://wasdi.readthedocs.io/en/latest/index.html)**
### Prerequisites:
mandatory:
- a [WASDI](http://www.wasdi.net) registered user (with a username/password, google users are not supported yet)
- at least one workspace
- some EO products in your workspace
### Installation
To start working with WASPY, just install the library using:
```bash
pip install wasdi
```
To quickly check if the installation worked correctly, try running the following code:
```python
import wasdi
print(wasdi.hello())
```
You should see this kind of output:
```json
{"boolValue":null,"doubleValue":null,"intValue":null,"stringValue":"Hello Wasdi!!"}
```
### Configuration
Create a `config.json` file. It is a standard json file, which is used to store the credentials of the user and some other settings. The syntax is:
```json
“VARIABLE_NAME”: value
```
Hint: exploit an editor which can check the syntax (there are many which can be accessed online for free)
The minimal configuration to begin working with WASPY is:
```json
{
  "USER": "yourUser@wasdi.net",
  "PASSWORD": "yourPasswordHere",
  "WORKSPACE": "nameOfTheWorkspaceYouWantToUse"
}
```
For the other available parameters please refer to the Documentation.
### Start WASPY
To start WASPY and check if everything is working, run the following code:
```python
wasdi.init('./config.json')
```
(Adapt the path if the file is not located in your working directory)
The Lib will read the configuration file, load the user and password, log the user in, and then open the workspace specified in the configuration file. To check if everything is working, try to get the list of workspaces available for the user:
```python
wasdi.getWorkspaces()
```
You should be able to see a result similar to the following one:
```python
[{u'ownerUserId': u'yourUser@wasdi.net',
  u'sharedUsers': [],
  u'workspaceId': u'23ab54f3-b453-2b3e-284a-b6a4243f0f2c',
  u'workspaceName': u'nameOfTheWorkspaceYouWantToUse'},
 {u'ownerUserId': u'yourUser@wasdi.net',
  u'sharedUsers': [],
  u'workspaceId': u'103fbf01-2e68-22d3-bd45-2cf95665dac2',
  u'workspaceName': u'theNameOfAnotherWorkspace'}]
```
The configured Workspace is already opened.  The use can open another workspace using:
```python
wasdi.openWorkspace('theNameOfAnotherWorkspace')
```
and the lib replies showing the workspace unique id:
```python
u'9ce787d4-1d59-4146-8df7-3fc9516d4eb3'
```
To get the list of the products available in the workspace, call
```python
wasdi.getProductsByWorkspace('nameOfTheWorkspaceYouWantToUse')
```
and the lib returns a list of the products in the given workspace:
```python
[u'S1A_IW_GRDH_1SDV_20190517T053543_20190517T053608_027263_0312F1_F071.zip',
u'S1B_IW_RAW__0SDV_20190506T052631_20190506T052703_016119_01E53A_D2AD.zip', u'S1A_IW_GRDH_1SDV_20190517T053608_20190517T053633_027263_0312F1_3382.zip']
```
Now try something more, let's search for some Sentinel 1 images. Let's assume we are interested in images taken from "2018-09-01" to "2018-09-02". Also, we'd better specify a bounding box. Assume we're interested in images with *latitude* in `[43, 44]` and *longitude* in `[11, 12]`. We can think of these coordinates as a rectangle limited by the upper left corner `(44, 11)` and the lower right corner`(43, 12)`. 
 The corresponding code is:
```python
wasdi.wasdiLog('Let\'s search some images')
aoImages = wasdi.searchEOImages("S1", "2018-09-01", "2018-09-02", 44, 11, 43, 12, None, None, None, None)
wasdi.wasdiLog('Found ' + str(len(aoImages)))
```
The output should be similar to this:
```
 Let's search some images
[INFO] waspy.searchEOImages: search results:
[{
		'footprint': 'POLYGON ((8.8724 45.3272, 8.4505 43.3746, 11.4656 43.0981, 11.9901 45.0472, 8.8724 45.3272, 8.8724 45.3272))',
		'id': 'cba6c104-3006-4af7-a2d1-cbd55f58b939',
		'link': 'https://catalogue.onda-dias.eu/dias-catalogue/Products(cba6c104-3006-4af7-a2d1-cbd55f58b939)/$value',
		'preview': None,
		'properties': {
			'offline': 'false',
			'downloadable': '',
			'filename': 'S1A_IW_RAW__0SDV_20180902T052727_20180902T052759_023515_028F75_7325.zip',
			'size': '1.54 GB',
			'pseudopath': 'RADAR/LEVEL-0/2018/09/02, S1/1A/SAR-C/LEVEL-0/IW_RAW__0S/2018/09/02, S1/1A/LEVEL-0/IW_RAW__0S/2018/09/02, S1/SAR-C/LEVEL-0/IW_RAW__0S/2018/09/02, S1/LEVEL-0/IW_RAW__0S/2018/09/02, 2014-016A/SAR-C/LEVEL-0/IW_RAW__0S/2018/09/02, 2014-016A/LEVEL-0/IW_RAW__0S/2018/09/02',
			'link': 'https://catalogue.onda-dias.eu/dias-catalogue/Products(cba6c104-3006-4af7-a2d1-cbd55f58b939)/$value',
			'format': 'application/zip',
			'creationDate': '2018-09-03T05:12:37.000Z'
		},
		'provider': 'ONDA',
		'summary': 'Date: 2018-09-03T05:12:37.000Z, Instrument: null, Mode: null, Satellite: null, Size: 1.54 GB',
		'title': 'S1A_IW_RAW__0SDV_20180902T052727_20180902T052759_023515_028F75_7325'
},
{'(...7 more results similar to this one, omitted for brevity)'}]
Found 8
```
Now we can import one of those products in WASDI: let's download the first one:
```python
sImportWithDict = wasdi.importProduct(None, None, aoImages[0])
```
We can see a list of the products in the workspace as follows:
```python
asProducts = wasdi.getProductsByActiveWorkspace()
wasdi.wasdiLog(asProducts)
```
The second line logs the list of products
### Running an existing workflow
If you wish to run an existing SNAP workflow you can use `wasdi.executeWorkflow`. For example, if you wish to execute a workflow that calibrates and corrects the georeference of a Sentinel 1 image, you may use the workflow called `LISTSinglePreproc` in this way:
```python
asProducts = wasdi.getProductsByActiveWorkspace()
sStatus = wasdi.executeWorkflow([asProducts[0]], ['lovelyOutput'], 'LISTSinglePreproc')
```
Here the first line gets the list of products and the second calls the workflow `LISTSinglePreproc` on the first product of the workspace and creates another product called `lovelyOutput`.
### A more complete example
Now put everything back together. Create a file called [`myProcessor.py`](https://github.com/fadeoutsoftware/WASDI/blob/develop/libraries/waspy/examples/myProcessor.py) (follow the link to download the file) with the following content:
```python
import wasdi
def run(parameters, processId):
    wasdi.wasdiLog('Here\'s the list of your workspaces:')
    aoWorkspaces = wasdi.getWorkspaces()
    wasdi.wasdiLog(aoWorkspaces)
    wasdi.wasdiLog('The ID of currently selected workspace is:')
    sActiveWorkspace = wasdi.getActiveWorkspaceId()
    wasdi.wasdiLog(sActiveWorkspace)
    wasdi.wasdiLog('Let\'s search some images...')
    aoImages = wasdi.searchEOImages("S1", "2018-09-01", "2018-09-02", 44, 11, 43, 12, sProductType='GRD')
    wasdi.wasdiLog('Found ' + str(len(aoImages)) + ' images')
    wasdi.wasdiLog('Download the first one passing the dictionary...')
    sImportWithDict = wasdi.importProduct(None, None, aoImages[0])
    wasdi.wasdiLog('Import with dict returned: ' + sImportWithDict)
    wasdi.wasdiLog('Now, these are the products in your workspace: ')
    asProducts = wasdi.getProductsByActiveWorkspace()
    wasdi.wasdiLog(asProducts)
    wasdi.wasdiLog('Let\'s run a workflow on the first image to rectify its georeference...')
    sStatus = wasdi.executeWorkflow([asProducts[0]], ['lovelyOutput'], 'LISTSinglePreproc')
    if sStatus == 'DONE':
        wasdi.wasdiLog('The product is now in your workspace, look at it on the website')
    wasdi.wasdiLog('It\'s over!')
def WasdiHelp():
    sHelp = "Wasdi Tutorial"
    return sHelp
```
Then create another file to start the processor. Let's call it [`tutorial.py`](https://github.com/fadeoutsoftware/WASDI/blob/develop/libraries/waspy/examples/tutorial.py) (follow the link to download the file), with the following content:
```python
import myProcessor
import wasdi
bInitResult = wasdi.init('config.json')
if bInitResult:
    myProcessor.run(wasdi.getParametersDict(), '')
```
Now, if you run `tutorial.py`, it will call `myProcessor.py`, which will go through the instructions we saw above. Pro tip: keep the browser open in wasdi.net (make sure you are logged in) and open the workspace you are using, to see the evolution of the script in real time.
### Deploy your processor on WASDI
Finally, to deply our processor on WASDI, you need first to create a text file called [`pip.txt`](https://github.com/fadeoutsoftware/WASDI/blob/develop/libraries/waspy/examples/pip.txt) (follow the link to download the file) containg the packages we imported in `myProcessor.py`, one per line. Since we just imported `wasdi`, it should look like this:
```
wasdi
```
Now, create a zip file containing these two files:
- `myProcessor.py`
- `pip.txt`
You can now upload the zip file on wasdi.net from *Edit* -> *Processor* -> *New WASDI App* by giving it a name and completing the other details. You will need to do this just once.

%package help
Summary:	Development documents and examples for wasdi
Provides:	python3-wasdi-doc
%description help
## Python tutorial
WASPY is the **WAS**DI **Py**thon Library. 
**GET UPDATED DOCUMENTATION, TUTORIALS AND MORE [here](https://wasdi.readthedocs.io/en/latest/index.html)**
### Prerequisites:
mandatory:
- a [WASDI](http://www.wasdi.net) registered user (with a username/password, google users are not supported yet)
- at least one workspace
- some EO products in your workspace
### Installation
To start working with WASPY, just install the library using:
```bash
pip install wasdi
```
To quickly check if the installation worked correctly, try running the following code:
```python
import wasdi
print(wasdi.hello())
```
You should see this kind of output:
```json
{"boolValue":null,"doubleValue":null,"intValue":null,"stringValue":"Hello Wasdi!!"}
```
### Configuration
Create a `config.json` file. It is a standard json file, which is used to store the credentials of the user and some other settings. The syntax is:
```json
“VARIABLE_NAME”: value
```
Hint: exploit an editor which can check the syntax (there are many which can be accessed online for free)
The minimal configuration to begin working with WASPY is:
```json
{
  "USER": "yourUser@wasdi.net",
  "PASSWORD": "yourPasswordHere",
  "WORKSPACE": "nameOfTheWorkspaceYouWantToUse"
}
```
For the other available parameters please refer to the Documentation.
### Start WASPY
To start WASPY and check if everything is working, run the following code:
```python
wasdi.init('./config.json')
```
(Adapt the path if the file is not located in your working directory)
The Lib will read the configuration file, load the user and password, log the user in, and then open the workspace specified in the configuration file. To check if everything is working, try to get the list of workspaces available for the user:
```python
wasdi.getWorkspaces()
```
You should be able to see a result similar to the following one:
```python
[{u'ownerUserId': u'yourUser@wasdi.net',
  u'sharedUsers': [],
  u'workspaceId': u'23ab54f3-b453-2b3e-284a-b6a4243f0f2c',
  u'workspaceName': u'nameOfTheWorkspaceYouWantToUse'},
 {u'ownerUserId': u'yourUser@wasdi.net',
  u'sharedUsers': [],
  u'workspaceId': u'103fbf01-2e68-22d3-bd45-2cf95665dac2',
  u'workspaceName': u'theNameOfAnotherWorkspace'}]
```
The configured Workspace is already opened.  The use can open another workspace using:
```python
wasdi.openWorkspace('theNameOfAnotherWorkspace')
```
and the lib replies showing the workspace unique id:
```python
u'9ce787d4-1d59-4146-8df7-3fc9516d4eb3'
```
To get the list of the products available in the workspace, call
```python
wasdi.getProductsByWorkspace('nameOfTheWorkspaceYouWantToUse')
```
and the lib returns a list of the products in the given workspace:
```python
[u'S1A_IW_GRDH_1SDV_20190517T053543_20190517T053608_027263_0312F1_F071.zip',
u'S1B_IW_RAW__0SDV_20190506T052631_20190506T052703_016119_01E53A_D2AD.zip', u'S1A_IW_GRDH_1SDV_20190517T053608_20190517T053633_027263_0312F1_3382.zip']
```
Now try something more, let's search for some Sentinel 1 images. Let's assume we are interested in images taken from "2018-09-01" to "2018-09-02". Also, we'd better specify a bounding box. Assume we're interested in images with *latitude* in `[43, 44]` and *longitude* in `[11, 12]`. We can think of these coordinates as a rectangle limited by the upper left corner `(44, 11)` and the lower right corner`(43, 12)`. 
 The corresponding code is:
```python
wasdi.wasdiLog('Let\'s search some images')
aoImages = wasdi.searchEOImages("S1", "2018-09-01", "2018-09-02", 44, 11, 43, 12, None, None, None, None)
wasdi.wasdiLog('Found ' + str(len(aoImages)))
```
The output should be similar to this:
```
 Let's search some images
[INFO] waspy.searchEOImages: search results:
[{
		'footprint': 'POLYGON ((8.8724 45.3272, 8.4505 43.3746, 11.4656 43.0981, 11.9901 45.0472, 8.8724 45.3272, 8.8724 45.3272))',
		'id': 'cba6c104-3006-4af7-a2d1-cbd55f58b939',
		'link': 'https://catalogue.onda-dias.eu/dias-catalogue/Products(cba6c104-3006-4af7-a2d1-cbd55f58b939)/$value',
		'preview': None,
		'properties': {
			'offline': 'false',
			'downloadable': '',
			'filename': 'S1A_IW_RAW__0SDV_20180902T052727_20180902T052759_023515_028F75_7325.zip',
			'size': '1.54 GB',
			'pseudopath': 'RADAR/LEVEL-0/2018/09/02, S1/1A/SAR-C/LEVEL-0/IW_RAW__0S/2018/09/02, S1/1A/LEVEL-0/IW_RAW__0S/2018/09/02, S1/SAR-C/LEVEL-0/IW_RAW__0S/2018/09/02, S1/LEVEL-0/IW_RAW__0S/2018/09/02, 2014-016A/SAR-C/LEVEL-0/IW_RAW__0S/2018/09/02, 2014-016A/LEVEL-0/IW_RAW__0S/2018/09/02',
			'link': 'https://catalogue.onda-dias.eu/dias-catalogue/Products(cba6c104-3006-4af7-a2d1-cbd55f58b939)/$value',
			'format': 'application/zip',
			'creationDate': '2018-09-03T05:12:37.000Z'
		},
		'provider': 'ONDA',
		'summary': 'Date: 2018-09-03T05:12:37.000Z, Instrument: null, Mode: null, Satellite: null, Size: 1.54 GB',
		'title': 'S1A_IW_RAW__0SDV_20180902T052727_20180902T052759_023515_028F75_7325'
},
{'(...7 more results similar to this one, omitted for brevity)'}]
Found 8
```
Now we can import one of those products in WASDI: let's download the first one:
```python
sImportWithDict = wasdi.importProduct(None, None, aoImages[0])
```
We can see a list of the products in the workspace as follows:
```python
asProducts = wasdi.getProductsByActiveWorkspace()
wasdi.wasdiLog(asProducts)
```
The second line logs the list of products
### Running an existing workflow
If you wish to run an existing SNAP workflow you can use `wasdi.executeWorkflow`. For example, if you wish to execute a workflow that calibrates and corrects the georeference of a Sentinel 1 image, you may use the workflow called `LISTSinglePreproc` in this way:
```python
asProducts = wasdi.getProductsByActiveWorkspace()
sStatus = wasdi.executeWorkflow([asProducts[0]], ['lovelyOutput'], 'LISTSinglePreproc')
```
Here the first line gets the list of products and the second calls the workflow `LISTSinglePreproc` on the first product of the workspace and creates another product called `lovelyOutput`.
### A more complete example
Now put everything back together. Create a file called [`myProcessor.py`](https://github.com/fadeoutsoftware/WASDI/blob/develop/libraries/waspy/examples/myProcessor.py) (follow the link to download the file) with the following content:
```python
import wasdi
def run(parameters, processId):
    wasdi.wasdiLog('Here\'s the list of your workspaces:')
    aoWorkspaces = wasdi.getWorkspaces()
    wasdi.wasdiLog(aoWorkspaces)
    wasdi.wasdiLog('The ID of currently selected workspace is:')
    sActiveWorkspace = wasdi.getActiveWorkspaceId()
    wasdi.wasdiLog(sActiveWorkspace)
    wasdi.wasdiLog('Let\'s search some images...')
    aoImages = wasdi.searchEOImages("S1", "2018-09-01", "2018-09-02", 44, 11, 43, 12, sProductType='GRD')
    wasdi.wasdiLog('Found ' + str(len(aoImages)) + ' images')
    wasdi.wasdiLog('Download the first one passing the dictionary...')
    sImportWithDict = wasdi.importProduct(None, None, aoImages[0])
    wasdi.wasdiLog('Import with dict returned: ' + sImportWithDict)
    wasdi.wasdiLog('Now, these are the products in your workspace: ')
    asProducts = wasdi.getProductsByActiveWorkspace()
    wasdi.wasdiLog(asProducts)
    wasdi.wasdiLog('Let\'s run a workflow on the first image to rectify its georeference...')
    sStatus = wasdi.executeWorkflow([asProducts[0]], ['lovelyOutput'], 'LISTSinglePreproc')
    if sStatus == 'DONE':
        wasdi.wasdiLog('The product is now in your workspace, look at it on the website')
    wasdi.wasdiLog('It\'s over!')
def WasdiHelp():
    sHelp = "Wasdi Tutorial"
    return sHelp
```
Then create another file to start the processor. Let's call it [`tutorial.py`](https://github.com/fadeoutsoftware/WASDI/blob/develop/libraries/waspy/examples/tutorial.py) (follow the link to download the file), with the following content:
```python
import myProcessor
import wasdi
bInitResult = wasdi.init('config.json')
if bInitResult:
    myProcessor.run(wasdi.getParametersDict(), '')
```
Now, if you run `tutorial.py`, it will call `myProcessor.py`, which will go through the instructions we saw above. Pro tip: keep the browser open in wasdi.net (make sure you are logged in) and open the workspace you are using, to see the evolution of the script in real time.
### Deploy your processor on WASDI
Finally, to deply our processor on WASDI, you need first to create a text file called [`pip.txt`](https://github.com/fadeoutsoftware/WASDI/blob/develop/libraries/waspy/examples/pip.txt) (follow the link to download the file) containg the packages we imported in `myProcessor.py`, one per line. Since we just imported `wasdi`, it should look like this:
```
wasdi
```
Now, create a zip file containing these two files:
- `myProcessor.py`
- `pip.txt`
You can now upload the zip file on wasdi.net from *Edit* -> *Processor* -> *New WASDI App* by giving it a name and completing the other details. You will need to do this just once.

%prep
%autosetup -n wasdi-0.8.0.2

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-wasdi -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Wed May 31 2023 Python_Bot <Python_Bot@openeuler.org> - 0.8.0.2-1
- Package Spec generated