wfdb 4.2.0__tar.gz → 4.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. {wfdb-4.2.0 → wfdb-4.3.0}/.github/workflows/test.yml +5 -3
  2. {wfdb-4.2.0 → wfdb-4.3.0}/PKG-INFO +4 -2
  3. {wfdb-4.2.0 → wfdb-4.3.0}/docs/changes.rst +10 -0
  4. {wfdb-4.2.0 → wfdb-4.3.0}/docs/conf.py +1 -1
  5. wfdb-4.3.0/docs/requirements.txt +4 -0
  6. wfdb-4.3.0/ecg-record.dat +0 -0
  7. wfdb-4.3.0/ecg-record.hea +3 -0
  8. {wfdb-4.2.0 → wfdb-4.3.0}/pyproject.toml +3 -1
  9. wfdb-4.3.0/test01_00s.dat +0 -0
  10. wfdb-4.3.0/test01_00s_framex.hea +6 -0
  11. wfdb-4.3.0/tmp_dl_dir/0001.atr +0 -0
  12. wfdb-4.3.0/tmp_dl_dir/0001.dat +0 -0
  13. wfdb-4.3.0/tmp_dl_dir/0001.hea +3 -0
  14. wfdb-4.3.0/tmp_dl_dir/0201.atr +0 -0
  15. wfdb-4.3.0/tmp_dl_dir/0201.dat +0 -0
  16. wfdb-4.3.0/tmp_dl_dir/0201.hea +3 -0
  17. wfdb-4.3.0/tmp_dl_dir/STAFF-Studies-bibliography-2016.pdf +0 -0
  18. wfdb-4.3.0/tmp_dl_dir/data/001a.dat +0 -0
  19. wfdb-4.3.0/tmp_dl_dir/data/001a.hea +12 -0
  20. wfdb-4.3.0/tmp_dl_dir/data/001b.dat +0 -0
  21. wfdb-4.3.0/tmp_dl_dir/data/001b.hea +12 -0
  22. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/_coreio.py +17 -4
  23. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/_signal.py +40 -14
  24. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/annotation.py +20 -10
  25. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/record.py +52 -24
  26. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/util.py +39 -0
  27. wfdb-4.3.0/wfdb/version.py +1 -0
  28. wfdb-4.2.0/docs/requirements.txt +0 -4
  29. wfdb-4.2.0/wfdb/version.py +0 -1
  30. {wfdb-4.2.0 → wfdb-4.3.0}/.gitattributes +0 -0
  31. {wfdb-4.2.0 → wfdb-4.3.0}/.github/workflows/docs.yml +0 -0
  32. {wfdb-4.2.0 → wfdb-4.3.0}/.gitignore +0 -0
  33. {wfdb-4.2.0 → wfdb-4.3.0}/.readthedocs.yml +0 -0
  34. {wfdb-4.2.0 → wfdb-4.3.0}/DEVELOPING.md +0 -0
  35. {wfdb-4.2.0 → wfdb-4.3.0}/LICENSE +0 -0
  36. {wfdb-4.2.0 → wfdb-4.3.0}/README.md +0 -0
  37. {wfdb-4.2.0 → wfdb-4.3.0}/activate +0 -0
  38. {wfdb-4.2.0 → wfdb-4.3.0}/docs/Makefile +0 -0
  39. {wfdb-4.2.0 → wfdb-4.3.0}/docs/_static/.gitkeep +0 -0
  40. {wfdb-4.2.0 → wfdb-4.3.0}/docs/_templates/.gitkeep +0 -0
  41. {wfdb-4.2.0 → wfdb-4.3.0}/docs/convert.rst +0 -0
  42. {wfdb-4.2.0 → wfdb-4.3.0}/docs/index.rst +0 -0
  43. {wfdb-4.2.0 → wfdb-4.3.0}/docs/installation.rst +0 -0
  44. {wfdb-4.2.0 → wfdb-4.3.0}/docs/io.rst +0 -0
  45. {wfdb-4.2.0 → wfdb-4.3.0}/docs/plot.rst +0 -0
  46. {wfdb-4.2.0 → wfdb-4.3.0}/docs/processing.rst +0 -0
  47. {wfdb-4.2.0 → wfdb-4.3.0}/docs/wfdb-specifications.rst +0 -0
  48. {wfdb-4.2.0 → wfdb-4.3.0}/docs/wfdb.rst +0 -0
  49. {wfdb-4.2.0 → wfdb-4.3.0}/pylintrc +0 -0
  50. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/__init__.py +0 -0
  51. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/__init__.py +0 -0
  52. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/_header.py +0 -0
  53. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/_url.py +0 -0
  54. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/convert/__init__.py +0 -0
  55. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/convert/csv.py +0 -0
  56. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/convert/edf.py +0 -0
  57. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/convert/matlab.py +0 -0
  58. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/convert/tff.py +0 -0
  59. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/convert/wav.py +0 -0
  60. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/datasource.py +0 -0
  61. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/download.py +0 -0
  62. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/io/header.py +0 -0
  63. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/plot/__init__.py +0 -0
  64. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/plot/plot.py +0 -0
  65. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/processing/__init__.py +0 -0
  66. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/processing/basic.py +0 -0
  67. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/processing/evaluate.py +0 -0
  68. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/processing/filter.py +0 -0
  69. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/processing/hr.py +0 -0
  70. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/processing/peaks.py +0 -0
  71. {wfdb-4.2.0 → wfdb-4.3.0}/wfdb/processing/qrs.py +0 -0
