Skip to content

Commit 415e510

Browse files
blackJoepVanlier
black
authored andcommitted
black: reformat the tests
1 parent 3291b08 commit 415e510

16 files changed

+111
-77
lines changed

lumicks/pylake/force_calibration/tests/data/simulate_calibration_data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def response_peak_ideal(corner_frequency, driving_frequency, driving_amplitude):
4444
Flyvbjerg, H. (2006). Calibration of optical tweezers with positional detection in the back
4545
focal plane. Review of scientific instruments, 77(10), 103101.
4646
"""
47-
return driving_amplitude ** 2 / (2 * (1 + (corner_frequency / driving_frequency) ** 2))
47+
return driving_amplitude**2 / (2 * (1 + (corner_frequency / driving_frequency) ** 2))
4848

4949

5050
def generate_active_calibration_test_data(

lumicks/pylake/kymotracker/tests/data/generate_gaussian_data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class GaussianParameters1D:
1717

1818
@property
1919
def amplitude(self):
20-
return self.total_photons * self.pixel_size * 1 / np.sqrt(2 * np.pi * self.width ** 2)
20+
return self.total_photons * self.pixel_size * 1 / np.sqrt(2 * np.pi * self.width**2)
2121

2222
def generate_coordinates(self, n_pixels):
2323
return np.arange(n_pixels) * self.pixel_size

lumicks/pylake/kymotracker/tests/test_algorithm_scaling.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ def test_kymotracker_positional_scaling(vel, dt, dx):
3838
np.testing.assert_allclose(traces[0].position, ref_positions, rtol=1e-2)
3939

4040
# Check whether a wrong velocity also fails to track the line
41-
traces = track_greedy(kymo, "red", pixel_threshold=3, track_width=1, sigma=0.01, velocity=2 * vel)
41+
traces = track_greedy(
42+
kymo, "red", pixel_threshold=3, track_width=1, sigma=0.01, velocity=2 * vel
43+
)
4244
np.testing.assert_equal(len(traces[0].seconds), 1)
4345
np.testing.assert_equal(len(traces[0].position), 1)
4446

4547
# When sigma is large, we expect the line to be strung together despite the velocity being zero
46-
traces = track_greedy(kymo, "red", pixel_threshold=3, track_width=1, sigma=0.5 * vel * dx, velocity=0)
48+
traces = track_greedy(
49+
kymo, "red", pixel_threshold=3, track_width=1, sigma=0.5 * vel * dx, velocity=0
50+
)
4751
np.testing.assert_allclose(traces[0].seconds, ref_seconds)
4852
np.testing.assert_allclose(traces[0].position, ref_positions, rtol=1e-2)

lumicks/pylake/kymotracker/tests/test_derived_quantities/test_msd.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,18 @@ def test_diffusion_estimate_ols(
243243
(2.0, 1000, 5, 0.01, 0.5, 2.0191353993755534, 0.2691422691544549, 2, False),
244244
(2.0, 1000, 3, 0.01, 0.5, 1.5714322945079129, 0.8912916583320089, 2, True),
245245
(2.0, 5000, 5, 0.01, 0.5, 1.9352306588121024, 0.23809537086111288, 2, True),
246-
]
246+
],
247247
)
248248
def test_regression_ols_with_skipped_frames(
249-
diffusion, num_points, max_lag, time_step, obs_noise, diff_est, std_err_est, skip, shuffle,
249+
diffusion,
250+
num_points,
251+
max_lag,
252+
time_step,
253+
obs_noise,
254+
diff_est,
255+
std_err_est,
256+
skip,
257+
shuffle,
250258
):
251259
with temp_seed(0):
252260
trace = _simulate_diffusion_1d(diffusion, num_points, time_step, obs_noise)
@@ -426,7 +434,7 @@ def test_cve_skipped_samples(
426434
time_step,
427435
blur_constant,
428436
localization_var,
429-
var_of_localization_var
437+
var_of_localization_var,
430438
)
431439
np.testing.assert_allclose(diffusion_est, diffusion_ref)
432440
np.testing.assert_allclose(diffusion_var_est, diffusion_var_ref)

lumicks/pylake/kymotracker/tests/test_greedy_algorithm.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def test_kymotracker_subset_test_greedy(kymo_integration_test_data):
3939
pixel_size = kymo_integration_test_data.pixelsize_um[0]
4040
rect = [[0.0 * line_time, 15.0 * pixel_size], [30 * line_time, 30.0 * pixel_size]]
4141

42-
tracks = track_greedy(kymo_integration_test_data, "red", track_width=3 * pixel_size, pixel_threshold=4, rect=rect)
42+
tracks = track_greedy(
43+
kymo_integration_test_data, "red", track_width=3 * pixel_size, pixel_threshold=4, rect=rect
44+
)
4345
np.testing.assert_allclose(
4446
tracks[0].sample_from_image(1, correct_origin=True), [40] * np.ones(10)
4547
)
@@ -81,7 +83,9 @@ def test_kymotracker_greedy_algorithm_integration_tests(kymo_integration_test_da
8183
np.testing.assert_allclose(tracks[1].photon_counts, np.full((10,), 42))
8284

8385
rect = [[0.0 * line_time, 15.0 * pixel_size], [30 * line_time, 30.0 * pixel_size]]
84-
tracks = track_greedy(test_data, "red", track_width=3 * pixel_size, pixel_threshold=4, rect=rect)
86+
tracks = track_greedy(
87+
test_data, "red", track_width=3 * pixel_size, pixel_threshold=4, rect=rect
88+
)
8589
np.testing.assert_allclose(tracks[0].coordinate_idx, [21] * np.ones(10))
8690
np.testing.assert_allclose(tracks[0].time_idx, np.arange(15, 25))
8791

@@ -128,10 +132,11 @@ def test_greedy_algorithm_input_validation(kymo_integration_test_data):
128132
def test_default_parameters(kymo_pixel_calibrations):
129133
# calibrated in microns, kilobase pairs, pixels
130134
for kymo, default_width in zip(kymo_pixel_calibrations, [0.35, 0.35 / 0.34, 4]):
131-
132135
# test that default values are used when `None` is supplied
133136
default_threshold = np.percentile(kymo.get_image("red"), 98)
134-
ref_tracks = track_greedy(kymo, "red", track_width=default_width, pixel_threshold=default_threshold)
137+
ref_tracks = track_greedy(
138+
kymo, "red", track_width=default_width, pixel_threshold=default_threshold
139+
)
135140

136141
tracks = track_greedy(kymo, "red", track_width=None, pixel_threshold=default_threshold)
137142
for ref, track in zip(ref_tracks, tracks):
@@ -157,12 +162,12 @@ def test_default_parameters(kymo_pixel_calibrations):
157162

158163
# To verify this for the width, we have to make sure we go to the next odd window size.
159164
tracks = track_greedy(
160-
kymo, "red",
165+
kymo,
166+
"red",
161167
track_width=default_width / kymo.pixelsize[0] + 2,
162168
pixel_threshold=None,
163169
bias_correction=False,
164170
)
165171
with pytest.raises(AssertionError):
166172
for ref, track in zip(ref_tracks, tracks):
167173
np.testing.assert_allclose(ref.position, track.position)
168-

lumicks/pylake/kymotracker/tests/test_image_sampling.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ def test_sampling():
2727
start=np.int64(20e9),
2828
dt=np.int64(1e9),
2929
samples_per_pixel=1,
30-
line_padding=0
30+
line_padding=0,
3131
)
3232

3333
# Tests the bound handling
3434
kymotrack = KymoTrack([0, 1, 2, 3, 4], [0, 1, 2, 3, 4], test_img, "red", 0)
35-
np.testing.assert_allclose(kymotrack.sample_from_image(
36-
50, correct_origin=True), [0, 2, 3, 2, 0]
35+
np.testing.assert_allclose(
36+
kymotrack.sample_from_image(50, correct_origin=True), [0, 2, 3, 2, 0]
3737
)
3838
np.testing.assert_allclose(kymotrack.sample_from_image(2, correct_origin=True), [0, 2, 3, 2, 0])
3939
np.testing.assert_allclose(kymotrack.sample_from_image(1, correct_origin=True), [0, 2, 2, 2, 0])
@@ -46,8 +46,8 @@ def test_sampling():
4646
)
4747

4848
kymotrack = KymoTrack([0, 1, 2, 3, 4], [0.1, 1.1, 2.1, 3.1, 4.1], test_img, "red", 0)
49-
np.testing.assert_allclose(kymotrack.sample_from_image(
50-
50, correct_origin=True), [0, 2, 3, 2, 0]
49+
np.testing.assert_allclose(
50+
kymotrack.sample_from_image(50, correct_origin=True), [0, 2, 3, 2, 0]
5151
)
5252
np.testing.assert_allclose(kymotrack.sample_from_image(2, correct_origin=True), [0, 2, 3, 2, 0])
5353
np.testing.assert_allclose(kymotrack.sample_from_image(1, correct_origin=True), [0, 2, 2, 2, 0])
@@ -71,10 +71,10 @@ def test_kymotrack_regression_sample_from_image_clamp():
7171
start=np.int64(20e9),
7272
dt=np.int64(1e9),
7373
samples_per_pixel=1,
74-
line_padding=0
74+
line_padding=0,
7575
)
76-
assert np.array_equal(KymoTrack([0, 1], [2, 2], img, "red", 0).sample_from_image(
77-
0, correct_origin=True), [1, 3]
76+
assert np.array_equal(
77+
KymoTrack([0, 1], [2, 2], img, "red", 0).sample_from_image(0, correct_origin=True), [1, 3]
7878
)
7979

8080

@@ -111,6 +111,6 @@ def test_origin_warning_sample_from_image():
111111
"the correct behavior and silence this warning, specify `correct_origin=True`. "
112112
"The old (incorrect) behavior is maintained until the next major release to "
113113
"ensure backward compatibility. To silence this warning use `correct_origin=False`"
114-
)
114+
),
115115
):
116116
tracks[0].sample_from_image(0)

lumicks/pylake/kymotracker/tests/test_io.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
def compare_kymotrack_group(group1, group2):
2121
assert len(group1) == len(group2)
2222
attributes = (
23-
"coordinate_idx", "time_idx", "position", "seconds", "_minimum_observable_duration"
23+
"coordinate_idx",
24+
"time_idx",
25+
"position",
26+
"seconds",
27+
"_minimum_observable_duration",
2428
)
2529
for track1, track2 in zip(group1, group2):
2630
for attr in attributes:

lumicks/pylake/kymotracker/tests/test_kymotrack.py

+28-17
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def test_kymotrack_split(blank_kymo):
592592
np.array([1, 3, 4]),
593593
blank_kymo,
594594
"red",
595-
2 * blank_kymo.line_time_seconds
595+
2 * blank_kymo.line_time_seconds,
596596
)
597597
k2, k3 = k1._split(1)
598598
np.testing.assert_allclose(k2.position, [1])
@@ -716,9 +716,9 @@ def test_kymotrackgroup_flip():
716716
for track, flipped_track in zip(tracks, flipped_tracks):
717717
np.testing.assert_allclose(track._flip(kymo.flip()).position, flipped_track.position)
718718

719-
tracks2 = tracks + KymoTrackGroup([
720-
KymoTrack([], [], copy(kymo), "red", kymo.line_time_seconds)
721-
])
719+
tracks2 = tracks + KymoTrackGroup(
720+
[KymoTrack([], [], copy(kymo), "red", kymo.line_time_seconds)]
721+
)
722722
with pytest.raises(
723723
NotImplementedError,
724724
match=re.escape(
@@ -813,12 +813,15 @@ def test_binding_profile_histogram():
813813
KymoTrackGroup([])._histogram_binding_profile(3, 0.2, 4)
814814

815815

816-
@pytest.mark.parametrize("discrete, exclude_ambiguous_dwells, ref_value", [
817-
(False, True, 1.002547),
818-
(False, False, 1.25710457),
819-
(True, True, 1.46272938),
820-
(True, False, 1.73359969),
821-
])
816+
@pytest.mark.parametrize(
817+
"discrete, exclude_ambiguous_dwells, ref_value",
818+
[
819+
(False, True, 1.002547),
820+
(False, False, 1.25710457),
821+
(True, True, 1.46272938),
822+
(True, False, 1.73359969),
823+
],
824+
)
822825
def test_fit_binding_times(
823826
blank_kymo, blank_kymo_track_args, discrete, exclude_ambiguous_dwells, ref_value
824827
):
@@ -875,10 +878,13 @@ def test_fit_binding_times_warning(blank_kymo_track_args):
875878
ktg.fit_binding_times(1, observed_minimum=False)
876879

877880

878-
@pytest.mark.parametrize("observed_minimum, ref_minima", [
879-
(False, [10e-4, 10e-4, 10e-3, 10e-3]),
880-
(True, [0.002, 0.002, 0.02, 0.02]),
881-
])
881+
@pytest.mark.parametrize(
882+
"observed_minimum, ref_minima",
883+
[
884+
(False, [10e-4, 10e-4, 10e-3, 10e-3]),
885+
(True, [0.002, 0.002, 0.02, 0.02]),
886+
],
887+
)
882888
def test_multi_kymo_dwell(observed_minimum, ref_minima):
883889
kymos = [
884890
_kymo_from_array(np.zeros((10, 10, 3)), "rgb", line_time_seconds=time, pixel_size_um=size)
@@ -894,7 +900,9 @@ def test_multi_kymo_dwell(observed_minimum, ref_minima):
894900

895901
# Normal use case
896902
dwell, obs_min, obs_max, removed, dt = KymoTrackGroup._extract_dwelltime_data_from_groups(
897-
[KymoTrackGroup([k1, k2]), KymoTrackGroup([k3, k4])], False, observed_minimum=observed_minimum,
903+
[KymoTrackGroup([k1, k2]), KymoTrackGroup([k3, k4])],
904+
False,
905+
observed_minimum=observed_minimum,
898906
)
899907
assert removed is False
900908
np.testing.assert_allclose(dwell, [0.002, 0.003, 0.02, 0.02])
@@ -904,7 +912,9 @@ def test_multi_kymo_dwell(observed_minimum, ref_minima):
904912

905913
# Drop one "empty" dwell
906914
dwell, obs_min, obs_max, removed, dt = KymoTrackGroup._extract_dwelltime_data_from_groups(
907-
[KymoTrackGroup([k1, k2]), KymoTrackGroup([k3, k4, k5])], False, observed_minimum=observed_minimum
915+
[KymoTrackGroup([k1, k2]), KymoTrackGroup([k3, k4, k5])],
916+
False,
917+
observed_minimum=observed_minimum,
908918
)
909919
np.testing.assert_allclose(dwell, [0.002, 0.003, 0.02, 0.02])
910920
np.testing.assert_allclose(obs_min, ref_minima)
@@ -968,7 +978,8 @@ def test_missing_minimum_time(blank_kymo):
968978
(1.90610454, 5.84528685),
969979
(0.45196325, 0.54803675),
970980
(1.90610454, 5.84528685),
971-
), (
981+
),
982+
(
972983
20,
973984
(0.65421428, 0.34578572),
974985
(2.08205178, 10.81570587),

lumicks/pylake/kymotracker/tests/test_peakfinding.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ def test_bounds_to_centroid_data(bounds, selection_ref, center_ref, weights_ref)
141141
# fmt:on
142142
)
143143
def test_unbiased_centroid_estimator(data, ref_estimate):
144-
np.testing.assert_allclose(
145-
unbiased_centroid(np.array((3.5, 3.5)), data), ref_estimate
146-
)
144+
np.testing.assert_allclose(unbiased_centroid(np.array((3.5, 3.5)), data), ref_estimate)
147145

148146

149147
@pytest.mark.parametrize(

lumicks/pylake/kymotracker/tests/test_refinement.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ def test_refinement_with_background(loc, ref_count):
107107

108108
def test_refinement_error(kymo_integration_test_data):
109109
args = [
110-
[0], [25], kymo_integration_test_data, "red", kymo_integration_test_data.line_time_seconds
110+
[0],
111+
[25],
112+
kymo_integration_test_data,
113+
"red",
114+
kymo_integration_test_data.line_time_seconds,
111115
]
112116
with pytest.raises(
113117
ValueError, match=re.escape("track_width must at least be 3 pixels (0.150 [um])")
@@ -255,9 +259,7 @@ def gen_gaussians(locs):
255259
)
256260
group = KymoTrackGroup(
257261
[
258-
KymoTrack(
259-
np.array([0, 1]), np.array([loc, loc]), kymo, "red", kymo.line_time_seconds
260-
)
262+
KymoTrack(np.array([0, 1]), np.array([loc, loc]), kymo, "red", kymo.line_time_seconds)
261263
for loc in locations
262264
]
263265
)
@@ -406,7 +408,9 @@ def test_gaussian_refinement_plotting():
406408
group = KymoTrackGroup(
407409
[
408410
KymoTrack(np.array([0, 2]), np.array([2, 2]), kymo, "red", kymo.line_time_seconds),
409-
KymoTrack(np.array([0, 1, 2]), np.array([4, 4, 4]), kymo, "red", kymo.line_time_seconds),
411+
KymoTrack(
412+
np.array([0, 1, 2]), np.array([4, 4, 4]), kymo, "red", kymo.line_time_seconds
413+
),
410414
]
411415
)
412416

lumicks/pylake/kymotracker/tests/test_stitching.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def test_distance_line_to_point():
1616

1717

1818
def test_stitching(blank_kymo, blank_kymo_track_args):
19-
2019
segment_1 = KymoTrack([0, 1], [0, 1], *blank_kymo_track_args)
2120
segment_2 = KymoTrack([2, 3], [2, 3], *blank_kymo_track_args)
2221
segment_3 = KymoTrack([2, 3], [0, 0], *blank_kymo_track_args)
@@ -52,14 +51,14 @@ def test_stitching(blank_kymo, blank_kymo_track_args):
5251

5352
# Check whether the alignment has to work in both directions
5453
# - and - should connect
55-
track1, track2 = KymoTrack(
56-
[0, 1], [0, 0], *blank_kymo_track_args), KymoTrack([2, 3], [0, 0], *blank_kymo_track_args
54+
track1, track2 = KymoTrack([0, 1], [0, 0], *blank_kymo_track_args), KymoTrack(
55+
[2, 3], [0, 0], *blank_kymo_track_args
5756
)
5857
assert len(stitch_kymo_lines([track1, track2], radius, 1, 2)) == 1
5958

6059
# - and | should not connect.
61-
track1, track2 = KymoTrack(
62-
[0, 1], [0, 0], *blank_kymo_track_args), KymoTrack([2, 3], [0, 1], *blank_kymo_track_args
60+
track1, track2 = KymoTrack([0, 1], [0, 0], *blank_kymo_track_args), KymoTrack(
61+
[2, 3], [0, 1], *blank_kymo_track_args
6362
)
6463
assert len(stitch_kymo_lines([track1, track2], radius, 1, 2)) == 2
6564

lumicks/pylake/nb_widgets/tests/test_kymotracker_widget.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class MockLabel:
1616
def __init__(self):
1717
self.value = ""
1818

19+
1920
def calibrate_to_kymo(kymo):
2021
return (
2122
lambda coord_idx: kymo.pixelsize_um[0] * coord_idx,
@@ -29,7 +30,8 @@ def test_widget_open(kymograph):
2930

3031
def test_parameters_kymo(kymograph):
3132
"""Test whether the parameter setting is passed correctly to the algorithm. By setting the threshold to different
32-
values we can check which tracks are detected and use that to verify that the parameter is used."""
33+
values we can check which tracks are detected and use that to verify that the parameter is used.
34+
"""
3335
kymo_widget = KymoWidgetGreedy(kymograph, "red", axis_aspect_ratio=1, use_widgets=False)
3436
kymo_widget._algorithm_parameters["pixel_threshold"].value = 30
3537
kymo_widget._track_all()

lumicks/pylake/population/tests/data/generate_trace_data.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ def generate_parameters(n_states):
1212
}
1313

1414

15-
def generate_trace(n_states, initial_state_prob, transition_prob, means, st_devs, n_frames=100, seed=123):
15+
def generate_trace(
16+
n_states, initial_state_prob, transition_prob, means, st_devs, n_frames=100, seed=123
17+
):
1618
"""Generate a time trace from HMM parameters.
1719
1820
Parameters

0 commit comments

Comments
 (0)