def test_equality(self): """Check the equality of two GriddedField objects.""" # Create two different objects with same content. a = xml.load(self.ref_dir + 'GriddedField3.xml') b = xml.load(self.ref_dir + 'GriddedField3.xml') assert a == b
def test_load_arts_xml_data(xmlfile): """Try to load all XML files in ARTS_DATA_PATH. Search for XML files in ARTS_DATA_PATH. If files are found, try to load them. It is just checked, if xml.load runs without exception. """ xml.load(xmlfile) pass
def test_nonequality(self): """Check the non-equality of two GriddedField objects.""" # Create two different objects with same content. a = xml.load(self.ref_dir + 'GriddedField3.xml') b = xml.load(self.ref_dir + 'GriddedField3.xml') a.name = 'foo' b.name = 'bar' assert a != b
def test_load_xml_search_arts_path(self): """Test loading file from ARTS_DATA_PATH""" backup_path = environ.get("ARTS_DATA_PATH") environ["ARTS_DATA_PATH"] = self.ref_dir xml.load("vector.xml") if backup_path: environ["ARTS_DATA_PATH"] = backup_path else: environ.pop("ARTS_DATA_PATH")
def test_copy(self): """Test copying of GriddedFields.""" a = xml.load(self.ref_dir + 'GriddedField3.xml') b = a.copy() # GriddedFields should be equal but not the same object. assert a is not b and a == b
def test_deepcopy(self): """Test deepcopying of GriddedField attributes.""" a = xml.load(self.ref_dir + 'GriddedField3.xml') b = a.copy() # Grids should not be the same object. assert a.grids is not b.grids
def test_slicing(self): """Test GriddedField slicing.""" gf3 = xml.load(self.ref_dir + 'GriddedField3.xml') # Create new GriddedField which is a sliced subset of the initial one. gf_sliced = gf3.extract_slice(slice(1, None), axis=1) assert np.allclose(gf3.data[:, 1:, :], gf_sliced.data)
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 fromArtsXML(cls, sat, instr, ch): """Read SRF from ArtsXML files. Requires that in the TYPHONRC configuration file, the fields `srf_backend_f` and `srf_backend_response` in the section corresponding to instrument `instr` are defined to point to the respective files in ArtsXML format. Within those definitions, {sat:s} will be substituted with the satellite name. For example, in typhonrc, one might have: [hirs] srf_backend_response = /path/to/{sat}_HIRS.backend_channel_response.xml srf_backend_f = /path/to/{sat}_HIRS.f_backend.xml so that we can do: >>> srf = SRF.fromArtsXML("NOAA15", "hirs", 12) >>> R_300 = srf.blackbody_radiance(ureg.Quantity(atleast_1d(250), 'K')) >>> print(R_300) [ 2.13002925e-13] watt / hertz / meter ** 2 / steradian >>> print(R_300.to("cm * mW / m**2 / sr", "radiance")) [ 6.38566704] centimeter * milliwatt / meter ** 2 / steradian Arguments: sat [str] Satellite name, such as 'NOAA15' instr [str] Instrument name, such as 'hirs'. ch [int] Channel number (start counting at 1). """ from pyarts import xml cf = config.conf[instr] centres = xml.load(cf["srf_backend_f"].format(sat=sat)) gfs = xml.load(cf["srf_backend_response"].format(sat=sat)) freq = gfs[ch - 1].grids[0] + centres[ch - 1] response = gfs[ch - 1].data return cls(freq, response)
def test_load_tensor(self, n): """Load tensor of dimension n and compare data to reference. Args: n (int): number of dimensions """ reference = _create_tensor(n) test_data = xml.load(self.ref_dir + 'tensor{}.xml'.format(n)) assert np.array_equal(test_data, reference)
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_plot_looup(self): lookup_file = join(dirname(__file__), 'reference', 'abs_lookup_small.xml') fig, ax = plot_arts_lookup(axml.load(lookup_file)) fig.suptitle('Lookup table opacities') fig.subplots_adjust(top=0.88) plt.savefig("lookup_opacities.pdf") lookup_file = join(dirname(__file__), 'reference', 'abs_lookup_small.xml') fig, ax = plot_arts_lookup( axml.load(lookup_file), species=ArrayOfArrayOfSpeciesTag([[SpeciesTag("N2O")], [SpeciesTag("O3")]]), opacity=False) fig.suptitle('Lookup table absorption cross sections [m$^2$]') fig.subplots_adjust(top=0.88) plt.savefig("lookup_crosssections.pdf")
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 to_arts(self): """ Return the value of this variable as a typhon type. This function writes the value of the variable to a temporary file and reads it into Python using typhon load function. The purpose of this function is to access WSV whose groups are not natively supported by the C API. Returns: A typhon object with the same value as the WSV in the associated workspace. """ from pyarts.xml import load if not self.ws: raise Exception("Cannot retrieve the value of a variable without " + " associated Workspace.") with tempfile.TemporaryDirectory() as tmpdir: tfile = os.path.join(tmpdir, 'wsv.xml') self.ws.WriteXML("binary", self, tfile) v = load(tfile) return v
def test_from_xarray(self): a = xml.load(self.ref_dir + 'GriddedField3.xml') a.dataname = 'Testdata' da = a.to_xarray() b = griddedfield.GriddedField3.from_xarray(da) assert a == b
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_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_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_load_dimension(self): """Load reference XML file for GriddedField3 and run check.""" gf3 = xml.load(self.ref_dir + 'GriddedField3.xml') assert gf3.check_dimension()
def test_load_directory(self): """Test loading all XML files in a directory.""" t = xml.load_directory(self.ref_dir) ref = xml.load(join(self.ref_dir, 'vector.xml')) assert np.allclose(t['vector'], ref)
def test_load_grids(self): """Load reference XML file for GriddedField3 and check the grids.""" reference = [np.arange(2)] * 3 gf3 = xml.load(self.ref_dir + 'GriddedField3.xml') test_data = gf3.grids assert all(np.allclose(a, b) for a, b in zip(test_data, reference))
def test_load_data(self): """Load reference XML file for GriddedField3 and check the data.""" reference = _create_tensor(3) gf3 = xml.load(self.ref_dir + 'GriddedField3.xml') test_data = gf3.data assert np.array_equal(test_data, reference)
def test_repr(self): """Test string represenation of GriddedField objects.""" str(xml.load(self.ref_dir + 'GriddedField3.xml'))
def test_data_subscription(self): """Test direct data subscription.""" gf3 = xml.load(self.ref_dir + 'GriddedField3.xml') assert gf3[0, 1, 0] == gf3.data[0, 1, 0]
def test_load_index(self): """Load reference XML file for ARTS type Index.""" assert xml.load(self.ref_dir + 'index.xml') == 0
def test_load_gridnames(self): """Load reference XML file for GriddedField3 and check gridnames.""" reference = ['grid1', 'grid2', 'grid3'] gf3 = xml.load(self.ref_dir + 'GriddedField3.xml') test_data = gf3.gridnames assert np.array_equal(test_data, reference)
def test_shape(self): """Test return of data shape.""" gf3 = xml.load(self.ref_dir + 'GriddedField3.xml') assert gf3.shape == gf3.data.shape == (2, 2, 2)
def test_load_vector(self): """Load reference XML file for ARTS type Vector.""" reference = _create_tensor(1) test_data = xml.load(self.ref_dir + 'vector.xml') assert np.array_equal(test_data, reference)