Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions tasi/dataset/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,14 @@ def from_attributes(
boundingbox: pd.DataFrame = None,
):

assert (
dimension is None or boundingbox is None
), "either dimension or boundingbox needs to be specified"
from tasi.utils.base import resolve_dimension_and_boundingbox

if boundingbox is None or boundingbox.empty:
from tasi.calculus import boundingbox_from_dimension

boundingbox = boundingbox_from_dimension(
dimension, heading, relative_to=position
)
boundingbox = resolve_dimension_and_boundingbox(
dimension=dimension,
boundingbox=boundingbox,
heading=heading,
position=position,
)

if velocity.empty:
from tasi.calculus import calc_velocity_from_origins
Expand Down
19 changes: 7 additions & 12 deletions tasi/pose/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,16 @@ def from_attributes(
"classifications": classifications,
}

assert not (
dimension is None and boundingbox is None
), "either dimension or boundingbox needs to be specified"

if dimension is not None:
attributes["dimension"] = dimension

if (boundingbox is None or boundingbox.empty) and dimension is not None:
from tasi.calculus import boundingbox_from_dimension

boundingbox = boundingbox_from_dimension(
dimension, heading, relative_to=position
)

attributes["boundingbox"] = boundingbox
from tasi.utils.base import resolve_dimension_and_boundingbox
attributes["boundingbox"] = resolve_dimension_and_boundingbox(
dimension=dimension,
boundingbox=boundingbox,
heading=heading,
position=position,
)

if yaw_rate is not None:
attributes["yaw_rate"] = yaw_rate
Expand Down
23 changes: 23 additions & 0 deletions tasi/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,29 @@ def to_pandas_multiindex(
return pd.MultiIndex.from_arrays(np.array(names).T)


def resolve_dimension_and_boundingbox(
dimension: Optional[pd.DataFrame],
boundingbox: Optional[pd.DataFrame],
heading: Union[pd.Series, pd.DataFrame],
position: pd.DataFrame,
):
"""Resolve missing bounding box from dimensions or validate the provided box.

Either `dimension` or `boundingbox` must be provided. If `boundingbox` is missing,
it is computed from `dimension` and `heading`.
"""
if dimension is None and (boundingbox is None or boundingbox.empty):
raise ValueError("either dimension or boundingbox needs to be specified")

if boundingbox is None or boundingbox.empty:
from tasi.calculus import boundingbox_from_dimension
boundingbox = boundingbox_from_dimension(
dimension, heading, relative_to=position
)

return boundingbox


def requires_module(module_name: Union[str, List[str]], extra: Extra | str = ""):

if isinstance(module_name, str):
Expand Down