diff --git a/scenes/cache.py b/scenes/cache.py index aa2ada8693c591aa68831f239d4a6b2d886eaa2e..77a944796c0e9cde9c9b62d01792541925ef3df3 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 6bc70f5ca85a71b784bc11acc5230064bc72832a..8ae96d1e30ce5bce336ddd00a2438e8425276f82 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 443f39d1f68bde874f1431ee5d435c1a4d0f6754..4d4abeff18ccffa13cc1fbcd19bc2672894d12fd 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 3def11df83ed3c85d88e74ed9f9aee28e2380753..656cf1a2da3066cdb7e5fac030ecb4085191b281 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 2c93123f20c01f2ad795a8b91b7f738422e49cb4..287f4a9bde55c66b5daa4ea804e446414422307f 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 78fc0c0102ef2af0482932a808cdf8a279695dfb..af09efb2c26b2851d3b00dff9992a7ff0f08a0e9 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 1b5fa7236da47376008366fce9f4b84fc9839b69..237cf351b2190500653e509ec41c8cd37d774ac0 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 2210bcdba066e77567e3496eda7d24a8a07af37e..07fbee38ab20f380077259af37c80740bcdbbd62 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 b86ac717adfc6ed83075bfbfe12f46c37270eb8f..3824887490592179c76b672a8d10a5e1c5c492a1 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 498cf4dcb52707fe3cf216ebb1f9cef2ed07ae80..19d587519909315e8d7fddcd12012889bd73c78b 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