コード例 #1
0
def test_remove_bad_channels():
    num_channels = 4
    sampling_frequency = 30000.
    durations = [10.325, 3.5]

    num_segments = len(durations)
    num_timepoints = [int(sampling_frequency * d) for d in durations]

    traces_list = []
    for i in range(num_segments):
        traces = np.random.randn(num_timepoints[i], num_channels).astype('float32')
        # one channel have big noise
        traces[:, 1] *= 10
        times = np.arange(num_timepoints[i]) / sampling_frequency
        traces += np.sin(2 * np.pi * 50 * times)[:, None]
        traces_list.append(traces)
    rec = NumpyRecording(traces_list, sampling_frequency)

    probe = generate_linear_probe(num_elec=num_channels)
    probe.set_device_channel_indices(np.arange(num_channels))
    rec.set_probe(probe, in_place=True)

    rec2 = remove_bad_channels(rec, bad_threshold=5.)

    # Check that the noisy channel is taken out
    assert np.array_equal(rec2.get_channel_ids(), [0, 2, 3]), "wrong channel detected."
    # Check that the number of segments is maintained after preprocessor
    assert np.array_equal(rec2.get_num_segments(), rec.get_num_segments()), "wrong numbber of segments."
    # Check that the size of the segments os maintained after preprocessor
    assert np.array_equal(*([r.get_num_frames(x) for x in range(rec.get_num_segments())] for r in
                            [rec, rec2])), "wrong lenght of resulting segments."
    # Check that locations are mantained
    assert np.array_equal(rec.get_channel_locations()[[0, 2, 3]],
                          rec2.get_channel_locations()), "wrong channels locations."
コード例 #2
0
def test_ChannelSliceRecording():
    num_seg = 2
    num_chan = 3
    num_samples = 30
    sampling_frequency = 10000
    dtype = 'int16'

    file_paths = [f'test_BinaryRecordingExtractor_{i}.raw' for i in range(num_seg)]
    for i in range(num_seg):
        traces = np.memmap(file_paths[i], dtype=dtype, mode='w+', shape=(num_samples, num_chan))
        traces[:] = np.arange(3)[None, :]
    rec = BinaryRecordingExtractor(file_paths, sampling_frequency, num_chan, dtype)

    # keep original ids
    rec_sliced = ChannelSliceRecording(rec, channel_ids=[0, 2])
    assert np.all(rec_sliced.get_channel_ids() == [0, 2])
    traces = rec_sliced.get_traces(segment_index=1)
    assert traces.shape[1] == 2
    traces = rec_sliced.get_traces(segment_index=1, channel_ids=[0, 2])
    assert traces.shape[1] == 2
    traces = rec_sliced.get_traces(segment_index=1, channel_ids=[2, 0])
    assert traces.shape[1] == 2
    
    assert np.allclose(rec_sliced.get_times(0), rec.get_times(0))
    
    # with channel ids renaming
    rec_sliced2 = ChannelSliceRecording(rec, channel_ids=[0, 2], renamed_channel_ids=[3, 4])
    assert np.all(rec_sliced2.get_channel_ids() == [3, 4])
    traces = rec_sliced2.get_traces(segment_index=1)
    assert traces.shape[1] == 2
    assert np.all(traces[:, 0] == 0)
    assert np.all(traces[:, 1] == 2)

    traces = rec_sliced2.get_traces(segment_index=1, channel_ids=[4, 3])
    assert traces.shape[1] == 2
    assert np.all(traces[:, 0] == 2)
    assert np.all(traces[:, 1] == 0)

    # with probe and after save()
    probe = pi.generate_linear_probe(num_elec=num_chan)
    probe.set_device_channel_indices(np.arange(num_chan))
    rec_p = rec.set_probe(probe)
    rec_sliced3 = ChannelSliceRecording(rec_p, channel_ids=[0, 2], renamed_channel_ids=[3, 4])
    probe3 = rec_sliced3.get_probe()
    locations3 = probe3.contact_positions
    cache_folder = Path('./my_cache_folder')
    folder = cache_folder / 'sliced_recording'
    rec_saved = rec_sliced3.save(folder=folder, chunk_size=10, n_jobs=2)
    probe = rec_saved.get_probe()
    assert np.array_equal(locations3, rec_saved.get_channel_locations())
    traces3 = rec_saved.get_traces(segment_index=0)
    assert np.all(traces3[:, 0] == 0)
    assert np.all(traces3[:, 1] == 2)
コード例 #3
0
def test_generate():
    probe = generate_dummy_probe()
    probegroup = generate_dummy_probe_group()
    
    tetrode = generate_tetrode()
    
    multi_columns = generate_multi_columns_probe(num_columns=3,
                num_elec_per_column=[10, 12, 10],
                xpitch=22, ypitch=20,
                y_shift_per_column=[0, -10, 0])
    
    linear = generate_linear_probe(num_elec=16,  ypitch=20,
                    electrode_shapes='square', electrode_shape_params={'width': 15})
    
    multi_shank = generate_multi_shank()
