|
1 | 1 | import datetime |
2 | 2 | import os |
3 | 3 | import re |
| 4 | +from typing import List, Tuple |
4 | 5 |
|
5 | 6 | import numpy as np |
6 | 7 | import pandas as pd |
7 | 8 |
|
8 | | -from wfdb.io import download |
9 | 9 | from wfdb.io import _signal |
10 | 10 |
|
11 | 11 |
|
@@ -872,7 +872,7 @@ def get_sig_name(self): |
872 | 872 | return sig_name |
873 | 873 |
|
874 | 874 |
|
875 | | -def wfdb_strptime(time_string): |
| 875 | +def wfdb_strptime(time_string: str) -> datetime.time: |
876 | 876 | """ |
877 | 877 | Given a time string in an acceptable WFDB format, return |
878 | 878 | a datetime.time object. |
@@ -905,73 +905,45 @@ def wfdb_strptime(time_string): |
905 | 905 | return datetime.datetime.strptime(time_string, time_fmt).time() |
906 | 906 |
|
907 | 907 |
|
908 | | -def _read_header_lines(base_record_name, dir_name, pn_dir): |
| 908 | +def parse_header_content( |
| 909 | + header_content: str, |
| 910 | +) -> Tuple[List[str], List[str]]: |
909 | 911 | """ |
910 | | - Read the lines in a local or remote header file. |
| 912 | + Parse the text of a header file. |
911 | 913 |
|
912 | 914 | Parameters |
913 | 915 | ---------- |
914 | | - base_record_name : str |
915 | | - The base name of the WFDB record to be read, without any file |
916 | | - extensions. |
917 | | - dir_name : str |
918 | | - The local directory location of the header file. This parameter |
919 | | - is ignored if `pn_dir` is set. |
920 | | - pn_dir : str |
921 | | - Option used to stream data from Physionet. The Physionet |
922 | | - database directory from which to find the required record files. |
923 | | - eg. For record '100' in 'http://physionet.org/content/mitdb' |
924 | | - pn_dir='mitdb'. |
| 916 | + header_content: str |
| 917 | + The string content of the full header file |
925 | 918 |
|
926 | 919 | Returns |
927 | 920 | ------- |
928 | | - header_lines : list |
929 | | - List of strings corresponding to the header lines. |
930 | | - comment_lines : list |
931 | | - List of strings corresponding to the comment lines. |
932 | | -
|
| 921 | + header_lines : List[str] |
| 922 | + A list of all the non-comment lines |
| 923 | + comment_lines : List[str] |
| 924 | + A list of all the comment lines |
933 | 925 | """ |
934 | | - file_name = base_record_name + ".hea" |
935 | | - |
936 | | - # Read local file |
937 | | - if pn_dir is None: |
938 | | - with open( |
939 | | - os.path.join(dir_name, file_name), "r", errors="ignore" |
940 | | - ) as fp: |
941 | | - # Record line followed by signal/segment lines if any |
942 | | - header_lines = [] |
943 | | - # Comment lines |
944 | | - comment_lines = [] |
945 | | - for line in fp: |
946 | | - line = line.strip() |
947 | | - # Comment line |
948 | | - if line.startswith("#"): |
949 | | - comment_lines.append(line) |
950 | | - # Non-empty non-comment line = header line. |
951 | | - elif line: |
952 | | - # Look for a comment in the line |
953 | | - ci = line.find("#") |
954 | | - if ci > 0: |
955 | | - header_lines.append(line[:ci]) |
956 | | - # comment on same line as header line |
957 | | - comment_lines.append(line[ci:]) |
958 | | - else: |
959 | | - header_lines.append(line) |
960 | | - # Read online header file |
961 | | - else: |
962 | | - header_lines, comment_lines = download._stream_header(file_name, pn_dir) |
| 926 | + header_lines, comment_lines = [], [] |
| 927 | + for line in header_content.splitlines(): |
| 928 | + line = line.strip() |
| 929 | + # Comment line |
| 930 | + if line.startswith("#"): |
| 931 | + comment_lines.append(line) |
| 932 | + # Non-empty non-comment line = header line. |
| 933 | + elif line: |
| 934 | + header_lines.append(line) |
963 | 935 |
|
964 | 936 | return header_lines, comment_lines |
965 | 937 |
|
966 | 938 |
|
967 | | -def _parse_record_line(record_line): |
| 939 | +def _parse_record_line(record_line: str) -> dict: |
968 | 940 | """ |
969 | 941 | Extract fields from a record line string into a dictionary. |
970 | 942 |
|
971 | 943 | Parameters |
972 | 944 | ---------- |
973 | 945 | record_line : str |
974 | | - The name of the record line that will be used to extact fields. |
| 946 | + The record line contained in the header file |
975 | 947 |
|
976 | 948 | Returns |
977 | 949 | ------- |
|
0 commit comments