@@ -38,18 +38,20 @@ jobs:
38
38
  - name: Check style
39
39
  run: uv run --extra dev black --check --diff .
40
40
 
41
- test-deb10-i386:
42
- name: Python 3.7 on Debian 10 i386
41
+ test-deb11-i386:
42
+ name: Python 3.7 on Debian 11 i386
43
43
  runs-on: ubuntu-latest
44
- container: i386/debian:10
44
+ container: i386/debian:11
45
45
  steps:
46
46
  - name: Install dependencies
47
47
  run: |
48
48
  apt-get update
49
49
  apt-get install -y --no-install-recommends \
50
+ python3-fsspec \
50
51
  python3-matplotlib \
51
52
  python3-numpy \
52
53
  python3-pandas \
54
+ python3-pip \
53
55
  python3-requests \
54
56
  python3-scipy \
55
57
  python3-soundfile \
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wfdb
3
- Version: 4.2.0
3
+ Version: 4.3.0
4
4
  Summary: The WFDB Python package: tools for reading, writing, and processing physiologic signals and annotations.
5
5
  Project-URL: homepage, https://github.com/MIT-LCP/wfdb-python/
6
6
  Project-URL: repository, https://github.com/MIT-LCP/wfdb-python/
@@ -9,6 +9,8 @@ Author-email: The Laboratory for Computational Physiology <contact@physionet.org
9
9
  License: MIT License
10
10
  License-File: LICENSE
11
11
  Requires-Python: >=3.9
12
+ Requires-Dist: aiohttp>=3.10.11
13
+ Requires-Dist: fsspec>=2023.10.0
12
14
  Requires-Dist: matplotlib>=3.2.2
13
15
  Requires-Dist: numpy>=1.26.4
14
16
  Requires-Dist: pandas>=2.2.3
@@ -20,7 +22,7 @@ Requires-Dist: black>=22.3.0; extra == 'dev'
20
22
  Requires-Dist: pylint>=2.13.7; extra == 'dev'
21
23
  Requires-Dist: pytest-xdist>=2.5.0; extra == 'dev'
22
24
  Requires-Dist: pytest>=7.1.1; extra == 'dev'
23
- Requires-Dist: sphinx>=4.5.0; extra == 'dev'
25
+ Requires-Dist: sphinx>=7.0.0; extra == 'dev'
24
26
  Description-Content-Type: text/markdown
25
27
 
26
28
  # The WFDB Python Package
@@ -5,6 +5,16 @@ This page lists recent changes in the `wfdb` package (since version 4.0.0) that
5
5
 
6
6
  .. _development repository: https://github.com/MIT-LCP/wfdb-python
