def test_hdf5_io(self): basepath = appdirs.user_cache_dir(appname=Configuration.NAME, appauthor=Configuration.ATHOR) testpath = os.path.join(basepath, 'bla.hdf5') if not os.path.isdir(basepath): os.makedirs(basepath, 0o0750) testlist = [1, 2, 3, 4, 5, 6, 7, 8, 9] testarray = np.array(testlist) store_array_data(testpath, testlist) self.assertTrue((read_array_data(testpath) == testarray).all()) store_array_data(testpath, testarray) self.assertTrue((read_array_data(testpath) == testarray).all())
def get_array(self, location, temporary=False): """ Read array data from an hdf5 file in the cache. :param location: The locations of all entities as path or URL. :type location: str :returns: The raw file data. :rtype: numpy.ndarray|list """ ident = helper.id_from_location(location) path = self.__cache.file_cache_path(ident, temporary) if os.path.isfile(path): data = hdfio.read_array_data(path) return data else: return None
def get_array(self, location): """ Get raw file data from the G-Node REST API, store it temporarily as an HDF5 file and extract the array data from the file. :param location: The locations of all entities as path or URL. :type location: str :returns: The raw file data. :rtype: numpy.ndarray|list """ fd, tmppath = tempfile.mkstemp() with open(tmppath, 'w') as f: f.write(self.get_file(location)) array_data = read_array_data(tmppath) os.close(fd) os.remove(tmppath) return array_data