From 4ec8494c62fa0377b48c52b01ffb5e649aacefcb Mon Sep 17 00:00:00 2001
From: Remi Cresson <remi.cresson@inrae.fr>
Date: Wed, 22 Mar 2023 20:23:59 +0100
Subject: [PATCH] REFAC: STAC, theia-picker, pyotb

---
 scenes/cache.py      |  3 ++-
 scenes/core.py       | 14 +++++++++-----
 scenes/dates.py      |  8 ++++----
 scenes/deepnets.py   |  8 +++++---
 scenes/indexation.py |  8 ++++++--
 scenes/raster.py     |  4 +++-
 scenes/sentinel.py   | 17 ++++++++++-------
 scenes/spatial.py    |  6 +++---
 scenes/spot.py       | 19 +++++++++++--------
 scenes/utils.py      |  3 ++-
 10 files changed, 55 insertions(+), 35 deletions(-)

diff --git a/scenes/cache.py b/scenes/cache.py
index aa2ada8..77a9447 100644
--- a/scenes/cache.py
+++ b/scenes/cache.py
@@ -1,5 +1,6 @@
 """
-This module provides mechanisms to enable pyotb raster caching on the local filesystem.
+This module provides mechanisms to enable pyotb raster caching on the local
+filesystem.
 """
 from __future__ import annotations
 import hashlib
diff --git a/scenes/core.py b/scenes/core.py
index 6bc70f5..8ae96d1 100644
--- a/scenes/core.py
+++ b/scenes/core.py
@@ -141,7 +141,7 @@ class Source(pyotb.Output):
         assert parent is not self, "You cannot assign a new source to its " \
                                    "parent instance"
         self.parent = parent  # parent source (is another Source instance)
-        self._app_stack = []  # list of otb applications or output to keep trace
+        self._app_stack = []  # list of otb applications or output to keep
 
     def new_source(self, *args, **kwargs) -> Source:
         """
@@ -166,7 +166,8 @@ class Source(pyotb.Output):
         """
         This function is called when an attribute or a method has been called,
         but not found in the object properties.
-        We override it to avoid falling back into the depths of pyotb.otbObject.
+        We override it to avoid falling back into the depths of
+        `pyotb.otbObject`.
 
         Args:
             name: name of the attribute or method to access
@@ -288,7 +289,8 @@ class CommonImagerySource(Source):
             ref_img: Union[str, pyotb.core.otbObject]
     ) -> CommonImagerySource:
         """
-        Return the source clipped over the ROI specified by the input image extent
+        Return the source clipped over the ROI specified by the input image
+        extent.
 
         Args:
             ref_img: reference image
@@ -309,7 +311,8 @@ class CommonImagerySource(Source):
             ref_vec: str
     ) -> CommonImagerySource:
         """
-        Return the source clipped over the ROI specified by the input vector extent
+        Return the source clipped over the ROI specified by the input vector
+        extent.
 
         Args:
             ref_vec: reference vector data
@@ -412,7 +415,8 @@ class Scene(ABC):
         self.acquisition_date = acquisition_date
         assert isinstance(epsg, int), "epsg must be an int"
         self.epsg = epsg
-        assert len(extent_wgs84) >= 4, "extent must have at least 4 coordinates"
+        assert len(extent_wgs84) >= 4, "extent must have at least 4 " \
+                                       "coordinates"
         self.extent_wgs84 = extent_wgs84
         self.bbox_wgs84 = coord_list_to_bbox(extent_wgs84)
         assert isinstance(assets_paths, dict)
diff --git a/scenes/dates.py b/scenes/dates.py
index 443f39d..4d4abef 100644
--- a/scenes/dates.py
+++ b/scenes/dates.py
@@ -44,18 +44,18 @@ MINDATE = datetime.strptime("1000-01-01", "%Y-%m-%d")
 MAXDATE = datetime.strptime("3000-01-01", "%Y-%m-%d")
 
 
-def get_timestamp(dt: datetime) -> int:
+def get_timestamp(date: datetime) -> int:
     """
-    Converts datetime.datetime into a timestamp (in seconds)
+    Converts `datetime` into a timestamp (in seconds)
 
     Args:
-        dt: datetime.datetime instance
+        date: date
 
     Returns:
         timestamp (in seconds)
 
     """
