def setup_class_methods(request): """ Fixture to setup class to test EcgBatch methods separately. """ path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/') ind = ds.FilesIndex(path=os.path.join(path, 'A*.hea'), no_ext=True, sort=True) batch_loaded = (EcgBatch(ind, unique_labels=["A", "O", "N"]) .load(fmt="wfdb", components=["signal", "annotation", "meta"])) def teardown_class_methods(): """ Teardown class """ request.addfinalizer(teardown_class_methods) return batch_loaded
def test_load_wav(self, setup_module_load): #pylint: disable=redefined-outer-name """ Testing EDF loader. """ # Arrange path = setup_module_load[1] ind = ds.FilesIndex(path=os.path.join(path, 'sample*.wav'), no_ext=True, sort=True) batch = EcgBatch(ind) # Act batch = batch.load(fmt="wav", components=["signal", "annotation", "meta"]) # Assert assert isinstance(batch.signal, np.ndarray) assert isinstance(batch.meta, np.ndarray) assert isinstance(batch.annotation, np.ndarray) assert batch.signal.shape == (1,) assert batch.annotation.shape == (1,) assert batch.meta.shape == (1,) assert isinstance(batch.signal[0], np.ndarray) assert isinstance(batch.annotation[0], dict) assert isinstance(batch.meta[0], dict) del batch
def test_load_wfdb_annotation(self, setup_module_load): #pylint: disable=redefined-outer-name """ Testing wfdb loader for annotation. """ # Arrange path = setup_module_load[1] ind = ds.FilesIndex(path=os.path.join(path, 'sel100.hea'), no_ext=True, sort=True) batch = EcgBatch(ind) # Act batch = batch.load(fmt="wfdb", components=["signal", "annotation", "meta"], ann_ext="pu1") # Assert assert isinstance(batch.signal, np.ndarray) assert isinstance(batch.meta, np.ndarray) assert isinstance(batch.annotation, np.ndarray) assert batch.signal.shape == (1,) assert batch.annotation.shape == (1,) assert batch.meta.shape == (1,) assert isinstance(batch.signal[0], np.ndarray) assert isinstance(batch.annotation[0], dict) assert isinstance(batch.meta[0], dict) assert 'annsamp' in batch.annotation[0] assert 'anntype' in batch.annotation[0] del batch
def setup_module_load(request): """ Fixture to setup module. Performs check for presence of test files, creates initial batch object. """ path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') files = ["A00001.hea", "A00001.mat", "A00002.hea", "A00002.mat", "A00004.hea", "A00004.mat", "A00005.hea", "A00005.mat", "A00008.hea", "A00008.mat", "A00013.hea", "A00013.mat", "REFERENCE.csv"] # TODO: make better test for presence of files .hea and # REFERENCE.csv if np.all([os.path.isfile(os.path.join(path, file)) for file in files]): ind = ds.FilesIndex(path=os.path.join(path, 'A*.hea'), no_ext=True, sort=True) else: raise FileNotFoundError("Test files not found in 'tests/data/'!") def teardown_module_load(): """ Teardown module """ request.addfinalizer(teardown_module_load) return ind, path
import sys import numpy as np from matplotlib import pyplot as plt sys.path.append('..') import cardio import cardio.dataset as ds index = ds.FilesIndex(path='C:/training2017/A*.hea', no_ext=True, sort=True) #print(index.indices) from cardio import EcgBatch eds = ds.Dataset(index, batch_class=EcgBatch) batch = eds.next_batch(batch_size=6, unique_labels=['A', 'N', 'O']) batch_with_data = batch.load(fmt='wfdb', components=['signal', 'meta']) batch_with_data = batch.load(src='C:/training2017/REFERENCE.csv', fmt='csv', components='target') #print(batch_with_data['A00001'].target) ## now trying different actions original_batch = batch_with_data.deepcopy() changed_batch = batch_with_data.deepcopy() ## CONVOLUTION to remove noise from Ecg kernel = cardio.kernels.gaussian( size=10) # will convolute signal with gaussian curve to remove noise length = original_batch["A00001"].signal.shape[1]