gavo.votable.simple module

A simplified API to single-table VOTables.

The basic idea is: open(…) -> (table, metadata),

where table is a numpy array.

class gavo.votable.simple.TableMetadata(tableElement, infos)[source]

Bases: object

Metadata for a VOTable table instance, i.e., column definitions, groups, etc.

These are constructed with a VOTable TABLE instance and infos, a dictionary mapping info names to lists of V.INFO items.

getFields()[source]
iterDicts(data)[source]

iterates over data, but returns each row as a dict.

data is a result set as returned by load.

gavo.votable.simple.load(source, raiseOnInvalid=True)[source]

returns (data, metadata) from the first table of a VOTable.

data is a list of records (as a list), metadata a TableMetadata instance.

source can be a string that is then interpreted as a local file name, or it can be a file-like object.

gavo.votable.simple.loads(stuff, raiseOnInvalid=True)[source]

returns data,metadata for a VOTable literal in stuff.

gavo.votable.simple.makeDtype(tableMetadata, defaultStringLength=20)[source]

returns an record array datatype for a given table metadata.

defaultStringLength lets you specify a length for char(*) fields; since makeDtype has no access to the tabular data and numpy insists on having string length, DaCHS needs to guess here.

If this isn’t fine-grained enough for you, you can always path tableMetadata, replacing * arraysizes with more appropriate values in individual cases.

gavo.votable.simple.save(data, tableDef, destF)[source]

saves (data, tableDef) in VOTable format to destF.

data is a sequence of tuples, tableDef V.TABLE instance as, for example, obtainable from metadata.votTable as returned by load. data must contain type-right python values that match the table definition.

A load-save cycle loses all top-level and resource level metadata in the simplified interface. Use the full interface if that hurts you.