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 set_array(self, array_data, location): """ Create a temporary HDF5 file with the array data and upload the file data to the G-Node REST API. :param array_data: The raw data to store. :type array_data: numpy.ndarray|list """ fd, tmppath = tempfile.mkstemp() store_array_data(tmppath, array_data) with open(tmppath, 'rb') as f: self.set_file(f.read(), location) os.close(fd) os.remove(tmppath)
def set_array(self, array_data, location=None, temporary=False): """ Save array data in a cached HDF5 file. :param array_data: The raw data to store. :type array_data: numpy.ndarray|list :param location: The location of the file. :type location: str :returns: The url to the uploaded file. :rtype: str """ if location is None: ident = helper.random_base32() location = "/api/v1/temp/datafile/" + ident + "/" else: ident = helper.id_from_location(location) path = self.__cache.file_cache_path(ident, temporary) hdfio.store_array_data(path, array_data) return location