@@ -296,7 +296,7 @@ def generate_sorting_to_inject(
296296 injected_spike_train = injected_spike_train [~ violations ]
297297
298298 if len (injected_spike_train ) > n_injection :
299- injected_spike_train = np .sort (np . random .choice (injected_spike_train , n_injection , replace = False ))
299+ injected_spike_train = np .sort (rng .choice (injected_spike_train , n_injection , replace = False ))
300300
301301 injected_spike_trains [segment_index ][unit_id ] = injected_spike_train
302302
@@ -1519,7 +1519,7 @@ def exp_growth(start_amp, end_amp, duration_ms, tau_ms, sampling_frequency, flip
15191519 return y [:- 1 ]
15201520
15211521
1522- def get_ellipse (positions , center , b = 1 , c = 1 , x_angle = 0 , y_angle = 0 , z_angle = 0 ):
1522+ def get_ellipse (positions , center , x_factor = 1 , y_factor = 1 , x_angle = 0 , y_angle = 0 , z_angle = 0 ):
15231523 """
15241524 Compute the distances to a particular ellipsoid in order to take into account
15251525 spatial inhomogeneities while generating the template. In a carthesian, centered
@@ -1537,7 +1537,7 @@ def get_ellipse(positions, center, b=1, c=1, x_angle=0, y_angle=0, z_angle=0):
15371537 z - z0
15381538
15391539 In this new space, we can compute the radius of the ellipsoidal shape given the same formula
1540- R = X **2 + (Y/b )**2 + (Z/c )**2
1540+ R = (X/x_factor) **2 + (Y/y_factor )**2 + (Z/1 )**2
15411541
15421542 and thus obtain putative amplitudes given the ellipsoidal projections. Note that in case of a=b=1 and
15431543 no rotation, the distance is the same as the euclidean distance
@@ -1555,7 +1555,7 @@ def get_ellipse(positions, center, b=1, c=1, x_angle=0, y_angle=0, z_angle=0):
15551555 Rx = np .zeros ((3 , 3 ))
15561556 Rx [0 , 0 ] = 1
15571557 Rx [1 , 1 ] = np .cos (- x_angle )
1558- Rx [1 , 0 ] = - np .sin (- x_angle )
1558+ Rx [1 , 2 ] = - np .sin (- x_angle )
15591559 Rx [2 , 1 ] = np .sin (- x_angle )
15601560 Rx [2 , 2 ] = np .cos (- x_angle )
15611561
@@ -1573,10 +1573,12 @@ def get_ellipse(positions, center, b=1, c=1, x_angle=0, y_angle=0, z_angle=0):
15731573 Rz [1 , 0 ] = np .sin (- z_angle )
15741574 Rz [1 , 1 ] = np .cos (- z_angle )
15751575
1576- inv_matrix = np . dot ( Rx , Ry , Rz )
1577- P = np . dot ( inv_matrix , p )
1576+ rot_matrix = Rx @ Ry @ Rz
1577+ P = rot_matrix @ p
15781578
1579- return np .sqrt (P [0 ] ** 2 + (P [1 ] / b ) ** 2 + (P [2 ] / c ) ** 2 )
1579+ distances = np .sqrt ((P [0 ] / x_factor ) ** 2 + (P [1 ] / y_factor ) ** 2 + (P [2 ] / 1 ) ** 2 )
1580+
1581+ return distances
15801582
15811583
15821584def generate_single_fake_waveform (
@@ -1632,7 +1634,10 @@ def generate_single_fake_waveform(
16321634 smooth_kernel = np .exp (- (bins ** 2 ) / (2 * smooth_size ** 2 ))
16331635 smooth_kernel /= np .sum (smooth_kernel )
16341636 # smooth_kernel = smooth_kernel[4:]
1637+ old_max = np .max (np .abs (wf ))
16351638 wf = np .convolve (wf , smooth_kernel , mode = "same" )
1639+ new_max = np .max (np .abs (wf ))
1640+ wf *= old_max / new_max
16361641
16371642 # ensure the the peak to be extatly at nbefore (smooth can modify this)
16381643 ind = np .argmin (wf )
@@ -1653,13 +1658,10 @@ def generate_single_fake_waveform(
16531658 recovery_ms = (1.0 , 1.5 ),
16541659 positive_amplitude = (0.1 , 0.25 ),
16551660 smooth_ms = (0.03 , 0.07 ),
1656- spatial_decay = (20 , 40 ),
1661+ spatial_decay = (10.0 , 45.0 ),
16571662 propagation_speed = (250.0 , 350.0 ), # um / ms
1658- b = (0.1 , 1 ),
1659- c = (0.1 , 1 ),
1660- x_angle = (0 , np .pi ),
1661- y_angle = (0 , np .pi ),
1662- z_angle = (0 , np .pi ),
1663+ ellipse_shrink = (0.4 , 1 ),
1664+ ellipse_angle = (0 , np .pi * 2 ),
16631665)
16641666
16651667
@@ -1813,21 +1815,21 @@ def generate_templates(
18131815 distances = get_ellipse (
18141816 channel_locations ,
18151817 units_locations [u ],
1816- 1 ,
1817- 1 ,
1818- 0 ,
1819- 0 ,
1820- 0 ,
1818+ x_factor = 1 ,
1819+ y_factor = 1 ,
1820+ x_angle = 0 ,
1821+ y_angle = 0 ,
1822+ z_angle = 0 ,
18211823 )
18221824 elif mode == "ellipsoid" :
18231825 distances = get_ellipse (
18241826 channel_locations ,
18251827 units_locations [u ],
1826- params [ "b" ][ u ] ,
1827- params ["c " ][u ],
1828- params [ " x_angle" ][ u ] ,
1829- params [ " y_angle" ][ u ] ,
1830- params ["z_angle " ][u ],
1828+ x_factor = 1 ,
1829+ y_factor = params ["ellipse_shrink " ][u ],
1830+ x_angle = 0 ,
1831+ y_angle = 0 ,
1832+ z_angle = params ["ellipse_angle " ][u ],
18311833 )
18321834
18331835 channel_factors = alpha * np .exp (- distances / spatial_decay )
@@ -2166,7 +2168,7 @@ def _generate_multimodal(rng, size, num_modes, lim0, lim1):
21662168 sigma = mode_step / 5.0
21672169 prob += np .exp (- ((bins - center ) ** 2 ) / (2 * sigma ** 2 ))
21682170 prob /= np .sum (prob )
2169- choices = np . random .choice (np .arange (bins .size ), size , p = prob )
2171+ choices = rng .choice (np .arange (bins .size ), size , p = prob )
21702172 values = bins [choices ] + rng .uniform (low = - bin_step / 2 , high = bin_step / 2 , size = size )
21712173 return values
21722174
0 commit comments