muse2wfdb 1.0.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.
- muse2wfdb-1.0.0/LICENSE +21 -0
- muse2wfdb-1.0.0/PKG-INFO +55 -0
- muse2wfdb-1.0.0/README.md +39 -0
- muse2wfdb-1.0.0/muse2wfdb/converter.py +171 -0
- muse2wfdb-1.0.0/muse2wfdb.egg-info/PKG-INFO +55 -0
- muse2wfdb-1.0.0/muse2wfdb.egg-info/SOURCES.txt +9 -0
- muse2wfdb-1.0.0/muse2wfdb.egg-info/dependency_links.txt +1 -0
- muse2wfdb-1.0.0/muse2wfdb.egg-info/requires.txt +3 -0
- muse2wfdb-1.0.0/muse2wfdb.egg-info/top_level.txt +1 -0
- muse2wfdb-1.0.0/pyproject.toml +17 -0
- muse2wfdb-1.0.0/setup.cfg +4 -0
muse2wfdb-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 nagyl1999
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
muse2wfdb-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: muse2wfdb
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Convert GE MUSE ECG XML exports to WFDB format
|
|
5
|
+
Author: Levente Nagy
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/nagyl1999/muse2wfdb
|
|
8
|
+
Project-URL: Issues, https://github.com/nagyl1999/muse2wfdb/issues
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: wfdb>=4.1.0
|
|
13
|
+
Requires-Dist: xmltodict>=0.13.0
|
|
14
|
+
Requires-Dist: numpy>=1.22
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# muse2wfdb
|
|
18
|
+
### Convert GE MUSE XML ECG exports to WFDB format
|
|
19
|
+
|
|
20
|
+
`muse2wfdb` is a lightweight Python library that converts ECG data exported from the GE MUSE Resting ECG System (in XML format) into WFDB (WaveForm DataBase) format, compatible with PhysioNet tools and the wfdb Python package.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
Install directly from PyPI:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install muse2wfdb
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or install locally from source:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone https://github.com/nagyl1999/muse2wfdb.git
|
|
34
|
+
cd muse2wfdb
|
|
35
|
+
pip install .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
An example is provided in the `examples` folder.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from muse2wfdb.converter import muse_to_wfdb
|
|
44
|
+
import wfdb
|
|
45
|
+
|
|
46
|
+
muse_export = "examples/anonim_pac_xml_export.txt"
|
|
47
|
+
wfdb_filename = "patient001_ecg"
|
|
48
|
+
|
|
49
|
+
muse_to_wfdb(muse_export, wfdb_filename)
|
|
50
|
+
|
|
51
|
+
record = wfdb.rdrecord(wfdb_filename)
|
|
52
|
+
annotation = wfdb.rdann(wfdb_filename, 'atr')
|
|
53
|
+
|
|
54
|
+
wfdb.plot_wfdb(record=record, annotation=annotation, title="MUSE exported ECG")
|
|
55
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# muse2wfdb
|
|
2
|
+
### Convert GE MUSE XML ECG exports to WFDB format
|
|
3
|
+
|
|
4
|
+
`muse2wfdb` is a lightweight Python library that converts ECG data exported from the GE MUSE Resting ECG System (in XML format) into WFDB (WaveForm DataBase) format, compatible with PhysioNet tools and the wfdb Python package.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Install directly from PyPI:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install muse2wfdb
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or install locally from source:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
git clone https://github.com/nagyl1999/muse2wfdb.git
|
|
18
|
+
cd muse2wfdb
|
|
19
|
+
pip install .
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
An example is provided in the `examples` folder.
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from muse2wfdb.converter import muse_to_wfdb
|
|
28
|
+
import wfdb
|
|
29
|
+
|
|
30
|
+
muse_export = "examples/anonim_pac_xml_export.txt"
|
|
31
|
+
wfdb_filename = "patient001_ecg"
|
|
32
|
+
|
|
33
|
+
muse_to_wfdb(muse_export, wfdb_filename)
|
|
34
|
+
|
|
35
|
+
record = wfdb.rdrecord(wfdb_filename)
|
|
36
|
+
annotation = wfdb.rdann(wfdb_filename, 'atr')
|
|
37
|
+
|
|
38
|
+
wfdb.plot_wfdb(record=record, annotation=annotation, title="MUSE exported ECG")
|
|
39
|
+
```
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""
|
|
2
|
+
muse2wfdb.converter
|
|
3
|
+
-------------------
|
|
4
|
+
Convert GE MUSE XML ECG exports to WFDB (WaveForm Database) format.
|
|
5
|
+
|
|
6
|
+
Author: Levente Nagy
|
|
7
|
+
License: MIT
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import wfdb
|
|
11
|
+
import array
|
|
12
|
+
import base64
|
|
13
|
+
import xmltodict
|
|
14
|
+
import numpy as np
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Dict, Any, Optional, List
|
|
17
|
+
|
|
18
|
+
# Standard 12-lead ECG names
|
|
19
|
+
LEAD_NAMES: List[str] = [
|
|
20
|
+
'I', 'II', 'III', 'aVR', 'aVL', 'aVF',
|
|
21
|
+
'V1', 'V2', 'V3', 'V4', 'V5', 'V6'
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
QRS_TYPE_MAP = {
|
|
25
|
+
"0": "N", # Normal
|
|
26
|
+
"1": "V", # Ventricular
|
|
27
|
+
"2": "S", # Supraventricular
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def read_muse_file(path: str) -> Dict[str, Any]:
|
|
32
|
+
"""
|
|
33
|
+
Read and parse a GE MUSE XML file into a Python dictionary.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
path: Path to the XML file exported from MUSE.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
Parsed XML structure as a Python dictionary.
|
|
40
|
+
"""
|
|
41
|
+
path = Path(path)
|
|
42
|
+
if not path.exists():
|
|
43
|
+
raise FileNotFoundError(f"MUSE file not found: {path}")
|
|
44
|
+
|
|
45
|
+
with open(path, "rb") as muse_file:
|
|
46
|
+
return xmltodict.parse(muse_file.read().decode("utf-8"))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def select_waveform(ecg: Dict[str, Any]) -> Dict[str, Any]:
|
|
50
|
+
"""
|
|
51
|
+
Select the 'Rhythm' waveform section from the MUSE ECG XML structure.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
ecg: Parsed MUSE ECG dictionary.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
The waveform dictionary that corresponds to the 'Rhythm' ECG signal.
|
|
58
|
+
"""
|
|
59
|
+
for waveform in ecg["RestingECG"]["Waveform"]:
|
|
60
|
+
if waveform["WaveformType"] == "Rhythm":
|
|
61
|
+
return waveform
|
|
62
|
+
raise ValueError("No 'Rhythm' waveform found in MUSE ECG file.")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def process_waveforms(waveform: Dict[str, Any]) -> Dict[str, np.ndarray]:
|
|
66
|
+
"""
|
|
67
|
+
Decode base64 ECG waveforms for each lead and compute derived leads.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
waveform: The selected waveform dictionary from the MUSE file.
|
|
71
|
+
"""
|
|
72
|
+
lead_waveforms: Dict[str, np.ndarray] = {lead_name: [] for lead_name in LEAD_NAMES}
|
|
73
|
+
|
|
74
|
+
for lead in waveform["LeadData"]:
|
|
75
|
+
lead_data = lead["WaveFormData"]
|
|
76
|
+
decoded = base64.b64decode(lead_data)
|
|
77
|
+
samples = np.array(array.array("h", decoded))
|
|
78
|
+
lead_waveforms[lead["LeadID"]] = samples / 1000 # convert to mV
|
|
79
|
+
|
|
80
|
+
# Compute derived leads
|
|
81
|
+
lead_waveforms["III"] = lead_waveforms["II"] - lead_waveforms["I"]
|
|
82
|
+
lead_waveforms["aVR"] = -(lead_waveforms["I"] + lead_waveforms["II"]) / 2
|
|
83
|
+
lead_waveforms["aVL"] = lead_waveforms["I"] - 0.5 * lead_waveforms["II"]
|
|
84
|
+
lead_waveforms["aVF"] = lead_waveforms["II"] - 0.5 * lead_waveforms["I"]
|
|
85
|
+
|
|
86
|
+
return lead_waveforms
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def save_wfdb(lead_waveforms: Dict[str, np.ndarray], output_name: str = "wfdb_record", fs: int = 500) -> None:
|
|
90
|
+
"""
|
|
91
|
+
Save the processed ECG signals into WFDB format (.hea and .dat files).
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
lead_waveforms: The processed waveforms of the MUSE export.
|
|
95
|
+
output_name: The base name for the output WFDB files.
|
|
96
|
+
fs: Sampling frequency in Hz (default: 500).
|
|
97
|
+
"""
|
|
98
|
+
signals = []
|
|
99
|
+
for lead in LEAD_NAMES:
|
|
100
|
+
if lead_waveforms[lead].size == 0:
|
|
101
|
+
raise ValueError(f"Missing waveform data for lead: {lead}")
|
|
102
|
+
signals.append(lead_waveforms[lead])
|
|
103
|
+
|
|
104
|
+
# Stack all leads into (N, 12) matrix
|
|
105
|
+
signals = np.column_stack(signals)
|
|
106
|
+
|
|
107
|
+
wfdb.wrsamp(
|
|
108
|
+
record_name=output_name,
|
|
109
|
+
fs=fs,
|
|
110
|
+
units=["mV"] * len(LEAD_NAMES),
|
|
111
|
+
sig_name=LEAD_NAMES,
|
|
112
|
+
p_signal=signals,
|
|
113
|
+
fmt=['16'] * signals.shape[1]
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def save_qrs_annotations(record_name: str, qrs_data: list, fs: int = 500):
|
|
118
|
+
"""
|
|
119
|
+
Save QRS annotations from parsed MUSE XML data to a WFDB .qrs file.
|
|
120
|
+
|
|
121
|
+
Parameters
|
|
122
|
+
----------
|
|
123
|
+
record_name : str
|
|
124
|
+
Name of the WFDB record (without extension)
|
|
125
|
+
qrs_data : list[dict]
|
|
126
|
+
List of QRS entries, each with keys ['Number', 'Type', 'Time']
|
|
127
|
+
fs : int
|
|
128
|
+
Sampling frequency (Hz)
|
|
129
|
+
"""
|
|
130
|
+
# Convert <Time> (ms) to sample index
|
|
131
|
+
samples = np.array([int(qrs['Time']) for qrs in qrs_data])
|
|
132
|
+
|
|
133
|
+
# Symbol: all 'N' (normal) by default; can map from 'Type'
|
|
134
|
+
symbols = np.array([QRS_TYPE_MAP.get(qrs['Type'], 'N') for qrs in qrs_data])
|
|
135
|
+
|
|
136
|
+
# Optional aux notes
|
|
137
|
+
aux_notes = np.array([f"QRS_{qrs['Number']}" for qrs in qrs_data])
|
|
138
|
+
|
|
139
|
+
ann = wfdb.wrann(
|
|
140
|
+
record_name=record_name,
|
|
141
|
+
sample=samples,
|
|
142
|
+
symbol=symbols,
|
|
143
|
+
aux_note=aux_notes,
|
|
144
|
+
extension='atr'
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def muse_to_wfdb(path: str, output_name: str = "wfdb_record") -> None:
|
|
149
|
+
"""
|
|
150
|
+
Main function to convert a MUSE XML ECG file into WFDB format.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
path: Path to the input MUSE XML file.
|
|
154
|
+
output_name: Output WFDB record name (without extension).
|
|
155
|
+
"""
|
|
156
|
+
ecg = read_muse_file(path)
|
|
157
|
+
waveform = select_waveform(ecg)
|
|
158
|
+
|
|
159
|
+
# Process leads
|
|
160
|
+
frequency = int(ecg["RestingECG"]["Waveform"][0]["SampleBase"])
|
|
161
|
+
lead_waveforms = process_waveforms(waveform)
|
|
162
|
+
|
|
163
|
+
# Save processed data in WFDB format
|
|
164
|
+
save_wfdb(lead_waveforms, output_name, frequency)
|
|
165
|
+
|
|
166
|
+
if "QRS" not in ecg["RestingECG"]["QRSTimesTypes"]:
|
|
167
|
+
raise ValueError("No 'Rhythm' waveform found in MUSE ECG file, .dat file saved.")
|
|
168
|
+
|
|
169
|
+
# Save complexes in WFDB format
|
|
170
|
+
complexes = ecg["RestingECG"]["QRSTimesTypes"]["QRS"]
|
|
171
|
+
save_qrs_annotations(output_name, complexes)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: muse2wfdb
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Convert GE MUSE ECG XML exports to WFDB format
|
|
5
|
+
Author: Levente Nagy
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/nagyl1999/muse2wfdb
|
|
8
|
+
Project-URL: Issues, https://github.com/nagyl1999/muse2wfdb/issues
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: wfdb>=4.1.0
|
|
13
|
+
Requires-Dist: xmltodict>=0.13.0
|
|
14
|
+
Requires-Dist: numpy>=1.22
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# muse2wfdb
|
|
18
|
+
### Convert GE MUSE XML ECG exports to WFDB format
|
|
19
|
+
|
|
20
|
+
`muse2wfdb` is a lightweight Python library that converts ECG data exported from the GE MUSE Resting ECG System (in XML format) into WFDB (WaveForm DataBase) format, compatible with PhysioNet tools and the wfdb Python package.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
Install directly from PyPI:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install muse2wfdb
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or install locally from source:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone https://github.com/nagyl1999/muse2wfdb.git
|
|
34
|
+
cd muse2wfdb
|
|
35
|
+
pip install .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
An example is provided in the `examples` folder.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from muse2wfdb.converter import muse_to_wfdb
|
|
44
|
+
import wfdb
|
|
45
|
+
|
|
46
|
+
muse_export = "examples/anonim_pac_xml_export.txt"
|
|
47
|
+
wfdb_filename = "patient001_ecg"
|
|
48
|
+
|
|
49
|
+
muse_to_wfdb(muse_export, wfdb_filename)
|
|
50
|
+
|
|
51
|
+
record = wfdb.rdrecord(wfdb_filename)
|
|
52
|
+
annotation = wfdb.rdann(wfdb_filename, 'atr')
|
|
53
|
+
|
|
54
|
+
wfdb.plot_wfdb(record=record, annotation=annotation, title="MUSE exported ECG")
|
|
55
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
muse2wfdb
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "muse2wfdb"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "Convert GE MUSE ECG XML exports to WFDB format"
|
|
5
|
+
authors = [{ name = "Levente Nagy" }]
|
|
6
|
+
license = { text = "MIT" }
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
requires-python = ">=3.8"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"wfdb>=4.1.0",
|
|
11
|
+
"xmltodict>=0.13.0",
|
|
12
|
+
"numpy>=1.22"
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Homepage = "https://github.com/nagyl1999/muse2wfdb"
|
|
17
|
+
Issues = "https://github.com/nagyl1999/muse2wfdb/issues"
|