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
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@
- fix: deprecated `export.hdf5_autocomplete_config` raised an
AttributeError when given a path (`.close()` was called on the path
instead of on the file opened by `RTDCWriter`) (#423)
- fix: `find_smooth_contour_spacing` returned half of the last
evaluated contour spacing when the maximum number of iterations
was reached (#424)
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
16 changes: 10 additions & 6 deletions dclab/kde/smooth_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,20 @@ def find_smooth_contour_spacing(
}

corners_found = False
for _ in range(max_iter): # hard-limit is 15 iterations
corners_found = False

for ii in range(max_iter): # hard-limit is 15 iterations
if abort_event is not None and abort_event.is_set():
results["reason"] = "abort event"
break

if ii > 0:
# The contours computed with the previous spacing were not
# smooth enough. Halve the spacing here (and not at the end
# of the previous iteration), so that the spacing returned
# is always the last one that was evaluated.
xacc /= 2
yacc /= 2

corners_found = False
results["total iterations"] += 1

# maximum difference of opening angle from 180° [rad]
Expand Down Expand Up @@ -185,9 +192,6 @@ def find_smooth_contour_spacing(
results["reason"] = "maximum contour length reached"
results["success"] = True
break
else:
xacc /= 2
yacc /= 2

results["corners found"] = corners_found
results["spacing x"] = xacc
Expand Down
6 changes: 4 additions & 2 deletions tests/test_kde_smooth_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ def test_find_smooth_contour_spacing_max_iter():
assert not res["success"]
assert not res["corners found"]
assert res["reason"] == "maximum iterations reached"
assert np.allclose(res["spacing x"], 0.46201586550424045,
# The returned spacing is the one that was evaluated in the last
# iteration (here: the initial estimate, not half of it).
assert np.allclose(res["spacing x"], 2 * 0.46201586550424045,
rtol=0, atol=1e-12)
assert np.allclose(res["spacing y"], 0.00024627719927894213,
assert np.allclose(res["spacing y"], 2 * 0.00024627719927894213,
rtol=0, atol=1e-12)


Expand Down
Loading