Skip to content

Commit

Permalink
Merge branch 'develop' into GEOPY-1257
Browse files Browse the repository at this point in the history
  • Loading branch information
benk-mira committed Dec 13, 2023
2 parents 74b5a19 + 8546e10 commit aed3328
Showing 1 changed file with 43 additions and 20 deletions.
63 changes: 43 additions & 20 deletions peak_finder/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def __init__(
Input(component_id="line_figure", component_property="clickData"),
Input(component_id="full_lines_figure", component_property="clickData"),
Input(component_id="line_id", component_property="value"),
Input(component_id="update_computation", component_property="data"),
)(self.update_click_data)
self.app.callback(
Output(component_id="line_figure", component_property="figure"),
Expand Down Expand Up @@ -698,7 +699,7 @@ def compute_line( # pylint: disable=too-many-arguments, too-many-locals
results = compute(line_computation)

# Remove un-needed lines
if self.lines is None or "n_groups" in triggers:
if self.lines is None or "line_ids" not in triggers:
self.lines = {}
else:
entries_to_remove = [line for line in self.lines if line not in line_ids]
Expand Down Expand Up @@ -1096,7 +1097,6 @@ def update_markers( # noqa: C901 # pylint: disable=too-many-arguments, too-man
},
},
}

n_parts = len(self.lines[line_id]["position"])
for ind in range(n_parts): # pylint: disable=R1702
position = self.lines[line_id]["position"][ind]
Expand Down Expand Up @@ -1317,12 +1317,18 @@ def update_residuals( # pylint: disable=too-many-arguments, too-many-locals
or self.figure is None
):
return no_update
if not show_residuals:
self.figure.data[trace_map["pos_residuals_legend"]]["visible"] = False
self.figure.data[trace_map["neg_residuals_legend"]]["visible"] = False

triggers = [t["prop_id"].split(".")[0] for t in callback_context.triggered]
if "update_computation" in triggers or (
"show_residuals" in triggers and not show_residuals
):
for ind in range(len(trace_map), len(self.figure.data)):
self.figure.data[ind]["x"] = []
self.figure.data[ind]["y"] = []

if not show_residuals:
self.figure.data[trace_map["pos_residuals_legend"]]["visible"] = False
self.figure.data[trace_map["neg_residuals_legend"]]["visible"] = False
return update_residuals + 1

self.figure.data[trace_map["pos_residuals_legend"]]["visible"] = True
Expand Down Expand Up @@ -1376,6 +1382,7 @@ def update_click_data(
line_click_data: dict | None,
full_lines_click_data: dict | None,
line_id: int,
update_computation: int,
) -> int:
"""
Update the markers on the single line figure from clicking on either figure.
Expand All @@ -1384,24 +1391,32 @@ def update_click_data(
:param line_click_data: Click data from the single line figure.
:param full_lines_click_data: Click data from the full lines figure.
:param line_id: Line ID.
:param update_computation: Trigger for recomputation of line.
:return: Trigger for updating the click data.
"""
if self.figure is None:
if (
self.figure is None
or self.figure.layout.shapes is None
or self.lines is None
):
return no_update

if len(self.figure.layout.shapes) == 0:
self.figure.add_vline(x=0)

triggers = [t["prop_id"].split(".")[0] for t in callback_context.triggered]
if line_click_data is not None and "line_figure" in triggers:
x_val = line_click_data["points"][0]["x"]
self.figure.update_shapes({"x0": x_val, "x1": x_val})

if (
full_lines_click_data is not None
and "full_lines_figure" in triggers
and self.lines is not None
"update_computation" in triggers
and "line_id" in triggers
and line_id in self.lines
):
self.figure.update_shapes({"x0": 0, "x1": 0})
elif line_click_data is not None and "line_figure" in triggers:
x_val = line_click_data["points"][0]["x"]
self.figure.update_shapes({"x0": x_val, "x1": x_val})
elif full_lines_click_data is not None and "full_lines_figure" in triggers:
x_min = np.min(
np.concatenate(
tuple(pos.x_locations for pos in self.lines[line_id]["position"])
Expand Down Expand Up @@ -1642,6 +1657,8 @@ def initialize_figure(
for ind, (key, trace) in enumerate(all_traces.items()):
self.figure.add_trace(go.Scatter(**trace))
trace_map[key] = ind

self.figure.add_vline(x=None)
return trace_map

def update_full_lines_figure( # pylint: disable=too-many-arguments, too-many-locals, too-many-branches
Expand Down Expand Up @@ -1719,11 +1736,11 @@ def update_full_lines_figure( # pylint: disable=too-many-arguments, too-many-lo

marker_x = None
marker_y = None

line_dict = {}
for line in self.lines: # type: ignore # pylint: disable=C0206
line_position = self.lines[line]["position"]
line_anomalies = self.lines[line]["anomalies"]

label = line_ids_labels[int(line)] # type: ignore
n_parts = len(line_position)

Expand All @@ -1739,20 +1756,26 @@ def update_full_lines_figure( # pylint: disable=too-many-arguments, too-many-lo
position = line_position[ind]
anomalies = line_anomalies[ind]

if position is not None:
if position is not None and position.locations_resampled is not None:
x_locs = position.x_locations
y_locs = position.y_locations
if line == line_id:
marker_x = position.x_locations[0]
marker_y = position.y_locations[0]
line_dict[line]["x"] += list(position.x_locations) # type: ignore
line_dict[line]["y"] += list(position.y_locations) # type: ignore
marker_x = x_locs[0]
marker_y = y_locs[0]
line_dict[line]["x"] += list(x_locs) # type: ignore
line_dict[line]["y"] += list(y_locs) # type: ignore

x_min = np.min(position.x_locations)
if anomalies is not None:
for anom in anomalies:
peak = position.locations[anom.peaks[0]]
x_val = x_min + peak
ind = (np.abs(x_locs - x_val)).argmin()
anomaly_traces[anom.property_group.name]["x"].append(
anom.group_center[0]
x_locs[ind]
)
anomaly_traces[anom.property_group.name]["y"].append(
anom.group_center[1]
y_locs[ind]
)

for trace in list(line_dict.values()):
Expand Down

0 comments on commit aed3328

Please sign in to comment.