11import copy
2+ import fsspec
23import numpy as np
34import os
45import pandas as pd
910from wfdb .io import download
1011from wfdb .io import _header
1112from wfdb .io import record
13+ from wfdb .io import util
14+ from wfdb .io .record import CLOUD_PROTOCOLS
1215
1316
1417class Annotation (object ):
@@ -1892,7 +1895,7 @@ def rdann(
18921895 ----------
18931896 record_name : str
18941897 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.
18961899 extension : str
18971900 The annotatator extension of the annotation file. ie. for file
18981901 '100.atr', extension='atr'.
@@ -1936,11 +1939,17 @@ def rdann(
19361939 >>> ann = wfdb.rdann('sample-data/100', 'atr', sampto=300000)
19371940
19381941 """
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+ )
19441953
19451954 return_label_elements = check_read_inputs (
19461955 sampfrom , sampto , return_label_elements
@@ -2071,7 +2080,7 @@ def load_byte_pairs(record_name, extension, pn_dir):
20712080 ----------
20722081 record_name : str
20732082 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.
20752084 extension : str
20762085 The annotatator extension of the annotation file. ie. for file
20772086 '100.atr', extension='atr'.
@@ -2086,10 +2095,11 @@ def load_byte_pairs(record_name, extension, pn_dir):
20862095 The input filestream converted to an Nx2 array of unsigned bytes.
20872096
20882097 """
2089- # local file
2098+ # local or cloud file
20902099 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+
20932103 # PhysioNet file
20942104 else :
20952105 filebytes = download ._stream_annotation (
0 commit comments