Skip to content

Commit f4c27a2

Browse files
committed
# Conflicts: # CHANGELOG.md
2 parents bd7bcad + ef76ac2 commit f4c27a2

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ In this release, test coverage is 80%.
77
🛠️ Bug fixes:
88

99
* [Issue #42](https://github.com/PlotPyStack/PlotPy/issues/42) - Image profiles: when moving/resizing image, profile plots are not refreshed
10+
* [Issue #41](https://github.com/PlotPyStack/PlotPy/issues/41) - Average profile visualization: empty profile is displayed when the target rectangular area is outside the image area
1011

1112
## Version 2.7.3 ##
1213

plotpy/items/image/base.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,18 @@ def get_closest_indexes(
216216
return i, j
217217

218218
def get_closest_index_rect(
219-
self, x0: float, y0: float, x1: float, y1: float
219+
self, x0: float, y0: float, x1: float, y1: float, avoid_empty: bool = True
220220
) -> tuple[int, int, int, int]:
221-
"""Get closest image rectangular pixel area index bounds
221+
"""Get closest image rectangular pixel area index bounds, optionally
222+
avoid returning an empty rectangular area (return at least 1x1 pixel area)
222223
223224
Args:
224225
x0: X coordinate of first point
225226
y0: Y coordinate of first point
226227
x1: X coordinate of second point
227228
y1: Y coordinate of second point
229+
avoid_empty: True to avoid returning an empty rectangular area.
230+
Defaults to True.
228231
229232
Returns:
230233
Closest image rectangular pixel area index bounds
@@ -240,9 +243,9 @@ def get_closest_index_rect(
240243
ix1, ix0 = ix0, ix1
241244
if iy0 > iy1:
242245
iy1, iy0 = iy0, iy1
243-
if ix0 == ix1:
246+
if ix0 == ix1 and avoid_empty:
244247
ix1 += 1
245-
if iy0 == iy1:
248+
if iy0 == iy1 and avoid_empty:
246249
iy1 += 1
247250
return ix0, iy0, ix1, iy1
248251

@@ -1083,7 +1086,9 @@ def get_average_xsection(
10831086
Returns:
10841087
Average cross section along x-axis
10851088
"""
1086-
ix0, iy0, ix1, iy1 = self.get_closest_index_rect(x0, y0, x1, y1)
1089+
ix0, iy0, ix1, iy1 = self.get_closest_index_rect(
1090+
x0, y0, x1, y1, avoid_empty=False
1091+
)
10871092
ydata = self.data[iy0:iy1, ix0:ix1]
10881093
if ydata.size == 0:
10891094
return np.array([]), np.array([])
@@ -1108,7 +1113,9 @@ def get_average_ysection(
11081113
Returns:
11091114
Average cross section along y-axis
11101115
"""
1111-
ix0, iy0, ix1, iy1 = self.get_closest_index_rect(x0, y0, x1, y1)
1116+
ix0, iy0, ix1, iy1 = self.get_closest_index_rect(
1117+
x0, y0, x1, y1, avoid_empty=False
1118+
)
11121119
ydata = self.data[iy0:iy1, ix0:ix1]
11131120
if ydata.size == 0:
11141121
return np.array([]), np.array([])

0 commit comments

Comments
 (0)