diff --git a/docs/conf.py b/docs/conf.py index 390e55384..5c18c0b26 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -256,7 +256,7 @@ # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. "preamble": r"\definecolor{VerbatimBorderColor}{rgb}{1,1,1}" - r"\usepackage{etoolbox}\patchcmd{\thebibliography}{\section*{\refname}}{}{}{}" + r"\usepackage{etoolbox}\patchcmd{\thebibliography}{\section*{\refname}}{}{}{}", # Latex figure (float) alignment # 'figure_align': 'htbp', } diff --git a/lumicks/pylake/calibration.py b/lumicks/pylake/calibration.py index 10ecbefce..e82829af3 100644 --- a/lumicks/pylake/calibration.py +++ b/lumicks/pylake/calibration.py @@ -132,9 +132,11 @@ def format_timestamp(timestamp): item.kind, f"{item.stiffness:.2f}" if item.stiffness else "N/A", f"{item.force_sensitivity:.2f}" if item.force_sensitivity else "N/A", - f"{item.displacement_sensitivity:.2f}" - if item.displacement_sensitivity - else "N/A", + ( + f"{item.displacement_sensitivity:.2f}" + if item.displacement_sensitivity + else "N/A" + ), item.hydrodynamically_correct, item.distance_to_surface is not None, bool( diff --git a/lumicks/pylake/detail/mixin.py b/lumicks/pylake/detail/mixin.py index afe8bf283..f10e73ad4 100644 --- a/lumicks/pylake/detail/mixin.py +++ b/lumicks/pylake/detail/mixin.py @@ -1,4 +1,5 @@ """Mixin class which add properties for predefined channels""" + from ..channel import Slice, empty_slice diff --git a/lumicks/pylake/detail/tests/test_bead_crop.py b/lumicks/pylake/detail/tests/test_bead_crop.py index f885d13bc..4f2eb01d6 100644 --- a/lumicks/pylake/detail/tests/test_bead_crop.py +++ b/lumicks/pylake/detail/tests/test_bead_crop.py @@ -31,8 +31,10 @@ def test_bead_cropping_allow_negative_beads(filename, ref_edges, ref_edges_no_ne # because the fluorescence typically tails out wide. np.testing.assert_equal(edges, ref_edges) - with nullcontext() if ref_edges_no_negative else pytest.raises( - RuntimeError, match="Did not find two beads" + with ( + nullcontext() + if ref_edges_no_negative + else pytest.raises(RuntimeError, match="Did not find two beads") ): edges = find_beads_brightness( np.atleast_2d(data["green"]).T, @@ -50,7 +52,7 @@ def test_bead_cropping_failure(): def test_plotting(): - data = np.load(pathlib.Path(__file__).parent / "data" / f"kymo_sum0.npz") + data = np.load(pathlib.Path(__file__).parent / "data" / "kymo_sum0.npz") for allow_negative in (False, True): edges = find_beads_brightness( np.atleast_2d(data["green"]).T, diff --git a/lumicks/pylake/fitting/detail/model_implementation.py b/lumicks/pylake/fitting/detail/model_implementation.py index a6b33566c..051b1ddaa 100644 --- a/lumicks/pylake/fitting/detail/model_implementation.py +++ b/lumicks/pylake/fitting/detail/model_implementation.py @@ -889,16 +889,8 @@ def ewlc_marko_siggia_force_jac(d, Lp, Lc, St, kT=4.11): denom1 = Lc**3 * (Lp * St + kT) ** 2 denom2 = Lc * (Lp**2 * St**2 + 2.0 * Lp * St * kT + kT**2) dkT = d * kT - dc_dLc = ( - St**3 * dkT * (1.5 * Lc**2 - 4.5 * Lc * d + 3.0 * d**2) / (Lc**4 * (Lp * St + kT)) - ) - dc_dSt = ( - -(St**2) - * dkT - * (2 * Lp * St + 3 * kT) - * (1.5 * Lc**2 - 2.25 * Lc * d + d**2) - / denom1 - ) + dc_dLc = St**3 * dkT * (1.5 * Lc**2 - 4.5 * Lc * d + 3.0 * d**2) / (Lc**4 * (Lp * St + kT)) + dc_dSt = -(St**2) * dkT * (2 * Lp * St + 3 * kT) * (1.5 * Lc**2 - 2.25 * Lc * d + d**2) / denom1 dc_dLp = St**4 * dkT * (1.5 * Lc**2 - 2.25 * Lc * d + d**2) / denom1 dc_dkT = -Lp * St**4 * d * (1.5 * Lc**2 - 2.25 * Lc * d + d**2) / denom1 db_dLc = ( @@ -1287,9 +1279,7 @@ def ewlc_marko_siggia_distance_derivative(f, Lp, Lc, St, kT=4.11): ) / (St**3 * kT) ) - db_df = ( - Lc**2 * (4 * f * Lp * St + 6 * f * kT + 2 * Lp * St**2 + 4.5 * St * kT) / (St**2 * kT) - ) + db_df = Lc**2 * (4 * f * Lp * St + 6 * f * kT + 2 * Lp * St**2 + 4.5 * St * kT) / (St**2 * kT) da_df = -Lc * Lp / kT - 3 * Lc / St return total_dy_da * da_df + total_dy_db * db_df + total_dy_dc * dc_df diff --git a/lumicks/pylake/force_calibration/calibration_models.py b/lumicks/pylake/force_calibration/calibration_models.py index 32a3bbc79..d22a9715c 100644 --- a/lumicks/pylake/force_calibration/calibration_models.py +++ b/lumicks/pylake/force_calibration/calibration_models.py @@ -866,9 +866,9 @@ def __init__( bead_radius=self.bead_diameter * 1e-6 / 2.0, # um diameter -> m radius rho_sample=self.rho_sample, rho_bead=self.rho_bead, - distance_to_surface=None - if self.distance_to_surface is None - else self.distance_to_surface * 1e-6, # um => m + distance_to_surface=( + None if self.distance_to_surface is None else self.distance_to_surface * 1e-6 + ), # um => m ) else: self._theoretical_driving_power_model = partial( diff --git a/lumicks/pylake/kymotracker/kymotracker.py b/lumicks/pylake/kymotracker/kymotracker.py index 4b21d6b24..e2bb221a5 100644 --- a/lumicks/pylake/kymotracker/kymotracker.py +++ b/lumicks/pylake/kymotracker/kymotracker.py @@ -189,9 +189,11 @@ def track_greedy( bias_correction=bias_correction, filter_width=filter_width / kymograph.pixelsize_um[0] if filter_width is not None else 0.5, adjacency_half_width=half_width_pixels if adjacency_filter else None, - rect=_to_pixel_rect(rect, kymograph.pixelsize[0], kymograph.line_time_seconds) - if rect - else None, + rect=( + _to_pixel_rect(rect, kymograph.pixelsize[0], kymograph.line_time_seconds) + if rect + else None + ), ) if not peaks: @@ -389,9 +391,11 @@ def minimum_observable_time(track, min_length, min_duration): track._with_minimum_time( max( # We can't unfilter tracks. - track._minimum_observable_duration - if track._minimum_observable_duration is not None - else 0, + ( + track._minimum_observable_duration + if track._minimum_observable_duration is not None + else 0 + ), minimum_observable_time(track, minimum_length, minimum_duration), ) ) diff --git a/lumicks/pylake/kymotracker/tests/test_io.py b/lumicks/pylake/kymotracker/tests/test_io.py index 429337ce9..d1b42eed1 100644 --- a/lumicks/pylake/kymotracker/tests/test_io.py +++ b/lumicks/pylake/kymotracker/tests/test_io.py @@ -198,13 +198,17 @@ def test_csv_version(version, read_with_version): ) testfile = Path(__file__).parent / f"./data/tracks_v{version}.csv" - with pytest.warns( - RuntimeWarning, - match=( - "This CSV file is from a version in which the minimum observable track duration " - "was incorrectly rounded to an integer." - ), - ) if version == 3 else contextlib.nullcontext(): + with ( + pytest.warns( + RuntimeWarning, + match=( + "This CSV file is from a version in which the minimum observable track duration " + "was incorrectly rounded to an integer." + ), + ) + if version == 3 + else contextlib.nullcontext() + ): imported_tracks = import_kymotrackgroup_from_csv(testfile, kymo, "red", delimiter=";") data, pylake_version, csv_version = _read_txt(testfile, ";") @@ -228,7 +232,7 @@ def test_bad_csv(filename, blank_kymo): def test_min_obs_csv_regression(tmpdir_factory, blank_kymo): """This tests a regression where saving a freshly imported older file does not function""" - testfile = Path(__file__).parent / f"./data/tracks_v0.csv" + testfile = Path(__file__).parent / "./data/tracks_v0.csv" imported_tracks = import_kymotrackgroup_from_csv(testfile, blank_kymo, "red", delimiter=";") out_file = f"{tmpdir_factory.mktemp('pylake')}/no_min_lengths.csv" diff --git a/lumicks/pylake/nb_widgets/image_editing.py b/lumicks/pylake/nb_widgets/image_editing.py index 367a4cf24..fe3d29043 100644 --- a/lumicks/pylake/nb_widgets/image_editing.py +++ b/lumicks/pylake/nb_widgets/image_editing.py @@ -59,8 +59,8 @@ def __init__( self.channel = channel self.current_frame = frame self.num_frames = self._current_image.num_frames - self.make_title = ( - lambda: make_image_title(self._current_image, self.current_frame, show_name=False) + self.make_title = lambda: ( + make_image_title(self._current_image, self.current_frame, show_name=False) if show_title else (lambda: "") ) diff --git a/lumicks/pylake/nb_widgets/kymotracker_widgets.py b/lumicks/pylake/nb_widgets/kymotracker_widgets.py index d0f6c4f8d..83b3f47e9 100644 --- a/lumicks/pylake/nb_widgets/kymotracker_widgets.py +++ b/lumicks/pylake/nb_widgets/kymotracker_widgets.py @@ -760,9 +760,11 @@ def _create_algorithm_sliders(self): def threshold_slider_callback(change): self._set_label( "warning", - "" - if change["new"] > min_threshold - else f"Tracking with threshold of {change['new']} may be slow.", + ( + "" + if change["new"] > min_threshold + else f"Tracking with threshold of {change['new']} may be slow." + ), ) threshold_slider.observe( diff --git a/lumicks/pylake/population/detail/fit_info.py b/lumicks/pylake/population/detail/fit_info.py index 06ecc56b3..5905f952b 100644 --- a/lumicks/pylake/population/detail/fit_info.py +++ b/lumicks/pylake/population/detail/fit_info.py @@ -31,6 +31,7 @@ class PopulationFitInfo: log_likelihood: float log of the maximized value of the likelihood function of the fitted data """ + converged: bool n_iter: int bic: float diff --git a/lumicks/pylake/tests/test_imaging_confocal/test_kymo_plotting.py b/lumicks/pylake/tests/test_imaging_confocal/test_kymo_plotting.py index faec3ec66..58a85223e 100644 --- a/lumicks/pylake/tests/test_imaging_confocal/test_kymo_plotting.py +++ b/lumicks/pylake/tests/test_imaging_confocal/test_kymo_plotting.py @@ -290,10 +290,14 @@ def process_binning(px_per_bin, axis): for px_per_bin in range(1, ref.image.shape[0] + 1): ref_counts, ref_bin_widths, msg = process_binning(px_per_bin, "position") - with pytest.warns( - UserWarning, - match=msg, - ) if msg else nullcontext(): + with ( + pytest.warns( + UserWarning, + match=msg, + ) + if msg + else nullcontext() + ): kymo.plot_with_position_histogram(color_channel="red", pixels_per_bin=px_per_bin) counts, bin_widths = get_hist_data("position") diff --git a/lumicks/pylake/tests/test_imaging_confocal/test_kymo_slice_crop.py b/lumicks/pylake/tests/test_imaging_confocal/test_kymo_slice_crop.py index a8bfb504c..8e7eeb32d 100644 --- a/lumicks/pylake/tests/test_imaging_confocal/test_kymo_slice_crop.py +++ b/lumicks/pylake/tests/test_imaging_confocal/test_kymo_slice_crop.py @@ -1,5 +1,3 @@ -import pathlib - import numpy as np import pytest @@ -39,43 +37,43 @@ def test_kymo_slicing(test_kymo): np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :, 0]) num_lines = 2 - sliced = kymo["0s":f"{num_lines * line_time}s"] + sliced = kymo["0s" :f"{num_lines * line_time}s"] assert sliced.get_image("red").shape == (ref_pixels, num_lines) assert sliced.shape == (ref_pixels, num_lines, 3) np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :num_lines, 0]) - sliced = kymo["0s":f"-{line_time * 0.6}s"] + sliced = kymo["0s" :f"-{line_time * 0.6}s"] assert sliced.get_image("red").shape == (ref_pixels, ref_lines - 1) np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :-1, 0]) - sliced = kymo["0s":f"-{2 * line_time}s"] + sliced = kymo["0s" :f"-{2 * line_time}s"] assert sliced.get_image("red").shape == (ref_pixels, ref_lines - 2) np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, : (ref_lines - 2), 0]) # get a sliver of the next frame # stop needs to be > halfway the deadtime between lines - sliced = kymo["0s":f"-{2 * line_time - deadtime_slice_offset}s"] + sliced = kymo["0s" :f"-{2 * line_time - deadtime_slice_offset}s"] assert sliced.get_image("red").shape == (ref_pixels, ref_lines - 1) np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :-1, 0]) # Two full frames - sliced = kymo["0s":f"{2 * line_time}s"] + sliced = kymo["0s" :f"{2 * line_time}s"] assert sliced.get_image("red").shape == (ref_pixels, 2) np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :2, 0]) # Two full frames plus a bit - sliced = kymo["0s":f"{2 * scan_time + 2 * dead_time + deadtime_slice_offset}s"] + sliced = kymo["0s" :f"{2 * scan_time + 2 * dead_time + deadtime_slice_offset}s"] assert sliced.get_image("red").shape == (ref_pixels, 3) np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :3, 0]) # slice from deadtime before first line until deadtime after first line - sliced = kymo[f"{scan_time + dead_time / 2}s":f"{2 * line_time - dead_time / 2}s"] + sliced = kymo[f"{scan_time + dead_time / 2}s" :f"{2 * line_time - dead_time / 2}s"] assert sliced.get_image("red").shape == (ref_pixels, 1) assert sliced.shape == (ref_pixels, 1, 3) np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, 1:2, 0]) # slice over entire kymo - sliced = kymo["0s":f"{line_time * (ref.metadata.lines_per_frame + 1)}s"] + sliced = kymo["0s" :f"{line_time * (ref.metadata.lines_per_frame + 1)}s"] assert sliced.get_image("red").shape == (ref_pixels, ref_lines) assert sliced.shape == (ref_pixels, ref_lines, 3) np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :, 0]) @@ -245,7 +243,7 @@ def test_kymo_slice_crop(cropping_kymo): dead_time = (ref.timestamps.dt * ref.infowave.line_padding * 2) * 1e-9 line_time = scan_time + dead_time - sliced_cropped = kymo[f"{line_time}s":f"{5 * line_time}s"].crop_by_distance( + sliced_cropped = kymo[f"{line_time}s" :f"{5 * line_time}s"].crop_by_distance( 2 * px_size, 4 * px_size ) np.testing.assert_equal(sliced_cropped.timestamps, ref.timestamps.data[2:4, 1:5]) diff --git a/lumicks/pylake/tests/test_imaging_confocal/test_scan.py b/lumicks/pylake/tests/test_imaging_confocal/test_scan.py index baf9b0942..bf529496d 100644 --- a/lumicks/pylake/tests/test_imaging_confocal/test_scan.py +++ b/lumicks/pylake/tests/test_imaging_confocal/test_scan.py @@ -29,9 +29,11 @@ def test_scan_attrs(test_scans, test_scans_multiframe): np.testing.assert_equal( scan.frame_timestamp_ranges(include_dead_time=True), - ref.timestamps.timestamp_ranges # For the single frame case, there is no dead time - if scan.num_frames == 1 - else ref.timestamps.timestamp_ranges_deadtime, + ( + ref.timestamps.timestamp_ranges # For the single frame case, there is no dead time + if scan.num_frames == 1 + else ref.timestamps.timestamp_ranges_deadtime + ), ) np.testing.assert_equal(scan.frame_timestamp_ranges(), ref.timestamps.timestamp_ranges) diff --git a/lumicks/pylake/tests/test_imaging_confocal/test_scan_slice_crop.py b/lumicks/pylake/tests/test_imaging_confocal/test_scan_slice_crop.py index 7e4f8d21c..398a96a44 100644 --- a/lumicks/pylake/tests/test_imaging_confocal/test_scan_slice_crop.py +++ b/lumicks/pylake/tests/test_imaging_confocal/test_scan_slice_crop.py @@ -255,22 +255,22 @@ def test_scan_slicing_by_time(test_scan_slicing): wiggle = 0.01 # start of frame 2, until frame 2 signal stop - assert isinstance(multi_frame[f"{rng[2, 0]}s":f"{rng[2, 1]}s"], EmptyScan) + assert isinstance(multi_frame[f"{rng[2, 0]}s" :f"{rng[2, 1]}s"], EmptyScan) # start of frame 2, just over frame 2 signal stop - sliced = multi_frame[f"{rng[2, 0]}s":f"{rng[2, 1] + wiggle}s"] + sliced = multi_frame[f"{rng[2, 0]}s" :f"{rng[2, 1] + wiggle}s"] np.testing.assert_equal(sliced.get_image("rgb"), ref.image[2]) # start of frame 2, until frame 3 signal stop - sliced = multi_frame[f"{rng[2, 0]}s":f"{rng[3, 1]}s"] + sliced = multi_frame[f"{rng[2, 0]}s" :f"{rng[3, 1]}s"] np.testing.assert_equal(sliced.get_image("rgb"), ref.image[2]) # start of frame 2, just over frame 3 signal stop - sliced = multi_frame[f"{rng[2, 0]}s":f"{rng[3, 1] + wiggle}s"] + sliced = multi_frame[f"{rng[2, 0]}s" :f"{rng[3, 1] + wiggle}s"] np.testing.assert_equal(sliced.get_image("rgb"), ref.image[2:4]) # start of frame 2, until start of frame 4 - sliced = multi_frame[f"{rng[2, 0]}s":f"{rng[4, 0]}s"] + sliced = multi_frame[f"{rng[2, 0]}s" :f"{rng[4, 0]}s"] np.testing.assert_equal(sliced.get_image("rgb"), ref.image[2:4]) # from start of frame 2 @@ -332,15 +332,15 @@ def test_scan_slicing_by_time_iterative(test_scan_slicing): wiggle = 0.01 # first slice frame 2 through 5 (inclusive) - first_slice = multi_frame[f"{rng[2, 0]}s":f"{rng[5, 1] + wiggle}s"] + first_slice = multi_frame[f"{rng[2, 0]}s" :f"{rng[5, 1] + wiggle}s"] ref_sliced = ref.image[2:6] # start of frame 1, just over frame 3 signal stop - sliced = first_slice[f"{rng[1, 0]}s":f"{rng[3, 1] + wiggle}s"] + sliced = first_slice[f"{rng[1, 0]}s" :f"{rng[3, 1] + wiggle}s"] np.testing.assert_equal(sliced.get_image("rgb"), ref_sliced[1:4]) # start of frame 1, until frame 3 signal stop - sliced = first_slice[f"{rng[1, 0]}s":f"{rng[3, 1]}s"] + sliced = first_slice[f"{rng[1, 0]}s" :f"{rng[3, 1]}s"] np.testing.assert_equal(sliced.get_image("rgb"), ref_sliced[1:3]) # from start of frame 1