Skip to content

Commit

Permalink
Support for custom delimiter in region sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
lukacu committed Apr 17, 2024
1 parent 244e2dd commit 84a9b4b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
12 changes: 7 additions & 5 deletions vot/region/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions vot/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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(",")]

Expand Down
1 change: 1 addition & 0 deletions vot/report/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 84a9b4b

Please sign in to comment.