Preprocessor

Baseclass for preprocessing as well as the preprocessing classes for the supported datasets.

class ecgan.preprocessing.preprocessor.BasePreprocessor(cfg, dataset_name)[source]

Bases: abc.ABC

Base class for preprocessors.

Generally, preprocessors expect data to be in <target_dir>/<dataset_name>/raw (e.g. data/mitbih/raw) with target_dir being given in the config. Processed data should always be saved as data.pkl and label.pkl into <target_dir>/<dataset_name>/processed (e.g. data/mitbih/processed).

Parameters
  • cfg (PreprocessingConfig) -- Configuration determining data source and desired preprocessing.

  • dataset_name (str) -- Name of dataset which has to be preprocessed.

abstract preprocess()[source]

Preprocess a given dataset.

Return type

Tuple[ndarray, ndarray]

Returns

Data and label tensors.

save()[source]

Save the data as well as the labels to save_dir.

class ecgan.preprocessing.preprocessor.ExtractedBeatsPreprocessor(cfg, dataset_name)[source]

Bases: ecgan.preprocessing.preprocessor.BasePreprocessor

Preprocess the MITBIH/PTB dataset to retrieve beatwise segmented data.

The data is already preprocessed according to Kachuee et al. 2018.

preprocess()[source]

Preprocess the dataset.

Load the raw CSV data, reshape the univariate series into multivariate series, extract labels, call the _preprocess_worker to cleanse and resample the data. Each initial raw sample has 187 values and contains the label in the last column.

Return type

Tuple[ndarray, ndarray]

Returns

Tuple of data and labels in a framework compatible format.

class ecgan.preprocessing.preprocessor.MitbihExtractedBeatsPreprocessor(cfg, dataset_name)[source]

Bases: ecgan.preprocessing.preprocessor.ExtractedBeatsPreprocessor

Preprocess the MITBIH dataset from Kachuee et al. 2018.

class ecgan.preprocessing.preprocessor.PtbExtractedBeatsPreprocessor(cfg, dataset_name)[source]

Bases: ecgan.preprocessing.preprocessor.ExtractedBeatsPreprocessor

Preprocess the PTB dataset from Kachuee et al. 2018.

class ecgan.preprocessing.preprocessor.CMUMoCapPreprocessor(cfg, dataset_name)[source]

Bases: ecgan.preprocessing.preprocessor.BasePreprocessor

Preprocess the CMU MoCap subset used in Zhou et al. 2019.

preprocess()[source]

Preprocess the dataset.

Load the raw CSV data, reshape the univariate series into multivariate series, extract labels, call the _preprocess_worker to cleanse and resample the data.

Data is sampled as described in Zhou et al. 2019.

Return type

Tuple[ndarray, ndarray]

Returns

Tuple of data and labels in a framework compatible format.

class ecgan.preprocessing.preprocessor.ExtendedCMUMoCapPreprocessor(cfg, dataset_name)[source]

Bases: ecgan.preprocessing.preprocessor.CMUMoCapPreprocessor

Preprocess the CMU MoCap subset used in Zhou et al. 2019.

The original dataset by Zhou et al. is extended an additional class _dancing_.

preprocess()[source]

Preprocess the dataset.

Load the raw CSV data, reshape the univariate series into multivariate series, extract labels, call the _preprocess_worker to cleanse and resample the data.

Data is sampled as described in Zhou et al. 2019. Extended data of class _dancing_ is sampled same as the _walking_ class in the original.

Return type

Tuple[ndarray, ndarray]

Returns

Tuple of data and labels in a framework compatible format.

class ecgan.preprocessing.preprocessor.ElectricDevicesPreprocessor(cfg, dataset_name)[source]

Bases: ecgan.preprocessing.preprocessor.BasePreprocessor

Preprocess the Electric Devices Dataset from TODO.

preprocess()[source]

Preprocess the dataset.

Return type

Tuple[ndarray, ndarray]

Returns

Tuple of data and labels in a framework compatible format.

class ecgan.preprocessing.preprocessor.WaferPreprocessor(cfg, dataset_name)[source]

Bases: ecgan.preprocessing.preprocessor.BasePreprocessor

Preprocess the Electric Devices Dataset from TODO.

preprocess()[source]

Preprocess the dataset.

Return type

Tuple[ndarray, ndarray]

Returns

Tuple of data and labels in a framework compatible format.

class ecgan.preprocessing.preprocessor.MitbihBeatganPreprocessor(cfg, dataset_name)[source]

Bases: ecgan.preprocessing.preprocessor.BasePreprocessor

Preprocess the MITBIH dataset from Zhou et al. 2019.

preprocess()[source]

Preprocess the MITBIH BEATGAN dataset.

Since the data itself is already preprocessed according to the paper, data classes are concatenated, reshaped and labeled according to the format used in ECGAN. Data can be additionally resampled, additional cleansing is not supported.

It can be useful to remove the second dim (the second feature) since the leads differ across many series.

Warning

The data has not been validated and might be erroneous.

Return type

Tuple[ndarray, ndarray]

class ecgan.preprocessing.preprocessor.ShaoxingPreprocessor(cfg, dataset_name)[source]

Bases: ecgan.preprocessing.preprocessor.BasePreprocessor

Preprocess the Shaoxing dataset from Zheng et al. 2020.

preprocess()[source]

Start preprocessing the Shaoxing data and save it to disc.

Return type

Tuple[ndarray, ndarray]

class ecgan.preprocessing.preprocessor.PreprocessorFactory[source]

Bases: object

Meta module for creating preprocessor instances.