def test_save_binary_gzip(self): """Check for exception when attempting to write zipped binary file.""" f = self.f + '.gz' ref = np.arange(10) with pytest.raises(Exception): xml.save(ref, f, format='binary')
def test_save_gzip(self): """Test writing/reading of gzipped files.""" f = self.f + '.gz' ref = np.arange(10) xml.save(ref, f) assert np.array_equal(ref, xml.load(f))
def test_write_load_griddedfield(self, dim): gf = _get_griddedfield_type(dim)() gf.grids = [np.arange(2)] * dim gf.data = _create_tensor(dim) xml.save(gf, self.f) test_data = xml.load(self.f) assert np.array_equal(gf.data, test_data.data)
def test_save_empty_tensor(self, n): """Save empty tensor of dimension n to file, read it and compare data to reference. Args: n (int): number of dimensions """ reference = _create_empty_tensor(n) xml.save(reference, self.f) test_data = xml.load(self.f) assert np.array_equal(test_data, reference)
def test_save_load_tensor(self, n, fileformat): """Save tensor of dimension n to file, read it and compare data to reference. Args: n (int): number of dimensions fileformat (str): 'ascii' or 'binary'. """ reference = _create_tensor(n) xml.save(reference, self.f, format=fileformat) test_data = xml.load(self.f) assert np.array_equal(test_data, reference)
def test_xml_io(self): save(self.covmat, self.f) covmat2 = load(self.f) def compare_matrices(args): b1, b2 = args m1 = b1.matrix m2 = b2.matrix if isinstance(m1, sp.sparse.spmatrix): m1 = m1.todense() m2 = m2.todense() print(m1) return np.allclose(m1, m2) assert (all( map(compare_matrices, zip(self.covmat.blocks, covmat2.blocks))))
def from_arts(self, var): """ Set the value of this WSV in the associated workspace to the given typhon type. This function writes the value in ASCII format to a temporary file and reads it into the workspace Args: var: The value to which this WSV should be set in the associated workspace. """ from pyarts.xml import save if not self.ws: raise Exception("Cannot set the value of a variable without " + " associated Workspace.") with tempfile.TemporaryDirectory() as tmpdir: tfile = os.path.join(tmpdir, 'wsv.xml') save(var, tfile, format='binary') self.ws.ReadXML(self, tfile)
def test_save_arrayofindex_binary(self, inttype): """Save ArrayOfIndex to binary file, read it and compare the result.""" reference = [inttype(i) for i in [1., 2., 3.]] xml.save(reference, self.f, format='binary') test_data = xml.load(self.f) assert np.array_equal(test_data, reference)
def test_save_vector_binary(self): """Save Vector to binary file, read it and compare the results.""" reference = _create_tensor(1) xml.save(reference, self.f, format='binary') test_data = xml.load(self.f) assert np.array_equal(test_data, reference)
def test_save_index(self, inttype): """Save Index to file, read it and compare the results.""" reference = inttype(0) xml.save(reference, self.f) test_data = xml.load(self.f) assert test_data == reference
def test_save_matrix(self): """Save Matrix to file, read it and compare the results.""" reference = _create_tensor(2) xml.save(reference, self.f) test_data = xml.load(self.f) assert np.array_equal(test_data, reference)
def test_save_empty_vector(self): """Save empty Vector to file, read it and compare the results.""" reference = _create_empty_tensor(1) xml.save(reference, self.f) test_data = xml.load(self.f) assert np.array_equal(test_data, reference)
def test_save_arrayofvector(self): """Save ArrayOfIndex to file, read it and compare the results.""" reference = [np.arange(1), np.arange(1)] xml.save(reference, self.f) test_data = xml.load(self.f) assert np.array_equal(test_data, reference)
def test_save_arrayofstring(self): """Save ArrayOfString to file, read it and compare the results.""" reference = ['a', 'bb', 'ccc'] xml.save(reference, self.f) test_data = xml.load(self.f) assert np.array_equal(test_data, reference)
def test_save_arrayofindex(self): """Save ArrayOfIndex to file, read it and compare the results.""" reference = [1., 2., 3.] xml.save(reference, self.f) test_data = xml.load(self.f) assert np.array_equal(test_data, reference)
def test_save_complex_matrix_binary(self): """Save complex Matrix to file, read it and compare the results.""" reference = _create_complex_tensor(2) xml.save(reference, self.f, format='binary') test_data = xml.load(self.f) assert np.array_equal(test_data, reference)
def test_sparse(self, fileformat): """Save Sparse to file, read it and compare the result.""" reference = _create_sparse(10) xml.save(reference, self.f, format=fileformat) test_data = xml.load(self.f) assert np.array_equal(test_data.toarray(), reference.toarray())