Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@
- fix: `Isoelastics.get` and `Isoelastics.get_with_rtdcbase` returned
zero-valued emodulus for `viscosity=0` or `viscosity=False`; a
ValueError is now raised for viscosities that are not positive (#418)
- fix: `find_smooth_contour_spacing` reported success ("target opening
angle reached") when the abort event was set while iterating over
the datasets; also pass a flat list of quantiles to
`get_contour_lines` (nested list only worked by chance) (#419)
0.74.0
- fix: CLI commands compress, condense, join, and repack deleted the
input file if it was also given as the output path
Expand Down
21 changes: 13 additions & 8 deletions dclab/kde/smooth_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def find_smooth_contour_spacing(
break
# Compute the contour for the highest percentile of the plot.
contours = kdi.get_contour_lines(
quantiles=[[np.max(quantiles)]],
quantiles=[np.max(quantiles)],
xax=xax,
yax=yax,
xacc=xacc,
Expand Down Expand Up @@ -162,13 +162,18 @@ def find_smooth_contour_spacing(

max_dphi = max(max_dphi, dphi)
max_length = min(max_length, len(cc))
else:
results["reason"] = "maximum iterations reached"
results["success"] = False
if not num_contours:
# There is no contour we could smooth.
results["reason"] = "no contour found"
break

if abort_event is not None and abort_event.is_set():
# Aborted while iterating over the datasets; the contours
# of the remaining datasets were not checked.
results["reason"] = "abort event"
break
elif not num_contours:
# There is no contour we could smooth.
results["reason"] = "no contour found"
break

results["reason"] = "maximum iterations reached"

if max_dphi < np.deg2rad(23):
# A contour is considered smooth when the maximum angle between
Expand Down
34 changes: 34 additions & 0 deletions tests/test_kde_smooth_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,40 @@ def test_find_smooth_contour_abort():
rtol=0, atol=1e-12)


def test_find_smooth_contour_abort_during_iteration():
"""Aborting while iterating over datasets must not report success"""
np.random.seed(47)
x0 = np.random.normal(loc=100, scale=10, size=100)
y0 = np.random.normal(loc=.1, scale=.01, size=100)

ds = dclab.new_dataset({"area_um": x0, "deform": y0})

class LateEvent(threading.Event):
"""Event that is set at the second call of `is_set`"""
def __init__(self):
super().__init__()
self.calls = 0

def is_set(self):
self.calls += 1
return self.calls >= 2

res = smooth_contour.find_smooth_contour_spacing(
ds_list=[ds],
xax="area_um",
yax="deform",
xrange=(50, 150),
yrange=(0.09, 0.11),
quantiles=[0.90],
abort_event=LateEvent(),
)

# The abort event was set before the first contour was computed.
assert res["total iterations"] == 1
assert not res["success"]
assert res["reason"] == "abort event"


@pytest.mark.parametrize("angles", [
# NaN values and an opening angle of ~86 degrees
[np.nan, np.nan, 1.5],
Expand Down
Loading