TransformGraph¶
-
class
astropy.coordinates.TransformGraph[source]¶ Bases:
objectA graph representing the paths between coordinate frames.
Attributes Summary
frame_attributesA dictof all the attributes of all frame classes in thisTransformGraph.frame_component_namesA setof all component names every defined within any frame class in thisTransformGraph.frame_setA setof all the frame classes present in thisTransformGraph.Methods Summary
add_transform(fromsys, tosys, transform)Add a new coordinate transformation to the graph. find_shortest_path(fromsys, tosys)Computes the shortest distance along the transform graph from one system to another. get_names()Returns all available transform names. get_transform(fromsys, tosys)Generates and returns the CompositeTransformfor a transformation between two coordinate systems.invalidate_cache()Invalidates the cache that stores optimizations for traversing the transform graph. lookup_name(name)Tries to locate the coordinate class with the provided alias. remove_transform(fromsys, tosys, transform)Removes a coordinate transform from the graph. to_dot_graph([priorities, addnodes, savefn, …])Converts this transform graph to the graphviz DOT format. to_networkx_graph()Converts this transform graph into a networkx graph. transform(transcls, fromsys, tosys[, priority])A function decorator for defining transformations. Attributes Documentation
-
frame_attributes¶ A
dictof all the attributes of all frame classes in thisTransformGraph.
-
frame_component_names¶ A
setof all component names every defined within any frame class in thisTransformGraph.
-
frame_set¶ A
setof all the frame classes present in thisTransformGraph.
Methods Documentation
-
add_transform(fromsys, tosys, transform)[source]¶ Add a new coordinate transformation to the graph.
Parameters: - fromsys : class
The coordinate frame class to start from.
- tosys : class
The coordinate frame class to transform into.
- transform : CoordinateTransform or similar callable
The transformation object. Typically a
CoordinateTransformobject, although it may be some other callable that is called with the same signature.
Raises: - TypeError
If
fromsysortosysare not classes ortransformis not callable.
-
find_shortest_path(fromsys, tosys)[source]¶ Computes the shortest distance along the transform graph from one system to another.
Parameters: - fromsys : class
The coordinate frame class to start from.
- tosys : class
The coordinate frame class to transform into.
Returns: - path : list of classes or
None The path from
fromsystotosysas an in-order sequence of classes. This list includes bothfromsysandtosys. IsNoneif there is no possible path.- distance : number
The total distance/priority from
fromsystotosys. If priorities are not set this is the number of transforms needed. Isinfif there is no possible path.
-
get_names()[source]¶ Returns all available transform names. They will all be valid arguments to
lookup_name.Returns: - nms : list
The aliases for coordinate systems.
-
get_transform(fromsys, tosys)[source]¶ Generates and returns the
CompositeTransformfor a transformation between two coordinate systems.Parameters: - fromsys : class
The coordinate frame class to start from.
- tosys : class
The coordinate frame class to transform into.
Returns: - trans :
CompositeTransformorNone If there is a path from
fromsystotosys, this is a transform object for that path. If no path could be found, this isNone.
Notes
This function always returns a
CompositeTransform, becauseCompositeTransformis slightly more adaptable in the way it can be called than other transform classes. Specifically, it takes care of intermediate steps of transformations in a way that is consistent with 1-hop transformations.
-
invalidate_cache()[source]¶ Invalidates the cache that stores optimizations for traversing the transform graph. This is called automatically when transforms are added or removed, but will need to be called manually if weights on transforms are modified inplace.
-
lookup_name(name)[source]¶ Tries to locate the coordinate class with the provided alias.
Parameters: - name : str
The alias to look up.
Returns: - coordcls
The coordinate class corresponding to the
nameorNoneif no such class exists.
-
remove_transform(fromsys, tosys, transform)[source]¶ Removes a coordinate transform from the graph.
Parameters: - fromsys : class or
None The coordinate frame class to start from. If
None,transformwill be searched for and removed (tosysmust also beNone).- tosys : class or
None The coordinate frame class to transform into. If
None,transformwill be searched for and removed (fromsysmust also beNone).- transform : callable or
None The transformation object to be removed or
None. IfNoneandtosysandfromsysare supplied, there will be no check to ensure the correct object is removed.
- fromsys : class or
-
to_dot_graph(priorities=True, addnodes=[], savefn=None, savelayout='plain', saveformat=None, color_edges=True)[source]¶ Converts this transform graph to the graphviz DOT format.
Optionally saves it (requires graphviz be installed and on your path).
Parameters: - priorities : bool
If
True, show the priority values for each transform. Otherwise, the will not be included in the graph.- addnodes : sequence of str
Additional coordinate systems to add (this can include systems already in the transform graph, but they will only appear once).
- savefn :
Noneor str The file name to save this graph to or
Noneto not save to a file.- savelayout : str
The graphviz program to use to layout the graph (see graphviz for details) or ‘plain’ to just save the DOT graph content. Ignored if
savefnisNone.- saveformat : str
The graphviz output format. (e.g. the
-Txxxoption for the command line program - see graphviz docs for details). Ignored ifsavefnisNone.- color_edges : bool
Color the edges between two nodes (frames) based on the type of transform.
FunctionTransform: red,StaticMatrixTransform: blue,DynamicMatrixTransform: green.
Returns: - dotgraph : str
A string with the DOT format graph.
-
to_networkx_graph()[source]¶ Converts this transform graph into a networkx graph.
Note
You must have the networkx package installed for this to work.
Returns: - nxgraph : networkx.Graph
This
TransformGraphas a networkx.Graph.
-
transform(transcls, fromsys, tosys, priority=1, **kwargs)[source]¶ A function decorator for defining transformations.
Note
If decorating a static method of a class,
@staticmethodshould be added above this decorator.Parameters: - transcls : class
The class of the transformation object to create.
- fromsys : class
The coordinate frame class to start from.
- tosys : class
The coordinate frame class to transform into.
- priority : number
The priority if this transform when finding the shortest coordinate transform path - large numbers are lower priorities.
- Additional keyword arguments are passed into the ``transcls``
- constructor.
Returns: - deco : function
A function that can be called on another function as a decorator (see example).
Notes
This decorator assumes the first argument of the
transclsinitializer accepts a callable, and that the second and third arefromsysandtosys. If this is not true, you should just initialize the class manually and useadd_transforminstead of using this decorator.Examples
graph = TransformGraph() class Frame1(BaseCoordinateFrame): ... class Frame2(BaseCoordinateFrame): ... @graph.transform(FunctionTransform, Frame1, Frame2) def f1_to_f2(f1_obj): ... do something with f1_obj ... return f2_obj
-