def _run_pyfibre(self): input_files = [] for file_path in self.file_paths: input_files += parse_file_path(file_path, self.key) file_sets = [] for label, parser in self.supported_parsers.items(): file_sets += parser.get_file_sets(input_files) for label, reader in self.supported_readers.items(): logger.info(f"Analysing {label} images") analyser = self.supported_analysers[label] image_databases = [pd.DataFrame() for _ in analyser.database_names] generator = self.runner.run(file_sets, analyser, reader) for databases in generator: for index, database in enumerate(databases): if isinstance(database, pd.Series): image_databases[index] = image_databases[index].append( database, ignore_index=True) elif isinstance(database, pd.DataFrame): image_databases[index] = pd.concat( [image_databases[index], database]) if self.database_name: for index, name in enumerate(analyser.database_names): save_database(image_databases[index], self.database_name, name)
def test_load_database(self): with NamedTemporaryFile() as temp_file: save_database(self.database, temp_file.name) database = load_database(temp_file.name) self.assertArrayAlmostEqual(self.database['one'], database['one']) self.assertArrayAlmostEqual(self.database['two'], database['two'])
def test_save_database(self): with NamedTemporaryFile() as temp_file: save_database(self.database, temp_file.name) self.assertTrue(os.path.exists(f'{temp_file.name}.h5')) self.assertTrue(os.path.exists(f'{temp_file.name}.xls')) save_database(self.database, temp_file.name, 'extra') self.assertTrue(os.path.exists(f'{temp_file.name}_extra.h5')) self.assertTrue(os.path.exists(f'{temp_file.name}_extra.xls'))
def save_database(self, filename): """Save databases successfully generated by all loaded images""" for tag, analyser in self.supported_analysers.items(): for index, name in enumerate(analyser.database_names): try: save_database(self.image_databases[tag][index], filename, name) except IOError: logger.exception("Error when saving databases") return False return True
def save_databases(self, databases): """Save pandas DataFrame instances created during the analysis""" for index, name in enumerate(self.database_names): save_database(databases[index], self._data_file, f'{name}_metric')