-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetDataRecords.py
More file actions
executable file
·51 lines (38 loc) · 1.52 KB
/
getDataRecords.py
File metadata and controls
executable file
·51 lines (38 loc) · 1.52 KB
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
import math
import os
import argparse
# script to check the number of data records in an EDF file
def main(file):
# number of bytes in whole file
numBytes = os.path.getsize(file)
with open(file, 'r+b') as thisFile:
# number of bytes in header
thisFile.read(184)
headerBytes = int(thisFile.read(8).decode("utf-8").strip())
thisFile.read(44)
numRec = int(thisFile.read(8).decode("utf-8").strip())
thisFile.read(8)
# recDur = float(thisFile.read(8).decode("utf-8").strip())
numSigs = int(thisFile.read(4).decode("utf-8").strip())
thisFile.read(numSigs*(16+80+8+8+8+8+8+80))
numSamps = []
for i in range(numSigs):
numSamps.append(int(thisFile.read(8).decode("utf-8").strip()))
# required bytes for calculation
remBytes = numBytes - headerBytes
# If the number of data record is not known
# if(numRec < 0):
R = sum(numSamps) * 2 # length of record for all the samples
numRecs = math.floor(remBytes/R) # number of records
print("data records from the file: ", numRec)
print("The number of data records is: ", numRecs)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='get the number of data records for edf file', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('edfFileLocation', help='File name and location for final edf file , eg:(directory/filename.edf)')
args = parser.parse_args()
edf_file = args.edfFileLocation
# checking if all the arguments are given
if not edf_file:
sys.exit('Must provide input edf file location.')
else:
main(edf_file)