From b09b01e2909896ac37f08395b9cfe717a8df4c14 Mon Sep 17 00:00:00 2001 From: Victor Poughon <victor.poughon@cnes.fr> Date: Tue, 25 Jun 2019 14:33:49 +0200 Subject: [PATCH] DOC: update Python UpdateParameters corner case --- Documentation/Cookbook/rst/PythonAPI.rst | 41 +++--------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/Documentation/Cookbook/rst/PythonAPI.rst b/Documentation/Cookbook/rst/PythonAPI.rst index 6f61f1b408..2c44b5a545 100644 --- a/Documentation/Cookbook/rst/PythonAPI.rst +++ b/Documentation/Cookbook/rst/PythonAPI.rst @@ -387,43 +387,10 @@ happens, this documentation will report the OTB version that fixes the issue. Calling UpdateParameters() ^^^^^^^^^^^^^^^^^^^^^^^^^^ -These wrappers are made as a mirror of the C++ API, so there is a function -``UpdateParameters()``. Its role is to update parameters that depend on others. -It is called at least once at the beginning of ``Execute()``. - -In command line and GUI launchers, this functions gets called each time a -parameter of the application is modified. In Python, this mechanism is not -automated: there are cases where you may have to call it yourself. - -Let's take an example with the application ``PolygonClassStatictics``. In this -application, the choices available in the parameter ``field`` depend on the list -of fields actually present in the vector file ``vec``. If you try to set the -parameters ``vec`` and ``field``, you will get an error: - -.. code-block:: python - - import otbApplication as otb - app = otb.Registry.CreateApplication("PolygonClassStatistics") - app.SetParameterString("vec","../../src/OTB-Data/Input/Classification/variousVectors.sqlite") - app.SetParameterString("field", "label") - -:: - - Traceback (most recent call last): - File "<stdin>", line 1, in <module> - File "/home/gpasero/Projet_OTB/build/OTB/lib/otb/python/otbApplication.py", line 897, in SetParameterString - def SetParameterString(self, *args): return _otbApplication.Application_SetParameterString(self, *args) - RuntimeError: Exception thrown in otbApplication Application_SetParameterString: /home/gpasero/Projet_OTB/src/OTB/Modules/Wrappers/ApplicationEngine/src/otbWrapperListViewParameter.cxx:141: - itk::ERROR: ListViewParameter(0x149da10): Cannot find label - -The error says that the choice ``label`` is not recognized, because ``UpdateParameters()`` -was not called after setting the vector file. The solution is to call it before -setting the ``field`` parameter: - -.. code-block:: python - - app.UpdateParameters() - app.SetParameterString("field", "label") +``UpdateParameters()`` is available to the Python API. But in normal use, it +does not need to be called manually. From OTB 7.0.0 and later, it is called +automatically after each call to ``SetParameter*()`` methods. With previous versions +of OTB you may need to call it after setting a parameter. No metadata in NumPy arrays ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- GitLab