diff --git a/CI/SCRIPTS_WEEKLY/test_all_sat_end_to_end_on_disk.py b/CI/SCRIPTS_WEEKLY/test_all_sat_end_to_end_on_disk.py index 8bb8b234..13ac9634 100644 --- a/CI/SCRIPTS_WEEKLY/test_all_sat_end_to_end_on_disk.py +++ b/CI/SCRIPTS_WEEKLY/test_all_sat_end_to_end_on_disk.py @@ -7,7 +7,7 @@ import xarray as xr from lxml import etree -from sertit import AnyPath, ci, path +from sertit import AnyPath, ci, path, types from CI.scripts_utils import ( CI_EOREADER_S3, @@ -166,8 +166,7 @@ def _test_core( with xr.set_options(warn_for_unclosed_files=debug): # DATA paths - if not isinstance(prod_dirs, list): - prod_dirs = [prod_dirs] + prod_dirs = types.make_interable(prod_dirs) pattern_paths = [] for prod_dir in prod_dirs: diff --git a/eoreader/bands/__init__.py b/eoreader/bands/__init__.py index 14b01fc0..33ac3c62 100644 --- a/eoreader/bands/__init__.py +++ b/eoreader/bands/__init__.py @@ -460,8 +460,8 @@ def convert_to_band(tc) -> BandNames: if as_list: band_list = [] - if not types.is_iterable(to_convert): - to_convert = [to_convert] + to_convert = types.make_interable(to_convert) + for tc in to_convert: tc_band = convert_to_band(tc=tc) band_list.append(tc_band) @@ -492,8 +492,7 @@ def to_str( list: str bands """ if as_list: - if not types.is_iterable(to_convert): - to_convert = [to_convert] + to_convert = types.make_interable(to_convert) bands_str = [] for tc in to_convert: diff --git a/eoreader/bands/band_names.py b/eoreader/bands/band_names.py index 9dbc0fd4..61d8fbc8 100644 --- a/eoreader/bands/band_names.py +++ b/eoreader/bands/band_names.py @@ -25,8 +25,8 @@ def from_list(cls, name_list: Union[list, str]) -> list: Returns: list: List of enums """ - if not types.is_iterable(name_list): - name_list = [name_list] + name_list = types.make_interable(name_list) + try: band_names = [cls(name) for name in name_list] except ValueError as ex: diff --git a/eoreader/products/custom_product.py b/eoreader/products/custom_product.py index 99d3d946..41ac11f8 100644 --- a/eoreader/products/custom_product.py +++ b/eoreader/products/custom_product.py @@ -423,8 +423,7 @@ def _load_bands( return {} # Get band paths - if not types.is_iterable(bands): - bands = [bands] + bands = types.make_interable(bands) if pixel_size is None and size is not None: pixel_size = self._pixel_size_from_img_size(size) diff --git a/eoreader/products/optical/hls_product.py b/eoreader/products/optical/hls_product.py index 5bba779d..a055bb27 100644 --- a/eoreader/products/optical/hls_product.py +++ b/eoreader/products/optical/hls_product.py @@ -873,8 +873,7 @@ def _load_bands( return {} # Get band paths - if not types.is_iterable(bands): - bands = [bands] + bands = types.make_interable(bands) if pixel_size is None and size is not None: pixel_size = self._pixel_size_from_img_size(size) diff --git a/eoreader/products/optical/landsat_product.py b/eoreader/products/optical/landsat_product.py index 18416bb2..6cd00af6 100644 --- a/eoreader/products/optical/landsat_product.py +++ b/eoreader/products/optical/landsat_product.py @@ -1430,8 +1430,7 @@ def _load_bands( return {} # Get band paths - if not types.is_iterable(bands): - bands = [bands] + bands = types.make_interable(bands) if pixel_size is None and size is not None: pixel_size = self._pixel_size_from_img_size(size) diff --git a/eoreader/products/optical/planet_product.py b/eoreader/products/optical/planet_product.py index f2b73693..18d5fcca 100644 --- a/eoreader/products/optical/planet_product.py +++ b/eoreader/products/optical/planet_product.py @@ -1004,8 +1004,8 @@ def _get_path( Union[list, str]: Paths(s) """ - if invalid_lookahead is not None and not types.is_iterable(invalid_lookahead): - invalid_lookahead = [invalid_lookahead] + if invalid_lookahead is not None: + invalid_lookahead = types.make_interable(invalid_lookahead) ok_paths = [] try: diff --git a/eoreader/products/optical/s2_e84_product.py b/eoreader/products/optical/s2_e84_product.py index d9fc8e4f..71f0a968 100644 --- a/eoreader/products/optical/s2_e84_product.py +++ b/eoreader/products/optical/s2_e84_product.py @@ -310,8 +310,7 @@ def _load_bands( return {} # Get band paths - if not types.is_iterable(bands): - bands = [bands] + bands = types.make_interable(bands) if pixel_size is None and size is not None: pixel_size = self._pixel_size_from_img_size(size) diff --git a/eoreader/products/optical/s2_theia_product.py b/eoreader/products/optical/s2_theia_product.py index c09d6066..ad8c3d13 100644 --- a/eoreader/products/optical/s2_theia_product.py +++ b/eoreader/products/optical/s2_theia_product.py @@ -820,8 +820,7 @@ def _create_mask( xr.DataArray: Mask masked array """ - if not types.is_iterable(bit_ids): - bit_ids = [bit_ids] + bit_ids = types.make_interable(bit_ids) conds = rasters.read_bit_array(bit_array.astype(np.uint8), bit_ids) cond = reduce(lambda x, y: x | y, conds) # Use every condition (bitwise or) diff --git a/eoreader/products/optical/s3_product.py b/eoreader/products/optical/s3_product.py index 264bd3aa..ea7d8897 100644 --- a/eoreader/products/optical/s3_product.py +++ b/eoreader/products/optical/s3_product.py @@ -555,8 +555,7 @@ def _load_bands( return {} # Get band paths - if not types.is_iterable(bands): - bands = [bands] + bands = types.make_interable(bands) if pixel_size is None and size is not None: pixel_size = self._pixel_size_from_img_size(size) diff --git a/eoreader/products/optical/s3_slstr_product.py b/eoreader/products/optical/s3_slstr_product.py index 90504542..cd68dab6 100644 --- a/eoreader/products/optical/s3_slstr_product.py +++ b/eoreader/products/optical/s3_slstr_product.py @@ -1098,8 +1098,7 @@ def _create_mask( xr.DataArray: Mask masked array """ - if not types.is_iterable(bit_ids): - bit_ids = [bit_ids] + bit_ids = types.make_interable(bit_ids) conds = rasters.read_bit_array(bit_array, bit_ids) cond = reduce(lambda x, y: x | y, conds) # Use every condition (bitwise or) diff --git a/eoreader/products/product.py b/eoreader/products/product.py index 02ec8b9a..f7884f05 100644 --- a/eoreader/products/product.py +++ b/eoreader/products/product.py @@ -1239,9 +1239,7 @@ def has_bands(self, bands: Union[list, BandNames, str]) -> bool: Returns: bool: True if the products has the specified band """ - if not types.is_iterable(bands): - bands = [bands] - + bands = types.make_interable(bands) return all([self.has_band(band) for band in set(bands)]) @abstractmethod @@ -1715,8 +1713,7 @@ def _update_attrs( # Are we sure of that ? xarr.attrs = {} - if not types.is_iterable(bands): - bands = [bands] + bands = types.make_interable(bands) long_name = to_str(bands) xr_name = "_".join(long_name) attr_name = " ".join(long_name) @@ -2032,8 +2029,7 @@ def to_band(self, raw_bands: Union[list, BandNames, str, int]) -> list: Returns: list: Mapped bands """ - if not types.is_iterable(raw_bands): - raw_bands = [raw_bands] + raw_bands = types.make_interable(raw_bands) bands = [] for raw_band in raw_bands: diff --git a/eoreader/products/sar/sar_product.py b/eoreader/products/sar/sar_product.py index 0cc1a0cd..0b7e6ece 100644 --- a/eoreader/products/sar/sar_product.py +++ b/eoreader/products/sar/sar_product.py @@ -633,8 +633,7 @@ def _load_bands( return {} # Get band paths - if not types.is_iterable(bands): - bands = [bands] + bands = types.make_interable(bands) if pixel_size is None and size is not None: pixel_size = self._pixel_size_from_img_size(size)