Example #1
0
def load(path, nchan, cutmin):
    ndpoints = cutmin * 60 * 30000
    dim = int(math.floor((ndpoints / 1024)))
    raw = np.empty((dim * 1024, nchan))

    for i in range(nchan):
        i += 1
        # dump=[]
        data = op.loadContinuous(str(path) + '\\100_CH%s.continuous' % i,
                                 stop_record=ndpoints / 1024)
        print('loaded %s' % i, 'start cutting')
        # cutting
        timestamps = data['data']  #[0:cutmin*60*30000]
        raw[:, i - 1] = (timestamps)

    return raw
Example #2
0
#del stim_array[0]
#st= np.array(stim_array)/25000.

##file_name = '/home/cat/neuron/in_vivo/dan/M149873/2015-02-06_13-02-32_flash_CSD/data/stim_times.txt'
#file_name = file_dir+'stim_times.txt'

#np.savetxt(file_name,st, fmt='%8.3f')
#quit()

#******************************* LOAD RAW DATA AND PREP FOR .TSF FILE ***************************

data=[]
for i in range(128):
    file_name = file_dir + '100_CH'+ str(i+1) +'.continuous'
    data.append(oe.loadContinuous(file_name)['data'])

dt = np.array(data, dtype=np.int16)

print dt.shape
####Plot first 10000 steps from channel 0
#x = np.arange(0,len(dt1),1.)/SampleFrequency
#plt.plot(x,dt1, 'r-', color='black',linewidth=1)
#plt.plot(x,dt2+1000, 'r-', color='black',linewidth=1)

#plt.plot(x,dt[probe128[0]][0:100000], 'r-', color='black',linewidth=1)
#plt.plot(x,dt[probe128[2]][0:100000]-100, 'r-', color='black',linewidth=1)

#plt.show()

Example #3
0
    pathname = f"./plx/{dirname}"
    #Ephys形式で記録されたチャネルマップ配置
    channel_map = [9, 8, 10, 7, 13, 4, 12, 5, 15, 2, 16, 1, 14, 3, 11, 6]

    #刺激方法の設定をSetting.jsonのファイルから読み込む
    #jsonファイルは日程-時間で記録されているため、result.jsonに記載された日程を参照する
    with open(f"./json/{jsonfile[:14]}Settings.json",
              encoding="UTF-8") as json_fp:
        stim_setting = json.load(json_fp)

    if not (os.path.exists(f"./waveform/{dirname}")):
        os.mkdir(f"./waveform/{dirname}")
    num = 1
    for i in channel_map:
        #OpenEphys.pyを使用してcontinuousファイルの読み込み
        tmp = OpenEphys.loadContinuous(
            f"./plx/{dirname}/101_CH{str(i)}.continuous")
        #lowpassフィルタがかけられた波形を抽出
        waveform = glia.nucleus.Waveform(lowpass(tmp["data"], 30000, 450, 600,
                                                 10, 30),
                                         rate=glia.Frequency(30000))
        #tmp(['header', 'timestamps', 'data', 'recordingNumber'])が記載されている
        #timestampsはサンプリングレートで記録された記録点
        timestamps = tmp["timestamps"][0]
        if num < 10:
            glia.save(f"./waveform/{dirname}/0{num}.lfp", waveform)
        else:
            glia.save(f"./waveform/{dirname}/{num}.lfp", waveform)
        del tmp, waveform
        gc.collect()
        num += 1
Example #4
0
#file_dir = 'M150566/2015-04-01_16-41-14_flashes_vis/'

#file_dir = 'M150566/2015-04-01_20-55-32_flashes_vis/'

#file_dir = 'M181420/181420_2015-04-07_13-25-07_flashes_vis/'

#file_dir = 'M181420/181420_2015-04-07_18-10-46_flash_vis/'


##********************** LOAD STIMULUS TIMES AND SAVE THEM *****************************
if False:
    file_name = '103_PAI7.StimTimeshere.continuous'
    data=[]

    data = oe.loadContinuous(file_dir+mouse_dir+'/'+exp+dir+'/'+file_name)
    dt = np.array(data['data'])

    stim_array=[]
    state=0
    for i in range(len(dt)):
        if state==0:
            if dt[i]>1:
                print "ON"
                temp=i
                state=1
        if state==1:
            if dt[i]<1:
                print "OFF"
                stim_array.append([temp,i])
                state=0
    DataFiles = glob.glob(''.join([RecFolder,'/*.continuous']))
    DataFiles.sort()


