예제 #1
0
def load_openephys(folder, Experiment=1, Recording=1, TTLport=None):
    """Loads in openephys continuous and event data from processor. Openephys format ok, binary format not yet finished/vetted"""
    try:  # Load in openephys format
        cont_array = oe.loadFolder(folder)
        events = oe.loadEvents(os.path.join(folder, 'all_channels.events'))
        oe_type = 'oe'
        Rate = 'See cont_array variable'
    except ZeroDivisionError:  # load in binary format
        _, PluginNames = SettingsXML.GetRecChs(os.path.join(folder, 'settings.xml'))
        Proc = list(PluginNames.keys())[0]  # assume first node is the recording processor
        ProcName = PluginNames[Proc]  # Get processor name
        ProcFolderName = ProcName.replace(' ', '_') + '-' + Proc + '.0'
        cont_array, Rate = ob.Load(folder, Experiment=Experiment, Recording=Recording)
        Proc = list(Rate.keys())[0]
        SR = Rate[Proc][str(Experiment - 1)]  # get sample rate
        cont_time = np.load(os.path.join(folder, 'experiment' + str(Experiment) + '/recording' + str(Recording)
                                         + '/continuous/' + ProcFolderName + '/timestamps.npy'))

        if TTLport is not None:
            event_folder = os.path.join(folder, 'experiment' + str(Experiment) + '/recording' + str(Recording) +
                                        '/events/' + ProcFolderName + '/TTL_' + str(TTLport))
            event_data = load_binary_events(event_folder)
        else:
            event_data = None

        oe_type = 'binary'

    return event_data, cont_array, SR
예제 #2
0
def load_openephys(folder):
    """Loads in openephys continuous and event data. Openephys format ok, binary format not yet finished/vetted"""
    try:  # Load in openephys format
        cont_array = oe.loadFolder(folder)
        events = oe.loadEvents(os.path.join(folder, 'all_channels.events'))
        oe_type = 'oe'
        Rate = 'See cont_array variable'
    except ZeroDivisionError:  # load in binary format

        cont_array, Rate = ob.Load(folder)
        SR = Rate['100']['0']  # get sample rate
        cont_time = np.load(
            os.path.join(
                folder,
                'experiment1/recording1/continuous/Rhythm_FPGA-100.0/timestamps.npy'
            ))
        event_folder = os.path.join(
            folder, 'experiment1/recording1/events/Rhythm_FPGA-100.0/TTL_1')
        event_data = []
        for file_name in [
                'channel_states.npy', 'channels.npy', 'full_words.npy',
                'timestamps.npy'
        ]:
            event_data.append(np.load(os.path.join(event_folder, file_name)))

        oe_type = 'binary'

    return event_data, cont_array, Rate
예제 #3
0
def events2ms(exp_folder,
              Processor='100',
              Experiment=1,
              Recording=1,
              TTLport=1):
    """
    extract event times and convert to ms, with reference to recording start.
    :param exp_folder:
    :param Processor:
    :param Experiment:
    :param Recording:
    :param TTLport:
    :return: event_times_ms and channel_states: arrays of size (nevents,) with event timestamps in ms (0 = recording start time)
    and corresponding on/off channels.
    """

    event_data, timing_data = ob.LoadTTLEvents(
        exp_folder, TTLport=TTLport)  # load event data

    # extract variables
    timestamps = event_data[Processor][str(Experiment -
                                           1)][str(Recording -
                                                   1)]['timestamps']
    channel_states = event_data[Processor][str(Experiment -
                                               1)][str(Recording -
                                                       1)]['channel_states']
    start_time = int(timing_data[Processor][str(Experiment -
                                                1)][str(Recording -
                                                        1)]['start_time'])
    SR = int(timing_data[Processor][str(Experiment - 1)][str(Recording -
                                                             1)]['Rate'])

    # calculate event times in ms referenced to recording start
    event_times_ms = (timestamps - start_time) / SR * 1000

    return event_times_ms, channel_states
