Example #1
0
    def init(self):
        if not self.data_exist():
            self.download()
            src_dir = path.join(datasets_dir(self.root_dir), 'download',
                                'training2017')
            shutil.move(src_dir,
                        path.join(datasets_dir(self.root_dir), self.name()))
            print(
                f'Successfully downloaded dataset {self.name()} to {self.root_dir}.'
            )

        if self.features_exist():
            self.data = pd.read_pickle(
                path.join(data_dir(self.root_dir),
                          f'{self.name()}Features.pkl'))
            return

        if self.dataset_exists():
            self.data = pd.read_pickle(
                path.join(data_dir(self.root_dir), f'{self.name()}.pkl'))
        else:
            self.data = pd.read_csv(path.join(datasets_dir(self.root_dir),
                                              self.name(), 'REFERENCE.csv'),
                                    names=['Record', 'Label'],
                                    dtype={'Label': 'category'})
            self.data['Fs'] = 300
Example #2
0
    def init(self):
        if not self.data_exist():
            self.download()
            for dir in ['TrainingSet1', 'TrainingSet2', 'TrainingSet3']:
                src_dir = path.join(datasets_dir(self.root_dir), 'download',
                                    dir)
                shutil.copytree(src_dir,
                                path.join(datasets_dir(self.root_dir),
                                          self.name()),
                                dirs_exist_ok=True,
                                copy_function=shutil.move)
                os.rmdir(src_dir)
            print(
                f'Successfully downloaded dataset {self.name()} to {self.root_dir}.'
            )

        if self.features_exist():
            self.data = pd.read_pickle(
                path.join(data_dir(self.root_dir),
                          f'{self.name()}Features.pkl'))
            return

        if self.dataset_exists():
            self.data = pd.read_pickle(
                path.join(data_dir(self.root_dir), f'{self.name()}.pkl'))
        else:
            self.data = pd.read_csv(path.join(datasets_dir(self.root_dir),
                                              self.name(), 'REFERENCE.csv'),
                                    dtype={
                                        'First_label': 'Int64',
                                        'Second_label': 'Int64',
                                        'Third_label': 'Int64'
                                    })
            self.data.columns = ['Record', 'Label', 'Label2', 'Label3']
            self.data = self.data[self.data['Label2'].isnull()].reset_index(
                drop=True)
            self.data['Fs'] = 500
Example #3
0
    def init(self):
        if self.features_exist():
            self.data = pd.read_pickle(
                path.join(data_dir(self.root_dir),
                          f'{self.name()}Features.pkl'))
            return

        if self.dataset_exists():
            self.data = pd.read_pickle(
                path.join(data_dir(self.root_dir), f'{self.name()}.pkl'))
        else:
            self.data = pd.read_pickle(
                path.join(datasets_dir(self.root_dir), self.name(),
                          'private_dataset.pkl')).drop(columns=['Signal'])
            self.data.columns = ['Device', 'Label', 'Record']
            self.data['Fs'] = 200
Example #4
0
    def download(self):
        """
        Downloads and extracts the dataset's resources from self.resources.
        """
        if self.data_exist():
            return

        download_dir = path.join(datasets_dir(self.root_dir), 'download')
        ensure_directory_exists(download_dir)

        for filename, (url, md5) in self.resources.items():
            download_and_extract_archive(url,
                                         download_root=download_dir,
                                         filename=filename,
                                         md5=md5,
                                         remove_finished=False)

        print('Downloading done!')
Example #5
0
 def data_exist(self):
     """
     :return: True if the dataset is extracted in the datasets folder.
     """
     return path.exists(
         path.join(datasets_dir(self.root_dir), f'{self.name()}'))
Example #6
0
 def __init__(self, root_dir='.', transform=None, data=None, split=None):
     super().__init__(root_dir, transform, data, split)
     self.signals = pd.read_pickle(
         path.join(datasets_dir(self.root_dir), self.name(),
                   'private_dataset.pkl'))
Example #7
0
 def read_record(self, record):
     mat = loadmat(
         path.join(datasets_dir(self.root_dir), self.name(), record))
     signal = mat['ECG'][0, 0][2][self.lead]
     return signal.astype(np.float32)