#%% Generate TTLs

os.makedirs('DataArrays', exist_ok=True)
DirList = glob.glob('OpenEphysFiles/*'); DirList.sort()

for RecFolder in DirList:
    DataFiles = glob.glob(''.join([RecFolder,'/*.continuous']))
    EventsFile = ''.join([RecFolder,'/all_channels.events'])
    DataFiles.sort()
    
    TempData = OpenEphys.loadContinuous(DataFiles[0]) # Any ch would work ;)
    Events = OpenEphys.loadEvents(EventsFile)
                                                                                
    # Draw TTL
    print('Drawing TTL channel...')                                              
    if len(Events['timestamps']) > 100: # arbitrary value, I never use < 100 stimulation pulses
        TTLSound = [0] * len(TempData['data'])
        for EvTS in range(len(Events['timestamps'])):
            if Events['eventType'][EvTS] == 3: # if event is a TTL
                if Events['eventId'][EvTS] == 1: # if TTL is on
                    TTLSound(find(TempTimestamps==EventsTimestamps(EvTS)): ...  
                        find(TempTimestamps==EventsTimestamps(EvTS+1))) = 1;    
                end                                                             
            end                                                                 
        end                                                                     
    else                                                                        
Example #6
0
#==============================================================================#
ntot = len(dfold_list)
ind = 0

for dfold in dfold_list:
    ind = ind + 1
    nrem = ntot - ind
    print('Converting ' + dfold + ': ' + str(nrem) + ' remaining')

    folderpath = ddir + dfold  # folderpath where data is stored

    #=============== SUBSAMPLE LOWPASS (LFP) SIGNAL AND CONVERT TO DAT ===========#
    lfpname = '102_CH2.continuous'
    filepath = ddir + dfold + '/' + lfpname
    LFP = OpenEphys.loadContinuous(filepath, dtype=float)
    LFP = LFP['data']
    ssLFP = LFP[::10].copy()  #subsampled LFP
    # save as dat file
    datnameLFP = dfold + '_LFP.dat'
    ssLFP.tofile(os.path.join(folderpath, datnameLFP))
    #==============================================================================#

    #======================== CONVERT HIGHPASS SIGNALS TO DAT ======================#
    # Load highpass signals of each sahnk in geometric order (bottom of shank to top)
    # then save to flat binary file

    # create shank1 and shank2 folders
    os.makedirs(folderpath + '/2017/' + shank1_fname)
    os.makedirs(folderpath + '/2017/' + shank2_fname)
 duration = glia.milliseconds(400)
 filename = i
 jsonfile = rec_stim_matching[filename]
 filename = "plx/" + filename
 with open("json/" + jsonfile[:14] + "Settings.json",
           encoding="utf-8") as json_fp:
     stim_setting = json.load(json_fp)
 if not reload and os.path.isfile("./waveform/" + filename[4:-4] +
                                  ".lfp") and os.path.isfile(
                                      "./waveform/" + filename[4:-4] +
                                      ".trig"):
     print("Load lfp, trig")
 else:
     wave = []
     for j in channel_map:
         tmp = OpenEphys.loadContinuous(filename + "/101_CH" + str(j) +
                                        ".continuous")
         #gliaの形式にそってローパスフィルタをかけた波形の出力
         wave.append(
             glia.nucleus.Waveform(lowpass(tmp["data"], 30000, 450, 600, 10,
                                           30),
                                   rate=glia.Frequency(30000)))
         timestamp = tmp["timestamps"][0]
 events = OpenEphys.loadEvents(filename + "/all_channels.events")
 e_tmp = (events["timestamps"] - timestamp)[0::2]
 trigger = []
 for i in (e_tmp / 30):
     trigger.append(glia.millisecond(i))
 trigger = np.array(trigger)
 glia.save("./waveform/" + filename[4:] + ".lfp", wave)
 glia.save("./waveform/" + filename[4:] + ".trig", trigger)
 if not reload and os.path.isfile("./waveform/" + filename[4:-4] +