1
1
import copy
2
+ import fsspec
2
3
import numpy as np
3
4
import os
4
5
import pandas as pd
9
10
from wfdb .io import download
10
11
from wfdb .io import _header
11
12
from wfdb .io import record
13
+ from wfdb .io import util
14
+ from wfdb .io .record import CLOUD_PROTOCOLS
12
15
13
16
14
17
class Annotation (object ):
@@ -1892,7 +1895,7 @@ def rdann(
1892
1895
----------
1893
1896
record_name : str
1894
1897
The record name of the WFDB annotation file. ie. for file '100.atr',
1895
- record_name='100'.
1898
+ record_name='100'. The path to the file can be a cloud URL.
1896
1899
extension : str
1897
1900
The annotatator extension of the annotation file. ie. for file
1898
1901
'100.atr', extension='atr'.
@@ -1936,11 +1939,17 @@ def rdann(
1936
1939
>>> ann = wfdb.rdann('sample-data/100', 'atr', sampto=300000)
1937
1940
1938
1941
"""
1939
- if (pn_dir is not None ) and ("." not in pn_dir ):
1940
- dir_list = pn_dir .split ("/" )
1941
- pn_dir = posixpath .join (
1942
- dir_list [0 ], download .get_version (dir_list [0 ]), * dir_list [1 :]
1943
- )
1942
+ if pn_dir is not None :
1943
+ # check to make sure a cloud path isn't being passed under pn_dir
1944
+ if any (pn_dir .startswith (proto ) for proto in CLOUD_PROTOCOLS ):
1945
+ raise ValueError (
1946
+ "Cloud paths should be passed under record_name, not under pn_dir"
1947
+ )
1948
+ if "." not in pn_dir :
1949
+ dir_list = pn_dir .split ("/" )
1950
+ pn_dir = posixpath .join (
1951
+ dir_list [0 ], download .get_version (dir_list [0 ]), * dir_list [1 :]
1952
+ )
1944
1953
1945
1954
return_label_elements = check_read_inputs (
1946
1955
sampfrom , sampto , return_label_elements
@@ -2071,7 +2080,7 @@ def load_byte_pairs(record_name, extension, pn_dir):
2071
2080
----------
2072
2081
record_name : str
2073
2082
The record name of the WFDB annotation file. ie. for file '100.atr',
2074
- record_name='100'.
2083
+ record_name='100'. The path to the file can be a cloud URL.
2075
2084
extension : str
2076
2085
The annotatator extension of the annotation file. ie. for file
2077
2086
'100.atr', extension='atr'.
@@ -2086,10 +2095,11 @@ def load_byte_pairs(record_name, extension, pn_dir):
2086
2095
The input filestream converted to an Nx2 array of unsigned bytes.
2087
2096
2088
2097
"""
2089
- # local file
2098
+ # local or cloud file
2090
2099
if pn_dir is None :
2091
- with open (record_name + "." + extension , "rb" ) as f :
2092
- filebytes = np .fromfile (f , "<u1" ).reshape ([- 1 , 2 ])
2100
+ with fsspec .open (record_name + "." + extension , "rb" ) as f :
2101
+ filebytes = util .fromfile (f , "<u1" ).reshape ([- 1 , 2 ])
2102
+
2093
2103
# PhysioNet file
2094
2104
else :
2095
2105
filebytes = download ._stream_annotation (
0 commit comments