From 644654c58c6e7f7ee15766d54c0b98df01be86ae Mon Sep 17 00:00:00 2001 From: Narcon Nicolas <nicolas.narcon@inrae.fr> Date: Tue, 15 Mar 2022 17:16:50 +0100 Subject: [PATCH 1/3] FIX: only set OTB_TF_NSOURCES if there is a valid source in args --- pyotb/apps.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyotb/apps.py b/pyotb/apps.py index 243131e..9927c83 100644 --- a/pyotb/apps.py +++ b/pyotb/apps.py @@ -108,7 +108,8 @@ for _app in AVAILABLE_APPLICATIONS: # Retrieving the number of `source#.il` parameters params_dic = {k: v for arg in args if isinstance(arg, dict) for k, v in arg.items()} n_sources = len([k for k in params_dic if k.startswith('source') and k.endswith('.il')]) - os.environ['OTB_TF_NSOURCES'] = str(n_sources) + if n_sources > 1: + os.environ['OTB_TF_NSOURCES'] = str(n_sources) def __init__(self, *args, n_sources=None, **kwargs): """ -- GitLab From 9d3253440dced68ca7cba0cc2d85cae9c2b51b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Nar=C3=A7on?= <nicolas.narcon@gmail.com> Date: Tue, 15 Mar 2022 16:24:40 +0000 Subject: [PATCH 2/3] FIX: transform > to >= --- pyotb/apps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyotb/apps.py b/pyotb/apps.py index 9927c83..9bf6759 100644 --- a/pyotb/apps.py +++ b/pyotb/apps.py @@ -108,7 +108,7 @@ for _app in AVAILABLE_APPLICATIONS: # Retrieving the number of `source#.il` parameters params_dic = {k: v for arg in args if isinstance(arg, dict) for k, v in arg.items()} n_sources = len([k for k in params_dic if k.startswith('source') and k.endswith('.il')]) - if n_sources > 1: + if n_sources >= 1: os.environ['OTB_TF_NSOURCES'] = str(n_sources) def __init__(self, *args, n_sources=None, **kwargs): -- GitLab From 4fccbbef4d20dbea1e43434e42ecdd1b3d637300 Mon Sep 17 00:00:00 2001 From: Narcon Nicolas <nicolas.narcon@inrae.fr> Date: Tue, 15 Mar 2022 17:43:01 +0100 Subject: [PATCH 3/3] DOC: bump version + improve example doc --- README.md | 17 +++++++++-------- pyotb/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 659880c..e0126e0 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Requirements: pip install pyotb --upgrade ``` -For Python>=3.6, latest version available is pyotb 1.3.1. For Python 3.5, latest version available is pyotb 1.2.2 +For Python>=3.6, latest version available is pyotb 1.3.2. For Python 3.5, latest version available is pyotb 1.2.2 ## Quickstart: running an OTB app as a oneliner pyotb has been written so that it is more convenient to run an application in Python. @@ -293,25 +293,26 @@ between Tensorflow and OTBTF, i.e. `import tensorflow` doesn't work in a script ## Some examples ### Compute the mean of several rasters, taking into account NoData -Let's consider we have at disposal 73 NDVI rasters and their 73 binary cloud masks (where cloud is 1 and clear pixel is 0), corresponding to 73 dates of a year. +Let's consider we have at disposal 73 NDVI rasters for a year, where clouds have been masked with NoData (nodata value of -10 000 for example). -Goal: compute the temporal mean (keeping the spatial dimension) of the NDVIs, excluding cloudy pixels. Piece of code to achieve that: +Goal: compute the mean across time (keeping the spatial dimension) of the NDVIs, excluding cloudy pixels. Piece of code to achieve that: ```python import pyotb -masks = [pyotb.Input(path) for path in mask_paths] +nodata = -10000 +ndvis = [pyotb.Input(path) for path in ndvi_paths] # For each pixel location, summing all valid NDVI values -summed = sum([pyotb.where(mask != 1, ndvi, 0) for mask, ndvi in zip(masks, ndvi_paths)]) +summed = sum([pyotb.where(ndvi != nodata, ndvi, 0) for ndvi in ndvis]) # Printing the generated BandMath expression -print(summed.exp) # this returns a very long exp: (0 + ((im1b1 != 1) ? im2b1 : 0)) + ((im3b1 != 1) ? im4b1 : 0)) + ... + ((im145b1 != 1) ? im146b1 : 0))) +print(summed.exp) # this returns a very long exp: "0 + ((im1b1 != -10000) ? im1b1 : 0) + ((im2b1 != -10000) ? im2b1 : 0) + ... + ((im73b1 != -10000) ? im73b1 : 0)" # For each pixel location, getting the count of valid pixels -count = sum([pyotb.where(mask == 1, 0, 1) for mask in masks]) +count = sum([pyotb.where(ndvi == nodata, 0, 1) for ndvi in ndvis]) -mean = summed / count # BandMath exp of this is very long: (0 + ((im1b1 != 1) ? im2b1 : 0)) + ... + ((im145b1 != 1) ? im146b1 : 0))) / (0 + ((im1b1 == 1) ? 0 : 1)) + ((im3b1 == 1) ? 0 : 1)) + ... + ((im145b1 == 1) ? 0 : 1))) +mean = summed / count # BandMath exp of this is very long: "(0 + ((im1b1 != -10000) ? im1b1 : 0) + ... + ((im73b1 != -10000) ? im73b1 : 0)) / (0 + ((im1b1 == -10000) ? 0 : 1) + ... + ((im73b1 == -10000) ? 0 : 1))" mean.write('ndvi_annual_mean.tif') ``` diff --git a/pyotb/__init__.py b/pyotb/__init__.py index 8ae8d7d..6dd93f6 100644 --- a/pyotb/__init__.py +++ b/pyotb/__init__.py @@ -2,7 +2,7 @@ """ This module provides convenient python wrapping of otbApplications """ -__version__ = "1.3" +__version__ = "1.3.2" from .apps import * from .core import App, Output, Input, get_nbchannels, get_pixel_type diff --git a/setup.py b/setup.py index 81f3366..5cdf0d6 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("README.md", "r", encoding="utf-8") as fh: setuptools.setup( name="pyotb", - version="1.3.1", + version="1.3.2", author="Nicolas Narçon", author_email="nicolas.narcon@gmail.com", description="Library to enable easy use of the Orfeo Tool Box (OTB) in Python", -- GitLab