Skip to content

Commit 350697f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6ba91e8 commit 350697f

3 files changed

Lines changed: 63 additions & 46 deletions

File tree

src/spikeinterface/core/generate.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,19 +2156,18 @@ def generate_channel_locations(num_channels, num_columns, contact_spacing_um):
21562156
return channel_locations
21572157

21582158

2159-
21602159
def _generate_multimodal(rng, size, num_modes, lim0, lim1):
21612160
bins = np.linspace(lim0, lim1, 10000)
21622161
bin_step = bins[1] - bins[0]
21632162
prob = np.zeros(bins.size)
21642163
mode_step = (lim1 - lim0) / (num_modes + 1)
21652164
for i in range(num_modes):
21662165
center = mode_step * (i + 1)
2167-
sigma = mode_step / 5.
2168-
prob += np.exp( -(bins - center)**2 / ( 2 * sigma **2))
2166+
sigma = mode_step / 5.0
2167+
prob += np.exp(-((bins - center) ** 2) / (2 * sigma**2))
21692168
prob /= np.sum(prob)
21702169
choices = np.random.choice(np.arange(bins.size), size, p=prob)
2171-
values = bins[choices] + rng.uniform(low=-bin_step/2, high=bin_step/2, size=size)
2170+
values = bins[choices] + rng.uniform(low=-bin_step / 2, high=bin_step / 2, size=size)
21722171
return values
21732172

21742173

