From 2a8c3414e37512ac0aadd2e82b1ff2c8331787db Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 6 Jul 2023 12:53:49 +0200 Subject: [PATCH 01/20] DOC: correct typing of ext_fname --- pyotb/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyotb/core.py b/pyotb/core.py index 94da09b..405e736 100644 --- a/pyotb/core.py +++ b/pyotb/core.py @@ -762,7 +762,7 @@ class App(OTBObject): path: str | Path | dict[str, str] = None, pixel_type: dict[str, str] | str = None, preserve_dtype: bool = False, - ext_fname: str = "", + ext_fname: dict[str, str] | str = None, **kwargs, ) -> bool: """Set output pixel type and write the output raster files. @@ -773,7 +773,7 @@ class App(OTBObject): non-standard characters such as a point, e.g. {'io.out':'output.tif'} - None if output file was passed during App init ext_fname: Optional, an extended filename as understood by OTB (e.g. "&gdal:co:TILED=YES") - Will be used for all outputs (Default value = "") + Will be used for all outputs (Default value = None) pixel_type: Can be : - dictionary {out_param_key: pixeltype} when specifying for several outputs - str (e.g. 'uint16') or otbApplication.ImagePixelType_... When there are several outputs, all outputs are written with this unique type. -- GitLab From 13cd7bbc1128907bbd53e10de51fe1e126ccd10e Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 6 Jul 2023 12:53:59 +0200 Subject: [PATCH 02/20] DOC: fix missing link --- doc/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/index.md b/doc/index.md index 448d139..7861878 100644 --- a/doc/index.md +++ b/doc/index.md @@ -11,7 +11,7 @@ to make OTB more Python friendly. - [Installation](installation.md) - [How to use pyotb](quickstart.md) - [Useful features](features.md) -- [Functions](features.md) +- [Functions](functions.md) - [Interaction with Python libraries (numpy, rasterio, tensorflow)](interaction.md) ## Examples -- GitLab From d21a0d6cd92fc80e9e87b80f205381932abb93b3 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 6 Jul 2023 12:54:14 +0200 Subject: [PATCH 03/20] DOC: enhance quickstart --- doc/quickstart.md | 118 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 89 insertions(+), 29 deletions(-) diff --git a/doc/quickstart.md b/doc/quickstart.md index 5e07e43..fa26d45 100644 --- a/doc/quickstart.md +++ b/doc/quickstart.md @@ -15,12 +15,11 @@ resampled = pyotb.RigidTransformResample({ }) ``` -Note that pyotb has a 'lazy' evaluation: it only performs operation when it is -needed, i.e. results are written to disk. -Thus, the previous line doesn't trigger the application. +For now, `resampled` has not been executed. Indeed, pyotb has a 'lazy' +evaluation: applications are executed only when required. Generally, like in +this example, executions happen to write output images to disk. -To actually trigger the application execution, you need to write the result to -disk: +To actually trigger the application execution, `write()` has to be called: ```python resampled.write('output.tif') # this is when the application actually runs @@ -28,32 +27,39 @@ resampled.write('output.tif') # this is when the application actually runs ### Using Python keyword arguments -It is also possible to use the Python keyword arguments notation for passing -the parameters: +One can use the Python keyword arguments notation for passing that parameters: ```python output = pyotb.SuperImpose(inr='reference_image.tif', inm='image.tif') ``` -is equivalent to: +Which is equivalent to: ```python output = pyotb.SuperImpose({'inr': 'reference_image.tif', 'inm': 'image.tif'}) ``` -Limitations : for this notation, python doesn't accept the parameter `in` or -any parameter that contains a dots (e.g. `io.in)`. -For `in` and other main input parameters of an OTB app, you may simply pass -the value as first argument, pyotb will guess the parameter name. -For parameters that contains dots, you can either use a dictionary, or replace dots (`.`) with underscores (`_`) as follow : +!!! warning -```python -resampled = pyotb.RigidTransformResample( - 'my_image.tif', - interpolator = 'linear', - transform_type_id_scaley = 0.5, - transform_type_id_scalex = 0.5 -) + For this notation, python doesn't accept the parameter `in` or any + parameter that contains a dots (e.g. `io.in)`. For `in` or other main + input parameters of an OTB application, you may simply pass the value as + first argument, pyotb will guess the parameter name. For parameters that + contains dots, you can either use a dictionary, or replace dots (`.`) + with underscores (`_`). Let's take the example of the `OrthoRectification` + application of OTB, with the input image parameter named "io.in": + + Option #1, keyword-arg-free: + + ```python + ortho = pyotb.OrthoRectification('my_image.tif') + ``` + + Option #2, replacing dots with underscores in parameter name: + + ```python + ortho = pyotb.OrthoRectification(io_in='my_image.tif') + ``` ## In-memory connections @@ -93,26 +99,38 @@ dilated.write('result.tif') ## Writing the result of an app -Any pyotb object can be written to disk using the `write` method, e.g. : +Any pyotb object can be written to disk using `write()`. + +Let's consider the following pyotb application instance: ```python import pyotb - resampled = pyotb.RigidTransformResample({ 'in': 'my_image.tif', 'interpolator': 'linear', 'transform.type.id.scaley': 0.5, 'transform.type.id.scalex': 0.5 }) +``` -# Here you can set optionally pixel type and extended filename variables -resampled.write( - {'out': 'output.tif'}, - pixel_type='uint16', - ext_fname='?nodata=65535' -) +We can then write the output of `resampled` as following: + +```python +resampled.write('output.tif') ``` +!!! note + + For applications that have multiple outputs, passing a `dict` of filenames + can be considered. Let's take the example of `MeanShiftSmoothing` which + has 2 output images: + + ```python + import pyotb + meanshift = pyotb.MeanShiftSmoothing('my_image.tif') + meanshift.write({'fout': 'output_1.tif', 'foutpos': 'output_2.tif'}) + ``` + Another possibility for writing results is to set the output parameter when initializing the application: @@ -126,4 +144,46 @@ resampled = pyotb.RigidTransformResample({ 'transform.type.id.scaley': 0.5, 'transform.type.id.scalex': 0.5 }) -``` \ No newline at end of file +``` + +### Pixel type + +Setting the pixel type is optional, and can be achieved setting the +`pixel_type` argument: + +```python +resampled.write('output.tif', pixel_type='uint16') +``` + +The value of `pixel_type` corresponds to the name of a pixel type from OTB +applications (e.g. `'uint8'`, `'float'`, etc). + +### Extended filenames + +Extended filenames can be passed as `str` or `dict`. + +As `str`: + +```python +resampled.write( + ... + ext_fname='nodata=65535&box=0:0:256:256' +) +``` + +As `dict`: + +```python +resampled.write( + ... + ext_fname={'nodata': '65535', 'box': '0:0:256:256'} +) +``` + +!!! info + + When `ext_fname` is provided and the output filenames contain already some + extended filename pattern, the ones provided in the filenames take + priority over the ones passed in `ext_fname`. This allows to fine-grained + tune extended filenames for each output, with a common extended filenames + keys/values basis. -- GitLab From 9dc224ea83cf79c5a213bc68e60f4ffe8dd0f193 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 6 Jul 2023 12:59:16 +0200 Subject: [PATCH 04/20] DOC: edit limitation description --- doc/interaction.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/doc/interaction.md b/doc/interaction.md index e4c73fb..a87da8e 100644 --- a/doc/interaction.md +++ b/doc/interaction.md @@ -138,10 +138,6 @@ memory !!! warning - Limitations : - - - For OTBTF versions < 4.0.0, it is not possible to use the tensorflow - python API inside a script where OTBTF is used because of libraries - clashing between Tensorflow and OTBTF, i.e. `import tensorflow` doesn't - work in a script where OTBTF apps have been initialized. This is why we - recommend to use latest OTBTF versions + Due to compilation issues in OTBTF before version 4.0.0, tensorflow and + pyotb can't be imported in the same python code. This problem has been + fixed in OTBTF 4.0.0. -- GitLab From e8d99fa004ba994daf88c11d5c0ccfab1169b184 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 6 Jul 2023 13:01:16 +0200 Subject: [PATCH 05/20] DOC: edit limitation description --- doc/interaction.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/interaction.md b/doc/interaction.md index a87da8e..0195b70 100644 --- a/doc/interaction.md +++ b/doc/interaction.md @@ -43,11 +43,9 @@ noisy_image.write('image_plus_noise.tif') !!! warning - Limitations : - - The whole image is loaded into memory - - The georeference can not be modified. Thus, numpy operations can not change - the image or pixel size + - The georeference can not be modified. Thus, numpy operations can not + change the image or pixel size ## Export to rasterio -- GitLab From 29792c3bb3daa389091ad739dc2a263d034d36a7 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 6 Jul 2023 14:30:07 +0200 Subject: [PATCH 06/20] DOC: use otb stylesheet.css --- doc/stylesheets/extra.css | 4 ---- mkdocs.yml | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 doc/stylesheets/extra.css diff --git a/doc/stylesheets/extra.css b/doc/stylesheets/extra.css deleted file mode 100644 index c67f70f..0000000 --- a/doc/stylesheets/extra.css +++ /dev/null @@ -1,4 +0,0 @@ -/* this is for readthedocs theme */ -.wy-nav-content { - max-width: 1000px; -} \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 29d51d4..d196b27 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -55,7 +55,7 @@ extra: - icon: fontawesome/brands/gitlab link: https://gitlab.orfeo-toolbox.org/nicolasnn/pyotb extra_css: - - stylesheets/extra.css + - https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/raw/8.1.2-rc1/Documentation/Cookbook/_static/css/otb_theme.css use_directory_urls: false # this creates some pyotb/core.html pages instead of pyotb/core/index.html markdown_extensions: -- GitLab From f226f2f232d818326b5200e4f7cca15ab3a3e100 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 6 Jul 2023 14:30:24 +0200 Subject: [PATCH 07/20] DOC: nipticks --- doc/quickstart.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/quickstart.md b/doc/quickstart.md index fa26d45..8343520 100644 --- a/doc/quickstart.md +++ b/doc/quickstart.md @@ -42,12 +42,12 @@ output = pyotb.SuperImpose({'inr': 'reference_image.tif', 'inm': 'image.tif'}) !!! warning For this notation, python doesn't accept the parameter `in` or any - parameter that contains a dots (e.g. `io.in)`. For `in` or other main + parameter that contains a dots (e.g. `io.in`). For `in` or other main input parameters of an OTB application, you may simply pass the value as first argument, pyotb will guess the parameter name. For parameters that contains dots, you can either use a dictionary, or replace dots (`.`) with underscores (`_`). Let's take the example of the `OrthoRectification` - application of OTB, with the input image parameter named "io.in": + application of OTB, with the input image parameter named `io.in`: Option #1, keyword-arg-free: -- GitLab From 51cc690ac7b3d62863dbafd51f513be7fbc41553 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 6 Jul 2023 14:55:11 +0200 Subject: [PATCH 08/20] DOC: add codehilite --- mkdocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/mkdocs.yml b/mkdocs.yml index d196b27..273d121 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -59,6 +59,7 @@ extra_css: use_directory_urls: false # this creates some pyotb/core.html pages instead of pyotb/core/index.html markdown_extensions: + - codehilite - admonition - toc: permalink: true -- GitLab From 8dcc384b0ecb008d990233845855ae6eda9a499a Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 6 Jul 2023 14:55:20 +0200 Subject: [PATCH 09/20] DOC: enh --- doc/quickstart.md | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/doc/quickstart.md b/doc/quickstart.md index 8343520..e65c68f 100644 --- a/doc/quickstart.md +++ b/doc/quickstart.md @@ -46,8 +46,10 @@ output = pyotb.SuperImpose({'inr': 'reference_image.tif', 'inm': 'image.tif'}) input parameters of an OTB application, you may simply pass the value as first argument, pyotb will guess the parameter name. For parameters that contains dots, you can either use a dictionary, or replace dots (`.`) - with underscores (`_`). Let's take the example of the `OrthoRectification` - application of OTB, with the input image parameter named `io.in`: + with underscores (`_`). + + Let's take the example of the `OrthoRectification` application of OTB, + with the input image parameter named `io.in`: Option #1, keyword-arg-free: @@ -63,13 +65,19 @@ output = pyotb.SuperImpose({'inr': 'reference_image.tif', 'inm': 'image.tif'}) ## In-memory connections -The big asset of pyotb is the ease of in-memory connections between apps. +One nice feature of pyotb is in-memory connection between apps. It relies on +the so-called [streaming](https://www.orfeo-toolbox.org/CookBook/C++/StreamingAndThreading.html) +mechanism of OTB, that enables to process huge images with a limited memory +footprint. -Let's start from our previous example. Consider the case where one wants to -apply optical calibration and binary morphological dilatation -following the undersampling. +pyotb allows to pass any application's output to another. This enables to +build pipelines composed of several applications. -Using pyotb, you can pass the output of an app as input of another app : +Let's start from our previous example. Consider the case where one wants to +resample the image, then apply optical calibration and binary morphological +dilatation. We can write the following code to build a pipeline that will +generate the output in an end-to-end fashion, without being limited with the +input image size, without writing temporary files. ```python import pyotb @@ -91,12 +99,21 @@ dilated = pyotb.BinaryMorphologicalOperation({ 'out': 'output.tif', 'filter': 'dilate', 'structype': 'ball', - 'xradius': 3, 'yradius': 3 + 'xradius': 3, + 'yradius': 3 }) +``` -dilated.write('result.tif') +We just have built our first pipeline! At this point, it's all symbolic since +no computation has been performed. To trigger our pipeline, one must call the +`write()` method from the pipeline termination: + +```python +dilated.write('output.tif') ``` +In the next section, we will detail how `write()` works. + ## Writing the result of an app Any pyotb object can be written to disk using `write()`. -- GitLab From 356600626849a294970e52daca988c3a6171fb7a Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 6 Jul 2023 15:03:24 +0200 Subject: [PATCH 10/20] DOC: add codehilite --- mkdocs.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mkdocs.yml b/mkdocs.yml index 273d121..e80cfac 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -71,6 +71,8 @@ markdown_extensions: - pymdownx.snippets - pymdownx.details - pymdownx.superfences + - pymdownx.highlight: + use_pygments: true # Rest of the navigation.. site_name: "pyotb documentation: a Python extension of OTB" -- GitLab From 58e1789e2ab613cce9f0099f0cdf829d929b4d7f Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 6 Jul 2023 15:03:33 +0200 Subject: [PATCH 11/20] DOC: add codehilite --- doc/doc_requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/doc_requirements.txt b/doc/doc_requirements.txt index 4f59692..931c3df 100644 --- a/doc/doc_requirements.txt +++ b/doc/doc_requirements.txt @@ -5,3 +5,4 @@ mkdocs-gen-files mkdocs-section-index mkdocs-literate-nav mkdocs-mermaid2-plugin +pygments -- GitLab From 0956d334b86e93471ec52596b73d03e1e05e815a Mon Sep 17 00:00:00 2001 From: Vincent Delbar <vincent.delbar@latelescop.fr> Date: Fri, 7 Jul 2023 07:26:15 +0000 Subject: [PATCH 12/20] Apply 1 suggestion(s) to 1 file(s) --- pyotb/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyotb/core.py b/pyotb/core.py index 405e736..f9c8aa6 100644 --- a/pyotb/core.py +++ b/pyotb/core.py @@ -772,14 +772,14 @@ class App(OTBObject): - dictionary containing key-arguments enumeration. Useful when a key contains non-standard characters such as a point, e.g. {'io.out':'output.tif'} - None if output file was passed during App init - ext_fname: Optional, an extended filename as understood by OTB (e.g. "&gdal:co:TILED=YES") - Will be used for all outputs (Default value = None) pixel_type: Can be : - dictionary {out_param_key: pixeltype} when specifying for several outputs - str (e.g. 'uint16') or otbApplication.ImagePixelType_... When there are several outputs, all outputs are written with this unique type. Valid pixel types are uint8, uint16, uint32, int16, int32, float, double, cint16, cint32, cfloat, cdouble. (Default value = None) preserve_dtype: propagate main input pixel type to outputs, in case pixel_type is None + ext_fname: Optional, an extended filename as understood by OTB (e.g. "&gdal:co:TILED=YES") + Will be used for all outputs (Default value = None) **kwargs: keyword arguments e.g. out='output.tif' Returns: -- GitLab From 167ed2c63725bd060f76f2d88331c0791aa7df85 Mon Sep 17 00:00:00 2001 From: Vincent Delbar <vincent.delbar@latelescop.fr> Date: Fri, 7 Jul 2023 07:27:42 +0000 Subject: [PATCH 13/20] Apply 1 suggestion(s) to 1 file(s) --- doc/quickstart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/quickstart.md b/doc/quickstart.md index e65c68f..111f283 100644 --- a/doc/quickstart.md +++ b/doc/quickstart.md @@ -45,7 +45,7 @@ output = pyotb.SuperImpose({'inr': 'reference_image.tif', 'inm': 'image.tif'}) parameter that contains a dots (e.g. `io.in`). For `in` or other main input parameters of an OTB application, you may simply pass the value as first argument, pyotb will guess the parameter name. For parameters that - contains dots, you can either use a dictionary, or replace dots (`.`) + contains dots, you can either use a dictionary, or replace dots (`.`) with underscores (`_`). Let's take the example of the `OrthoRectification` application of OTB, -- GitLab From ff05e9e5839382ac651141f47e42cd19dd2417f1 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Fri, 7 Jul 2023 09:38:41 +0200 Subject: [PATCH 14/20] DOC: wip snippets style --- mkdocs.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index e80cfac..b24d48c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -59,7 +59,6 @@ extra_css: use_directory_urls: false # this creates some pyotb/core.html pages instead of pyotb/core/index.html markdown_extensions: - - codehilite - admonition - toc: permalink: true -- GitLab From 70acbb8bd11812d31b01d2b36d5e929059e13931 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Fri, 7 Jul 2023 10:14:49 +0200 Subject: [PATCH 15/20] DOC: style, closer to OTB docs --- doc/doc_requirements.txt | 1 - doc/extra.css | 11 +++++++++++ mkdocs.yml | 3 +-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 doc/extra.css diff --git a/doc/doc_requirements.txt b/doc/doc_requirements.txt index 931c3df..4f59692 100644 --- a/doc/doc_requirements.txt +++ b/doc/doc_requirements.txt @@ -5,4 +5,3 @@ mkdocs-gen-files mkdocs-section-index mkdocs-literate-nav mkdocs-mermaid2-plugin -pygments diff --git a/doc/extra.css b/doc/extra.css new file mode 100644 index 0000000..ec4d4bb --- /dev/null +++ b/doc/extra.css @@ -0,0 +1,11 @@ +.rst-content div[class^=highlight] { + border: 0px; +} + +.rst-content div[class^=highlight] pre { + padding: 0px; +} + +.rst-content pre code { + background: #eeffcc; +} diff --git a/mkdocs.yml b/mkdocs.yml index b24d48c..18cc088 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -56,6 +56,7 @@ extra: link: https://gitlab.orfeo-toolbox.org/nicolasnn/pyotb extra_css: - https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/raw/8.1.2-rc1/Documentation/Cookbook/_static/css/otb_theme.css + - extra.css use_directory_urls: false # this creates some pyotb/core.html pages instead of pyotb/core/index.html markdown_extensions: @@ -70,8 +71,6 @@ markdown_extensions: - pymdownx.snippets - pymdownx.details - pymdownx.superfences - - pymdownx.highlight: - use_pygments: true # Rest of the navigation.. site_name: "pyotb documentation: a Python extension of OTB" -- GitLab From 3a1588266ae92d9bb9669260799dc808d8dfcccd Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Fri, 7 Jul 2023 10:35:03 +0200 Subject: [PATCH 16/20] DOC: more compact comparison OTB vs pyotb --- doc/comparison_otb.md | 168 ++++++++++++++++++++++++++---------------- 1 file changed, 105 insertions(+), 63 deletions(-) diff --git a/doc/comparison_otb.md b/doc/comparison_otb.md index 29d1e89..0129cb2 100644 --- a/doc/comparison_otb.md +++ b/doc/comparison_otb.md @@ -11,28 +11,32 @@ <td> ```python -import otbApplication +import otbApplication as otb input_path = 'my_image.tif' -resampled = otbApplication.Registry.CreateApplication( +app = otb.Registry.CreateApplication( 'RigidTransformResample' ) -resampled.SetParameterString('in', input_path) -resampled.SetParameterString('interpolator', 'linear') -resampled.SetParameterFloat( - 'transform.type.id.scalex', - 0.5 +app.SetParameterString( + 'in', input_path ) -resampled.SetParameterFloat( - 'transform.type.id.scaley', - 0.5 +app.SetParameterString( + 'interpolator', 'linear' ) -resampled.SetParameterString('out', 'output.tif') -resampled.SetParameterOutputImagePixelType( - 'out', otbApplication.ImagePixelType_uint16 +app.SetParameterFloat( + 'transform.type.id.scalex', 0.5 +) +app.SetParameterFloat( + 'transform.type.id.scaley', 0.5 +) +app.SetParameterString( + 'out', 'output.tif' +) +app.SetParameterOutputImagePixelType( + 'out', otb.ImagePixelType_uint16 ) -resampled.ExecuteAndWriteOutput() +app.ExecuteAndWriteOutput() ``` </td> @@ -41,14 +45,17 @@ resampled.ExecuteAndWriteOutput() ```python import pyotb -resampled = pyotb.RigidTransformResample({ +app = pyotb.RigidTransformResample({ 'in': 'my_image.tif', 'interpolator': 'linear', 'transform.type.id.scaley': 0.5, 'transform.type.id.scalex': 0.5 }) -resampled.write('output.tif', pixel_type='uint16') +app.write( + 'output.tif', + pixel_type='uint16' +) ``` </td> @@ -66,42 +73,55 @@ resampled.write('output.tif', pixel_type='uint16') <td> ```python -import otbApplication +import otbApplication as otb -app1 = otbApplication.Registry.CreateApplication( +app1 = otb.Registry.CreateApplication( 'RigidTransformResample' ) -app1.SetParameterString('in', 'my_image.tif') -app1.SetParameterString('interpolator', 'linear') +app1.SetParameterString( + 'in', 'my_image.tif' +) +app1.SetParameterString( + 'interpolator', 'linear' +) app1.SetParameterFloat( - 'transform.type.id.scalex', - 0.5 + 'transform.type.id.scalex', 0.5 ) app1.SetParameterFloat( - 'transform.type.id.scaley', - 0.5 + 'transform.type.id.scaley', 0.5 ) app1.Execute() -app2 = otbApplication.Registry.CreateApplication( +app2 = otb.Registry.CreateApplication( 'OpticalCalibration' ) app2.ConnectImage('in', app1, 'out') app2.SetParameterString('level', 'toa') app2.Execute() -app3 = otbApplication.Registry.CreateApplication( +app3 = otb.Registry.CreateApplication( 'BinaryMorphologicalOperation' ) -app3.ConnectImage('in', app2, 'out') -app3.SetParameterString('filter', 'dilate') -app3.SetParameterString('structype', 'ball') -app3.SetParameterInt('xradius', 3) -app3.SetParameterInt('yradius', 3) -app3.SetParameterString('out', 'output.tif') +app3.ConnectImage( + 'in', app2, 'out' +) +app3.SetParameterString( + 'filter', 'dilate' +) +app3.SetParameterString( + 'structype', 'ball' +) +app3.SetParameterInt( + 'xradius', 3 +) +app3.SetParameterInt( + 'yradius', 3 +) +app3.SetParameterString( + 'out', 'output.tif' +) app3.SetParameterOutputImagePixelType( - 'out', - otbApplication.ImagePixelType_uint16 + 'out', otb.ImagePixelType_uint16 ) app3.ExecuteAndWriteOutput() ``` @@ -159,28 +179,31 @@ Consider an example where we want to perform the arithmetic operation <td> ```python -import otbApplication +import otbApplication as otb -bmx = otbApplication.Registry.CreateApplication( +bmx = otb.Registry.CreateApplication( 'BandMathX' ) bmx.SetParameterStringList( 'il', - ['image1.tif', 'image2.tif', 'image3.tif'] -) # all images are 3-bands + ['im1.tif', 'im2.tif', 'im3.tif'] +) exp = ('im1b1*im2b1-2*im3b1; ' 'im1b2*im2b2-2*im3b2; ' 'im1b3*im2b3-2*im3b3') bmx.SetParameterString('exp', exp) -bmx.SetParameterString('out', 'output.tif') +bmx.SetParameterString( + 'out', + 'output.tif' +) bmx.SetParameterOutputImagePixelType( - 'out', - otbApplication.ImagePixelType_uint8 + 'out', + otb.ImagePixelType_uint8 ) bmx.ExecuteAndWriteOutput() ``` -In OTB, this code works for 3-bands images. +Note: code limited to 3-bands images. </td> <td> @@ -188,16 +211,19 @@ In OTB, this code works for 3-bands images. ```python import pyotb -# transforming filepaths to pyotb objects -input1 = pyotb.Input('image1.tif') -input2 = pyotb.Input('image2.tif') -input3 = pyotb.Input('image3.tif') +# filepaths --> pyotb objects +in1 = pyotb.Input('im1.tif') +in2 = pyotb.Input('im2.tif') +in3 = pyotb.Input('im3.tif') -res = input1 * input2 - 2 * input2 -res.write('output.tif', pixel_type='uint8') +res = in1 * in2 - 2 * in3 +res.write( + 'output.tif', + pixel_type='uint8' +) ``` -In pyotb,this code works with images of any number of bands. +Note: works with any number of bands. </td> </tr> @@ -215,13 +241,15 @@ In pyotb,this code works with images of any number of bands. ```python -import otbApplication +import otbApplication as otb # first 3 channels -app = otbApplication.Registry.CreateApplication( +app = otb.Registry.CreateApplication( 'ExtractROI' ) -app.SetParameterString('in', 'my_image.tif') +app.SetParameterString( + 'in', 'my_image.tif' +) app.SetParameterStringList( 'cl', ['Channel1', 'Channel2', 'Channel3'] @@ -229,16 +257,30 @@ app.SetParameterStringList( app.Execute() # 1000x1000 roi -app = otbApplication.Registry.CreateApplication( +app = otb.Registry.CreateApplication( 'ExtractROI' ) -app.SetParameterString('in', 'my_image.tif') -app.SetParameterString('mode', 'extent') -app.SetParameterString('mode.extent.unit', 'pxl') -app.SetParameterFloat('mode.extent.ulx', 0) -app.SetParameterFloat('mode.extent.uly', 0) -app.SetParameterFloat('mode.extent.lrx', 999) -app.SetParameterFloat('mode.extent.lry', 999) +app.SetParameterString( + 'in', 'my_image.tif' +) +app.SetParameterString( + 'mode', 'extent' +) +app.SetParameterString( + 'mode.extent.unit', 'pxl' +) +app.SetParameterFloat( + 'mode.extent.ulx', 0 +) +app.SetParameterFloat( + 'mode.extent.uly', 0 +) +app.SetParameterFloat( + 'mode.extent.lrx', 999 +) +app.SetParameterFloat( + 'mode.extent.lry', 999 +) app.Execute() ``` @@ -248,11 +290,11 @@ app.Execute() ```python import pyotb -# transforming filepath to pyotb object +# filepath --> pyotb object inp = pyotb.Input('my_image.tif') -extracted = inp[:, :, :3] # first 3 channels -extracted = inp[:1000, :1000] # 1000x1000 roi +extracted = inp[:, :, :3] # Bands 1,2,3 +extracted = inp[:1000, :1000] # ROI ``` </td> -- GitLab From ef5a1dd024a40cc67fa0e1fe86f168f4d7649ce2 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Fri, 7 Jul 2023 10:35:12 +0200 Subject: [PATCH 17/20] DOC: title --- mkdocs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index 18cc088..5d1e8b8 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -72,8 +72,8 @@ markdown_extensions: - pymdownx.details - pymdownx.superfences -# Rest of the navigation.. -site_name: "pyotb documentation: a Python extension of OTB" +# Rest of the navigation. +site_name: "pyotb: a Python extension of OTB" repo_url: https://gitlab.orfeo-toolbox.org/nicolasnn/pyotb repo_name: pyotb docs_dir: doc/ -- GitLab From bee275a5b23c49ee847d15b58d6b81a4ce0ce96c Mon Sep 17 00:00:00 2001 From: Vincent Delbar <vincent.delbar@latelescop.fr> Date: Fri, 7 Jul 2023 08:38:56 +0000 Subject: [PATCH 18/20] Apply 1 suggestion(s) to 1 file(s) --- doc/quickstart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/quickstart.md b/doc/quickstart.md index 111f283..fb15188 100644 --- a/doc/quickstart.md +++ b/doc/quickstart.md @@ -77,7 +77,7 @@ Let's start from our previous example. Consider the case where one wants to resample the image, then apply optical calibration and binary morphological dilatation. We can write the following code to build a pipeline that will generate the output in an end-to-end fashion, without being limited with the -input image size, without writing temporary files. +input image size or writing temporary files. ```python import pyotb -- GitLab From 2c94e26a34421d55728a3241da4c56da731a5aff Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Fri, 7 Jul 2023 12:20:42 +0200 Subject: [PATCH 19/20] DOC: fix python syntax highlight --- mkdocs.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index 5d1e8b8..88589b1 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -67,13 +67,15 @@ markdown_extensions: toc_depth: 1-2 - pymdownx.highlight: anchor_linenums: true - - pymdownx.inlinehilite - - pymdownx.snippets - pymdownx.details - - pymdownx.superfences + - pymdownx.superfences: + custom_fences: + - name: python + class: python + format: !!python/name:pymdownx.superfences.fence_code_format # Rest of the navigation. -site_name: "pyotb: a Python extension of OTB" +site_name: "pyotb: Orfeo ToolBox for Python" repo_url: https://gitlab.orfeo-toolbox.org/nicolasnn/pyotb repo_name: pyotb docs_dir: doc/ -- GitLab From 199a9c196ef8be6dcc41e2c21ece9b8fc7d85e09 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Fri, 7 Jul 2023 17:35:42 +0200 Subject: [PATCH 20/20] DOC: fix summarize api doc --- pyotb/core.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyotb/core.py b/pyotb/core.py index f9c8aa6..9bcd851 100644 --- a/pyotb/core.py +++ b/pyotb/core.py @@ -1660,8 +1660,7 @@ def summarize( useful to remove extended filenames. Returns: - nested dictionary with serialized App(s) containing name and - parameters of an app and its parents + nested dictionary with serialized App(s) containing name and parameters of an app and its parents """ -- GitLab