Exemplo n.º 1
0
def get_laser_train_psth_by_trial(h5, clu, bin_size,
                                  amplitude='',
                                  onset_delay=None,
                                  n_pulses=-1,
                                  time_window_ms=1000,
                                  pre_pad_ms=500,
                                  include_odor_trials=False,
                                  skip_last_trials=0,
                                  *args, **kwargs):
    """

    :param h5:
    :param clu:
    :param amplitude:
    :param onset_delay:
    :param time_window_ms:
    :param pre_pad_ms:
    :param args:
    :param kwargs:
    :return: this is returning both the psth and the baseline psths!!
    """
    rstrs = get_laser_train_rasters(h5, clu, amplitude=amplitude, onset_delay=onset_delay, n_pulses=n_pulses,
                                    time_window_ms=time_window_ms, pre_pad_ms=pre_pad_ms,
                                    include_odor_trials=include_odor_trials, skip_last_trials=skip_last_trials,
                                    *args, **kwargs)
    time_arrays = []
    spike_arrays = []

    for ras in rstrs:
        spike_array, time_array = make_spike_array(ras, bin_size, -pre_pad_ms, time_window_ms-pre_pad_ms)
        spike_arrays.append(spike_array)
        time_arrays.append(time_array)


    return spike_arrays, time_arrays
Exemplo n.º 2
0
def get_pre_odor_baseline_psths(h5, clu, odor, bin_size, n_sniffs=5,
                                include_laser_trials=False,
                                time_window_ms=1000,
                                pre_pad_ms=0,
                                skip_last_trials=0):
    """
    Gets the first inhalations before every finalvalve opening and averages them all to get a baseline psth.

    :param h5:
    :param clu:
    :param bin_size:
    :param time_window_ms:
    :param pre_pad_ms:
    :return:
    """
    pre_pad_samples = np.int(pre_pad_ms * h5.root.events._v_attrs['sample_rate_Hz'] / 1000.)
    sniff_events = h5.root.events.sniff.inh_events
    sniff_starts = sniff_events[:, 0]
    fv_events = find_odor_events(h5, odor,
                                 include_laser_trials=include_laser_trials,
                                 skip_last_trials=skip_last_trials)
    starts = []
    for fv_ev in fv_events:
        fv_start = fv_ev[0]
        for i_sn in xrange(1, n_sniffs + 1):
            last_inh = sniff_starts[sniff_starts < fv_start][-i_sn]
            starts.append(last_inh)
    starts = np.array(starts)
    rasters = get_rasters(h5, clu, starts - pre_pad_samples, time_window_ms, convert_to_ms=True)
    rasters -= pre_pad_ms
    spike_array, time_array = make_spike_array(rasters, bin_size, -pre_pad_ms, time_window_ms-pre_pad_ms)
    # psths = np.sum(spike_array, axis=1)
    n_trials = len(starts)
    psths_hz = (1000 / bin_size) * spike_array
    return psths_hz, time_array, n_trials
Exemplo n.º 3
0
def get_odor_psth(h5, clu, odor, odor_conc, bin_size,
                  time_window_ms=1000,
                  pre_pad_ms=0,
                  skip_last_trials=0,
                  *args, **kwargs):
    """
    Returns psth for all trials in which odor and concentration are met. Raster time 0 is the start of the first
    inhalation following odor onset.

    PSTH is not normalized or smoothed (ie it is simply a sum of the total number of spikes that for each bin across
    all odor events in the h5.

    :param h5:
    :param clu:
    :param odor:
    :param odor_conc:
    :param bin_size:
    :param time_window_ms:
    :param pre_pad_ms:
    :return:
    """

    rasters = get_odor_rasters(h5, clu, odor, odor_conc,
                               time_window_ms=time_window_ms,
                               pre_pad_ms=pre_pad_ms,
                               skip_last_trials=skip_last_trials,
                               *args, **kwargs)
    spike_array, time_array = make_spike_array(rasters, bin_size, -pre_pad_ms, time_window_ms-pre_pad_ms)
    psth = np.sum(spike_array, axis=1)
    n_trials = spike_array.shape[1]
    psth_hz = (1000 / bin_size) * psth / n_trials
    return psth_hz, time_array, n_trials
Exemplo n.º 4
0
def get_laser_train_psth(h5,
                         clu,
                         bin_size,
                         amplitude='',
                         onset_delay=None,
                         n_pulses=-1,
                         time_window_ms=1000,
                         pre_pad_ms=500,
                         include_odor_trials=False,
                         skip_last_trials=0,
                         *args,
                         **kwargs):
    """

    :param h5:
    :param clu:
    :param amplitude:
    :param onset_delay:
    :param time_window_ms:
    :param pre_pad_ms:
    :param args:
    :param kwargs:
    :return: this is returning both the psth and the baseline psths!!
    """
    rstrs = get_laser_train_rasters(h5,
                                    clu,
                                    amplitude=amplitude,
                                    onset_delay=onset_delay,
                                    n_pulses=n_pulses,
                                    time_window_ms=time_window_ms,
                                    pre_pad_ms=pre_pad_ms,
                                    include_odor_trials=include_odor_trials,
                                    skip_last_trials=skip_last_trials,
                                    *args,
                                    **kwargs)
    time_arrays = []
    spike_arrays = []
    n_trialss = []
    psths = []

    for ras in rstrs:
        spike_array, time_array = make_spike_array(ras, bin_size, -pre_pad_ms,
                                                   time_window_ms - pre_pad_ms)
        spike_arrays.append(spike_array)
        time_arrays.append(time_array)
        n_trials = spike_array.shape[1]
        n_trialss.append(n_trials)
        psth = np.sum(spike_array, axis=1)
        psth_hz = (1000 / bin_size) * psth / n_trials
        psths.append(psth_hz)

    return psths, time_arrays, n_trialss