Skip to content

Commit

Permalink
diffusion: better error for "ols" of empty track
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Oct 24, 2023
1 parent a9040e5 commit 679b129
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#### Improvements

* Kymographs that only consist of a single line no longer raise, but report a `line_time_seconds`. This also allows you to now call `Kymo.plot()` on these.
* Issue a more descriptive error when attempting to compute a diffusion constant of a track with no points.

## v1.2.1 | 2023-10-17

Expand Down
6 changes: 6 additions & 0 deletions lumicks/pylake/kymotracker/detail/msd_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,12 @@ def determine_optimal_points(frame_idx, coordinate, max_iterations=100):

num_slopes.add(num_slope)

if len(coordinate) <= 4:
raise RuntimeError(
"You need at least 5 time points to estimate the number of points to include in "
"the fit."
)

# Determine the number of points to include in the next fit
num_slope, num_intercept = optimal_points(
calculate_localization_error(frame_lags[:num_slope], msd[:num_slope]), len(coordinate)
Expand Down
12 changes: 12 additions & 0 deletions lumicks/pylake/kymotracker/tests/test_kymotrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,18 @@ def make_coordinates(length, divisor):
d = tracks.estimate_diffusion("ols", min_length=2)


@pytest.mark.parametrize("data", [[], [1, 2, 3, 4]])
def test_ols_empty_kymotrack(blank_kymo, data):
track = KymoTrack(data, data, blank_kymo, "red", 0)

with pytest.raises(
RuntimeError,
match="You need at least 5 time points to estimate the number of points to include in the "
"fit.",
):
track.estimate_diffusion("ols")


@pytest.mark.parametrize("kbp_calibration, line_width", [(None, 7), (4, 7), (None, 8)])
def test_ensemble_msd_calibration_from_kymo(blank_kymo, kbp_calibration, line_width):
"""Checks whether all the properties are correctly forwarded from the Kymo"""
Expand Down

0 comments on commit 679b129

Please sign in to comment.