neuroprob/utils/neural.py
def bin_data(bin_size, bin_time, spiketimes, track_samples, behaviour_data=None, average_behav=True, binned=False):
    """
    Bin the spike train into a given bin size.
    
    :param int bin_size: desired binning of original time steps into new bin
    :param float bin_time: time step of each original bin or time point
    :param np.array spiketimes: input spikes in train or index format
    :param int track_samples: number of time steps in the recording
    :param tuple behaviour_data: input behavioural time series
    :param bool average_behav: takes the middle element in bins for behavioural data if False
    :param bool binned: spiketimes is a spike train is True, otherwise it is spike time indices
    """
    tbin = bin_size*bin_time
    resamples = int(np.floor(track_samples/bin_size))
    centre = bin_size // 2
    # leave out data with full bins
    
    rcov_t = ()
    if behaviour_data is not None:
        if isinstance(average_behav, list) is False:
            average_behav = [average_behav for _ in range(len(behaviour_data))]
        
        for k, cov_t in enumerate(behaviour_data):
            if average_behav[k]:
                rcov_t += (cov_t[:resamples*bin_size].reshape(resamples, bin_size).mean(1),)
            else:
                rcov_t += (cov_t[centre:resamples*bin_size:bin_size],)
            
    if binned:
        rc_t = spiketimes[:, :resamples*bin_size].reshape(spiketimes.shape[0], resamples, bin_size).sum(-1)
    else:
        units = len(spiketimes)
        rc_t = np.zeros((units, resamples))
        for u in range(units):
            retimes = np.floor(spiketimes[u]/bin_size).astype(int)
            np.add.at(rc_t[u], retimes[retimes < resamples], 1)
        
    return tbin, resamples, rc_t, rcov_t

    Bin the spike train into a given bin size.
    
    :param int bin_size: desired binning of original time steps into new bin
    :param float bin_time: time step of each original bin or time point
    :param np.array spiketimes: input spikes in train or index format
    :param int track_samples: number of time steps in the recording
    :param tuple behaviour_data: input behavioural time series
    :param bool average_behav: takes the middle element in bins for behavioural data if False
    :param bool binned: spiketimes is a spike train is True, otherwise it is spike time indices
    
Bin the spike train into a given bin size.
Bin the spike train into a given bin size .
def bin_data(bin_size, bin_time, spiketimes, track_samples, behaviour_data=None, average_behav=True, binned=False):
    tbin = bin_size*bin_time
    resamples = int(np.floor(track_samples/bin_size))
    centre = bin_size // 2
    rcov_t = ()
    if behaviour_data is not None:
        if isinstance(average_behav, list) is False:
            average_behav = [average_behav for _ in range(len(behaviour_data))]
        for k, cov_t in enumerate(behaviour_data):
            if average_behav[k]:
                rcov_t += (cov_t[:resamples*bin_size].reshape(resamples, bin_size).mean(1),)
            else:
                rcov_t += (cov_t[centre:resamples*bin_size:bin_size],)
    if binned:
        rc_t = spiketimes[:, :resamples*bin_size].reshape(spiketimes.shape[0], resamples, bin_size).sum(-1)
    else:
        units = len(spiketimes)
        rc_t = np.zeros((units, resamples))
        for u in range(units):
            retimes = np.floor(spiketimes[u]/bin_size).astype(int)
            np.add.at(rc_t[u], retimes[retimes < resamples], 1)
    return tbin, resamples, rc_t, rcov_t
def bin_data ( bin_size , bin_time , spiketimes , track_samples , behaviour_data = None , average_behav = True , binned = False ) : tbin = bin_size * bin_time resamples = int ( np . floor ( track_samples / bin_size ) ) centre = bin_size // 2 rcov_t = ( ) if behaviour_data is not None : if isinstance ( average_behav , list ) is False : average_behav = [ average_behav for _ in range ( len ( behaviour_data ) ) ] for k , cov_t in enumerate ( behaviour_data ) : if average_behav [ k ] : rcov_t += ( cov_t [ : resamples * bin_size ] . reshape ( resamples , bin_size ) . mean ( 1 ) , ) else : rcov_t += ( cov_t [ centre : resamples * bin_size : bin_size ] , ) if binned : rc_t = spiketimes [ : , : resamples * bin_size ] . reshape ( spiketimes . shape [ 0 ] , resamples , bin_size ) . sum ( - 1 ) else : units = len ( spiketimes ) rc_t = np . zeros ( ( units , resamples ) ) for u in range ( units ) : retimes = np . floor ( spiketimes [ u ] / bin_size ) . astype ( int ) np . add . at ( rc_t [ u ] , retimes [ retimes < resamples ] , 1 ) return tbin , resamples , rc_t , rcov_t
Bin the spike train into a given bin size.
Bin the spike train into a given bin size .
"""
    Bin the spike train into a given bin size.
    
    :param int bin_size: desired binning of original time steps into new bin
    :param float bin_time: time step of each original bin or time point
    :param np.array spiketimes: input spikes in train or index format
    :param int track_samples: number of time steps in the recording
    :param tuple behaviour_data: input behavioural time series
    :param bool average_behav: takes the middle element in bins for behavioural data if False
    :param bool binned: spiketimes is a spike train is True, otherwise it is spike time indices
    """ # leave out data with full bins
bin_size
desired binning of original time steps into new bin
desired binning of original time steps into new bin
bin_time
time step of each original bin or time point
time step of each original bin or time point
spiketimes
input spikes in train or index format
input spikes in train or index format
track_samples
number of time steps in the recording
number of time steps in the recording
behaviour_data
input behavioural time series
input behavioural time series
average_behav
takes the middle element in bins for behavioural data if False
takes the middle element in bins for behavioural data if False
binned
spiketimes is a spike train is True, otherwise it is spike time indices
spiketimes is a spike train is True otherwise it is spike time indices