|
6 | 6 | import os |
7 | 7 | import math |
8 | 8 |
|
9 | | -def check_time_resolution(filebytes,annfs,bpi): |
10 | | - # Check the beginning of the annotation file to see if it is storing the |
11 | | - # 'time resolution' field. |
| 9 | +def check_time_resolution(filebytes): |
| 10 | + """Check the beginning of the annotation file to see if it is storing the |
| 11 | + 'time resolution' field. |
| 12 | + """ |
| 13 | + annfs = [] # Store frequencies if they appear in the annotation file. |
| 14 | + bpi = 0 # Byte pair index, for searching through bytes of the annotation file. |
12 | 15 | if filebytes.size > 24: |
13 | 16 | testbytes = filebytes[:12, :].flatten() |
14 | 17 | # First 2 bytes indicate dt=0 and anntype=NOTE. Next 2 indicate auxlen |
15 | 18 | # and anntype=AUX. Then follows "## time resolution: " |
16 | 19 | if [ |
17 | 20 | testbytes[i] for i in [ |
18 | | - 0, |
19 | | - 1] + |
| 21 | + 0,1] + |
20 | 22 | list( |
21 | | - range( |
22 | | - 3, |
23 | | - 24))] == [ |
24 | | - 0, |
25 | | - 88, |
26 | | - 252, |
27 | | - 35, |
28 | | - 35, |
29 | | - 32, |
30 | | - 116, |
31 | | - 105, |
32 | | - 109, |
33 | | - 101, |
34 | | - 32, |
35 | | - 114, |
36 | | - 101, |
37 | | - 115, |
38 | | - 111, |
39 | | - 108, |
40 | | - 117, |
41 | | - 116, |
42 | | - 105, |
43 | | - 111, |
44 | | - 110, |
45 | | - 58, |
46 | | - 32]: # The file's leading bytes match the expected pattern for encoding fs. |
| 23 | + range(3,24))] == [0,88,252,35,35,32,116,105,109,101,32,114, |
| 24 | + 101,115,111,108,117,116,105,111,110,58,32]: |
| 25 | + # The file's leading bytes match the expected pattern for encoding fs. |
47 | 26 | # Length of the auxilliary string that includes the fs written into |
48 | 27 | # the file. |
49 | 28 | auxlen = testbytes[2] |
@@ -97,17 +76,14 @@ def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1): |
97 | 76 | chan = np.empty(filebytes.shape[0]) |
98 | 77 | num = np.empty(filebytes.shape[0]) |
99 | 78 | aux = [''] * filebytes.shape[0] |
100 | | - # Stores the frequencies written in the annotation file if it exists. |
101 | | - annfs = [] |
| 79 | + |
102 | 80 | # Annotation index, the number of annotations processed. Not to be |
103 | 81 | # comfused with the 'num' field of an annotation. |
104 | 82 | ai = 0 |
105 | | - # Byte pair index, for searching through bytes of the annotation file. |
106 | | - bpi = 0 |
107 | 83 |
|
108 | 84 | # Check the beginning of the annotation file to see if it is storing the |
109 | 85 | # 'time resolution' field. |
110 | | - annfs,bpi = check_time_resolution(filebytes,annfs,bpi) |
| 86 | + annfs,bpi = check_time_resolution(filebytes) |
111 | 87 |
|
112 | 88 | # Total number of samples of current annotation from beginning of record. |
113 | 89 | # Annotation bytes only store dt. |
|
0 commit comments