Table Of Contents

Previous topic

Introduction to vo.table

Next topic

Introduction to vo.conesearch

This Page

vo.table API documentation

vo.table: Loading entire VOTable files

This file contains a contains the high-level functions to read a VOTable file.

vo.table.parse(source, columns=None, invalid='exception', pedantic=True, chunk_size=256, table_number=None, filename=None, _debug_python_based_parser=False)

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.

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.

table_number is the number of table in the file to read in. If None, all tables will be read. If a number, 0 refers to the first table in the file.

filename is a filename, URL or other identifier to use in error messages. If filename is None and source is a string (i.e. a path), then source will be used as a filename for error messages.

vo.table.parse_single_table(source, **kwargs)

Parses a VOTABLE xml file (or file-like object), assuming it only contains a single TABLE element, and returns a Table instance.

See parse() for a description of the keyword arguments.

vo.tree: Accessing and modifying the individual parts of VOTable files

Inheritance diagram of vo.tree

This file defines the nodes that make up the VOTABLE XML tree.

class vo.tree.CooSys(ID=None, equinox=None, epoch=None, system=None, id=None, config={}, pos=None, **extra)

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.

ID

[required] The XML ID of the COOSYS element, used for cross-referencing. May be None or a string conforming to XML ID syntax.

epoch

Specifies the epoch of the positions. It must be a string specifying an astronomical year.

equinox

A parameter required to fix the equatorial or ecliptic systems (as e.g. “J2000” as the default “eq_FK5” or “B1950” as the default “eq_FK4”).

system

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’
class vo.tree.Element

Bases: object

A base class for all classes that represent XML elements in the VOTABLE file.

class vo.tree.Field(votable, ID=None, name=None, datatype=None, arraysize=None, ucd=None, unit=None, width=None, precision=None, utype=None, ref=None, type=None, id=None, xtype=None, config={}, pos=None, **extra)

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.

parse(iterator, config)
to_xml(w, **kwargs)
classmethod uniqify_names(fields)

Make sure that all names and titles in a list of fields are unique, by appending numbers if necessary.

ID

The XML ID of the FIELD element, used for cross-referencing. May be None or a string conforming to XML ID syntax.

arraysize

Specifies the size of the multidimensional array if this FIELD contains more than a single value.

See multidimensional arrays.

datatype

