-
Notifications
You must be signed in to change notification settings - Fork 0
/
NWBInterface.py
61 lines (58 loc) · 3.82 KB
/
NWBInterface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import h5py
import numpy as np
import FormatInterface
#These classes inherit from FormatInterface.
class HandelNWBFile(FormatInterface.FormatInterface):
def __init__(self,inputFile,isGui):
super().__init__()
self.isGui = isGui
self.inputFile = inputFile
self.listOfRecordings = []
self.listOfProcessors = []
self.extractedFile = []
#GetData- extracts the data (usually done via python packages).
#it should extract the data according to the selected channels and time window.
#It should also extract the time step (sampling rate), the total time duration and the number of channels for
# both GUI and Console applications.
def GetData(self):
try:
self.extractedFile = h5py.File(self.inputFile,"r")
self.listOfRecordings = self.ShowFileInnerSection(self.extractedFile['/acquisition/timeseries/'])
for recording in self.listOfRecordings:
self. listOfProcessors = self.ShowFileInnerSection(self.extractedFile['/acquisition/timeseries/'
+recording+'/continuous/'])
for processor in self.listOfProcessors:
# sampling rate calculation:
startTimestamps = np.array(self.extractedFile['/acquisition/timeseries/' + recording +
'/continuous/' + processor + '/timestamps'][0])
secondTimestamps = np.array(self.extractedFile['/acquisition/timeseries/' + recording +
'/continuous/' + processor + '/timestamps'][1])
self.timeStepMS = (secondTimestamps-startTimestamps)*1e3
self.durationMS=(self.extractedFile['/acquisition/timeseries/' + recording + '/continuous/' +
processor + '/timestamps']).shape[0]*self.timeStepMS
self.nChannels = self.extractedFile['/acquisition/timeseries/'+
recording+'/continuous/'+processor+'/data'].shape[1]
if (self.isGui==False):
self.GetRelevantTimestamps()
self.GetRelevantChannels()
if ((self.startTimeIndex != None) and (self.endTimeIndex != None) and
( self.startChannel != None) and (self.endChannel != None) and
( self.timestamps[0] != None)):
# metadata contains all the requested data, arranged by channels as columns and
# timestamps as rows
self.metaData = np.array((self.extractedFile['/acquisition/timeseries/'
+ recording+'/continuous/'+processor+'/data']
[self.startTimeIndex:self.endTimeIndex,self.startChannel - 1:self.endChannel]))
self.PlotData(self.isGui)
else:
print("Error Loading Data, Please Try Again")
except Exception as e:
print("An exception occurred. Please Try Again")
print(e)
return
#GetAndPlotMetaData- Extract the data for GUI application and plots it.
def GetAndPlotMetaData(self):
self.metaData = np.array((self.extractedFile[
'/acquisition/timeseries/' + self.listOfRecordings[0] + '/continuous/' + self.listOfProcessors[0] + '/data'][
self.startTimeIndex:self.endTimeIndex, 0:self.nChannels]))
return self.PlotData(True)