def make_continuous_replay(sampling_frequency=SAMPLING_FREQUENCY,
                           track_height=TRACK_HEIGHT,
                           running_speed=RUNNING_SPEED,
                           place_field_means=PLACE_FIELD_MEANS,
                           replay_speedup=REPLAY_SPEEDUP,
                           is_outbound=True):

    replay_speed = running_speed * replay_speedup
    n_samples = int(2 * sampling_frequency * track_height / replay_speed)
    replay_time = simulate_time(n_samples, sampling_frequency)
    true_replay_position = simulate_linear_distance(
        replay_time, track_height, replay_speed)

    # Make inbound or outbound
    replay_time = replay_time[:n_samples // 2]
    if is_outbound:
        true_replay_position = true_replay_position[:n_samples // 2]
    else:
        true_replay_position = true_replay_position[n_samples // 2:]

    min_times_ind = np.argmin(
        np.abs(true_replay_position[:, np.newaxis] - place_field_means),
        axis=0)

    n_neurons = place_field_means.shape[0]
    test_spikes = np.zeros((replay_time.size, n_neurons))
    test_spikes[(min_times_ind, np.arange(n_neurons),)] = 1.0

    return replay_time, test_spikes
def make_continuous_replay(sampling_frequency=SAMPLING_FREQUENCY,
                           track_height=TRACK_HEIGHT,
                           running_speed=RUNNING_SPEED,
                           place_field_means=PLACE_FIELD_MEANS,
                           replay_speedup=REPLAY_SPEEDUP,
                           n_tetrodes=N_TETRODES,
                           n_features=N_FEATURES,
                           mark_spacing=MARK_SPACING):
    replay_speed = running_speed * replay_speedup
    n_samples = int(0.5 * sampling_frequency * 2 * track_height / replay_speed)
    replay_time = simulate_time(n_samples, sampling_frequency)
    true_replay_position = simulate_linear_distance(replay_time, track_height,
                                                    replay_speed)
    place_field_means = place_field_means.reshape(((n_tetrodes, -1)))

    min_times_ind = np.argmin(np.abs(true_replay_position[:, np.newaxis] -
                                     place_field_means.ravel()),
                              axis=0)
    tetrode_ind = (np.ones_like(place_field_means) *
                   np.arange(5)[:, np.newaxis]).ravel()

    test_multiunits = np.full((replay_time.size, n_features, n_tetrodes),
                              np.nan)
    n_neurons = place_field_means.shape[1]

    mark_centers = np.arange(0, n_neurons * mark_spacing, mark_spacing)
    mark_ind = (np.ones_like(place_field_means) * np.arange(4)).ravel()

    for i in range(n_features):
        test_multiunits[(min_times_ind, i,
                         tetrode_ind)] = mark_centers[mark_ind]

    return replay_time, test_multiunits
Exemplo n.º 3
0
def make_simulated_run_data(sampling_frequency=SAMPLING_FREQUENCY,
                            track_height=TRACK_HEIGHT,
                            running_speed=RUNNING_SPEED,
                            n_runs=N_RUNS,
                            place_field_variance=PLACE_FIELD_VARIANCE,
                            place_field_means=PLACE_FIELD_MEANS):
    '''Make simulated data of a rat running back and forth
    on a linear maze with sorted spikes.

    Parameters
    ----------
    sampling_frequency : float, optional
    track_height : float, optional
    running_speed : float, optional
    n_runs : int, optional
    place_field_variance : float, optional
    place_field_means : ndarray, shape (n_neurons,), optional

    Returns
    -------
    time : ndarray, shape (n_time,)
    linear_distance : ndarray, shape (n_time,)
    sampling_frequency : float
    spikes : ndarray, shape (n_time, n_neurons)
    place_fields : ndarray, shape (n_time, n_neurons)

    '''
    n_samples = int(n_runs * sampling_frequency * 2 * track_height /
                    running_speed)

    time = simulate_time(n_samples, sampling_frequency)
    linear_distance = simulate_linear_distance(time, track_height,
                                               running_speed)

    place_fields = np.stack([
        simulate_place_field_firing_rate(
            place_field_mean, linear_distance, variance=place_field_variance)
        for place_field_mean in place_field_means
    ],
                            axis=1)

    spikes = np.stack([
        simulate_neuron_with_place_field(place_field_mean,
                                         linear_distance,
                                         max_rate=15,
                                         variance=place_field_variance,
                                         sampling_frequency=sampling_frequency)
        for place_field_mean in place_field_means.T
    ],
                      axis=1)

    return time, linear_distance, sampling_frequency, spikes, place_fields
def make_simulated_run_data(sampling_frequency=SAMPLING_FREQUENCY,
                            track_height=TRACK_HEIGHT,
                            running_speed=RUNNING_SPEED,
                            n_runs=N_RUNS,
                            place_field_variance=PLACE_FIELD_VARIANCE,
                            place_field_means=PLACE_FIELD_MEANS,
                            n_tetrodes=N_TETRODES):
    '''Make simulated data of a rat running back and forth
    on a linear maze with unclustered spikes.

    Parameters
    ----------
    sampling_frequency : float, optional
    track_height : float, optional
    running_speed : float, optional
    n_runs : int, optional
    place_field_variance : float, optional
    place_field_means : ndarray, shape (n_neurons,), optional

    Returns
    -------
    time : ndarray, shape (n_time,)
    linear_distance : ndarray, shape (n_time,)
    sampling_frequency : float
    multiunits : ndarray, shape (n_time, n_features, n_electrodes)
    multiunits_spikes : ndarray (n_time, n_electrodes)
    place_field_means : ndarray (n_tetrodes, n_place_fields)
    '''
    n_samples = int(n_runs * sampling_frequency * 2 * track_height /
                    running_speed)

    time = simulate_time(n_samples, sampling_frequency)
    linear_distance = simulate_linear_distance(time, track_height,
                                               running_speed)

    multiunits = []
    for place_means in place_field_means.reshape(((n_tetrodes, -1))):
        multiunits.append(
            simulate_multiunit_with_place_fields(
                place_means,
                linear_distance,
                mark_spacing=10,
                n_mark_dims=4,
                sampling_frequency=sampling_frequency))
    multiunits = np.stack(multiunits, axis=-1)
    multiunits_spikes = np.any(~np.isnan(multiunits), axis=1)

    return (time, linear_distance, sampling_frequency, multiunits,
            multiunits_spikes)
def make_simulated_run_data(sampling_frequency=SAMPLING_FREQUENCY,
                            track_height=TRACK_HEIGHT,
                            running_speed=RUNNING_SPEED, n_runs=N_RUNS,
                            place_field_variance=PLACE_FIELD_VARIANCE,
                            place_field_means=PLACE_FIELD_MEANS,
                            make_inbound_outbound_neurons=False):
    '''Make simulated data of a rat running back and forth
    on a linear maze with sorted spikes.

    Parameters
    ----------
    sampling_frequency : float, optional
    track_height : float, optional
    running_speed : float, optional
    n_runs : int, optional
    place_field_variance : float, optional
    place_field_means : ndarray, shape (n_neurons,), optional

    Returns
    -------
    time : ndarray, shape (n_time,)
    linear_distance : ndarray, shape (n_time,)
    sampling_frequency : float
    spikes : ndarray, shape (n_time, n_neurons)
    place_fields : ndarray, shape (n_time, n_neurons)

    '''
    n_samples = int(n_runs * sampling_frequency *
                    2 * track_height / running_speed)

    time = simulate_time(n_samples, sampling_frequency)
    linear_distance = simulate_linear_distance(
        time, track_height, running_speed)

    if not make_inbound_outbound_neurons:
        place_fields = np.stack(
            [simulate_place_field_firing_rate(
                place_field_mean, linear_distance,
                variance=place_field_variance)
             for place_field_mean in place_field_means], axis=1)
        spikes = np.stack([simulate_neuron_with_place_field(
            place_field_mean, linear_distance, max_rate=15,
            variance=place_field_variance,
            sampling_frequency=sampling_frequency)
            for place_field_mean in place_field_means.T], axis=1)
    else:
        trajectory_direction = get_trajectory_direction(linear_distance)
        place_fields = []
        spikes = []
        for direction in np.unique(trajectory_direction):
            is_condition = trajectory_direction == direction
            for place_field_mean in place_field_means:
                place_fields.append(
                    simulate_place_field_firing_rate(
                        place_field_mean, linear_distance,
                        variance=place_field_variance,
                        is_condition=is_condition))
                spikes.append(
                    simulate_neuron_with_place_field(
                        place_field_mean, linear_distance, max_rate=15,
                        variance=place_field_variance,
                        sampling_frequency=sampling_frequency,
                        is_condition=is_condition))

        place_fields = np.stack(place_fields, axis=1)
        spikes = np.stack(spikes, axis=1)

    return time, linear_distance, sampling_frequency, spikes, place_fields