Skip to content

Commit f8d43b6

Browse files
Update optical display to show PD ID
1 parent 90ddb4c commit f8d43b6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

spine/vis/geo.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,27 +167,35 @@ def optical_traces(self, meta=None, shared_legend=True, legendgroup=None,
167167
if shared_legend and legendgroup is None:
168168
legendgroup = 'group_' + str(time.time())
169169

170+
# Add a hovertext to the optical detectors
171+
hovertexts = [f'PD ID: {i}' for i in range(len(positions))]
172+
if color is not None and not np.isscalar(color):
173+
hovertexts = [f'{ht}<br>PE: {c:.3f}' for ht, c in zip(hovertexts, color)]
174+
170175
# Draw each of the optical detectors
171176
traces = []
172177
for i, shape in enumerate(self.geo.optical.shape):
173178
# Restrict the positions to those of this shape, if needed
174179
if shape_ids is None:
175180
pos = positions
176181
col = color
182+
ht = hovertexts
177183
else:
178184
index = np.where(np.asarray(shape_ids) == i)[0]
179185
pos = positions[index]
180186
if color is not None and not np.isscalar(color):
181187
col = color[index]
182188
else:
183189
col = color
190+
ht = [hovertexts[i] for i in index]
184191

185192
# If zero-supression is requested, only draw the optical detectors
186193
# which record a non-zero signal
187194
if zero_supress and color is not None and not np.isscalar(color):
188195
index = np.where(np.asarray(col) != 0)[0]
189196
pos = pos[index]
190197
col = col[index]
198+
ht = [ht[i] for i in index]
191199

192200
# Determine wheter to show legends or not
193201
showlegend = not shared_legend or i == 0
@@ -202,7 +210,7 @@ def optical_traces(self, meta=None, shared_legend=True, legendgroup=None,
202210
traces += box_traces(
203211
lower, upper, shared_legend=shared_legend, name=name,
204212
color=col, cmin=cmin, cmax=cmax, draw_faces=True,
205-
legendgroup=legendgroup, showlegend=showlegend, **kwargs)
213+
hovertext=ht, legendgroup=legendgroup, showlegend=showlegend, **kwargs)
206214

207215
else:
208216
# Convert the optical detector dimensions to a covariance matrix
@@ -212,7 +220,7 @@ def optical_traces(self, meta=None, shared_legend=True, legendgroup=None,
212220
traces += ellipsoid_traces(
213221
pos, covmat, shared_legend=shared_legend, name=name,
214222
color=col, cmin=cmin, cmax=cmax,
215-
legendgroup=legendgroup, showlegend=showlegend, **kwargs)
223+
hovertext=ht, legendgroup=legendgroup, showlegend=showlegend, **kwargs)
216224

217225
return traces
218226

0 commit comments

Comments
 (0)