@@ -51,8 +51,9 @@ consisting of two simple mathematical operations
51
51
52
52
We can represent this in openEO's JSON based format as follows
53
53
(don't worry too much about the syntax details of this representation,
54
- the openEO Python client will hide this usually)::
54
+ the openEO Python client will hide this usually):
55
55
56
+ .. code-block :: json
56
57
57
58
{
58
59
"subtract32" : {
@@ -69,11 +70,13 @@ the openEO Python client will hide this usually)::
69
70
70
71
The important point here is the parameter reference ``{"from_parameter": "fahrenheit"} `` in the subtraction.
71
72
When we call this user-defined process we will have to provide a Fahrenheit value.
72
- For example with 70 degrees Fahrenheit (again in openEO JSON format here)::
73
+ For example with 70 degrees Fahrenheit (again in openEO JSON format here):
74
+
75
+ .. code-block :: json
73
76
74
77
{
75
78
"process_id" : " fahrenheit_to_celsius" ,
76
- "arguments" {"fahrenheit": 70}
79
+ "arguments" : {"fahrenheit" : 70 }
77
80
}
78
81
79
82
@@ -90,7 +93,9 @@ The openEO Python client lets you define parameters as
90
93
:class: `~openeo.api.process.Parameter ` instances.
91
94
In general you have to specify at least the parameter name,
92
95
a description and a schema (to declare the expected parameter type).
93
- The "fahrenheit" parameter from the example above can be defined like this::
96
+ The "fahrenheit" parameter from the example above can be defined like this:
97
+
98
+ .. code-block :: python
94
99
95
100
from openeo.api.process import Parameter
96
101
@@ -103,7 +108,9 @@ The "fahrenheit" parameter from the example above can be defined like this::
103
108
To simplify working with parameter schemas, the :class: `~openeo.api.process.Parameter ` class
104
109
provides a couple of helpers to create common types of parameters.
105
110
In the example above, the "fahrenheit" parameter (a number) can also be created more compactly
106
- with the :py:meth: `Parameter.number() <openeo.api.process.Parameter.number> ` helper::
111
+ with the :py:meth: `Parameter.number() <openeo.api.process.Parameter.number> ` helper:
112
+
113
+ .. code-block :: python
107
114
108
115
fahrenheit_param = Parameter.number(
109
116
name = " fahrenheit" , description = " Degrees Fahrenheit"
@@ -139,7 +146,9 @@ Some useful parameter helpers (class methods of the :py:class:`~openeo.api.proce
139
146
140
147
141
148
Consult the documentation of these helper class methods for additional features.
142
- For example, declaring a default value for an integer parameter::
149
+ For example, declaring a default value for an integer parameter:
150
+
151
+ .. code-block :: python
143
152
144
153
size_param = Parameter.integer(
145
154
name = " size" , description = " Kernel size" , default = 4
@@ -163,7 +172,9 @@ Basic primitives can be declared through a (required) "type" field, for example:
163
172
164
173
Likewise, arrays can be defined with a minimal ``{"type": "array"} ``.
165
174
In addition, the expected type of the array items can also be specified,
166
- e.g. an array of integers::
175
+ e.g. an array of integers:
176
+
177
+ .. code-block :: json
167
178
168
179
{
169
180
"type" : " array" ,
@@ -173,7 +184,9 @@ e.g. an array of integers::
173
184
Another, more complex type is ``{"type": "object"} `` for parameters
174
185
that are like Python dictionaries (or mappings).
175
186
For example, to define a bounding box parameter
176
- that should contain certain fields with certain type::
187
+ that should contain certain fields with certain type:
188
+
189
+ .. code-block :: json
177
190
178
191
{
179
192
"type" : " object" ,
@@ -192,7 +205,9 @@ for even more features.
192
205
On top of these generic types, the openEO API also defines a couple of custom (sub)types
193
206
in the `openeo-processes project <https://github.com/Open-EO/openeo-processes >`_
194
207
(see the ``meta/subtype-schemas.json `` listing).
195
- For example, the schema of an openEO data cube is::
208
+ For example, the schema of an openEO data cube is:
209
+
210
+ .. code-block :: json
196
211
197
212
{
198
213
"type" : " object" ,
@@ -221,7 +236,9 @@ Through "process functions"
221
236
222
237
The openEO Python Client Library defines the
223
238
official processes in the :py:mod: `openeo.processes ` module,
224
- which can be used to build a process graph as follows::
239
+ which can be used to build a process graph as follows:
240
+
241
+ .. code-block :: python
225
242
226
243
from openeo.processes import subtract, divide
227
244
from openeo.api.process import Parameter
@@ -246,7 +263,9 @@ We can pass it directly to :py:meth:`~openeo.rest.connection.Connection.save_use
246
263
247
264
If you want to inspect its openEO-style process graph representation,
248
265
use the :meth: `~openeo.rest.datacube.DataCube.to_json() `
249
- or :meth: `~openeo.rest.datacube.DataCube.print_json() ` method::
266
+ or :meth: `~openeo.rest.datacube.DataCube.print_json() ` method:
267
+
268
+ .. code-block :: pycon
250
269
251
270
>>> fahrenheit_to_celsius.print_json()
252
271
{
@@ -283,7 +302,9 @@ It's also possible to work with a :class:`~openeo.rest.datacube.DataCube` direct
283
302
and parameterize it.
284
303
Let's create, as a simple but functional example, a custom ``load_collection ``
285
304
with hardcoded collection id and band name
286
- and a parameterized spatial extent (with default)::
305
+ and a parameterized spatial extent (with default):
306
+
307
+ .. code-block :: python
287
308
288
309
spatial_extent = Parameter(
289
310
name = " bbox" ,
@@ -306,7 +327,9 @@ while building a :class:`~openeo.rest.datacube.DataCube`.
306
327
:class: `~openeo.api.process.Parameter ` arguments.
307
328
Please submit a bug report when you encounter missing or wrong parameterization support.
308
329
309
- We can now store this as a user-defined process called "fancy_load_collection" on the back-end::
330
+ We can now store this as a user-defined process called "fancy_load_collection" on the back-end:
331
+
332
+ .. code-block :: python
310
333
311
334
connection.save_user_defined_process(
312
335
" fancy_load_collection" ,
@@ -316,7 +339,9 @@ We can now store this as a user-defined process called "fancy_load_collection" o
316
339
317
340
If you want to inspect its openEO-style process graph representation,
318
341
use the :meth: `~openeo.rest.datacube.DataCube.to_json() `
319
- or :meth: `~openeo.rest.datacube.DataCube.print_json() ` method::
342
+ or :meth: `~openeo.rest.datacube.DataCube.print_json() ` method:
343
+
344
+ .. code-block :: pycon
320
345
321
346
>>> cube.print_json()
322
347
{
@@ -351,7 +376,9 @@ or you prefer to fine-tune process graphs in a JSON editor.
351
376
It is very straightforward to submit this as a user-defined process.
352
377
353
378
Say we start from the following Python dictionary,
354
- representing the Fahrenheit to Celsius conversion we discussed before::
379
+ representing the Fahrenheit to Celsius conversion we discussed before:
380
+
381
+ .. code-block :: python
355
382
356
383
fahrenheit_to_celsius = {
357
384
" subtract1" : {
@@ -366,7 +393,9 @@ representing the Fahrenheit to Celsius conversion we discussed before::
366
393
367
394
We can store this directly, taking into account that we have to define
368
395
a parameter named ``f `` corresponding with the ``{"from_parameter": "f"} `` argument
369
- from the dictionary above::
396
+ from the dictionary above:
397
+
398
+ .. code-block :: python
370
399
371
400
connection.save_user_defined_process(
372
401
user_defined_process_id = " fahrenheit_to_celsius" ,
@@ -382,7 +411,9 @@ Some use cases might require storing the user-defined process in,
382
411
for example, a JSON file instead of storing it directly on a back-end.
383
412
Use :py:func: `~openeo.rest.udp.build_process_dict ` to build a dictionary
384
413
compatible with the "process graph with metadata" format of the openEO API
385
- and dump it in JSON format to a file::
414
+ and dump it in JSON format to a file:
415
+
416
+ .. code-block :: python
386
417
387
418
import json
388
419
from openeo.rest.udp import build_process_dict
@@ -401,7 +432,9 @@ and dump it in JSON format to a file::
401
432
with open (" fahrenheit_to_celsius.json" , " w" ) as f:
402
433
json.dump(spec, f, indent = 2 )
403
434
404
- This results in a JSON file like this::
435
+ This results in a JSON file like this:
436
+
437
+ .. code-block :: json
405
438
406
439
{
407
440
"id" : " fahrenheit_to_celsius" ,
@@ -425,7 +458,9 @@ Let's evaluate the user-defined processes we defined.
425
458
Because there is no pre-defined
426
459
wrapper function for our user-defined process, we use the
427
460
generic :func:`openeo.processes.process` function to build a simple
428
- process graph that calls our ``fahrenheit_to_celsius `` process::
461
+ process graph that calls our ``fahrenheit_to_celsius`` process:
462
+
463
+ .. code-block:: pycon
429
464
430
465
>>> pg = openeo.processes.process("fahrenheit_to_celsius", f=70)
431
466
>>> pg.print_json(indent=None)
@@ -441,7 +476,9 @@ we only have to specify a temporal extent,
441
476
and let the predefined and default values do their work.
442
477
We will use :func:`~openeo.rest.connection.Connection.datacube_from_process`
443
478
to construct a :class:`~openeo.rest.datacube.DataCube` object
444
- which we can process further and download::
479
+ which we can process further and download:
480
+
481
+ .. code-block:: python
445
482
446
483
cube = connection.datacube_from_process("fancy_load_collection")
447
484
cube = cube.filter_temporal("2020-09-01", "2020-09-10")
0 commit comments