gavo.stc.stcxast module¶
Building ASTs from STC-X trees.
The idea here is run buildTree on an ElementTree of the STC-X input.
buildTree has a dictionary mapping element names to handlers. This dictionary is built with a modicum of metaprogramming within _getHandlers.
Each handler receives the ElementTree node it is to operate on, the current buildArgs (i.e., a dictionary containing for building instances collected by buildTree while walking the tree), and a context object.
Handlers yield keyword-value pairs that are added to the buildArgs. If the value is a tuple or list, it will be appended to the current value for that keyword, otherwise it will fill this keyword. Overwrites are not allowed.
- class gavo.stc.stcxast.BoxActions[source]¶
Bases:
ContextActions
Context actions for Boxes: register a special handler for Size.
- boxHandlers = {<QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Size'>: <function _makeKwValueBuilder.<locals>.buildNode>}¶
- class gavo.stc.stcxast.ContextActions[source]¶
Bases:
object
A specification of context actions for certain elements.
You will want to override both start and stop. The methods should not change node.
- class gavo.stc.stcxast.CooSysActions[source]¶
Bases:
ContextActions
Actions for containers of coordinates.
The actions push and pop the system ids of the coordinate containers so leaves can build their frame proxies from them.
If none are present, None is pushed, which is to be understood as “use any ol’ AstroCoordSystem you can find”.
- class gavo.stc.stcxast.IdProxy(id=None, idref=None, ucd=None, useAttr=None)[source]¶
Bases:
ASTNode
A stand-in for a coordinate system during parsing.
We do this to not depend on ids being located before positions. STC should have that in general, but let’s be defensive here.
- class gavo.stc.stcxast.SIBLING_ASTRO_SYSTEM[source]¶
Bases:
object
A sentinel class to tell the id resolver to use the sibling AstroCoordSys element.
- class gavo.stc.stcxast.STCXContext(elementHandlers, activeTags, vecTags={<QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}AllSky'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Box'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Box2'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Circle'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Circle2'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Convex'>: 3, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Difference'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Ellipse'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Error2'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Error3'>: 3, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}HiLimit2Vec'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}HiLimit3Vec'>: 3, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Intersection'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}LoLimit2Vec'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}LoLimit3Vec'>: 3, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Negation'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}PixSize2'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}PixSize3'>: 3, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Polygon'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Polygon2'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Position2D'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Position2VecInterval'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Position3D'>: 3, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Position3VecInterval'>: 3, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}PositionInterval'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Resolution2'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Resolution3'>: 3, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Size2'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Size3'>: 3, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Union'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Value2'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Value3'>: 3, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Velocity2D'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Velocity2VecInterval'>: 2, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Velocity3D'>: 3, <QName '{http://www.ivoa.net/xml/STC/stc-v1.30.xsd}Velocity3VecInterval'>: 3}, **kwargs)[source]¶
Bases:
object
A parse context containing handlers, stacks, etc.
A special feature is that there are “context-active” tags. For those the context gets notified by buildTree when their processing is started or ended. We use this to note the active coordinate systems during, e.g., AstroCoords parsing.
- gavo.stc.stcxast.buildTree(csNode, context)[source]¶
traverses the ElementTree cst, trying handler functions for each node.
The handler functions are taken from the context.elementHandler dictionary that maps QNames to callables. These callables have the signature handle(STCNode, context) -> iterator, where the iterator returns key-value pairs for inclusion into the argument dictionaries for STCNodes.
Unknown nodes are simply ignored. If you need to bail out on certain nodes, raise explicit exceptions in handlers.
This also manages the expected number of dimensions in vectors by pushing and popping from the context’s dimension stack. The actual wisdom on what elements set which dimensions is kept in the context object as well.
- gavo.stc.stcxast.getVecTags()[source]¶
returns a mapping from STC-X names to the number of dimensions child vectors should have.
- gavo.stc.stcxast.parseFromETree(eTree)[source]¶
returns a sequence of pairs (root element, AST) for eTree containing parsed STC-X.