Skip to main content

Code Collection for Medical Data Processing and Analysis

Project description

medipy

Code Collection for Medical Data Processing and Analysis in Python

License

This Python package provides a broad collection of code for processing and analyzing medical data (like ECG, EEG, ACC, EMG, GYRO, ..). Every modul reflects a model, algorithm or concept published in scientific journal (or similiar) and is named after its main author. The publications are cited in the docstring of each modul.

Implemented Code

These are the current modules which are implemented in this package:

  • R-Peak-Detection for 1D ECG Signals by Hamilton
  • RR-Interval-Error-Detection for 1D ECG Signals by Lipponen

Installation

You can install the package using pip:

pip install medipy

Usage

You can use any function of this package by either importing the complete package

import medipy as mp
r_peaks= mp.hamilton.detect_r_peaks(ecg, sampling_rate)

or single modules

from medipy import hamilton
r_peaks= hamilton.detect_r_peaks(ecg, sampling_rate)

Example

import math
from medipy import hamilton
from medipy import lipponen
from matplotlib import pyplot as plt
from scipy.misc import electrocardiogram

# Load ECG Data using scipy
ecg = electrocardiogram()
sample_rate = 360

# Detect R-Peaks
ecg_preprocessed = hamilton.preprocessing(ecg, sample_rate)
r_peaks = hamilton.detect_r_peaks(ecg, ecg_preprocessed, sample_rate, least_distance=0.2, th_coefficient=0.189, th_search_back=0.3)
r_peaks_refined = hamilton.refine_r_peaks(ecg, r_peaks, refine_samples=30)

# Calculate RR-Intervals
rr_intervals = [math.ceil(r_peaks[k] - r_peaks[k - 1]) for k in range(1, len(r_peaks))]

# Detect RR-Errors
rr_errors, ectopic_intervals, missed_intervals, extra_intervals, long_short_intervals = lipponen.rr_interval_error_detection(rr_intervals)

# Print Results
print("R-Peaks: ", len(r_peaks))
print("RR-Intervals: ", len(rr_intervals))
print("RR-Errors: ", sum(rr_errors))
print("Ectopic Intervals: ", sum(ectopic_intervals))
print("Missed Intervals: ", sum(missed_intervals))
print("Extra Intervals: ", sum(extra_intervals))
print("Long Short Intervals: ", sum(long_short_intervals))

# Plot
fig = plt.figure()
plt.plot(ecg)
plt.plot(r_peaks, ecg[r_peaks], 'rx')
plt.plot(r_peaks_refined, ecg[r_peaks_refined], 'go')
plt.show()

Contribution

If you want to support the project or contribute to the code, feel free to contact.

License

This project is licensed under the MIT License - see the License file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

medipy-0.0.6.tar.gz (7.4 kB view hashes)

Uploaded Source

Built Distribution

medipy-0.0.6-py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page