[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.

A list of Link instances used to reference more details about the meaning of the FIELD. This is purely informational and is not used by the vo package.

name

An optional name for the FIELD.

precision

Along with width, defines the numerical accuracy associated with the data. These values are used to limit the precision when writing floating point values back to the XML file. Otherwise, it is purely informational – the Numpy recarray containing the data itself does not use this information.

ref

On FIELD elements, ref is used only for informational purposes, for example to refer to a COOSYS element.

type

The type attribute on FIELD elements is reserved for future extensions.

ucd

The unified content descriptor for the FIELD.

unit

A string specifying the units for the FIELD.

utype

The usage-specific or unique type of the FIELD.

values

A Values instance (or None) defining the domain of the column.

width

Along with precision, defines the numerical accuracy associated with the data. These values are used to limit the precision when writing floating point values back to the XML file. Otherwise, it is purely informational – the Numpy recarray containing the data itself does not use this information.

xtype

Extended data type information.

class vo.tree.FieldRef(table, ref, ucd=None, utype=None, config={}, pos=None, **extra)

Bases: vo.tree.SimpleElement

A class representing the FIELDref element, which is used inside of GROUP elements to refer to FIELD elements defined elsewhere.

table is the Table object that this FieldRef is a member of.

ref is the ID to reference a Field object defined elsewhere.

get_ref()

Lookup the Field instance that this FieldRef references.

ref

The ID of the FIELD that this FIELDref references.

ucd

The unified content descriptor for the FIELDref.

utype

The usage-specific or unique type of the FIELDref.

class vo.tree.Group(table, ID=None, name=None, ref=None, ucd=None, utype=None, id=None, config={}, pos=None, **extra)

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.

iter_fields_and_params()

Recursively iterate over all Param elements in this Group.

iter_groups()

Recursively iterate over all sub-Group instances in this Group.

parse(iterator, config)
to_xml(w, **kwargs)
ID

The XML ID of the GROUP element. May be None or a string conforming to XML ID syntax.

description

An optional string describing the GROUP. Corresponds to the DESCRIPTION element.

entries

A list of members of the GROUP. This list may only contain objects of type Param, Group, ParamRef and FieldRef.

name

An optional name for the grouping.

ref

Currently ignored, as it’s not clear from the spec how this is meant to work.

ucd

The unified content descriptor for the GROUP.

utype

The usage-specific or unique type of the GROUP.

class vo.tree.Info(ID=None, name=None, value=None, id=None, xtype=None, ref=None, unit=None, ucd=None, utype=None, config={}, pos=None, **extra)

Bases: vo.tree.SimpleElementWithContent

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.

ID

The XML ID of the INFO element. Used for cross-referencing.

content

The content inside the INFO element.

name

[required] The key of the key-value pair.

ref

Refer to another INFO element by ID, defined previously in the document.

unit

A string specifying the units for the INFO.

utype

The usage-specific or unique type of the INFO.

value

The value of the key-value pair. (Always stored as a string or unicode string).

xtype

Extended data type information.

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.

ID

The XML ID of the LINK element.

content_role

Defines the MIME role of the referenced object. Must be one of:

None, ‘query’, ‘hints’, ‘doc’ or ‘location’
content_type

Defines the MIME content type of the referenced object.

href

A URI to an arbitrary protocol. The vo package only supports http and anonymous ftp.

class vo.tree.Param(votable, ID=None, name=None, value=None, datatype=None, arraysize=None, ucd=None, unit=None, width=None, precision=None, utype=None, type=None, id=None, config={}, pos=None, **extra)

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.

to_xml(w, **kwargs)
value

[required] The constant value of the parameter. Its type is determined by the datatype member.

class vo.tree.ParamRef(table, ref, ucd=None, utype=None, config={}, pos=None)

Bases: vo.tree.SimpleElement

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.
get_ref()

Lookup the Param instance that this PARAMref references.

ref

The ID of the PARAM that this PARAMref references.

ucd

The unified content descriptor for the PARAMref.

utype

The usage-specific or unique type of the PARAMref.

class vo.tree.Resource(name=None, ID=None, utype=None, type='results', id=None, config={}, pos=None, **kwargs)

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.

iter_coosys()

Recursively iterates over all the COOSYS elements in the resource and nested resources.

iter_fields_and_params()

Recursively iterates over all FIELD and PARAM elements in the resource, its tables and nested resources.

iter_tables()

Recursively iterates over all tables in the resource and nested resources.

parse(votable, iterator, config)
to_xml(w, **kwargs)
ID

The XML ID of the RESOURCE element, used for cross-referencing. May be None or a string conforming to XML ID syntax.

coordinate_systems

A list of coordinate system definitions (COOSYS elements) for the RESOURCE. Must contain only CooSys objects.

description

An optional string describing the RESOURCE. Corresponds to the DESCRIPTION element.

extra_attributes

A dictionary of string keys to string values containing any extra attributes of the RESOURCE element that are not defined in the specification. (The specification explicitly allows for extra attributes here, but nowhere else.)

infos

A list of informational parameters (key-value pairs) for the resource. Must only contain Info objects.

A list of links (pointers to other documents or servers through a URI) for the resource. Must contain only Link objects.

name

An optional name for the RESOURCE.

params

A list of parameters (constant-valued columns) for the resource. Must contain only Param objects.

resources

A list of nested resources inside this resource. Must contain only Resource objects.

tables

A list of tables in the resource. Must contain only Table objects.

type

[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.
utype

The usage-specific or unique type of the FIELD.

class vo.tree.SimpleElement

Bases: vo.tree.Element

A base class for simple elements, such as FIELD, PARAM and INFO that don’t require any special parsing or outputting machinery.

parse(iterator, config)
to_xml(w, **kwargs)
class vo.tree.SimpleElementWithContent

Bases: vo.tree.SimpleElement

A base class for simple elements, such as FIELD, PARAM and INFO that don’t require any special parsing or outputting machinery.

to_xml(w, **kwargs)
content

The content of the element.

class vo.tree.Table(votable, ID=None, name=None, ref=None, ucd=None, utype=None, nrows=None, id=None, config={}, pos=None, **extra)

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_arrays(nrows=0, config={})

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.

get_field_by_id(ref, before=None)

Looks up a FIELD or PARAM element by the given ID.

get_field_by_id_or_name(ref, before=None)

Looks up a FIELD or PARAM element by the given ID or name.

get_group_by_id(ref, before=None)

Looks up a GROUP element by the given ID. Used by the group’s “ref” attribute

is_empty()

Returns True if this table doesn’t contain any real data because it was skipped over by the parser (through use of the table_number kwarg).

iter_fields_and_params()

Recursively iterate over all FIELD and PARAM elements in the TABLE.

iter_groups()

Recursively iterate over all GROUP elements in the TABLE.

parse(iterator, config)
to_xml(w, **kwargs)
ID

The XML ID of the TABLE element, used for cross-referencing. May be None or a string conforming to XML ID syntax.

description

An optional string describing the TABLE. Corresponds to the DESCRIPTION element.

fields

A list of Field objects describing the types of each of the data columns.

format

[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.

groups

A list of Group objects describing how the columns and parameters are grouped. Currently this information is only kept around for round-tripping and informational purposes.

infos

A list of Info objects for the table. Allows for post-operational diagnostics.

A list of Link objects (pointers to other documents or servers through a URI) for the table.

name

An optional name for the table.

nrows

[immutable] The number of rows in the table, as specified in the XML file.

params

A list of parameters (constant-valued columns) for the table. Must contain only Param objects.

ref

Refer to another TABLE, previously defined, by the ref ID for all metadata (FIELD, PARAM etc.) information.

ucd

The unified content descriptor for the TABLE.

class vo.tree.VOTableFile(ID=None, id=None, config={}, pos=None, version='1.2')

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.

version is settable at construction time only, since conformance tests for building the rest of the structure depend on it.

get_coosys_by_id(ref, before=None)

Looks up a COOSYS element by the given ID.

get_field_by_id(ref, before=None)

Looks up a FIELD element by the given ID. Used by the field’s “ref” attribute.

get_field_by_id_or_name(ref, before=None)

Looks up a FIELD element by the given ID or name.

get_first_table()

Often, you know there is only one table in the file, and that’s all you need. This method returns that first table.

get_group_by_id(ref, before=None)

Looks up a GROUP element by the given ID. Used by the group’s “ref” attribute

get_table_by_id(ref, before=None)

Looks up a TABLE element by the given ID. Used by the table “ref” attribute.

get_table_by_index(idx)

Get a table by its ordinal position in the file.

get_values_by_id(ref, before=None)

Looks up a VALUES element by the given ID. Used by the values “ref” attribute.

iter_coosys()

Recursively iterate over all COOSYS elements in the VOTABLE file.

iter_fields_and_params()

Recursively iterate over all FIELD and PARAM elements in the VOTABLE file.

iter_groups()

Recursively iterate over all GROUP elements in the VOTABLE file.

iter_tables()

Iterates over all tables in the VOTable file in a “flat” way, ignoring the nesting of resources etc.

iter_values()

Recursively iterate over all VALUES elements in the VOTABLE file.

parse(iterator, config)
set_all_tables_format(format)

Set the output storage format of all tables in the file.

to_xml(fd, write_null_values=False, _debug_python_based_parser=False)

Write to an XML file.

fd may be a path to a file, or a Python file-like object.

write_null_values:
When True, write the ‘null’ value (specified in the null attribute of the VALUES element for each FIELD) for empty values. When False (default), simply write no value.
ID

The XML ID of the VOTABLE element, used for cross-referencing. May be None or a string conforming to XML ID syntax.

coordinate_systems

A list of coordinate system descriptions for the file. Must contain only CooSys objects.

description

An optional string describing the VOTABLE. Corresponds to the DESCRIPTION element.

groups

A list of groups, in the order they appear in the file. Only supported as a child of the VOTABLE element in VOTable 1.2 or later.

infos

A list of informational parameters (key-value pairs) for the entire file. Must only contain Info objects.

params

A list of parameters (constant-valued columns) that apply to the entire file. Must contain only Param objects.

resources

A list of resources, in the order they appear in the file. Must only contain Resource objects.

version

The version of the VOTable specification that the file uses.

class vo.tree.Values(votable, field, ID=None, null=None, ref=None, type='legal', id=None, config={}, pos=None, **extras)

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.

is_defaults()
parse(iterator, config)
to_xml(w, **kwargs)
ID

The XML ID of the VALUES element, used for cross-referencing. May be None or a string conforming to XML ID syntax.

max

The maximum value of the domain. See max_inclusive.

max_inclusive

When True, the domain includes the maximum value.

min

The minimum value of the domain. See min_inclusive.

min_inclusive

When True, the domain includes the minimum value.

null

For integral datatypes, null is used to define the value used for missing values.

options

A list of string key-value tuples defining other OPTION elements for the domain. All options are ignored – they are stored for round-tripping purposes only.

ref

Refer to another VALUES element by ID, defined previously in the document, for MIN/MAX/OPTION information.

type

[required] Defines the applicability of the domain defined by this VALUES element. Must be one of the following strings:

  • ‘legal’: The domain of this column applies in general to this datatype. (default)
  • ‘actual’: The domain of this column applies only to the data enclosed in the parent table.
vo.tree.check_astroyear(year, field, config={}, pos=None)

Raises a VOTableSpecError if year is not a valid astronomical year as defined by the VOTABLE standard.

vo.tree.check_string(string, attr_name, config={}, pos=None)

Raises a VOTableSpecError if string is not a string or Unicode string.

vo.tree.check_ucd(ucd, config={}, pos=None)

Warns or raises a VOTableSpecError if ucd is not a valid unified content descriptor string as defined by the VOTABLE standard.

vo.tree.resolve_id(ID, id, config={}, pos=None)

vo.converters: Conversions between XML and Numpy datatypes

Inheritance diagram of vo.converters

This module handles the conversion of various VOTABLE datatypes to/from TABLEDATA and BINARY formats.

class vo.converters.Array(field, config={}, pos=None)

Bases: vo.converters.Converter

Handles both fixed and variable-lengths arrays

parse_scalar(value, config={}, pos=0)
class vo.converters.ArrayVarArray(field, base, arraysize, config={}, pos=None)

Bases: vo.converters.VarArray

Handles an array of variable-length arrays, i.e. where arraysize ends in ‘*’.

parse(value, config={}, pos=None)
class vo.converters.Bit(field, config={}, pos=None)

Bases: vo.converters.Converter

Handles the bit datatype.

array_type

alias of BitArray

vararray_type

alias of ScalarVarArray

binoutput(value, mask)
binparse(read)
output(value, mask)
parse(value, config={}, pos=None)
binary_one = '\x08'
binary_zero = '\x00'
default = False
format = 'b1'
class vo.converters.BitArray(field, base, arraysize, config={}, pos=None)

Bases: vo.converters.NumericArray

Handles an array of bits.

vararray_type

alias of ArrayVarArray

binoutput(value, mask)
binparse(read)
output(value, mask)
class vo.converters.Boolean(field, config={}, pos=None)

Bases: vo.converters.Converter

Handles the boolean datatype.

array_type

alias of BooleanArray

vararray_type

alias of VarArray

binoutput(value, mask)
binparse(read)
binparse_value(value)
output(value, mask)
parse(value, config={}, pos=None)
binary_false = 'F'
binary_question_mark = '?'
binary_true = 'T'
default = False
format = 'b1'
class vo.converters.BooleanArray(field, base, arraysize, config={}, pos=None)

Bases: vo.converters.NumericArray

Handles an array of boolean values.

vararray_type

alias of VarArray

binoutput(value, mask)
binparse(read)
class vo.converters.Char(field, config={}, pos=None)

Bases: vo.converters.Converter

Handles the char datatype. (7-bit unsigned characters)

Missing values are not handled for string or unicode types.

output(value, mask)
default = ''
class vo.converters.Complex(field, config={}, pos=None)

Bases: vo.converters.FloatingPoint, vo.converters.Array

The base class for complex numbers.

array_type

alias of ComplexArray

vararray_type

alias of ComplexVarArray

output(value, mask)
parse(value, config={}, pos=None)
parse_parts(parts, config={}, pos=None)
default = nan
class vo.converters.ComplexArray(field, base, arraysize, config={}, pos=None)

Bases: vo.converters.NumericArray

Handles a fixed-size array of complex numbers.

vararray_type

alias of ComplexArrayVarArray

parse(value, config={}, pos=None)
parse_parts(parts, config={}, pos=None)
class vo.converters.ComplexArrayVarArray(field, base, arraysize, config={}, pos=None)

Bases: vo.converters.VarArray

Handles an array of variable-length arrays of complex numbers.

parse(value, config={}, pos=None)
class vo.converters.ComplexVarArray(field, base, arraysize, config={}, pos=None)

Bases: vo.converters.VarArray

Handles a variable-length array of complex numbers.

parse(value, config={}, pos=None)
class vo.converters.Converter(field, config={}, pos=None)

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.

field is a vo.table.Field object describing the
datatype.
binoutput(value, mask)

Convert the object value in the native in-memory datatype to a string of bytes suitable for serialization in the BINARY format.

binparse(read)

Reads some number of bytes from the BINARY format representation by calling the function read, and returns the native in-memory object representation for the datatype handled by self. The result is returned as a tuple (value, mask).

output(value, mask)

Convert the object value in the native in-memory datatype to a string suitable for serializing in the TABLEDATA format. If mask is True, will return the string representation of a masked value.

parse(value, config={}, pos=None)

Convert the string value from the TABLEDATA format into an object with the correct native in-memory datatype. The result is returned as a tuple (value, mask).

parse_scalar(value, config={}, pos=None)

Parse a single scalar of the underlying type of the converter. For non-array converters, this is equivalent to parse. For array converters, this is equivalent to parsing a single element of the array. The result is returned as a tuple (value, mask).

class vo.converters.Double(field, config={}, pos=None)

Bases: vo.converters.FloatingPoint

Handles the double datatype. Double-precision IEEE floating-point.

format = 'f8'
class vo.converters.DoubleComplex(field, config={}, pos=None)

Bases: vo.converters.Complex

Handle doubleComplex datatype. Pair of double-precision IEEE floating-point numbers.

format = 'c16'
class vo.converters.Float(field, config={}, pos=None)

Bases: vo.converters.FloatingPoint

Handles the float datatype. Single-precision IEEE floating-point.

format = 'f4'
class vo.converters.FloatComplex(field, config={}, pos=None)

Bases: vo.converters.Complex

Handle floatComplex datatype. Pair of single-precision IEEE floating-point numbers.

format = 'c8'
class vo.converters.FloatingPoint(field, config={}, pos=None)

Bases: vo.converters.Numeric

The base class for floating-point datatypes.

binoutput(value, mask)
output(value, mask)
default = nan
class vo.converters.Int(field, config={}, pos=None)

Bases: vo.converters.Integer

Handles the int datatype. Signed 32-bit integer.

format = 'i4'
class vo.converters.Integer(field, config={}, pos=None)

Bases: vo.converters.Numeric

The base class for all the integral datatypes.

binoutput(value, mask)
filter_array(value, mask)
output(value, mask)
parse(value, config={}, pos=None)
default = 0
class vo.converters.Long(field, config={}, pos=None)

Bases: vo.converters.Integer

Handles the long datatype. Signed 64-bit integer.

format = 'i8'
class vo.converters.Numeric(field, config={}, pos=None)

Bases: vo.converters.Converter

The base class for all numeric data types.

array_type

alias of NumericArray

vararray_type

alias of ScalarVarArray

binparse(read)
null = None
class vo.converters.NumericArray(field, base, arraysize, config={}, pos=None)

Bases: vo.converters.Array

Handles a fixed-length array of numeric scalars.

vararray_type

alias of ArrayVarArray

binoutput(value, mask)
binparse(read)
output(value, mask)
parse(value, config={}, pos=None)
parse_parts(parts, config={}, pos=None)
class vo.converters.ScalarVarArray(field, base, arraysize, config={}, pos=None)

Bases: vo.converters.VarArray

Handles a variable-length array of numeric scalars.

parse(value, config={}, pos=None)
class vo.converters.Short(field, config={}, pos=None)

Bases: vo.converters.Integer

Handles the short datatype. Signed 16-bit integer.

format = 'i2'
class vo.converters.UnicodeChar(field, config={}, pos=None)

Bases: vo.converters.Converter

Handles the unicodeChar data type. UTF-16-BE.

Missing values are not handled for string or unicode types.

output(value, mask)
parse(value, config={}, pos=None)
default = u''
class vo.converters.UnsignedByte(field, config={}, pos=None)

Bases: vo.converters.Integer

Handles the unsignedByte datatype. Unsigned 8-bit integer.

format = 'u1'
class vo.converters.VarArray(field, base, arraysize, config={}, pos=None)

Bases: vo.converters.Array

Handles variable lengths arrays (i.e. where arraysize is ‘*’).

binoutput(value, mask)
binparse(read)
output(value, mask)
format = 'O'
vo.converters.bytes(s, encoding)
vo.converters.get_converter(field, config, pos)

Given a Field object field, return an appropriate converter class to handle the specified datatype.

vo.converters.pedantic_array_splitter = <_sre.SRE_Pattern object at 0x56c5300>

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.

vo.voexceptions: Exceptions raised by vo.table

Exceptions and warnings used by the vo package.

class vo.voexceptions.VOWarning(args, config={}, pos=None)

Bases: object

The base class of all VO warnings and exceptions. Handles the formatting of the message with a warning or exception code, filename, line and column number.

classmethod get_short_name()
default_args = ()
vo.voexceptions.warn_or_raise(warning_class, exception_class=None, args=(), config={}, pos=None)

Warn or raise an exception, depending on the pedantic setting.

vo.voexceptions.vo_raise(exception_class, args=(), config={}, pos=None)

Raise an exception, with proper position information if available.

vo.voexceptions.vo_reraise(exc, config={}, pos=None, additional='')

Raise an exception, with proper position information if available.

Restores the original traceback of the exception, and should only be called within an “except:” block of code.

vo.voexceptions.vo_warn(warning_class, args=(), config={}, pos=None)

Warn, with proper position information if available.

vo.voexceptions.parse_vowarning(line)

Parses the vo warning string back into its parts.

vo.ucd: Functions to parse and verify unified content descriptors

This file contains routines to verify the correctness of UCD strings.

class vo.ucd.UCDWords

A class to manage the list of acceptable UCD words. Works by reading in a data file exactly as provided by IVOA. This file resides in data/ucd1p-words.txt.

get_description(name)

Returns the official English description of the given UCD name.

is_primary(name)

Returns True if name is a valid primary name.

is_secondary(name)

Returns True if name is a valid secondary name.

normalize_capitalization(name)

Returns the standard capitalization form of the given name.

vo.ucd.check_ucd(ucd, check_controlled_vocabulary=False)

Returns False if ucd is not a valid unified content descriptor.

If check_controlled_vocabulary is True, then each word in the UCD will be verified against the UCD1+ controlled vocabulary, (as required by the VOTable specification version 1.2), otherwise not.

vo.ucd.parse_ucd(ucd, check_controlled_vocabulary=False, has_colon=False)

Parse the UCD into its component parts. The result is a list of tuples of the form:

(namespace, word)

If no namespace was explicitly specified, namespace will be returned as 'ivoa' (i.e., the default namespace).

If check_controlled_vocabulary is True, then each word in the UCD will be verified against the UCD1+ controlled vocabulary, (as required by the VOTable specification version 1.2), otherwise not.

Will raise ValueError if ucd is invalid.

vo.util: Low-level utilities used by the library

Various utilities and cookbook-like things.

class vo.util.HomogeneousList(types, values=[])

Bases: list

A subclass of list that contains only elements of a given type or types.

types is a sequence of acceptable types.

values (optional) is an initial set of values.

append(x)
insert(i, x)
class vo.util.ProgressBar(total, stream=<open file '<stdout>', mode 'w' at 0x7fe53686b1e0>)

A class to display a progress bar in the terminal.

It is designed for use with the with statement:

with ProgressBar(len(items)) as bar:
    for i, item in enumerate(items):
        bar.update(i)

total is the number of steps in the process.

update(value)

Update the progress bar to the given value (out of the total given to the constructor.

class vo.util.maxdict(maxsize=10)

Bases: dict

A dictionary with a maximum size.

clear()
pop(key, *args)
popitem()
setdefault(key, failobj=None)
update(dict=None, **kwargs)
class vo.util.memoized(func, maxsize=10)

Bases: object

Decorator that caches a function’s return value each time it is called. If called later with the same arguments, the cached value is returned, and not re-evaluated.

vo.util.coerce_range_list_param(p, frames=None, numeric=True)

Coerces and/or verifies the object p into a valid range-list-format parameter as defined in Section 8.7.2 of Simple Spectral Access Protocol.

p may be a string as passed verbatim to the service expecting a range-list, or a sequence. If a sequence, each item must be either:

  • a numeric value
  • a named value, such as, for example, ‘J’ for named spectrum (if the numeric kwarg is False)
  • a 2-tuple indicating a range
  • the last item my be a string indicating the frame of reference

The result is a tuple:

  • a string suitable for passing to a service as a range-list argument
  • an integer counting the number of elements

frames, if provided, should be a sequence of acceptable frame of reference keywords.

vo.util.color_print(color, s, bold=False, italic=False, stream=<open file '<stdout>', mode 'w' at 0x7fe53686b1e0>, newline=True)

Prints the string s in the given color where color is an ANSI terminal color name. stream may be any writable file-like object.

TODO: Be smart about when to use and not use color.

vo.util.convert_to_fd_or_read_function(fd)

Returns a function suitable for streaming input, or a file object.

fd may be:

  • a file object, in which case it is returned verbatim.
  • a function that reads from a stream, in which case it is returned verbatim.
  • a file path, in which case it is opened. If it ends in gz, it is assumed to be a gzipped file, and the read() method on the file object is returned. Otherwise, the raw file object is returned.
  • an object with a read() method, in which case that method is returned.
vo.util.convert_to_writable_filelike(fd)

Returns a writable file-like object suitable for streaming output.

fd may be:

  • 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.
vo.util.dict_soft_update(d, u)

Like dict.update, except if the values in u are None, d is not updated.

vo.util.is_callable(o)

Abstracts away the different ways to test for a callable object in Python 2.x and 3.x.

vo.util.map_with_progress(function, items, multiprocess=False, stream=<open file '<stdout>', mode 'w' at 0x7fe53686b1e0>)

Does a map while displaying a progress bar with percentage complete.

vo.util.version_compare(a, b)

Compare two version identifiers.

vo.xmlutil: XML-related utilities used by the library

Various XML-related utilities

class vo.xmlutil.XMLWriter(file)

file is a writable file-like object.

close(id)

Closes open elements, up to (and including) the element identified by the given identifier.

id: Element identifier, as returned by the start method.

comment(comment)

Adds a comment to the output stream.

comment: Comment text, as a Unicode string.

data(text)

Adds character data to the output stream.

text: Character data, as a Unicode string.

element(tag, text=None, wrap=False, attrib={}, **extra)

Adds an entire element. This is the same as calling start, data, and end in sequence. The text argument can be omitted.

end(tag=None, indent=True, wrap=False)

Closes the current element (opened by the most recent call to start).

tag: Element tag. If given, the tag must match the start tag. If omitted, the current element is closed.

flush()
get_indentation()

Returns the number of indentation levels the file is currently in.

get_indentation_spaces(offset=0)

Returns a string of spaces that matches the current indentation level.

start(tag, attrib={}, **extra)

Opens a new element. Attributes can be given as keyword arguments, or as a string/string dictionary. The method returns an opaque identifier that can be passed to the close() method, to close all open elements up to and including this one.

tag: Element tag.

attrib: Attribute dictionary. Alternatively, attributes can be given as keyword arguments.

Returns an element identifier.

tag(*args, **kwds)

A convenience method for use with the with statement:

with writer.tag('foo'):
    writer.element('bar')
# </foo> is implicitly closed here

Parameters are the same as to start.

vo.xmlutil.check_anyuri(uri, config={}, pos=None)

Raises a ValueError if uri is not a valid URI as defined in RFC 2396.

vo.xmlutil.check_id(ID, name='ID', config={}, pos=None)

Raises a VOTableSpecError if ID is not a valid XML ID. name is the name of the attribute being checked (used only for error messages).

vo.xmlutil.check_mime_content_type(content_type, config={}, pos=None)

Raises a ValueError if content_type is not a valid MIME content type (syntactically at least), as defined by RFC 2045.

vo.xmlutil.check_token(token, attr_name, config={}, pos=None)

Raises a ValueError if token is not a valid XML token, as defined by XML Schema Part 2.

vo.xmlutil.fix_id(ID, config={}, pos=None)

Given an arbitrary string, create one that can be used as an xml id. This is rather simplistic at the moment, since it just replaces non-valid characters with underscores.

vo.xmlutil.get_xml_iterator(source, _debug_python_based_parser=False)

Returns an iterator over the elements of an XML file. See fast_iterparse for more information.

vo.xmlutil.object_attrs(obj, attrs)

Converts an object with a bunch of attributes on an object into a dictionary for use by the XMLWriter.

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 output dictionary.

vo.xmlutil.slow_iterparse(fd, buffersize=1024)

Based on cElementTree.iterparse, but doesn’t ever build a tree at all. This makes things much faster and more memory efficient.

The iterator returns 3-tuples (event, tag, data):

  • event: may be either ‘start’ (when an element begins) or ‘end’ (when an element is completed).
  • tag: The name of the element
  • data: Depends on the value of event:
    • if event == ‘start’, data is a dictionary of attributes
    • if event == ‘end’, data is a list of strings, that when joined is the text content of the element
vo.xmlutil.validate_schema(filename, version='1.2')

Validates the given file against the appropriate VOTable schema corresponding to the given version, which must be a string “1.0”, “1.1”, or “1.2”.

For version “1.0”, it is checked against a DTD, since that version did not have an XML Schema.