Пример #1
0
def load_channel_locations(eid, one=None, probe=None):
    """
    From an eid, get brain locations from Alyx database
    analysis.
    :param eid: session eid or dictionary returned by one.alyx.rest('sessions', 'read', id=eid)
    :param dataset_types: additional spikes/clusters objects to add to the standard list
    :return: channels
    """
    if isinstance(eid, dict):
        ses = eid
        eid = ses['url'][-36:]
    else:
        # need to query alyx. Make sure we have a one client before we hit the endpoint
        if not one:
            one = ONE()
        ses = one.alyx.rest('sessions', 'read', id=eid)
    if isinstance(probe, str):
        probe = [probe]
    labels = probe if probe else [pi['name'] for pi in ses['probe_insertion']]
    channels = Bunch({})
    for label in labels:
        i = [
            i for i, pi in enumerate(ses['probe_insertion'])
            if pi['name'] == label
        ]
        if len(i) == 0:
            continue
        trajs = ses['probe_insertion'][i[0]]['trajectory_estimate']
        if not trajs:
            continue
        # the trajectories are ordered within the serializer: histology processed, histology,
        # micro manipulator, planned so the first is always the desired one
        traj = trajs[0]
        channels[label] = Bunch({
            'atlas_id':
            np.array([ch['brain_region']['id'] for ch in traj['channels']]),
            'acronym':
            np.array(
                [ch['brain_region']['acronym'] for ch in traj['channels']]),
            'x':
            np.array([ch['x'] for ch in traj['channels']]) / 1e6,
            'y':
            np.array([ch['y'] for ch in traj['channels']]) / 1e6,
            'z':
            np.array([ch['z'] for ch in traj['channels']]) / 1e6,
            'axial_um':
            np.array([ch['axial'] for ch in traj['channels']]),
            'lateral_um':
            np.array([ch['lateral'] for ch in traj['channels']])
        })

        # Check that channels mapping matches coordinate on Flatiron
        channel_coord = one.load_dataset(
            eid=eid, dataset_type='channels.localCoordinates')
        if len(traj['channels']) == 0:
            continue
        assert np.all(np.c_[channels[label]['lateral_um'],
                            channels[label]['axial_um']] == channel_coord)

    return channels
Пример #2
0
"""

import numpy as np
from brainbox.ephys_plots import scatter_raster_plot
from brainbox.plot_base import plot_scatter
from oneibl.one import ONE
import matplotlib.pyplot as plt
import matplotlib

one = ONE()

eid = '671c7ea7-6726-4fbe-adeb-f89c2c8e489b'
probe = 'probe00'

spikes = one.load_object(eid, obj='spikes', collection=f'alf/{probe}')
metrics = one.load_dataset(eid, dataset='clusters.metrics', collection=f'alf/{probe}')

# Find the clusters that have been labelled as good and their corresponding spike indices
good_clusters = np.where(metrics.label == 1)
spike_idx = np.where(np.isin(spikes['clusters'], good_clusters))[0]

# Also filter for nans in amplitude and depth
kp_idx = spike_idx[np.where(~np.isnan(spikes['depths'][spike_idx])
                            & ~np.isnan(spikes['amps'][spike_idx]))[0]]

# Get ScatterPlot object
data = scatter_raster_plot(spikes['amps'][kp_idx], spikes['depths'][kp_idx],
                           spikes['times'][kp_idx])

# Add v lines 10s after start and 10s before end or recording
x1 = np.min(spikes['times'][kp_idx] + 100)