2525
2626# this should be moved in probeinterface but later
2727_toy_probes = {
28- "Neuropixel -384" : dict (
28+ "Neuropixels1 -384" : dict (
2929 num_columns = 4 ,
3030 num_contact_per_column = [96 ] * 4 ,
3131 xpitch = 16 ,
3434 contact_shapes = "square" ,
3535 contact_shape_params = {"width" : 12 },
3636 ),
37- "Neuropixel-128" : dict (
37+ "Neuropixels2-384" : dict (
38+ num_columns = 2 ,
39+ num_contact_per_column = [192 ] * 2 ,
40+ xpitch = 32 ,
41+ ypitch = 15 ,
42+ contact_shapes = "square" ,
43+ contact_shape_params = {"width" : 12 },
44+ ),
45+ "Neuropixels1-128" : dict (
3846 num_columns = 4 ,
3947 num_contact_per_column = [32 ] * 4 ,
4048 xpitch = 16 ,
@@ -69,6 +77,8 @@ def make_one_displacement_vector(
6977):
7078 """
7179 Generates a toy displacement vector with ziagzag or bumps patterns.
80+ This displacement vector has no amplitde, this generate only the shape
81+ in the range [-0.5, 0.5]
7282
7383 Parameters
7484 ----------
@@ -141,8 +151,19 @@ def make_one_displacement_vector(
141151 else :
142152 displacement_vector [ind0 :ind1 ] = - 0.5
143153
154+ elif drift_mode == "random_walk" :
155+ rg = np .random .RandomState (seed = seed )
156+ steps = rg .random_integers (low = 0 , high = 1 , size = num_samples )
157+ steps = steps .astype ("float64" )
158+ # 0 -> -1 and 1 -> 1
159+ steps = steps * 2 - 1
160+ steps [:start_drift_index ] = 0
161+ steps [end_drift_index :] = 0
162+ displacement_vector = np .cumsum (steps , dtype = "float64" )
163+ displacement_vector /= np .max (np .abs (displacement_vector )) * 2
164+
144165 else :
145- raise ValueError ("drift_mode must be 'zigzag' or 'bump'" )
166+ raise ValueError ("drift_mode must be 'zigzag' or 'bump' or 'random_walk' " )
146167
147168 return displacement_vector * amplitude_factor
148169
@@ -151,8 +172,8 @@ def generate_displacement_vector(
151172 duration ,
152173 unit_locations ,
153174 displacement_sampling_frequency = 5.0 ,
154- drift_start_um = [0 , 20 .0 ],
155- drift_stop_um = [0 , - 20 .0 ],
175+ drift_start_um = [0 , 30 .0 ],
176+ drift_stop_um = [0 , - 30 .0 ],
156177 drift_step_um = 1 ,
157178 motion_list = [
158179 dict (
@@ -199,6 +220,8 @@ def generate_displacement_vector(
199220
200221 Returns
201222 -------
223+ unit_displacements : numpy.ndarray
224+ The final per unit, displacement vector with shape (num_times, num_units, 2)
202225 displacement_vectors : numpy.ndarray
203226 The drift vector is a numpy array with shape (num_times, 2, num_motions)
204227 num_motions is generally 1, but can be > 1 in case of combining several drift vectors
@@ -234,7 +257,9 @@ def generate_displacement_vector(
234257 ** motion_kwargs ,
235258 seed = seed ,
236259 )
260+
237261 one_displacement = one_displacement [:, np .newaxis ] * (drift_stop_um - drift_start_um ) + mid
262+
238263 displacement_vectors .append (one_displacement [:, :, np .newaxis ])
239264
240265 if non_rigid_gradient is None :
@@ -253,14 +278,36 @@ def generate_displacement_vector(
253278
254279 displacement_vectors = np .concatenate (displacement_vectors , axis = 2 )
255280
256- return displacement_vectors , displacement_unit_factor , displacement_sampling_frequency , displacements_steps
281+ # unit_displacements is the sum of all discplacements (times, units, direction_x_y)
282+ unit_displacements = np .zeros ((displacement_vectors .shape [0 ], num_units , 2 ))
283+ for direction in (0 , 1 ):
284+ # x and y
285+ for i in range (displacement_vectors .shape [2 ]):
286+ m = displacement_vectors [:, direction , i ][:, np .newaxis ] * displacement_unit_factor [:, i ][np .newaxis , :]
287+ unit_displacements [:, :, direction ] += m
288+
289+ lim0 = min (drift_start_um [direction ], drift_stop_um [direction ])
290+ lim1 = max (drift_start_um [direction ], drift_stop_um [direction ])
291+ if np .min (unit_displacements [:, :, direction ]) < lim0 or np .max (unit_displacements [:, :, direction ]) > lim1 :
292+ raise ValueError (
293+ "unit_displacements is too big when combining several motion (with motion_list)."
294+ "Please consider a smaller 'amplitude_factor' for each motion"
295+ )
296+
297+ return (
298+ unit_displacements ,
299+ displacement_vectors ,
300+ displacement_unit_factor ,
301+ displacement_sampling_frequency ,
302+ displacements_steps ,
303+ )
257304
258305
259306def generate_drifting_recording (
260307 num_units = 250 ,
261308 duration = 600.0 ,
262309 sampling_frequency = 30000.0 ,
263- probe_name = "Neuropixel -128" ,
310+ probe_name = "Neuropixels1 -128" ,
264311 generate_probe_kwargs = None ,
265312 generate_unit_locations_kwargs = dict (
266313 margin_um = 20.0 ,
@@ -269,6 +316,9 @@ def generate_drifting_recording(
269316 minimum_distance = 18.0 ,
270317 max_iteration = 100 ,
271318 distance_strict = False ,
319+ distribution = "uniform" ,
320+ # distribution="multimodal",
321+ # num_modes=2,
272322 ),
273323 generate_displacement_vector_kwargs = dict (
274324 displacement_sampling_frequency = 5.0 ,
@@ -311,7 +361,7 @@ def generate_drifting_recording(
311361 The duration in seconds.
312362 sampling_frequency : float, dfault: 30000.
313363 The sampling frequency.
314- probe_name : str, default: "Neuropixel -128"
364+ probe_name : str, default: "Neuropixels1 -128"
315365 The probe type if generate_probe_kwargs is None.
316366 generate_probe_kwargs : None or dict
317367 A dict to generate the probe, this supersede probe_name when not None.
@@ -371,17 +421,13 @@ def generate_drifting_recording(
371421 ** generate_unit_locations_kwargs ,
372422 )
373423
374- displacement_vectors , displacement_unit_factor , displacement_sampling_frequency , displacements_steps = (
375- generate_displacement_vector (duration , unit_locations [:, :2 ], seed = seed , ** generate_displacement_vector_kwargs )
376- )
377-
378- # unit_displacements is the sum of all discplacements (times, units, direction_x_y)
379- unit_displacements = np .zeros ((displacement_vectors .shape [0 ], num_units , 2 ))
380- for direction in (0 , 1 ):
381- # x and y
382- for i in range (displacement_vectors .shape [2 ]):
383- m = displacement_vectors [:, direction , i ][:, np .newaxis ] * displacement_unit_factor [:, i ][np .newaxis , :]
384- unit_displacements [:, :, direction ] += m
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 )
385431
386432 # unit_params need to be fixed before the displacement steps
387433 generate_templates_kwargs = generate_templates_kwargs .copy ()
0 commit comments