|
5 | 5 | __all__: tuple[str, ...] = () |
6 | 6 |
|
7 | 7 |
|
| 8 | +from jaxtyping import Shaped |
8 | 9 | from typing import cast |
9 | 10 |
|
10 | 11 | import astropy.coordinates as apyc |
11 | 12 | import astropy.units as apyu |
12 | | -from jaxtyping import Shaped |
13 | 13 | from plum import conversion_method, convert |
14 | 14 |
|
15 | 15 | import unxt as u |
16 | 16 |
|
17 | 17 | import coordinax as cx |
| 18 | +import coordinax.r as cxr |
| 19 | +import coordinax.vecs as cxv |
18 | 20 |
|
19 | 21 | ##################################################################### |
20 | 22 |
|
21 | 23 | # ===================================== |
22 | 24 | # Quantity |
23 | 25 |
|
24 | 26 |
|
25 | | -@conversion_method(cx.vecs.AbstractPos3D, apyu.Quantity) # type: ignore[arg-type] |
26 | | -def vec_to_q(obj: cx.vecs.AbstractPos3D, /) -> Shaped[apyu.Quantity, "*batch 3"]: |
| 27 | +@conversion_method(cxv.Vector, apyu.Quantity) # type: ignore[arg-type] |
| 28 | +def vec_to_q(obj: cxv.Vector, /) -> Shaped[apyu.Quantity, "*batch 3"]: |
27 | 29 | """`coordinax.AbstractPos3D` -> `astropy.units.Quantity`. |
28 | 30 |
|
29 | 31 | Examples |
30 | 32 | -------- |
31 | | - >>> import coordinax as cx |
| 33 | + >>> import coordinax.vecs as cxv |
32 | 34 | >>> from plum import convert |
33 | 35 | >>> import astropy.units as apyu |
34 | 36 |
|
35 | | - >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") |
| 37 | + >>> vec = cxv.CartesianPos3D.from_([1, 2, 3], "km") |
36 | 38 | >>> convert(vec, apyu.Quantity) |
37 | 39 | <Quantity [1., 2., 3.] km> |
38 | 40 |
|
39 | | - >>> vec = cx.SphericalPos(r=apyu.Quantity(1, unit="km"), |
| 41 | + >>> vec = cxv.SphericalPos(r=apyu.Quantity(1, unit="km"), |
40 | 42 | ... theta=apyu.Quantity(2, unit="deg"), |
41 | 43 | ... phi=apyu.Quantity(3, unit="deg")) |
42 | 44 | >>> convert(vec, apyu.Quantity) |
43 | 45 | <Quantity [0.03485167, 0.0018265 , 0.99939084] km> |
44 | 46 |
|
45 | | - >>> vec = cx.vecs.CylindricalPos(rho=apyu.Quantity(1, unit="km"), |
| 47 | + >>> vec = cxv.CylindricalPos(rho=apyu.Quantity(1, unit="km"), |
46 | 48 | ... phi=apyu.Quantity(2, unit="deg"), |
47 | 49 | ... z=apyu.Quantity(3, unit="m")) |
48 | 50 | >>> convert(vec, apyu.Quantity) |
49 | 51 | <Quantity [0.99939084, 0.0348995 , 0.003 ] km> |
50 | 52 |
|
51 | | - """ |
52 | | - return convert(convert(obj, u.Quantity), apyu.Quantity) |
53 | | - |
54 | | - |
55 | | -@conversion_method(cx.vecs.CartesianAcc3D, apyu.Quantity) # type: ignore[arg-type] |
56 | | -@conversion_method(cx.CartesianVel3D, apyu.Quantity) # type: ignore[arg-type] |
57 | | -def vec_diff_to_q( |
58 | | - obj: cx.CartesianVel3D | cx.vecs.CartesianAcc3D, / |
59 | | -) -> Shaped[apyu.Quantity, "*batch 3"]: |
60 | | - """`coordinax.CartesianVel3D` -> `astropy.units.Quantity`. |
61 | | -
|
62 | | - Examples |
63 | | - -------- |
64 | | - >>> import coordinax as cx |
65 | | - >>> from plum import convert |
66 | | - >>> from astropy.units import Quantity as AstropyQuantity |
67 | | -
|
68 | | - >>> dif = cx.CartesianVel3D.from_([1, 2, 3], "km/s") |
| 53 | + >>> dif = cxv.CartesianVel3D.from_([1, 2, 3], "km/s") |
69 | 54 | >>> convert(dif, AstropyQuantity) |
70 | 55 | <Quantity [1., 2., 3.] km / s> |
71 | 56 |
|
72 | | - >>> dif2 = cx.vecs.CartesianAcc3D.from_([1, 2, 3], "km/s2") |
| 57 | + >>> dif2 = cxv.CartesianAcc3D.from_([1, 2, 3], "km/s2") |
73 | 58 | >>> convert(dif2, AstropyQuantity) |
74 | 59 | <Quantity [1., 2., 3.] km / s2> |
75 | 60 |
|
76 | 61 | """ |
77 | 62 | return convert(convert(obj, u.Quantity), apyu.Quantity) |
78 | 63 |
|
79 | 64 |
|
| 65 | +# ===================================== |
| 66 | + |
| 67 | + |
| 68 | +@conversion_method(cxv.Vector, apyc.CartesianRepresentation) |
| 69 | +def convert_vector_to_astropy(obj: cxv.Vector, /) -> apyc.CartesianRepresentation: |
| 70 | + return apyc.CartesianRepresentation( |
| 71 | + x=convert(obj["x"], apyu.Quantity), |
| 72 | + y=convert(obj["y"], apyu.Quantity), |
| 73 | + z=convert(obj["z"], apyu.Quantity), |
| 74 | + ) |
| 75 | + |
| 76 | + |
80 | 77 | # ===================================== |
81 | 78 | # CartesianPos3D |
82 | 79 |
|
|
0 commit comments