1 """
2 "Conforming" of STCSpecs, i.e., bringing one to the system and units of the
3 other.
4
5 You can only conform STCSpecs rather than individual components, since
6 usually you need the whole information for the transformation (e.g.,
7 space and time for velocities.
8 """
9
10
11
12
13
14
15
16 from gavo.stc import sphermath
17 from gavo.stc import times
18 from gavo.stc import units
19 from gavo.stc import common
20
21
23 """A hack to delay loading of spherc.
24
25 We should probably use one of the many lazy import solutions and use
26 it for both what we're doing here and in coords.AstWCSLoader.
27 """
32
33 spherc = SphercLoader()
34
35
36 _conformedAttributes = [("time", "timeAs"), ("place", "areas"),
37 ("freq", "freqAs"), ("redshift", "redshiftAs"), ("velocity", "velocityAs")]
38
39
48
49 i = [0]
50
52 """yields changes to baseSTC to bring places and velocities to the
53 system and units of sysSTC.
54
55 sixTrans is a sphermath.SVConverter instance.
56
57 If the frame or units are not defined in sysSTC, there are taken from
58 baseSTC.
59 """
60 if baseSTC.place is None or sysSTC.place is None:
61 return
62 sixTrans = sphermath.SVConverter.fromSTC(baseSTC, slaComp=slaComp)
63 destFrame, srcFrame = sysSTC.place.frame, baseSTC.place.frame
64
65 bPlace, bVel = baseSTC.place, baseSTC.velocity
66 trafo = spherc.getTrafoFunction(baseSTC.place.frame.asTriple(),
67 sysSTC.place.frame.asTriple(), sixTrans)
68 if bPlace.value:
69 sv = trafo(sixTrans.to6(baseSTC.place.value,
70 getattr(baseSTC.velocity, "value", None)), sixTrans)
71 pos, vel = sixTrans.from6(sv)
72 else:
73 pos, vel = None, None
74
75
76 if bPlace:
77 yield "place", bPlace.change(value=pos, frame=destFrame)
78 if baseSTC.areas:
79 yield "areas", _transformAreas(baseSTC.areas,
80 sixTrans.getPlaceTransformer(trafo), srcFrame, destFrame)
81
82
83 if bVel:
84 yield "velocity", bVel.change(value=vel, frame=destFrame)
85 if baseSTC.velocityAs:
86 yield "velocityAs", _transformAreas(baseSTC.velocityAs,
87 sixTrans.getVelocityTransformer(trafo, bPlace.value), srcFrame,
88 destFrame)
89
90
92 if baseSTC.time is None or sysSTC.time is None:
93 return
94 destFrame = sysSTC.time.frame
95 transform = times.getTransformFromSTC(baseSTC, sysSTC)
96 if transform is None:
97 return
98 if baseSTC.time.value:
99 yield "time", baseSTC.time.change(value=transform(
100 baseSTC.time.value), frame=destFrame)
101 if baseSTC.timeAs:
102 yield "timeAs", tuple(ta.getTransformed(transform, destFrame)
103 for ta in baseSTC.timeAs)
104
105
116
117
126
127
135
136
138 """returns a function that transforms lat and long in srcSTC to lat and
139 long in destSTC.
140
141 srcSTC and destSTC are ASTs. Of course, all this
142 only works if srcSTC and destSTC are both SPHER2-flavored.
143 """
144 sixTrans = sphermath.SVConverter.fromSTC(srcSTC, slaComp=slaComp)
145 trafo = spherc.getTrafoFunction(srcSTC.place.frame.asTriple(),
146 destSTC.place.frame.asTriple(), sixTrans)
147
148 def convert(ra, dec):
149 pos, vel = sixTrans.from6(
150 trafo(sixTrans.to6((ra, dec), None), sixTrans))
151 return pos[0], pos[1]
152
153 return convert
154