예제 #4
0
    elif session == '2b':
        base_folder_dict = {
            'nt':
            r'C:\Users\Nat\Documents\UM\Working\Opto\Rat613\ClosedLoopTest2\Rat613_SWRstim_probe1_2020-08-07_10-55-22',
            'posix':
            r'/data/Working/Opto/Rat613/ClosedLoopTest2/Rat613_SWRstim_probe1_2020-08-07_10-55-22'
        }
        Experiment, Recording, set_append = 3, 1, '_3'
base_folder = base_folder_dict[os.name]

traces_ds = np.load(
    os.path.join(base_folder, 'continuous_eeg' + str(Experiment) + '.npy'))
SRlfp = 1250
detection_events, detection_timing = ob.LoadTTLEvents(base_folder,
                                                      Processor='104',
                                                      Experiment=Experiment,
                                                      Recording=Recording,
                                                      TTLport=2)
stim_events, stim_timing = ob.LoadTTLEvents(base_folder,
                                            Processor='111',
                                            Experiment=Experiment,
                                            Recording=Recording,
                                            TTLport=1)

sync_start_time = int(
    detection_timing[Ripple_Proc][str(Experiment - 1)][str(Recording -
                                                           1)]['start_time'])
SRoe = int(detection_timing[Ripple_Proc][str(Experiment - 1)][str(Recording -
                                                                  1)]['Rate'])
detect_time_sec = (detection_events[Ripple_Proc][str(Experiment - 1)][str(
    Recording - 1)]['timestamps'] - sync_start_time) / SRoe
예제 #5
0
import matplotlib.pyplot as plt
import os
import pandas as pd
import Analysis.python.LFP.helpers as lfhelp
import seaborn as sns
import matplotlib.patches as patches

## Plot settings
font = {'family': 'normal', 'weight': 'normal', 'size': 22}
plt.rc('font', **font)

## Relevant folder/files
chan_map_file = '/data/GitHub/dibalab_ephys/Channel Maps/MINT/2x32MINT_chan_map_good' # nat laptop location r'C:\Users\Nat\Documents\UM\Working\Opto\Rat613\2x32MINT_chan_map_good.txt'
data_folder = '/data/Working/Opto Project/Rat 613/Rat613Day1/Rat613simtest_2020-08-01_08-47-11/' # nat laptop location r'C:\Users\Nat\Documents\UM\Working\Opto\Rat613\Rat613Day1\Rat613track_2020-08-01_09-21-55'
## Load Data!
chan_map_dict = ob.LoadChannelMapFromText(chan_map_file)
chans_use = np.hstack((np.arange(0, 8), np.arange(16, 24)))  # Use only shank 1 and shank 3
# channels_use = [chan for chan in np.asarray(chan_map_dict['0']['mapping'])[chans_use]]  # not used
Data, Rate = ob.Load(data_folder, ChannelMap=chans_use, Experiment=1, Recording=1, mode='r')
event_data = ppd.load_binary_events()
channels_use = [chan for chan in np.asarray(chan_map_dict['0']['mapping'])[chans_use]]
Data, Rate = ob.Load(data_folder, ChannelMap=channels_use, Experiment=2, Recording=1, mode='r')

## Look at silencing for Jackie place stim day 2
adc_channel = 35  # channel with adc input
on_thresh = 1300000 # on voltage threshold
if os.environ['APPDATA'][0] == 'C':
    base_dir = r'C:\Users\Nat\Documents\UM\Working\Opto\Jackie671\placestim_day2\PRE'
    full_raw_path = r'C:\Users\Nat\Documents\UM\Working\Opto\Jackie671\placestim_day2\PRE\Jackie_PRE_2020-10-07_10-48-13\experiment1\recording1\continuous\Intan_Rec._Controller-100.0'
    save_loc = np.nan