| 1 |
from asdf.extension import Converter |
| 2 |
|
| 3 |
|
| 4 |
class RepresentationConverter(Converter): |
| 5 |
tags = ("tag:astropy.org:astropy/coordinates/representation-*",) |
| 6 |
types = ( |
| 7 |
"astropy.coordinates.representation.CartesianDifferential", |
| 8 |
"astropy.coordinates.representation.CartesianRepresentation", |
| 9 |
"astropy.coordinates.representation.CylindricalDifferential", |
| 10 |
"astropy.coordinates.representation.CylindricalRepresentation", |
| 11 |
"astropy.coordinates.representation.PhysicsSphericalDifferential", |
| 12 |
"astropy.coordinates.representation.PhysicsSphericalRepresentation", |
| 13 |
"astropy.coordinates.representation.RadialDifferential", |
| 14 |
"astropy.coordinates.representation.RadialRepresentation", |
| 15 |
"astropy.coordinates.representation.SphericalCosLatDifferential", |
| 16 |
"astropy.coordinates.representation.SphericalDifferential", |
| 17 |
"astropy.coordinates.representation.SphericalRepresentation", |
| 18 |
"astropy.coordinates.representation.UnitSphericalCosLatDifferential", |
| 19 |
"astropy.coordinates.representation.UnitSphericalDifferential", |
| 20 |
"astropy.coordinates.representation.UnitSphericalRepresentation", |
| 21 |
# classes were moved in https://github.com/astropy/astropy/pull/14792 |
| 22 |
"astropy.coordinates.representation.cartesian.CartesianDifferential", |
| 23 |
"astropy.coordinates.representation.cartesian.CartesianRepresentation", |
| 24 |
"astropy.coordinates.representation.cylindrical.CylindricalDifferential", |
| 25 |
"astropy.coordinates.representation.cylindrical.CylindricalRepresentation", |
| 26 |
"astropy.coordinates.representation.spherical.PhysicsSphericalDifferential", |
| 27 |
"astropy.coordinates.representation.spherical.PhysicsSphericalRepresentation", |
| 28 |
"astropy.coordinates.representation.spherical.RadialDifferential", |
| 29 |
"astropy.coordinates.representation.spherical.RadialRepresentation", |
| 30 |
"astropy.coordinates.representation.spherical.SphericalCosLatDifferential", |
| 31 |
"astropy.coordinates.representation.spherical.SphericalDifferential", |
| 32 |
"astropy.coordinates.representation.spherical.SphericalRepresentation", |
| 33 |
"astropy.coordinates.representation.spherical.UnitSphericalRepresentation", |
| 34 |
"astropy.coordinates.representation.spherical.UnitSphericalDifferential", |
| 35 |
"astropy.coordinates.representation.spherical.UnitSphericalCosLatDifferential", |
| 36 |
) |
| 37 |
|
| 38 |
def to_yaml_tree(self, obj, tag, ctx): |
| 39 |
components = {} |
| 40 |
for c in obj.components: |
| 41 |
value = getattr(obj, "_" + c, None) |
| 42 |
if value is not None: |
| 43 |
components[c] = value |
| 44 |
|
| 45 |
return { |
| 46 |
"type": type(obj).__name__, |
| 47 |
"components": components, |
| 48 |
} |
| 49 |
|
| 50 |
def from_yaml_tree(self, node, tag, ctx): |
| 51 |
from astropy.coordinates import representation |
| 52 |
|
| 53 |
return getattr(representation, node["type"])(**node["components"]) |