Skip to content

Commit 52c7158

Browse files
committed
Finetune docs on "logging from a UDF" a bit
1 parent 3c2b08c commit 52c7158

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

docs/batch_jobs.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ Working from a :py:class:`~openeo.rest.datacube.DataCube` instance
259259
.. index:: batch job; logs
260260
261261
262+
.. _batch-job-logs:
263+
262264
Batch job logs
263265
===============
264266

docs/udf.rst

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -480,34 +480,38 @@ An example code can be found `here <https://github.com/Open-EO/openeo-python-cli
480480
Logging from a UDF
481481
=====================
482482

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.
486487

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:
489489

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
494495
495496
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
496497
array = cube.get_array()
497498
inspect(data=[array.shape], message="UDF logging shape of my array")
498499
array.values = 0.0001 * array.values
499500
return cube
500-
""")
501501
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:
504506

505507
.. image:: _static/images/udf/logging_arrayshape.png
506508

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::
508512

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.
511515

512516

513517
.. _old_udf_api:

0 commit comments

Comments
 (0)