Skip to content

Commit

Permalink
terratorch.models.backbones.utils
Browse files Browse the repository at this point in the history
Signed-off-by: João Lucas de Sousa Almeida <[email protected]>
  • Loading branch information
Joao-L-S-Almeida committed Aug 9, 2024
1 parent 233a5c2 commit 6bd2bde
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions terratorch/models/backbones/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from terratorch.datasets import HLSBands

def _are_sublists_of_int(item) -> bool:

if all([isinstance(i, list) for i in item]):
if all([isinstance(i, int) for i in sum(item, [])]):
return True
else:
return False
else:
return False

def _estimate_in_chans(model_bands: list[HLSBands] | list[str] | tuple[int, int] = None) -> int:

# Conditional to deal with the different possible choices for the bands
# Bands as lists of strings or enum
if all([isinstance(b, str) for b in model_bands]):
in_chans = len(model_bands)
# Bands as intervals limited by integers
elif all([isinstance(b, int) for b in model_bands] or _are_sublists_of_int(model_bands)):

if _are_sublists_of_int(model_bands):
in_chans = sum([i[-1] - i[0] for i in model_bands])
else:
in_chans = model_bands[-1] - model_bands[0]
else:
raise Exception(f"Expected bands to be list(str) or [int, int] but received {model_bands}")

return in_chans


0 comments on commit 6bd2bde

Please sign in to comment.