def get_performance_curves(animal, data):
    trajs = [s.trajectories for s in data[animal]]
    slices = [
        process_trajectories.clump_trajectories(traj, crop) for traj in trajs
    ]
    intervals = [[len(traj[x, :]) / frames_per_second for x in s[1:]]
                 for traj, s in zip(trajs, slices)]
    return [np.mean(i) for i in intervals], [np.std(i) for i in intervals]
def get_trajectory_slices(animal, session, data):
    traj = data[animal][session].trajectories
    slices = process_trajectories.clump_trajectories(traj, crop)
    return slices
def get_motor_learning_curve(animal, data, trials):
    traj = data[animal][0].trajectories
    s = process_trajectories.clump_trajectories(traj, crop)
    return [(s[i].stop - s[i].start) / frames_per_second for i in trials]
def get_slice_video(data, animal, session, trial):
    traj = data[animal][session].trajectories
    slices = process_trajectories.clump_trajectories(traj, crop)
    return traj, slices[trial]
def plot_slice_video(data, animal, session, trial):
    traj = data[animal][session].trajectories
    slices = process_trajectories.clump_trajectories(traj, crop)
    plot(traj[slices[trial]])
def play_slice_video(data, animal, session, trial):
    traj = data[animal][session].trajectories
    slices = process_trajectories.clump_trajectories(traj, crop)
    video_player.play_video(data[animal][session].video, 0,
                            slices[trial].start, slices[trial].stop)
import plot_utilities as pltutils
import matplotlib.pyplot as plt

if not 'data' in locals():
    #    data = load_data.load_pickle(r'G:/Homework/trajectories.pickle')
    data = load_data.load_pickle(
        r'C:/Users/gonca_000/Documents/Insync/[email protected]/protocols/shuttling/data/trajectories_week1.pickle'
    )
    process_trajectories.rebase_video_path(data, 'D:')

width_pixel_to_cm = 50.0 / 1280.0
frames_per_second = 120.0

crop = [100, 1100]
traj = data[0][4].trajectories
slices = process_trajectories.clump_trajectories(traj, crop)
trajectory_interval = [len(traj[x, 0]) / frames_per_second for x in slices[1:]]
progression_speed = [
    np.diff(traj[x, 0]) * width_pixel_to_cm * frames_per_second
    for x in slices[1:]
]
average_speed = [np.mean(s) for s in progression_speed]


def clump_trajectories(trajectories, crop=[0, 1300], minpathlength=100):
    mask = np.ma.masked_outside(trajectories[:, 0], crop[0], crop[1])
    clump_slices = np.ma.clump_unmasked(mask)
    return [
        (s, 'right' if trajectories[s.start, 0] < 640 else 'left')
        for s in clump_slices
        if s.stop - s.start >= minpathlength and trajectories[s.start, 1] < 650
Esempio n. 8
0
    return [
        s for s in slices if any(trajectories[s][:, 0] < left) and any(
            trajectories[s][:, 0] > right)
    ]


def swap_head_tail(trajectories):
    trajectories[:, [0, 1, 2, 3]] = trajectories[:, [2, 3, 0, 1]]


trajectories = [np.genfromtxt(path + r'/trajectories.csv') for path in paths]
labels = [
    proctraj.load_trajectory_labels(path + r'/trajectory_labels.csv')
    for path in paths
]
slices = [proctraj.clump_trajectories(t) for t in trajectories]
[swap_head_tail(trajectory) for trajectory in trajectories[10:14]]

unstable_generator = [(i for i, label in enumerate(session)
                       if label['state'] == 'unstable') for session in labels]
unstable = [next(gen) for gen in unstable_generator]

up1t = np.array(
    [t[s[i - 3]] for i, s, t in zip(unstable, slices, trajectories)])
up2t = np.array(
    [t[s[i - 2]] for i, s, t in zip(unstable, slices, trajectories)])
u1t = np.array(
    [t[s[i - 1]] for i, s, t in zip(unstable, slices, trajectories)])
u2t = np.array(
    [t[s[i + 1]] for i, s, t in zip(unstable, slices, trajectories)])