@@ -2227,7 +2226,7 @@ def generate_unit_locations(
22272226
How units are spread.
22282227
"uniform" is units everywhere
22292228
"multimodal" mimic the distribution of units 'by layer' on the 'y' axis (dim=1)
2230-
Important note, when using multimodal in conjonction of minimum_distance not None, there is not garanty
2229+
Important note, when using multimodal in conjonction of minimum_distance not None, there is not garanty
22312230
of a true multimodal because units that do not respect the distance of move again and are most chance to be in between layers.
22322231
num_modes : int, default 2
22332232
In case of distribution="multimodal", this is the number of modes (layers)
@@ -2275,9 +2274,11 @@ def generate_unit_locations(
22752274
units_locations[:, 0][renew_inds] = rng.uniform(minimum_x, maximum_x, size=renew_inds.size)
22762275
if distribution == "uniform":
22772276
units_locations[:, 1][renew_inds] = rng.uniform(minimum_y, maximum_y, size=renew_inds.size)
2278-
2277+
22792278
elif distribution == "multimodal":
2280-
units_locations[:, 1][renew_inds] = _generate_multimodal(rng, renew_inds.size, num_modes, minimum_y, maximum_y)
2279+
units_locations[:, 1][renew_inds] = _generate_multimodal(
2280+
rng, renew_inds.size, num_modes, minimum_y, maximum_y
2281+
)
22812282
units_locations[:, 2][renew_inds] = rng.uniform(minimum_z, maximum_z, size=renew_inds.size)
22822283

22832284
else:

src/spikeinterface/generation/drifting_generator.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,18 @@ def make_one_displacement_vector(
150150
displacement_vector[ind0:ind1] = 0.5
151151
else:
152152
displacement_vector[ind0:ind1] = -0.5
153-
153+
154154
elif drift_mode == "random_walk":
155155
rg = np.random.RandomState(seed=seed)
156156
steps = rg.random_integers(low=0, high=1, size=num_samples)
157-
steps = steps.astype('float64')
157+
steps = steps.astype("float64")
158158
# 0 -> -1 and 1 -> 1
159-
steps = steps * 2 -1
159+
steps = steps * 2 - 1
160160
steps[:start_drift_index] = 0
161161
steps[end_drift_index:] = 0
162-
displacement_vector = np.cumsum(steps, dtype='float64')
162+
displacement_vector = np.cumsum(steps, dtype="float64")
163163
displacement_vector /= np.max(np.abs(displacement_vector)) * 2
164164

165-
166165
else:
167166
raise ValueError("drift_mode must be 'zigzag' or 'bump' or 'random_walk'")
168167

@@ -276,9 +275,8 @@ def generate_displacement_vector(
276275
factors = 1 - factors
277276
f = np.abs(non_rigid_gradient)
278277
displacement_unit_factor[:, m] = factors * (1 - f) + f
279-
280-
displacement_vectors = np.concatenate(displacement_vectors, axis=2)
281278

279+
displacement_vectors = np.concatenate(displacement_vectors, axis=2)
282280

283281
# unit_displacements is the sum of all discplacements (times, units, direction_x_y)
284282
unit_displacements = np.zeros((displacement_vectors.shape[0], num_units, 2))
@@ -296,7 +294,13 @@ def generate_displacement_vector(
296294
"Please consider a smaller 'amplitude_factor' for each motion"
297295
)
298296

299-
return unit_displacements, displacement_vectors, displacement_unit_factor, displacement_sampling_frequency, displacements_steps
297+
return (
298+
unit_displacements,
299+
displacement_vectors,
300+
displacement_unit_factor,
301+
displacement_sampling_frequency,
302+
displacements_steps,
303+
)
300304

301305

302306
def generate_drifting_recording(
@@ -417,9 +421,13 @@ def generate_drifting_recording(
417421
**generate_unit_locations_kwargs,
418422
)
419423

420-
unit_displacements, displacement_vectors, displacement_unit_factor, displacement_sampling_frequency, displacements_steps = (
421-
generate_displacement_vector(duration, unit_locations[:, :2], seed=seed, **generate_displacement_vector_kwargs)
422-
)
424+
(
425+
unit_displacements,
426+
displacement_vectors,
427+
displacement_unit_factor,
428+
displacement_sampling_frequency,
429+
displacements_steps,
430+
) = generate_displacement_vector(duration, unit_locations[:, :2], seed=seed, **generate_displacement_vector_kwargs)
423431

424432
# unit_params need to be fixed before the displacement steps
425433
generate_templates_kwargs = generate_templates_kwargs.copy()

src/spikeinterface/generation/tests/test_drifing_generator.py

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,48 @@ def test_generate_displacement_vector():
3333
unit_locations[:, 1] = np.linspace(-50, 50, 10)
3434

3535
# one motion Y only
36-
unit_displacements, displacement_vectors, displacement_unit_factor, displacement_sampling_frequency, displacements_steps = (
37-
generate_displacement_vector(duration, unit_locations)
38-
)
36+
(
37+
unit_displacements,
38+
displacement_vectors,
39+
displacement_unit_factor,
40+
displacement_sampling_frequency,
41+
displacements_steps,
42+
) = generate_displacement_vector(duration, unit_locations)
3943
assert unit_locations.shape[0] == unit_displacements.shape[1]
4044
assert unit_locations.shape[0] == displacement_unit_factor.shape[0]
4145
assert displacement_vectors.shape[2] == displacement_unit_factor.shape[1]
4246
assert displacement_vectors.shape[2] == 1
4347

4448
# two motion X and Y
45-
unit_displacements, displacement_vectors, displacement_unit_factor, displacement_sampling_frequency, displacements_steps = (
46-
generate_displacement_vector(
47-
duration,
48-
unit_locations,
49-
drift_start_um=[-5, 20.0],
50-
drift_stop_um=[5, -20.0],
51-
motion_list=[
52-
dict(
53-
drift_mode="zigzag",
54-
amplitude_factor=0.7,
55-
non_rigid_gradient=0.4,
56-
t_start_drift=60.0,
57-
t_end_drift=None,
58-
period_s=200,
59-
),
60-
dict(
61-
drift_mode="bump",
62-
amplitude_factor=0.3,
63-
non_rigid_gradient=0.4,
64-
t_start_drift=60.0,
65-
t_end_drift=None,
66-
bump_interval_s=(30, 90.0),
67-
),
68-
],
69-
)
49+
(
50+
unit_displacements,
51+
displacement_vectors,
52+
displacement_unit_factor,
53+
displacement_sampling_frequency,
54+
displacements_steps,
55+
) = generate_displacement_vector(
56+
duration,
57+
unit_locations,
58+
drift_start_um=[-5, 20.0],
59+
drift_stop_um=[5, -20.0],
60+
motion_list=[
61+
dict(
62+
drift_mode="zigzag",
63+
amplitude_factor=0.7,
64+
non_rigid_gradient=0.4,
65+
t_start_drift=60.0,
66+
t_end_drift=None,
67+
period_s=200,
68+
),
69+
dict(
70+
drift_mode="bump",
71+
amplitude_factor=0.3,
72+
non_rigid_gradient=0.4,
73+
t_start_drift=60.0,
74+
t_end_drift=None,
75+
bump_interval_s=(30, 90.0),
76+
),
77+
],
7078
)
7179
assert unit_locations.shape[0] == displacement_unit_factor.shape[0]
7280
assert displacement_vectors.shape[2] == displacement_unit_factor.shape[1]

0 commit comments

Comments
 (0)