7
7
 
8
+ Version 4.3.0 (Apr 2025)
9
+ -----------------------------
10
+
11
+ **Bump Sphinx to 7.0.0**
12
+ Bump Sphinx to 7.0.0
13
+
14
+ **Integrate `fsspec` for reading WFDB files from the cloud**
15
+ Enables reading WFDB files from cloud URLs
16
+
17
+
8
18
  Version 4.2.0 (Jan 2025)
9
19
  -----------------------------
10
20
 
@@ -82,7 +82,7 @@ release = __version__
82
82
  #
83
83
  # This is also used if you do content translation via gettext catalogs.
84
84
  # Usually you set "language" from the command line for these cases.
85
- language = None
85
+ language = "en"
86
86
 
87
87
  # List of patterns, relative to source directory, that match files and
88
88
  # directories to ignore when looking for source files.
@@ -0,0 +1,4 @@
1
+ numpydoc==1.7.0
2
+ sphinx==7.0.0
3
+ sphinx_rtd_theme==3.0.0
4
+ readthedocs-sphinx-search==0.3.2
Binary file
@@ -0,0 +1,3 @@
1
+ ecg-record 2 250 32500
2
+ ecg-record.dat 16 18880.19925093633(-8421)/mV 16 0 -9760 34371 0 I
3
+ ecg-record.dat 16 21737.727506426734(-8653)/mV 16 0 9016 32719 0 II
@@ -16,6 +16,8 @@ dependencies = [
16
16
  "soundfile >= 0.10.0",
17
17
  "matplotlib >= 3.2.2",
18
18
  "requests >= 2.8.1",
19
+ "fsspec >= 2023.10.0",
20
+ "aiohttp >= 3.10.11",
19
21
  ]
20
22
  dynamic = ["version"]
21
23
 
@@ -25,7 +27,7 @@ dev = [
25
27
  "pytest-xdist >= 2.5.0",
26
28
  "pylint >= 2.13.7",
27
29
  "black >= 22.3.0",
28
- "sphinx >= 4.5.0",
30
+ "sphinx >= 7.0.0",
29
31
  ]
30
32
 
31
33
  [project.urls]
Binary file
@@ -0,0 +1,6 @@
1
+ test01_00s_framex 3 500 4000
2
+ test01_00s.dat 16x1 100.0(0)/mV 16 0 10 114 0 ECG_1
3
+ test01_00s.dat 16x2 100.0(0)/mV 16 0 -8 822 0 ECG_2
4
+ test01_00s.dat 16x1 100.0(0)/mV 16 0 -57 65135 0 ECG_3
5
+ # <age>: 25 <sex>: M <diagnoses>: (none) <medications>: (none)
6
+ # This is a copy of test01_00s with 2 samples/frame for channel 1, cutting out channel 3.
Binary file
Binary file
@@ -0,0 +1,3 @@
1
+ 0001 2 250 2700000
2
+ 0001.dat 212 400 12 0 -83 -16218 0 ECG
3
+ 0001.dat 212 400 12 0 -21 6575 0 ECG
Binary file
Binary file
@@ -0,0 +1,3 @@
1
+ 0201 2 250 525000
2
+ 0201.dat 212 400 12 0 -42 23134 0 ECG
3
+ 0201.dat 212 400 12 0 -33 -29466 0 ECG
Binary file
@@ -0,0 +1,12 @@
1
+ 001a 9 1000 300000 20:26:00 27/09/1995
2
+ 001a.dat 16+512 1600 12 0 0 0 0 V1
3
+ 001a.dat 16+512 1600 12 0 0 0 0 V2
4
+ 001a.dat 16+512 1600 12 0 0 0 0 V3
5
+ 001a.dat 16+512 1600 12 0 0 0 0 V4
6
+ 001a.dat 16+512 1600 12 0 0 0 0 V5
7
+ 001a.dat 16+512 1600 12 0 0 0 0 V6
8
+ 001a.dat 16+512 1600 12 0 0 0 0 I
9
+ 001a.dat 16+512 1600 12 0 0 0 0 II
10
+ 001a.dat 16+512 1600 12 0 0 0 0 III
11
+ # Age: 52
12
+ # Sex: F
Binary file
@@ -0,0 +1,12 @@
1
+ 001b 9 1000 310938 23:21:00 27/09/1995
2
+ 001b.dat 16+512 1600 12 0 0 0 0 V1
3
+ 001b.dat 16+512 1600 12 0 0 0 0 V2
4
+ 001b.dat 16+512 1600 12 0 0 0 0 V3
5
+ 001b.dat 16+512 1600 12 0 0 0 0 V4
6
+ 001b.dat 16+512 1600 12 0 0 0 0 V5
7
+ 001b.dat 16+512 1600 12 0 0 0 0 V6
8
+ 001b.dat 16+512 1600 12 0 0 0 0 I
9
+ 001b.dat 16+512 1600 12 0 0 0 0 II
10
+ 001b.dat 16+512 1600 12 0 0 0 0 III
11
+ # Age: 52
12
+ # Sex: F
@@ -1,9 +1,15 @@
1
1
  import posixpath
