pyarts.xml
This module provides functionality for reading and writing ARTS XML files.
- pyarts.xml.load(filename, search_arts_path=True)[source]
Load a variable from an ARTS XML file.
The input file can be either a plain or gzipped XML file.
By default, the current directory, ARTS_INCLUDE_PATH and ARTS_DATA_PATH environment variables are searched (in that order) if the passed filename is a relative path.
- Parameters:
- Returns:
Data from the XML file. Type depends on data in file.
Example
>>> pyarts.xml.load('tests/reference/matrix.xml') array([[ 0., 1.], [ 2., 3.]])
- pyarts.xml.load_directory(directory, exclude=None)[source]
Load all XML files in a given directory.
Search given directory for files with
.xml
or.xml.gz
extension and try to load them usingload()
.- Parameters:
- Returns:
Filenames without extension are keys for the file content.
- Return type:
Example
Load all files in
foo
except for the lookup table inabs_lookup.xml.
>>> load_directory('foo', exclude=['abs_lookup.xml'])
- pyarts.xml.load_indexed(filename)[source]
Load all indexed XML files matching the given filename.
The function searches all files matching the pattern
<filename>.<file_index>.xml
or<filename>.<file_index>.xml.gz
.A list with the loaded file contents is returned. The list indices are equivalent to the file indices.
Example
Load all files matching the pattern
foo.<file_index>.xml
.>>> load_indexed_xml('foo')
- pyarts.xml.make_binary(filename, out='', absolute_out=False, parents=True)[source]
Loads xml-file at filename and saves it back in binary format
- Parameters:
filename (str) – Filename path.
out (str) – Path to save the binary. Empty causes overwrite of file.
absolute_out (bool) – If true, then write file to out-path rather than to the relative path out. Does nothing if file is in the working folder and out is relative.
parents (bool) – Create missing parent directories.
- Returns:
Path to the created binary file.
- Return type:
Example
Load t_field.xml and save it back as binary it as ./binary/t_field.xml and ./binary/t_field.bin
>>> make_binary('t_field.xml', out='binary') 'binary/t_field.xml'
- pyarts.xml.make_directory_binary(directory, out='', absolute_out=False, parents=True)[source]
Loads xml-files in directory and saves them back in binary format
- Parameters:
- Returns:
Paths to the created binary files.
- Return type:
Example
Load arts-xml-data/spectroscopy/cia/hitran2011/ and save it back as binary it at arts-xml-data-binary/spectroscopy/cia/hitran2011/
>>> make_directory_binary('arts-xml-data/spectroscopy/cia/hitran2011', out='arts-xml-data-binary/spectroscopy/cia/hitran2011', absolute_out=True) ['arts-xml-data-binary/spectroscopy/cia/hitran2011/hitran_cia2012_adapted.xml']
- pyarts.xml.save(var, filename, precision='.7e', format='ascii', comment=None, parents=False)[source]
Save a variable to an ARTS XML file.
- Parameters:
var – Variable to be stored.
filename (str) – Name of output XML file. If the name ends in .gz, the file is compressed on the fly.
precision (str) – Format for output precision.
format (str) – Output format: ‘ascii’ (default) or ‘binary’.
comment (str) – Comment string included in a tag above data.
parents (bool) – Create missing parent directories.
Note
Python’s gzip module is extremely slow in writing. Consider compressing files manually after writing them normally.
Example
>>> x = numpy.array([1.,2.,3.]) >>> pyarts.xml.save(x, 'myvector.xml')
- pyarts.xml.update(filename, precision='%g')[source]
Updates a file to the latest version of ARTS
Wraps load()+save() from higher up in this file
Only works for absolute paths. To ensure the path is absolute, os.path.abspath is applied on filename as the first operation
Attempts to store the file in the same format as it was read by, clobbering the original file.
- pyarts.xml.update_directory(directory, precision='%g')[source]
Update all files in a directory
Wraps update() from higher up in this file for all files ending with .xml in the given directory
Only works for absolute paths. To ensure the path is absolute, os.path.abspath is applied on directory as the first operation
There is a subset of .xml files that cannot be read by standard ARTS but requires specialized functions from within ARTS to be read. For example, the old Artscat-N format line catalog files.