Skip to content

Commit

Permalink
feat(eyepy.core): reflect plotted region in x and y axis for both loc…
Browse files Browse the repository at this point in the history
…alizer and B-scan; check if bscan_region bscan position indicators are in plotting region
  • Loading branch information
Oli4 committed Feb 13, 2023
1 parent 3c4efcd commit 2842424
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/eyepy/core/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def projection(self):
Returns:
"""

# The flip is required because in the volume the bottom most B-scan has the lowest index
# while in the enface projection the bottom most position should have the biggest index.
return np.flip(np.nansum(self.data, axis=1), axis=0)

@property
Expand Down
31 changes: 14 additions & 17 deletions src/eyepy/core/eyebscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,12 @@ def plot(
ax = plt.gca()

# Complete region index expression
if region[0].start is None:
r0_start = 0
else:
r0_start = region[0].start
if region[1].start is None:
r1_start = 0
else:
r1_start = region[1].start
if region[0].stop is None:
r0_stop = self.shape[0]
else:
r0_stop = region[0].stop
if region[1].stop is None:
r1_stop = self.shape[1]
else:
r1_stop = region[1].stop
region = np.s_[r0_start:r0_stop, r1_start:r1_stop]
y_start = region[0].start if region[0].start is not None else 0
y_stop = region[0].stop if region[0].stop is not None else self.shape[0]
x_start = region[1].start if region[1].start is not None else 0
x_stop = region[1].stop if region[1].stop is not None else self.shape[1]

region = np.s_[y_start:y_stop, x_start:x_stop]

if not layers:
layers = []
Expand Down Expand Up @@ -202,3 +191,11 @@ def plot(
label=layer,
**layer_kwargs,
)

# Hack to avoid a warning when setting the tick labels later
# Warning: FixedFormatter should only be used together with FixedLocator
ax.set_yticks(ax.get_yticks())
ax.set_xticks(ax.get_xticks())

ax.set_yticklabels((ax.get_yticks() + y_start).astype(int))
ax.set_xticklabels((ax.get_xticks() + x_start).astype(int))
9 changes: 9 additions & 0 deletions src/eyepy/core/eyeenface.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,12 @@ def plot(self,
if ax is None:
ax = plt.gca()
ax.imshow(self.data[region], cmap="gray")

ax.set_yticks(ax.get_yticks())
ax.set_xticks(ax.get_xticks())

y_start = region[0].start if region[0].start is not None else 0
x_start = region[1].start if region[1].start is not None else 0

ax.set_yticklabels((ax.get_yticks() + y_start).astype(int))
ax.set_xticklabels((ax.get_xticks() + x_start).astype(int))
31 changes: 28 additions & 3 deletions src/eyepy/core/eyevolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,16 @@ def plot(
"""

# Complete region index expression
y_start = region[0].start if region[0].start is not None else 0
y_stop = region[0].stop if region[
0].stop is not None else self.localizer.shape[0]
x_start = region[1].start if region[1].start is not None else 0
x_stop = region[1].stop if region[
1].stop is not None else self.localizer.shape[1]

region = np.s_[y_start:y_stop, x_start:x_stop]

if ax is None:
ax = plt.gca()

Expand Down Expand Up @@ -694,9 +704,15 @@ def _plot_bscan_positions(
start = self[i].meta["start_pos"] / scale
end = self[i].meta["end_pos"] / scale

# x = [start[0], end[0]]
# y = [start[1], end[1]]
# ax.plot(x, y, **line_kwargs)
for pos in [start, end]:
# Check for both axis if pos is in region
if not (region[0].start <= pos[0] <= region[0].stop
and region[1].start <= pos[1] <= region[1].stop):
logger.warning(
"B-scan position can not be plotted because the visualized region does not contain the complete B-scan."
)
return

polygon = patches.Polygon(
[start, end],
closed=False,
Expand Down Expand Up @@ -727,6 +743,15 @@ def _plot_bscan_region(self,
lower_right = self[0].meta["end_pos"] / scale
upper_right = self[-1].meta["end_pos"] / scale

for pos in [upper_left, lower_left, lower_right, upper_right]:
# Check for both axis if pos is in region
if not (region[0].start <= pos[0] <= region[0].stop
and region[1].start <= pos[1] <= region[1].stop):
logger.warning(
"B-scan region can not be plotted because the visualized region does not contain the complete B-scan region."
)
return

polygon = patches.Polygon(
[upper_left, lower_left, lower_right, upper_right],
closed=True,
Expand Down

0 comments on commit 2842424

Please sign in to comment.