2
2
 
3
+ import fsspec
4
+
3
5
  from wfdb.io import _url
4
6
  from wfdb.io.download import config
5
7
 
6
8
 
9
+ # Cloud protocols
10
+ CLOUD_PROTOCOLS = ["az://", "azureml://", "s3://", "gs://"]
11
+
12
+
7
13
  def _open_file(
8
14
  pn_dir,
9
15
  file_name,
@@ -26,10 +32,11 @@ def _open_file(
26
32
  ----------
27
33
  pn_dir : str or None
28
34
  The PhysioNet database directory where the file is stored, or None
29
- if file_name is a local path.
35
+ if file_name is a local or cloud path.
30
36
  file_name : str
31
- The name of the file, either as a local filesystem path (if
32
- `pn_dir` is None) or a URL path (if `pn_dir` is a string.)
37
+ The name of the file, either as a local filesystem path or cloud
38
+ URL (if `pn_dir` is None) or a PhysioNet URL path
39
+ (if `pn_dir` is a string.)
33
40
  mode : str, optional
34
41
  The standard I/O mode for the file ("r" by default). If `pn_dir`
35
42
  is not None, this must be "r", "rt", or "rb".
@@ -47,7 +54,7 @@ def _open_file(
47
54
 
48
55
  """
49
56
  if pn_dir is None:
50
- return open(
57
+ return fsspec.open(
51
58
  file_name,
52
59
  mode,
53
60
  buffering=buffering,
@@ -56,6 +63,12 @@ def _open_file(
56
63
  newline=newline,
57
64
  )
58
65
  else:
66
+ # check to make sure a cloud path isn't being passed under pn_dir
67
+ if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
68
+ raise ValueError(
69
+ "Cloud paths should be passed under record_name, not under pn_dir"
70
+ )
71
+
59
72
  url = posixpath.join(config.db_index_url, pn_dir, file_name)
60
73
  return _url.openurl(
61
74
  url,
@@ -1,11 +1,13 @@
1
1
  import math
2
2
  import os
3
+ import posixpath
3
4
  import sys
4
5
 
6
+ import fsspec
5
7
  import numpy as np
6
8
 
7
9
  from wfdb.io import download, _coreio, util
8
-
10
+ from wfdb.io._coreio import CLOUD_PROTOCOLS
9
11
 
10
12
  MAX_I32 = 2147483647
11
13
  MIN_I32 = -2147483648
@@ -1643,10 +1645,10 @@ def _rd_dat_file(file_name, dir_name, pn_dir, fmt, start_byte, n_samp):
1643
1645
  The name of the dat file.
1644
1646
  dir_name : str
1645
1647
  The full directory where the dat file(s) are located, if the dat
1646
- file(s) are local.
1648
+ file(s) are local or in the cloud.
1647
1649
  pn_dir : str
1648
1650
  The PhysioNet directory where the dat file(s) are located, if
1649
- the dat file(s) are remote.
1651
+ the dat file(s) are on a PhysioNet server.
1650
1652
  fmt : str
1651
1653
  The format of the dat file.
1652
1654
  start_byte : int
@@ -1686,15 +1688,22 @@ def _rd_dat_file(file_name, dir_name, pn_dir, fmt, start_byte, n_samp):
1686
1688
  element_count = n_samp
1687
1689
  byte_count = n_samp * BYTES_PER_SAMPLE[fmt]
1688
1690
 
1689
- # Local dat file
1691
+ # Local or cloud dat file
1690
1692
  if pn_dir is None:
1691
- with open(os.path.join(dir_name, file_name), "rb") as fp:
1693
+ with fsspec.open(os.path.join(dir_name, file_name), "rb") as fp:
1692
1694
  fp.seek(start_byte)
1693
- sig_data = np.fromfile(
1695
+ sig_data = util.fromfile(
1694
1696
  fp, dtype=np.dtype(DATA_LOAD_TYPES[fmt]), count=element_count
1695
1697
  )
1696
- # Stream dat file from Physionet
1698
+
1699
+ # Stream dat file from PhysioNet
1697
1700
  else:
1701
+ # check to make sure a cloud path isn't being passed under pn_dir
1702
+ if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
1703
+ raise ValueError(
1704
+ "Cloud paths should be passed under record_name, not under pn_dir"
1705
+ )
1706
+
1698
1707
  dtype_in = np.dtype(DATA_LOAD_TYPES[fmt])
1699
1708
  sig_data = download._stream_dat(
1700
1709
  file_name, pn_dir, byte_count, start_byte, dtype_in
@@ -1840,8 +1849,9 @@ def _rd_compressed_file(
1840
1849
  file_name : str
1841
1850
  The name of the signal file.
1842
1851
  dir_name : str
1843
- The full directory where the signal file is located, if local.
1844
- This argument is ignored if `pn_dir` is not None.
1852
+ The full directory where the signal file is located, if this
1853
+ is a local or cloud path. This argument is ignored if `pn_dir`
1854
+ is not None.
1845
1855
  pn_dir : str or None
1846
1856
  The PhysioNet database directory where the signal file is located.
1847
1857
  fmt : str
@@ -2585,10 +2595,10 @@ def _infer_sig_len(
2585
2595
  The byte offset of the dat file. None is equivalent to zero.
2586
2596
  dir_name : str
2587
2597
  The full directory where the dat file(s) are located, if the dat
2588
- file(s) are local.
2598
+ file(s) are local or on the cloud.
2589
2599
  pn_dir : str, optional
2590
2600
  The PhysioNet directory where the dat file(s) are located, if
2591
- the dat file(s) are remote.
2601
+ the dat file(s) are on a PhysioNet server.
2592
2602
 
2593
2603
  Returns
2594
2604
  -------
@@ -2600,13 +2610,29 @@ def _infer_sig_len(
2600
2610
  sig_len * tsamps_per_frame * bytes_per_sample == file_size
2601
2611
 
2602
2612
  """
2603
- if pn_dir is None:
2604
- file_size = os.path.getsize(os.path.join(dir_name, file_name))
2605
- else:
2613
+ from wfdb.io.record import CLOUD_PROTOCOLS
2614
+
2615
+ # If this is a cloud path, use posixpath to construct the path and fsspec to open file
2616
+ if any(dir_name.startswith(proto) for proto in CLOUD_PROTOCOLS):
2617
+ with fsspec.open(posixpath.join(dir_name, file_name), mode="rb") as f:
2618
+ file_size = f.seek(0, os.SEEK_END)
2619
+
2620
+ # If the PhysioNet database path is provided, construct the download path using the database version
2621
+ elif pn_dir is not None:
2622
+ # check to make sure a cloud path isn't being passed under pn_dir
2623
+ if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
2624
+ raise ValueError(
2625
+ "Cloud paths should be passed under record_name, not under pn_dir"
2626
+ )
2627
+
2606
2628
  file_size = download._remote_file_size(
2607
2629
  file_name=file_name, pn_dir=pn_dir
2608
2630
  )
2609
2631
 
2632
+ # If it isn't a cloud path or a PhysioNet path, we treat as a local file
2633
+ else:
2634
+ file_size = os.path.getsize(os.path.join(dir_name, file_name))
2635
+
2610
2636
  if byte_offset is None:
2611
2637
  byte_offset = 0
2612
2638
  data_size = file_size - byte_offset
@@ -1,4 +1,5 @@
1
1
  import copy
2
+ import fsspec
2
3
  import numpy as np
3
4
  import os
4
5
  import pandas as pd
@@ -9,6 +10,8 @@ import sys
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._coreio 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(
@@ -4,6 +4,7 @@ import posixpath
4
4
  import os
5
5
  import re
6
6
 
7
+ import fsspec
7
8
  import numpy as np
8
9
  import pandas as pd
9
10
 
@@ -13,6 +14,7 @@ from wfdb.io import _url
13
14
  from wfdb.io import download
14
15
  from wfdb.io import header
15
16
  from wfdb.io import util
17
+ from wfdb.io._coreio import CLOUD_PROTOCOLS
16
18
 
17
19
 
18
20
  # -------------- WFDB Signal Calibration and Classification ---------- #
@@ -1824,27 +1826,39 @@ def rdheader(record_name, pn_dir=None, rd_segments=False):
1824
1826
 
1825
1827
  """
1826
1828
  dir_name, base_record_name = os.path.split(record_name)
1827
- dir_name = os.path.abspath(dir_name)
1829
+ file_name = f"{base_record_name}.hea"
1828
1830
 
1829
- # Construct the download path using the database version
1830
- if (pn_dir is not None) and ("." not in pn_dir):
1831
- dir_list = pn_dir.split("/")
1832
- pn_dir = posixpath.join(
1833
- dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
1834
- )
1831
+ # If this is a cloud path, use posixpath to construct the path and fsspec to open file
1832
+ if any(dir_name.startswith(proto) for proto in CLOUD_PROTOCOLS):
1833
+ with fsspec.open(posixpath.join(dir_name, file_name), mode="r") as f:
1834
+ header_content = f.read()
1835
1835
 
1836
- # Read the local or remote header file.
1837
- file_name = f"{base_record_name}.hea"
1838
- if pn_dir is None:
1839
- with open(
1836
+ # If the PhysioNet database path is provided, construct the download path using the database version
1837
+ elif pn_dir is not None:
1838
+ # check to make sure a cloud path isn't being passed under pn_dir
1839
+ if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
1840
+ raise ValueError(
1841
+ "Cloud paths should be passed under record_name, not under pn_dir"
1842
+ )
1843
+
1844
+ if "." not in pn_dir:
1845
+ dir_list = pn_dir.split("/")
1846
+ pn_dir = posixpath.join(
1847
+ dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
1848
+ )
1849
+
1850
+ header_content = download._stream_header(file_name, pn_dir)
1851
+
1852
+ # If it isn't a cloud path or a PhysioNet path, we treat as a local file
1853
+ else:
1854
+ dir_name = os.path.abspath(dir_name)
1855
+ with fsspec.open(
1840
1856
  os.path.join(dir_name, file_name),
1841
1857
  "r",
1842
1858
  encoding="ascii",
1843
1859
  errors="ignore",
1844
1860
  ) as f:
1845
1861
  header_content = f.read()
1846
- else:
1847
- header_content = download._stream_header(file_name, pn_dir)
1848
1862
 
1849
1863
  # Separate comment and non-comment lines
1850
1864
  header_lines, comment_lines = header.parse_header_content(header_content)
@@ -2017,14 +2031,22 @@ def rdrecord(
2017
2031
 
2018
2032
  """
2019
2033
  dir_name, base_record_name = os.path.split(record_name)
2020
- dir_name = os.path.abspath(dir_name)
2034
+ # Update the dir_name using abspath unless it is a cloud path
2035
+ if not any(dir_name.startswith(proto) for proto in CLOUD_PROTOCOLS):
2036
+ dir_name = os.path.abspath(dir_name)
2021
2037
 
2022
2038
  # Read the header fields
2023
- if (pn_dir is not None) and ("." not in pn_dir):
2024
- dir_list = pn_dir.split("/")
2025
- pn_dir = posixpath.join(
2026
- dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
2027
- )
2039
+ if pn_dir is not None:
2040
+ # check to make sure a cloud path isn't being passed under pn_dir
2041
+ if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
2042
+ raise ValueError(
2043
+ "Cloud paths should be passed under record_name, not under pn_dir"
2044
+ )
2045
+ if "." not in pn_dir:
2046
+ dir_list = pn_dir.split("/")
2047
+ pn_dir = posixpath.join(
2048
+ dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
2049
+ )
2028
2050
 
2029
2051
  record = rdheader(record_name, pn_dir=pn_dir, rd_segments=False)
2030
2052
 
@@ -2308,11 +2330,17 @@ def rdsamp(
2308
2330
  channels=[1,3])
2309
2331
 
2310
2332
  """
2311
- if (pn_dir is not None) and ("." not in pn_dir):
2312
- dir_list = pn_dir.split("/")
2313
- pn_dir = posixpath.join(
2314
- dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
2315
- )
2333
+ if pn_dir is not None:
2334
+ # check to make sure a cloud path isn't being passed under pn_dir
2335
+ if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
2336
+ raise ValueError(
2337
+ "Cloud paths should be passed under record_name, not under pn_dir"
2338
+ )
2339
+ if "." not in pn_dir:
2340
+ dir_list = pn_dir.split("/")
2341
+ pn_dir = posixpath.join(
2342
+ dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
2343
+ )
2316
2344
 
2317
2345
  record = rdrecord(
2318
2346
  record_name=record_name,
@@ -2,9 +2,12 @@
2
2
  A module for general utility functions
3
3
  """
4
4
 
5
+ import io
5
6
  import math
6
7
  import os
7
8
 
9
+ import numpy as np
10
+
8
11
  from typing import List, Sequence, Tuple
9
12
 
10
13
 
@@ -121,3 +124,39 @@ def overlapping_ranges(
121
124
  for second in ranges_2
122
125
  if max(first[0], second[0]) < min(first[1], second[1])
123
126
  ]
127
+
128
+
129
+ def fromfile(fileobj, dtype, count=-1):
130
+ """
131
+ Read binary data from a file-like object into a NumPy array, using `np.fromfile` when possible.
132
+ Falls back to manual reading for file-like objects that are not compatible with np.fromfile.
133
+
134
+ Parameters
135
+ ----------
136
+ fileobj : file-like object
137
+ A binary file-like object
138
+ dtype :
139
+ The NumPy data type to read
140
+ count : int, optional
141
+ Number of elements or bytes to read depending on the format:
142
+ - For most formats, this is the number of elements (e.g., samples) to read.
143
+ - For formats "212", "310", "311", and "24", this is the number of bytes.
144
+ If set to -1 (default), reads until the end of the file and infers size from the stream
145
+ """
146
+ if isinstance(fileobj, io.FileIO) or (
147
+ isinstance(fileobj, (io.BufferedReader, io.BufferedRandom))
148
+ and isinstance(fileobj.raw, io.FileIO)
149
+ ):
150
+ return np.fromfile(fileobj, dtype=dtype, count=count)
151
+ else:
152
+ dtype = np.dtype(dtype)
153
+ if count < 0:
154
+ start = fileobj.tell()
155
+ fileobj.seek(0, os.SEEK_END)
156
+ end = fileobj.tell()
157
+ fileobj.seek(start, os.SEEK_SET)
158
+ count = (end - start) // dtype.itemsize
159
+ array = np.empty(count, dtype)
160
+ size = fileobj.readinto(array.view(np.uint8))
161
+ array.resize(size // dtype.itemsize)
162
+ return array
@@ -0,0 +1 @@
1
+ __version__ = "4.3.0"
@@ -1,4 +0,0 @@
1
- numpydoc<1.6
2
- sphinx==4.5.0
3
- sphinx_rtd_theme==1.0.0
4
- readthedocs-sphinx-search==0.3.2
@@ -1 +0,0 @@
1
- __version__ = "4.2.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes