This file contains a contains the high-level functions to read a VOTable file.
Parses a VOTABLE xml file (or file-like object), and returns a VOTable object, with a nested list of Resource instances and Table instances.
source may be a filename or a readable file-like object.
If the columns parameter is specified, it should be a list of field names to include in the output. The default is to include all fields.
The invalid parameter may be one of the following values:
- ‘exception’: throw an exception when an invalid value is encountered (default)
- ‘mask’: mask out invalid values
When pedantic is True, raise an error when the file violates the spec, otherwise issue a warning. Warnings may be controlled using the standard Python mechanisms. See the warnings module in the Python standard library for more information.
When support_hexadecimal is True, integer fields may contain hexadecimal numbers. When False, this part of the spec is unsupported for efficiency reasons.
chunk_size is the number of rows to read before converting to an array. Higher numbers are likely to be faster, but will consume more memory.
This file defines the nodes that make up the VOTABLE XML tree.
Bases: vo.tree._SimpleElement
A class representing the COOSYS element, which defines a coordinate system.
The keyword arguments correspond to setting members of the same name, documented below.
Specifies the type of coordinate system. Valid choices are:
‘eq_FK4’, ‘eq_FK5’, ‘ICRS’, ‘ecl_FK4’, ‘ecl_FK5’, ‘galactic’, ‘supergalactic’, ‘xy’, ‘barycentric’, or ‘geo_app’
Bases: object
A base class for all classes that represent XML elements in the VOTABLE file.
Bases: vo.tree._SimpleElement
A class that represents the FIELD element, which describes the datatype of a particular column of data.
The keyword arguments correspond to setting members of the same name, documented below.
If ID is provided, it is used for the column name in the resulting recarray of the table. If no ID is provided, name is used instead. If neither is provided, an exception will be raised.
Specifies the size of the multidimensional array if this FIELD contains more than a single value.
[required] The datatype of the column. Valid values (as defined by the spec) are:
‘boolean’, ‘bit’, ‘unsignedByte’, ‘short’, ‘int’, ‘long’, ‘char’, ‘unicodeChar’, ‘float’, ‘double’, ‘floatComplex’, or ‘doubleComplex’
Many VOTABLE files in the wild use ‘string’ instead of ‘char’, so that is also a valid option, though ‘string’ will always be converted to ‘char’ when writing the file back out.
Bases: vo.tree._SimpleElement
A class representing the FIELDref element, which is used inside of GROUP elements to refer to FIELD elements defined elsewhere.
Bases: vo.tree.Element
Stores information about the grouping of FIELD and PARAM elements.
This information is currently ignored by the vo package—that is the columns in the recarray are always flat—but the grouping information is stored so that it can be written out again to the XML file.
The keyword arguments correspond to setting members of the same name, documented below.
Bases: vo.tree._SimpleElement
A class for storing INFO elements, which contain arbitrary key-value pairs for extensions to the standard.
The keyword arguments correspond to setting members of the same name, documented below.
Bases: vo.tree._SimpleElement
A class for storing LINK elements, which are used to reference external documents and servers through a URI.
The keyword arguments correspond to setting members of the same name, documented below.
Defines the MIME role of the referenced object. Must be one of:
None, ‘query’, ‘hints’, ‘doc’ or ‘location’
Bases: vo.tree.Field
A class to represent the PARAM element, which are constant-valued columns in the data.
Param objects are a subclass of Field, and have all of its methods and members. Additionally, it defines value.
Bases: vo.tree.Element
A class representing the PARAMref element, which is used inside of GROUP elements to refer to PARAM elements defined elsewhere.
The keyword arguments correspond to setting members of the same name, documented below.
It contains the following publicly-accessible members:
ref: An XML ID refering to a <PARAM> element.
Bases: vo.tree.Element
A class to store the information in a RESOURCE element. Each resource may contain zero-or-more TABLE elements and zero-or-more nested RESOURCE elements.
The keyword arguments correspond to setting members of the same name, documented below.
[required] The type of the resource. Must be either:
- ‘results’: This resource contains actual result values (default)
- ‘meta’: This resource contains only datatype descriptions (FIELD elements), but no actual data.
Bases: vo.tree.Element
A class to store a TABLE element, which optionally contains data.
It contains the following publicly-accessible members, all of which are mutable:
array: A Numpy recarray of the data itself, where each row is a row of votable data, and columns are named and typed based on the <FIELD> elements of the table.
mask: A Numpy recarray of only boolean values, set to True wherever a value is undefined.
If the Table contains no data, (for example, its enclosing Resource has type == ‘meta’) array and mask will be zero-length arrays.
Note
In a future version of the vo package, the array and mask elements will likely be combined into a single Numpy masked record array. However, there are a number of deficiencies the current implementation of Numpy that prevent this.
The keyword arguments correspond to setting members of the same name, documented below.
Create new arrays to hold the data based on the current set of fields, and store them in the array and mask member variables. Any data in existing arrays will be lost.
nrows, if provided, is the number of rows to allocate.
[required] The serialization format of the table. Must be one of:
‘tabledata’ (TABLEDATA), ‘binary’ (BINARY), ‘fits’ (FITS_).
Note that the ‘fits’ format, since it requires an external file, can not be written out. Any file read in with ‘fits’ format will be read out, by default, in ‘tabledata’ format.
Bases: vo.tree.Element
A class to represent the top-level VOTABLE element.
The keyword arguments correspond to setting members of the same name, documented below.
Write to an XML file.
fd may be a path to a file, or a Python file-like object.
Bases: vo.tree.Element
A class to represent the VALUES element, used within FIELD and PARAM elements to define the domain of values.
The keyword arguments correspond to setting members of the same name, documented below.
This module handles the conversion of various VOTABLE datatypes to/from TABLEDATA and BINARY formats.
Bases: vo.converters.Converter
Handles both fixed and variable-lengths arrays
Bases: vo.converters.VarArray
Handles an array of variable-length arrays, i.e. where arraysize ends in ‘*’.
Bases: vo.converters.Converter
Handles the bit datatype.
Bases: vo.converters.NumericArray
Handles an array of bits.
Bases: vo.converters.Converter
Handles the boolean datatype.
Bases: vo.converters.NumericArray
Handles an array of boolean values.
Bases: vo.converters.Converter
Handles the char datatype. (7-bit unsigned characters)
Bases: vo.converters.FloatingPoint, vo.converters.Array
The base class for complex numbers.
Bases: vo.converters.NumericArray
Handles a fixed-size array of complex numbers.
Bases: vo.converters.VarArray
Handles an array of variable-length arrays of complex numbers.
Bases: vo.converters.VarArray
Handles a variable-length array of complex numbers.
Bases: object
The base class for all converters. Each subclass handles converting a specific VOTABLE data type to/from the TABLEDATA and BINARY on-disk representations.
Bases: vo.converters.FloatingPoint
Handles the double datatype. Double-precision IEEE floating-point.
Bases: vo.converters.Complex
Handle doubleComplex datatype. Pair of double-precision IEEE floating-point numbers.
Bases: vo.converters.FloatingPoint
Handles the float datatype. Single-precision IEEE floating-point.
Bases: vo.converters.Complex
Handle floatComplex datatype. Pair of single-precision IEEE floating-point numbers.
Bases: vo.converters.Numeric
The base class for floating-point datatypes.
Bases: vo.converters.Integer
Handles the int datatype. Signed 32-bit integer.
Bases: vo.converters.Numeric
The base class for all the integral datatypes.
Bases: vo.converters.Integer
Handles the long datatype. Signed 64-bit integer.
Bases: vo.converters.Converter
The base class for all numeric data types.
Bases: vo.converters.Array
Bases: vo.converters.VarArray
Bases: vo.converters.Integer
Handles the short datatype. Signed 16-bit integer.
Bases: vo.converters.Converter
Handles the unicodeChar data type. UTF-16-BE.
Bases: vo.converters.Integer
Handles the unsignedByte datatype. Unsigned 8-bit integer.
Bases: vo.converters.Array
Handles variable lengths arrays (i.e. where arraysize is ‘*’).
A regex to handle splitting values on either whitespace or commas.
SPEC: Usage of commas is not actually allowed by the spec, but many files in the wild use them.
Exceptions and warnings used by the vo package.
Bases: exceptions.SyntaxWarning
Warning emitted when the a feature of VOTABLE is not implemented.
Bases: exceptions.ValueError
Error raised when the input XML file violates the spec and there is no good workaround.
Bases: exceptions.SyntaxWarning
Warning emitted when the input XML file violates the spec, but there is an obvious workaround.
Various utilities and cookbook-like things.
Bases: list
A subclass of list that contains only elements of a given type or types.
Returns a function suitable for streaming output.
fd may be:
- a function that writes to a stream, in which case it is returned verbatim.
- a file path, in which case it is opened, and the write() method on the file object is returned.
- an object with a write() method, in which case that method is returned.
parse a dictionary from a file or file-like object. Only strings and numbers are permitted as primitives and the only containers allowed are lists and dictionaries. This is to ensure that use of this file cannot be used as a security breach.
>>> print safeeval("{'test':'123','hehe':['hooray',0x10]}")
{'test': '123', 'hehe': ['hooray', 16]}
Various XML-related utilities
Converts an object with a bunch of attributes into an XML attribute list (as a string).
obj is any Python object
attrs is a sequence of attribute names to pull from the object
If any of the attributes is None, it will not appear in the XML.
Writes out an XML element, wrapping the text as necessary.
write: a function that writes to a stream
element_name: The tag name of the element
content: the text of the element
indent: The number of spaces to indent