コード例 #1
0
def get_laser_train_rasters(h5, clu,
                            amplitude='',
                            onset_delay=None,
                            n_pulses=-1,
                            time_window_ms=1000,
                            pre_pad_ms=500,
                            include_odor_trials=False,
                            baseline_nsniffs=5,
                            skip_last_trials=0,
                            *args, **kwargs):
    """

    :param h5:
    :param clu:
    :param amplitude:
    :param onset_delay:
    :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.)
    train_events = find_laser_trains(h5, amplitude=amplitude, onset_delay=onset_delay,
                                     n_pulses=n_pulses, include_odor_trials=include_odor_trials,
                                     skip_last_trials=skip_last_trials, *args, **kwargs)

    train_starts = train_events[:, 0]

    rasters = get_rasters(h5, clu, train_starts-pre_pad_samples, time_window_ms, convert_to_ms=True)
    rasters -= pre_pad_ms

    #  now find a pre - stimulus sniff to calculate baseline from and get a raster centered around this sniff at the
    #  same latency as the laser stimulus.
    baseline_starts = []
    sniff_events = h5.root.events.sniff.inh_events
    sniff_starts = sniff_events[:, 0]
    for start in train_starts:

        last_inh = sniff_starts[sniff_starts < start][-1]
        latency = start - last_inh
        for i in xrange(baseline_nsniffs):
            two_sniffs_back = sniff_starts[sniff_starts < start][-3-i]  # find the inhalation 2 prior to the triggering one.
            baseline_starts.append(two_sniffs_back+latency)  # add the latency, because we want to center around the same point in the sniff as we did in the laser trial.

    baseline_starts = np.asarray(baseline_starts)
    baseline_rasters = get_rasters(h5, clu, baseline_starts - pre_pad_samples, time_window_ms, convert_to_ms=True)
    baseline_rasters -= pre_pad_ms

    return rasters, baseline_rasters
コード例 #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
コード例 #3
0
def get_odor_rasters_sniff(h5, clu, odor, odor_conc, time_window_ms=1000, pre_pad_ms=500, include_laser_trials=False,
                           only_laser_trials=False, *args, **kwargs):
    """

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

    fs = h5.root.events._v_attrs['sample_rate_Hz']
    pre_pad_samples = np.int(pre_pad_ms * fs / 1000.)
    fv_events = find_odor_events(h5, odor, odor_conc, include_laser_trials=include_laser_trials,
                                 only_laser_trials=only_laser_trials)
    inh_starts = list()
    sniff_events_all_trials = list()
    for i, ev in enumerate(fv_events):
        sn_events = find_sniff_events(h5, ev, *args, **kwargs)
        try:
            first_sn_event = sn_events[0]  # the first sniff after odor onset.
            first_inh = first_sn_event[0]  # this is the first inhalation after odor onset. THIS IS TIME 0!!!
            inh_starts.append(first_inh)

            sn_events_in_window = find_sniff_events(h5, [first_inh - pre_pad_samples,
                                                         first_inh - pre_pad_samples + (time_window_ms*fs)/1000.])
            sn_events_in_window = sn_events_in_window - first_inh  # must make relative to first inh = 0.
            sn_events_in_window_ms = sn_events_in_window / fs * 1000
            sniff_events_all_trials.append(sn_events_in_window_ms)
        except TypeError:   # empty array, no sniffs found
            print 'no sniffs found'
            pass

    inh_starts = np.array(inh_starts)
    rasters = get_rasters(h5, clu, inh_starts-pre_pad_samples, time_window_ms=time_window_ms, convert_to_ms=True)
    rasters -= pre_pad_ms
    assert len(rasters) == len(sniff_events_all_trials)

    return rasters, sniff_events_all_trials
コード例 #4
0
def get_odor_rasters(h5, clu, odor, odor_conc,
                     time_window_ms=1000,
                     pre_pad_ms=500,
                     include_laser_trials=False,
                     only_laser_trials=False,
                     skip_last_trials=0,
                     *args, **kwargs):
    """

    :param h5:
    :param clu:
    :param odor:
    :param odor_conc:
    :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.)
    fv_events = find_odor_events(h5, odor, odor_conc,
                                 include_laser_trials=include_laser_trials,
                                 only_laser_trials=only_laser_trials,
                                 skip_last_trials=skip_last_trials,
                                 *args, **kwargs)
    starts = []
    for i, ev in enumerate(fv_events):
        sn_events = find_sniff_events(h5, ev)
        try:
            sn_event = sn_events[0]  # the first inhalation after odor onset.
            starts.append(sn_event[0])
        except TypeError:   # empty array, no sniffs found
            print 'no sniffs found'
            pass
    starts = np.array(starts)
    rasters = get_rasters(h5, clu, starts-pre_pad_samples, time_window_ms=time_window_ms, convert_to_ms=True)
    rasters -= pre_pad_ms
    return rasters
コード例 #5
0
def get_laser_train_rasters(h5,
                            clu,
                            amplitude='',
                            onset_delay=None,
                            n_pulses=-1,
                            time_window_ms=1000,
                            pre_pad_ms=500,
                            include_odor_trials=False,
                            baseline_nsniffs=5,
                            skip_last_trials=0,
                            *args,
                            **kwargs):
    """

    :param h5:
    :param clu:
    :param amplitude:
    :param onset_delay:
    :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.)
    train_events = find_laser_trains(h5,
                                     amplitude=amplitude,
                                     onset_delay=onset_delay,
                                     n_pulses=n_pulses,
                                     include_odor_trials=include_odor_trials,
                                     skip_last_trials=skip_last_trials,
                                     *args,
                                     **kwargs)

    train_starts = train_events[:, 0]

    rasters = get_rasters(h5,
                          clu,
                          train_starts - pre_pad_samples,
                          time_window_ms,
                          convert_to_ms=True)
    rasters -= pre_pad_ms

    #  now find a pre - stimulus sniff to calculate baseline from and get a raster centered around this sniff at the
    #  same latency as the laser stimulus.
    baseline_starts = []
    sniff_events = h5.root.events.sniff.inh_events
    sniff_starts = sniff_events[:, 0]
    for start in train_starts:

        last_inh = sniff_starts[sniff_starts < start][-1]
        latency = start - last_inh
        for i in xrange(baseline_nsniffs):
            two_sniffs_back = sniff_starts[sniff_starts < start][
                -3 - i]  # find the inhalation 2 prior to the triggering one.
            baseline_starts.append(
                two_sniffs_back + latency
            )  # add the latency, because we want to center around the same point in the sniff as we did in the laser trial.

    baseline_starts = np.asarray(baseline_starts)
    baseline_rasters = get_rasters(h5,
                                   clu,
                                   baseline_starts - pre_pad_samples,
                                   time_window_ms,
                                   convert_to_ms=True)
    baseline_rasters -= pre_pad_ms

    return rasters, baseline_rasters