From 84a9b4b577b72075d40b5eaddde4ad00f4de1c11 Mon Sep 17 00:00:00 2001 From: Luka Cehovin Zajc Date: Wed, 17 Apr 2024 12:11:46 +0200 Subject: [PATCH] Support for custom delimiter in region sequences --- vot/region/io.py | 12 +++++++----- vot/report/__init__.py | 10 +++++----- vot/report/common.py | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/vot/region/io.py b/vot/region/io.py index 5847da8..b381a63 100644 --- a/vot/region/io.py +++ b/vot/region/io.py @@ -139,11 +139,12 @@ def encode_mask(mask): return (tl_x, tl_y, region_w, region_h), rle -def parse_region(string: str) -> "Region": +def parse_region(string: str, separator: str = ",") -> "Region": """Parse input string to the appropriate region format and return Region object Args: string (str): comma separated list of values + separator (str): separator of values in the input string Returns: Region: resulting region @@ -154,11 +155,11 @@ def parse_region(string: str) -> "Region": if string[0] == 'm': # input is a mask - decode it - m_, offset_ = create_mask_from_string(string[1:].split(',')) + m_, offset_ = create_mask_from_string(string[1:].split(separator)) return Mask(m_, offset=offset_, optimize=config.mask_optimize_read) else: # input is not a mask - check if special, rectangle or polygon - tokens = [float(t) for t in string.split(',')] + tokens = [float(t) for t in string.split(separator)] if len(tokens) == 1: return Special(tokens[0]) if len(tokens) == 4: @@ -244,11 +245,12 @@ def write_trajectory_binary(fp: io.RawIOBase, data: List["Region"]): else: raise IOError("Wrong region type") -def read_trajectory(fp: Union[str, TextIO]): +def read_trajectory(fp: Union[str, TextIO], separator: str = ","): """Reads a trajectory from a file and returns a list of regions. Args: fp (str or TextIO): File path or file pointer to the trajectory file + separator (str): Separator of values in the region, only used for text files Returns: list: List of regions @@ -274,7 +276,7 @@ def read_trajectory(fp: Union[str, TextIO]): else: regions = [] for line in fp.readlines(): - regions.append(parse_region(line.strip())) + regions.append(parse_region(line.strip(), separator)) if close: fp.close() diff --git a/vot/report/__init__.py b/vot/report/__init__.py index 74c8731..372ef8b 100644 --- a/vot/report/__init__.py +++ b/vot/report/__init__.py @@ -441,7 +441,7 @@ def __getitem__(self, key) -> PlotStyle: return self.plot_style(key) def legend(self, key) -> Legend: - """ Gets the legend for the given key.""" + """ Gets the legend for a given key.""" if inspect.isclass(key): klass = key else: @@ -453,15 +453,15 @@ def legend(self, key) -> Legend: return self._legends[klass] def plot_style(self, key) -> PlotStyle: - """ Gets the plot style for the given key.""" + """ Gets the plot style for a given key.""" return self.legend(key)[key] def make_axes(self, figure, rect=None, trait=None) -> Axes: - """ Makes the axes for the given figure.""" + """ Makes the axes for a given figure.""" return self.axes(figure, rect, trait) def make_figure(self, trait=None) -> typing.Tuple[Figure, Axes]: - """ Makes the figure for the given trait. + """ Makes the figure for a given trait. Args: trait (str): The trait for which to make the figure. @@ -713,7 +713,7 @@ def merge_tree(src, dest): sequences = workspace.dataset if not select_experiments is None: - experiments = [experiment for name, experiment in workspace.stack.items() if name in select_experiments.split(",")] + experiments = [experiment for name, experiment in workspace.stack.experiments.items() if name in select_experiments.split(",")] if not select_sequences is None: sequences = [sequence for sequence in sequences if sequence.name in select_sequences.split(",")] diff --git a/vot/report/common.py b/vot/report/common.py index 990fdfa..3d9123a 100644 --- a/vot/report/common.py +++ b/vot/report/common.py @@ -55,6 +55,7 @@ def safe(value, default): for tracker, values in zip(trackers, aresults): if not tracker in table_data: table_data[tracker] = list() + for i, description in enumerate(descriptions): if description is None: continue