diff --git a/scenes/sentinel.py b/scenes/sentinel.py index 8194aab3bb04b6e0d9f8133646d19a0cb8433165..2c1a4efbcf099a02cd372d70b5c9f7f8e9455259 100644 --- a/scenes/sentinel.py +++ b/scenes/sentinel.py @@ -165,6 +165,7 @@ rgb_nice.write("image.tif", pixel_type="uint8") from __future__ import annotations import datetime from abc import abstractmethod +from typing import Type import pyotb from scenes import utils from scenes.core import Source, Scene @@ -245,7 +246,7 @@ class Sentinel2SceneBase(Scene): """Base class for Sentinel-2 images""" @abstractmethod - def __init__(self, archive: str, tag: str): + def __init__(self, archive: str, tag: str, source_class: Type[Source]): """ Args: archive: product .zip or directory @@ -283,6 +284,9 @@ class Sentinel2SceneBase(Scene): datestr = onefile.split("_")[1] # 20180630-105440 acquisition_date = datetime.datetime.strptime(datestr, '%Y%m%d-%H%M%S-%f') + # Source class + self.source_class = source_class + # Call parent constructor super().__init__(acquisition_date=acquisition_date, bbox_wgs84=bbox_wgs84, epsg=epsg) @@ -324,7 +328,7 @@ class Sentinel2SceneBase(Scene): """ return self.get_file(endswith=f"_{suffix1}_{suffix2}.tif") - def get_10m_bands(self) -> Sentinel22ASource: + def get_10m_bands(self) -> Sentinel2Source: """ Returns 10m spacing bands @@ -336,9 +340,9 @@ class Sentinel2SceneBase(Scene): self.band3_file, self.band2_file, self.band8_file]) - return Sentinel22ASource(self, concatenate_10m_bands) + return self.source_class(self, concatenate_10m_bands) - def get_20m_bands(self) -> Sentinel22ASource: + def get_20m_bands(self) -> Sentinel2Source: """ Returns 20m spacing bands @@ -352,7 +356,7 @@ class Sentinel2SceneBase(Scene): self.band8a_file, self.band11_file, self.band12_file]) - return Sentinel22ASource(self, concatenate_20m_bands) + return self.source_class(self, concatenate_20m_bands) def get_metadata(self) -> dict[str, any]: """ @@ -393,7 +397,7 @@ class Sentinel22AScene(Sentinel2SceneBase): archive: .zip file or folder. Must be a product from MAJA. """ # Call parent constructor - super().__init__(archive=archive, tag="FRE") + super().__init__(archive=archive, tag="FRE", source_class=Sentinel22ASource) # Additional rasters self.clm_r1_msk_file = self.get_file("_CLM_R1.tif") @@ -431,7 +435,7 @@ class Sentinel23AScene(Sentinel2SceneBase): Args: archive: .zip file or folder. Must be a product from WASP. """ - super().__init__(archive=archive, tag="FRC") + super().__init__(archive=archive, tag="FRC", source_class=Sentinel23ASource) # Additional rasters self.flg_r1_msk_file = self.get_file("_FLG_R1.tif")