From 036c6899ca1d28f8fe554832ca3814e4e6a975a8 Mon Sep 17 00:00:00 2001 From: Remi Agier Date: Thu, 17 Nov 2022 13:32:35 +0100 Subject: [PATCH] Autodetermine Temporal position when calling .temporal() --- aloscene/tensors/spatial_augmented_tensor.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/aloscene/tensors/spatial_augmented_tensor.py b/aloscene/tensors/spatial_augmented_tensor.py index e9969c72..b85b36d8 100644 --- a/aloscene/tensors/spatial_augmented_tensor.py +++ b/aloscene/tensors/spatial_augmented_tensor.py @@ -206,13 +206,14 @@ def relative_to_absolute(self, x, dim, assert_integer=False): assert x.is_integer(), f"relative coordinates {x} have produced non-integer absolute coordinates" return round(x) - def temporal(self, dim=0): + def temporal(self, dim=None): """Add a temporal dimension on the tensor Parameters ---------- - dim : int - The dim on which to add the temporal dimension. Can be 0 or 1 + dim : int or None + The dim on which to add the temporal dimension. Can be 0 or 1 or None. + None automatically determine position of T dim in respect of convention. Returns ------- @@ -222,6 +223,16 @@ def temporal(self, dim=0): if "T" in self.names: # Already a temporal frame return self + if dim is None: + if self.names[0] == "B": + dim = 1 + elif "B" in self.names: + raise Exception( + "Cannot autodetermine temporal dimension position : tensor doesn't follow convention (B, T, ...) )" + ) + else: + dim = 0 + def set_n_names(names): pass