@@ -480,34 +480,38 @@ An example code can be found `here <https://github.com/Open-EO/openeo-python-cli
480
480
Logging from a UDF
481
481
=====================
482
482
483
- In some cases, you may want to log information from your user defined function,
484
- for instance to provide debug information or to log warnings. You can use the :py:class: `~openeo.udf.debug.inspect `
485
- logging function to achieve this.
483
+ From time to time, when things are not working as expected,
484
+ you may want to log some additional debug information from your UDF, inspect the data that is being processed,
485
+ or log warnings.
486
+ This can be done using the :py:class: `~openeo.udf.debug.inspect() ` function.
486
487
487
- For example, in the previous example of rescaling an RGB image(from SENTINEL2_L2A), suppose you
488
- want to keep a log of array shape encountered within a UDF::
488
+ For example: to discover the shape of the data cube chunk that you receive in your UDF function:
489
489
490
- # Create a UDF object from inline source code.
491
- udf = openeo.UDF("""
492
- from openeo.udf import XarrayDataCube
493
- from openeo.udf.debug import inspect
490
+ .. code-block :: python
491
+ :caption: Sample UDF code with `` inspect()`` logging
492
+ :emphasize- lines: 1 , 5
493
+
494
+ from openeo.udf import XarrayDataCube, inspect
494
495
495
496
def apply_datacube (cube : XarrayDataCube, context : dict ) -> XarrayDataCube:
496
497
array = cube.get_array()
497
498
inspect(data = [array.shape], message = " UDF logging shape of my array" )
498
499
array.values = 0.0001 * array.values
499
500
return cube
500
- """)
501
501
502
- If you are using Jupyter Notebook, you can see the log entries using :py:class: `~openeo.rest.job.BatchJob.logs `
503
- as shown in the image:
502
+ After the batch job is finished (or failed), you can find this information in the logs of the batch job.
503
+ For example (as explained at :ref: `batch-job-logs `),
504
+ use :py:class: `BatchJob.logs() <openeo.rest.job.BatchJob.logs> ` in a Jupyter notebook session
505
+ to retrieve and filter the logs interactively:
504
506
505
507
.. image :: _static/images/udf/logging_arrayshape.png
506
508
507
- Please note that this nice rendering only happens in Jupyter Notebook, while in plain Python you will get a dict.
509
+ Which reveals in this example a chunking shape of ``[3, 256, 256] ``.
510
+
511
+ .. note ::
508
512
509
- Thus, an array of shape 3x256x256 was logged in on which rescaling was performed. [Please note that at this moment ,
510
- this method is experimental and does not support all data types in `` data `` argument of :py:class: ` ~openeo.udf. debug.inspect `]
513
+ Not all kinds of data (types) are accepted/supported by the `` data `` argument of :py:class: ` ~openeo.udf.debug.inspect ` ,
514
+ so you might have to experiment a bit to make sure the desired debug information is logged as desired.
511
515
512
516
513
517
.. _old_udf_api :
0 commit comments