コード例 #4
0
def generate_recording(
        num_channels=2,
        sampling_frequency=30000.,  # in Hz
        durations=[10.325, 3.5],  #  in s for 2 segments
):
    num_segments = len(durations)
    num_timepoints = [int(sampling_frequency * d) for d in durations]

    traces_list = []
    for i in range(num_segments):
        traces = np.random.randn(num_timepoints[i],
                                 num_channels).astype('float32')
        times = np.arange(num_timepoints[i]) / sampling_frequency
        traces += np.sin(2 * np.pi * 50 * times)[:, None]
        traces_list.append(traces)
    recording = NumpyRecording(traces_list, sampling_frequency)

    probe = generate_linear_probe(num_elec=num_channels)
    probe.set_device_channel_indices(np.arange(num_channels))
    recording.set_probe(probe, in_place=True)

    return recording
コード例 #5
0
# A `Shank` is link to a `Probe` object and can also retrieve
# positions, electrode shapes, etc.:

for i, shank in enumerate(multi_shank.get_shanks()):
    print('shank', i)
    print(shank.__class__)
    print(shank.get_electrode_count())
    print(shank.electrode_positions.shape)

##############################################################################
# Another option to create multi-shank probes is to create several `Shank`
# objects as separate probes and then combine then into a single `Probe` object

# generate a 2 shanks linear
probe0 = generate_linear_probe(num_elec=16,
                               ypitch=20,
                               electrode_shapes='square',
                               electrode_shape_params={'width': 12})
probe1 = probe0.copy()
probe1.move([100, 0])

multi_shank = combine_probes([probe0, probe1])

##############################################################################

print(multi_shank.shank_ids)

##############################################################################

plot_probe(multi_shank)

plt.show()
コード例 #6
0
print('Sampling frequency = {} Hz'.format(recording.get_sampling_frequency()))
print('Num. timepoints seg0= {}'.format(recording.get_num_segments()))
print('Num. timepoints seg0= {}'.format(
    recording.get_num_frames(segment_index=0)))
print('Num. timepoints seg1= {}'.format(
    recording.get_num_frames(segment_index=1)))

##############################################################################
# The geometry of the Probe is handle with the :code:`probeinterface`.
# Let's generate a linear probe:

from probeinterface import generate_linear_probe
from probeinterface.plotting import plot_probe

probe = generate_linear_probe(num_elec=7,
                              ypitch=20,
                              contact_shapes='circle',
                              contact_shape_params={'radius': 6})

# the probe has to be wired to the recording
probe.set_device_channel_indices(np.arange(7))

recording = recording.set_probe(probe)
plot_probe(probe)

##############################################################################
# Some extractors also implement a :code:`write` function.

file_paths = ['traces0.raw', 'traces1.raw']
se.BinaryRecordingExtractor.write_recording(recording, file_paths)

##############################################################################
コード例 #7
0
    tetrode.move([i * 50, 0])
    probegroup.add_probe(tetrode)
probegroup.set_global_device_channel_indices(np.arange(16))

df = probegroup.to_dataframe()
df

plot_probe_group(probegroup, with_channel_index=True, same_axes=True)

##############################################################################
# Generate a linear probe:
# 

from probeinterface import generate_linear_probe

linear_probe = generate_linear_probe(num_elec=16, ypitch=20)
plot_probe(linear_probe, with_channel_index=True)

##############################################################################
# Generate a multi-column probe:
# 

from probeinterface import generate_multi_columns_probe

multi_columns = generate_multi_columns_probe(num_columns=3,
                                             num_contact_per_column=[10, 12, 10],
                                             xpitch=22, ypitch=20,
                                             y_shift_per_column=[0, -10, 0],
                                             contact_shapes='square', contact_shape_params={'width': 12})
plot_probe(multi_columns, with_channel_index=True, )
コード例 #8
0
import matplotlib.pyplot as plt

from probeinterface import Probe, ProbeGroup
from probeinterface.plotting import plot_probe, plot_probe_group
from probeinterface import generate_multi_columns_probe, generate_linear_probe

##############################################################################
# Some examples in 2d

fig, ax = plt.subplots()

probe0 = generate_multi_columns_probe()
plot_probe(probe0, ax=ax)

# make some colors for each probe
probe1 = generate_linear_probe(num_elec=9)
probe1.rotate(theta=15)
probe1.move([200, 0])
plot_probe(probe1, ax=ax, electrode_colors=['red', 'cyan', 'yellow'] * 3)

# prepare yourself for carnival!
probe2 = generate_linear_probe()
probe2.rotate(theta=-35)
probe2.move([400, 0])
n = probe2.get_electrode_count()
rand_colors = np.random.rand(n, 3)
plot_probe(probe2,
           ax=ax,
           electrode_colors=rand_colors,
           probe_shape_kwargs={
               'facecolor': 'purple',