-    return dt.replace(tzinfo=timezone.utc).timestamp()
+    return date.replace(tzinfo=timezone.utc).timestamp()
 
 
 def str2datetime(datestr: str) -> datetime:
diff --git a/scenes/deepnets.py b/scenes/deepnets.py
index 3def11d..656cf1a 100644
--- a/scenes/deepnets.py
+++ b/scenes/deepnets.py
@@ -9,9 +9,11 @@ OTBTF is needed to use this module.
 ## Super-resolution
 
 The SR4RS model can be applied over any `scenes.core.Source` instance.
-We recall that this model is intended to be used over Sentinel-2 optical images.
-For example, here is how we perform the super-resolution of a Theia S2 product.
-``` py
+We recall that this model is intended to be used over Sentinel-2 optical
+images. For example, here is how we perform the super-resolution of a Theia S2
+product:
+
+```python
 import scenes
 archive = "SENTINEL2B_..._T31TEJ_D_V1-8.zip"
 s2_scene = scenes.sentinel.Sentinel22AScene(archive)
diff --git a/scenes/indexation.py b/scenes/indexation.py
index 2c93123..287f4a9 100644
--- a/scenes/indexation.py
+++ b/scenes/indexation.py
@@ -77,8 +77,12 @@ def _bbox(
 
     """
     return (
-        bbox_wgs84.xmin, bbox_wgs84.ymin, get_timestamp(any2datetime(date_min)),
-        bbox_wgs84.xmax, bbox_wgs84.ymax, get_timestamp(any2datetime(date_max))
+        bbox_wgs84.xmin,
+        bbox_wgs84.ymin,
+        get_timestamp(any2datetime(date_min)),
+        bbox_wgs84.xmax,
+        bbox_wgs84.ymax,
+        get_timestamp(any2datetime(date_max))
     )
 
 
diff --git a/scenes/raster.py b/scenes/raster.py
index 78fc0c0..af09efb 100644
--- a/scenes/raster.py
+++ b/scenes/raster.py
@@ -60,7 +60,9 @@ def get_extent(
     return tuple([(xmin, ymax), (xmax, ymax), (xmax, ymin), (xmin, ymin)])
 
 
-def get_projection(raster: Union[gdal.Dataset, str, pyotb.core.otbObject]) -> str:
+def get_projection(
+        raster: Union[gdal.Dataset, str, pyotb.core.otbObject]
+) -> str:
     """
     Returns the projection (as str) of a raster.
 
diff --git a/scenes/sentinel.py b/scenes/sentinel.py
index 1b5fa72..237cf35 100644
--- a/scenes/sentinel.py
+++ b/scenes/sentinel.py
@@ -74,9 +74,9 @@ bands_10m_2a = sc_2a.get_10m_bands(["b4", "b8"])
 
 # Theia
 
-The `Sentinel22AScene` and `Sentinel23AScene` classes carry metadata and sources
-respectively for Sentinel-2 Level 2A and Level 3A products. They both inherit
-from the generic abstract `Sentinel2TheiaScene` class.
+The `Sentinel22AScene` and `Sentinel23AScene` classes carry metadata and
+sources respectively for Sentinel-2 Level 2A and Level 3A products. They both
+inherit from the generic abstract `Sentinel2TheiaScene` class.
 
 ## Instantiation
 
@@ -167,7 +167,8 @@ Note that the resulting transformed `Sentinel2Theia2ASource` and
 ## Usage with pyotb
 
 As `scenes.core.Source`, it also can be used like any `pyotb.core.otbObject`.
-The following example show how to use an OTB application with a source at input.
+The following example show how to use an OTB application with a source at
+input.
 
 ```python
 rgb_nice = pyotb.DynamicConvert(reprojected)
@@ -329,7 +330,7 @@ class Sentinel2SceneBase(Scene):
             for key, src_class in src_classes.items()
         }
 
-        # Sources for concatenated spectral bands: get_b10m_bands, get_20m_bands
+        # Sources for concatenated bands: get_b10m_bands, get_20m_bands
         for key, default_bands_names in self.concatenated_bands_dict.items():
             sources.update({
                 key: partial(
@@ -526,7 +527,7 @@ class Sentinel23AScene(Sentinel2TheiaScene):
 
 def get_scene(archive: str) -> Union[Sentinel22AScene, Sentinel23AScene]:
     """
-    Return the right sentinel scene instance from the given archive (L2A or L3A)
+    Return the right `Scene` instance from the given archive (L2A or L3A)
 
     Args:
         archive: L3A or L3A archive
@@ -606,7 +607,9 @@ class Sentinel2MPCScene(Sentinel2SceneBase):
         }
 
         # Sources classes
-        src_classes = {key: CommonImagerySource for key in updated_assets_paths}
+        src_classes = {
+            key: CommonImagerySource for key in updated_assets_paths
+        }
 
         # Date, extent
         b2_path = updated_assets_paths["b2"]
diff --git a/scenes/spatial.py b/scenes/spatial.py
index 2210bcd..07fbee3 100644
--- a/scenes/spatial.py
+++ b/scenes/spatial.py
@@ -1,6 +1,6 @@
 """
-This module provides classes and functions to help with light geospatial objects
-(projections, bounding boxes, etc).
+This module provides classes and functions to help with light geospatial
+objects (projections, bounding boxes, etc).
 """
 from __future__ import annotations
 from typing import List, Tuple
@@ -75,7 +75,7 @@ class BoundingBox:
 
     def to_list(self) -> List[float]:
         """
-        Converts the bbox into a list of coordinates, the same way rasterio does.
+        Converts the bbox into a list of coordinates, like rasterio does.
 
         Returns:
             [xmin, ymin, xmax, ymax]
diff --git a/scenes/spot.py b/scenes/spot.py
index b86ac71..3824887 100644
--- a/scenes/spot.py
+++ b/scenes/spot.py
@@ -33,7 +33,8 @@ classDiagram
 
 # Spot67Scene
 
-The `Spot67Scene` class carries metadata and image sources for Spot-6/7 sensors.
+The `Spot67Scene` class carries metadata and image sources for Spot-6/7
+sensors.
 
 ``` mermaid
 classDiagram
@@ -148,7 +149,8 @@ Note that the resulting transformed `Spot67DRSSource` is still an instance of
 # Usage with pyotb
 
 As `scenes.core.Source`, it also can be used like any `pyotb.core.otbObject`.
-The following example show how to use an OTB application with a source at input.
+The following example show how to use an OTB application with a source at
+input.
 
 ```python
 rgb_nice = pyotb.DynamicConvert(reprojected)
@@ -251,7 +253,9 @@ class Spot67DRSSource(CommonImagerySource):
     Source capabilities for Spot-6/7 ADS-DRS products
     """
 
-    def cld_msk_drilled(self, nodata: Union[float, int] = 0) -> Spot67DRSSource:
+    def cld_msk_drilled(
+            self, nodata: Union[float, int] = 0
+    ) -> Spot67DRSSource:
         """
         Return the source drilled from the cloud mask
 
@@ -369,9 +373,8 @@ class Spot67Scene(Scene):
         msg += f"\n\tXS: {extent_wgs84_xs} \n\tPAN: {extent_wgs84_pan}"
         if pxs_overlap == 0:
             raise ValueError(msg)
-        if max(pan_overlap,
-               xs_overlap) < self.PXS_OVERLAP_THRESH:  # meaning partial overlap
-            raise Warning(msg)
+        if max(pan_overlap, xs_overlap) < self.PXS_OVERLAP_THRESH:
+            raise Warning(msg)  # partial overlap
 
         # Final extent
         extent = extent_wgs84_pan if pan_overlap > xs_overlap else \
@@ -383,8 +386,8 @@ class Spot67Scene(Scene):
             "pxs": partial(self._get_pxs, src_class=src_class)
         }
 
-        additional_md = additional_metadata.copy() if additional_metadata else \
-            {}
+        additional_md = additional_metadata.copy() if additional_metadata \
+            else {}
         additional_md.update({
             "xs_extent_wgs84": extent_wgs84_xs,
             "pan_extent_wgs84": extent_wgs84_pan,
diff --git a/scenes/utils.py b/scenes/utils.py
index 498cf4d..19d5875 100644
--- a/scenes/utils.py
+++ b/scenes/utils.py
@@ -78,7 +78,8 @@ def list_files_in_zip(filename: str, endswith: str = None) -> List[str]:
 
     Args:
         filename: path of the zip
-        endswith: optional, end of filename to be matched (Default value = None)
+        endswith: optional, end of filename to be matched (Default value is
+         None)
 
     Returns:
         list of filepaths
-- 
GitLab