Skip to content

Commit 98fae3d

Browse files
committed
use explicit code-blocks in docs/udp.rst
Inspired by and test for PR #750
1 parent 66499f9 commit 98fae3d

File tree

1 file changed

+57
-20
lines changed

1 file changed

+57
-20
lines changed

docs/udp.rst

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ consisting of two simple mathematical operations
5151

5252
We can represent this in openEO's JSON based format as follows
5353
(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):
5555

56+
.. code-block:: json
5657
5758
{
5859
"subtract32": {
@@ -69,11 +70,13 @@ the openEO Python client will hide this usually)::
6970
7071
The important point here is the parameter reference ``{"from_parameter": "fahrenheit"}`` in the subtraction.
7172
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
7376
7477
{
7578
"process_id": "fahrenheit_to_celsius",
76-
"arguments" {"fahrenheit": 70}
79+
"arguments": {"fahrenheit": 70}
7780
}
7881
7982
@@ -90,7 +93,9 @@ The openEO Python client lets you define parameters as
9093
:class:`~openeo.api.process.Parameter` instances.
9194
In general you have to specify at least the parameter name,
9295
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
9499
95100
from openeo.api.process import Parameter
96101
@@ -103,7 +108,9 @@ The "fahrenheit" parameter from the example above can be defined like this::
103108
To simplify working with parameter schemas, the :class:`~openeo.api.process.Parameter` class
104109
provides a couple of helpers to create common types of parameters.
105110
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
107114
108115
fahrenheit_param = Parameter.number(
109116
name="fahrenheit", description="Degrees Fahrenheit"
@@ -139,7 +146,9 @@ Some useful parameter helpers (class methods of the :py:class:`~openeo.api.proce
139146

140147

141148
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
143152
144153
size_param = Parameter.integer(
145154
name="size", description="Kernel size", default=4
@@ -163,7 +172,9 @@ Basic primitives can be declared through a (required) "type" field, for example:
163172

164173
Likewise, arrays can be defined with a minimal ``{"type": "array"}``.
165174
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
167178
168179
{
169180
"type": "array",
@@ -173,7 +184,9 @@ e.g. an array of integers::
173184
Another, more complex type is ``{"type": "object"}`` for parameters
174185
that are like Python dictionaries (or mappings).
175186
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
177190
178191
{
179192
"type": "object",
@@ -192,7 +205,9 @@ for even more features.
192205
On top of these generic types, the openEO API also defines a couple of custom (sub)types
193206
in the `openeo-processes project <https://github.com/Open-EO/openeo-processes>`_
194207
(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
196211
197212
{
198213
"type": "object",
@@ -221,7 +236,9 @@ Through "process functions"
221236

222237
The openEO Python Client Library defines the
223238
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
225242
226243
from openeo.processes import subtract, divide
227244
from openeo.api.process import Parameter
@@ -246,7 +263,9 @@ We can pass it directly to :py:meth:`~openeo.rest.connection.Connection.save_use
246263

247264
If you want to inspect its openEO-style process graph representation,
248265
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
250269
251270
>>> fahrenheit_to_celsius.print_json()
252271
{
@@ -283,7 +302,9 @@ It's also possible to work with a :class:`~openeo.rest.datacube.DataCube` direct
283302
and parameterize it.
284303
Let's create, as a simple but functional example, a custom ``load_collection``
285304
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
287308
288309
spatial_extent = Parameter(
289310
name="bbox",
@@ -306,7 +327,9 @@ while building a :class:`~openeo.rest.datacube.DataCube`.
306327
:class:`~openeo.api.process.Parameter` arguments.
307328
Please submit a bug report when you encounter missing or wrong parameterization support.
308329

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
310333
311334
connection.save_user_defined_process(
312335
"fancy_load_collection",
@@ -316,7 +339,9 @@ We can now store this as a user-defined process called "fancy_load_collection" o
316339
317340
If you want to inspect its openEO-style process graph representation,
318341
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
320345
321346
>>> cube.print_json()
322347
{
@@ -351,7 +376,9 @@ or you prefer to fine-tune process graphs in a JSON editor.
351376
It is very straightforward to submit this as a user-defined process.
352377

353378
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
355382
356383
fahrenheit_to_celsius = {
357384
"subtract1": {
@@ -366,7 +393,9 @@ representing the Fahrenheit to Celsius conversion we discussed before::
366393
367394
We can store this directly, taking into account that we have to define
368395
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
370399
371400
connection.save_user_defined_process(
372401
user_defined_process_id="fahrenheit_to_celsius",
@@ -382,7 +411,9 @@ Some use cases might require storing the user-defined process in,
382411
for example, a JSON file instead of storing it directly on a back-end.
383412
Use :py:func:`~openeo.rest.udp.build_process_dict` to build a dictionary
384413
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
386417
387418
import json
388419
from openeo.rest.udp import build_process_dict
@@ -401,7 +432,9 @@ and dump it in JSON format to a file::
401432
with open("fahrenheit_to_celsius.json", "w") as f:
402433
json.dump(spec, f, indent=2)
403434
404-
This results in a JSON file like this::
435+
This results in a JSON file like this:
436+
437+
.. code-block:: json
405438
406439
{
407440
"id": "fahrenheit_to_celsius",
@@ -425,7 +458,9 @@ Let's evaluate the user-defined processes we defined.
425458
Because there is no pre-defined
426459
wrapper function for our user-defined process, we use the
427460
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
429464
430465
>>> pg = openeo.processes.process("fahrenheit_to_celsius", f=70)
431466
>>> pg.print_json(indent=None)
@@ -441,7 +476,9 @@ we only have to specify a temporal extent,
441476
and let the predefined and default values do their work.
442477
We will use :func:`~openeo.rest.connection.Connection.datacube_from_process`
443478
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
445482
446483
cube = connection.datacube_from_process("fancy_load_collection")
447484
cube = cube.filter_temporal("2020-09-01", "2020-09-10")

0 commit comments

Comments
 (0)