From 77df8bbfcbc19c3bdf1f3a59baaf64b4029a2931 Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Mon, 1 Jul 2024 12:30:26 -0700 Subject: [PATCH] up threshold and add opts --- holonote/annotate/display.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/holonote/annotate/display.py b/holonote/annotate/display.py index bd5761f..fe4fe4d 100644 --- a/holonote/annotate/display.py +++ b/holonote/annotate/display.py @@ -88,12 +88,14 @@ class Style(param.Parameterized): line_opts = _StyleOpts(default={}) span_opts = _StyleOpts(default={}) rectangle_opts = _StyleOpts(default={}) + points_opts = _StyleOpts(default={}) # Editor opts edit_opts = _StyleOpts(default={"line_color": "black"}) edit_line_opts = _StyleOpts(default={}) edit_span_opts = _StyleOpts(default={}) edit_rectangle_opts = _StyleOpts(default={}) + edit_points_opts = _StyleOpts(default={}) _groupby = () _colormap = None @@ -133,6 +135,7 @@ def indicator(self, **select_opts) -> tuple[hv.Options, ...]: hv.opts.HSpans(**opts, **self.span_opts), hv.opts.VLines(**opts, **self.line_opts), hv.opts.HLines(**opts, **self.line_opts), + hv.opts.Points(**opts, **self.points_opts), ) def editor(self) -> tuple[hv.Options, ...]: @@ -148,6 +151,7 @@ def editor(self) -> tuple[hv.Options, ...]: hv.opts.HSpan(**opts, **self.edit_span_opts), hv.opts.VLine(**opts, **self.edit_line_opts), hv.opts.HLine(**opts, **self.edit_line_opts), + hv.opts.Points(**opts, **self.edit_points_opts), ) def reset(self) -> None: @@ -235,7 +239,7 @@ class AnnotationDisplay(param.Parameterized): data = param.DataFrame(doc="Combined dataframe of annotation data", constant=True) _nearest_2d_point_threshold = param.Number( - default=0.1, + default=1, bounds=(0, None), doc=""" Threshold In the distance in data coordinates between the two dimensions; @@ -438,12 +442,12 @@ def get_indices_by_position(self, **inputs) -> list[Any]: out = list(df[subset].index) elif self.region_format == "point-point": xk, yk = list(inputs.keys()) - distance = (df[f"point[{xk}]"] - inputs[xk]) ** 2 + ( - df[f"point[{yk}]"] - inputs[yk] - ) ** 2 - if (distance > self._nearest_2d_point_threshold**2).all(): + xdist = (df[f"point[{xk}]"] - inputs[xk]) ** 2 + ydist = (df[f"point[{yk}]"] - inputs[yk]) ** 2 + distance_squared = xdist + ydist + if (distance_squared > self._nearest_2d_point_threshold**2).all(): return [] - out = [df.loc[distance.idxmin()].name] # index == name of series + out = [df.loc[distance_squared.idxmin()].name] # index == name of series elif "point" in self.region_format: iter_mask = ((df[f"point[{k}]"] - v).abs().argmin() for k, v in inputs.items()) out = list(df[reduce(np.logical_and, iter_mask)].index)