Skip to content

Commit

Permalink
build: bump unxt (#222)
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman authored Nov 15, 2024
1 parent 0cb55cf commit d2899f5
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 175 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"plum-dispatch>=2.5.2",
"quax>=0.0.5",
"quaxed>=0.6.4",
"unxt>=0.21",
"unxt>=0.22",
"xmmutablemap>=0.1",
]

Expand Down
10 changes: 5 additions & 5 deletions src/coordinax/_interop/coordinax_interop_astropy/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from collections.abc import Mapping

import astropy.coordinates as apyc
import astropy.units as u
import astropy.units as apyu
from plum import convert

from unxt import Quantity
import unxt as u

import coordinax as cx

Expand All @@ -18,7 +18,7 @@

@cx.AbstractVector.from_._f.dispatch # noqa: SLF001
def from_(
cls: type[cx.AbstractVector], obj: Mapping[str, u.Quantity], /
cls: type[cx.AbstractVector], obj: Mapping[str, apyu.Quantity], /
) -> cx.AbstractVector:
"""Construct a vector from a mapping.
Expand Down Expand Up @@ -486,7 +486,7 @@ def from_(


@cx.AbstractVector.from_._f.dispatch # noqa: SLF001
def from_(cls: type[cx.AbstractVector], obj: u.Quantity, /) -> cx.AbstractVector:
def from_(cls: type[cx.AbstractVector], obj: apyu.Quantity, /) -> cx.AbstractVector:
"""Construct a vector from an Astropy Quantity array.
The array is expected to have the components as the last dimension.
Expand Down Expand Up @@ -559,4 +559,4 @@ def from_(cls: type[cx.AbstractVector], obj: u.Quantity, /) -> cx.AbstractVector
Quantity['length'](Array([1., 4.], dtype=float32), unit='m')
"""
return cls.from_(convert(obj, Quantity))
return cls.from_(convert(obj, u.Quantity))
100 changes: 49 additions & 51 deletions src/coordinax/_interop/coordinax_interop_astropy/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@


import astropy.coordinates as apyc
import astropy.units as u
import astropy.units as apyu
from jaxtyping import Shaped
from plum import conversion_method, convert

import unxt as ux
import unxt as u

import coordinax as cx

Expand All @@ -20,59 +20,59 @@
# Quantity


@conversion_method(cx.AbstractPos3D, u.Quantity) # type: ignore[misc]
def vec_to_q(obj: cx.AbstractPos3D, /) -> Shaped[u.Quantity, "*batch 3"]:
@conversion_method(cx.AbstractPos3D, apyu.Quantity) # type: ignore[misc]
def vec_to_q(obj: cx.AbstractPos3D, /) -> Shaped[apyu.Quantity, "*batch 3"]:
"""`coordinax.AbstractPos3D` -> `astropy.units.Quantity`.
Examples
--------
>>> import coordinax as cx
>>> from plum import convert
>>> from astropy.units import Quantity
>>> import astropy.units as apyu
>>> vec = cx.CartesianPos3D.from_([1, 2, 3], "kpc")
>>> convert(vec, Quantity)
>>> convert(vec, apyu.Quantity)
<Quantity [1., 2., 3.] kpc>
>>> vec = cx.SphericalPos(r=Quantity(1, unit="kpc"),
... theta=Quantity(2, unit="deg"),
... phi=Quantity(3, unit="deg"))
>>> convert(vec, Quantity)
>>> vec = cx.SphericalPos(r=apyu.Quantity(1, unit="kpc"),
... theta=apyu.Quantity(2, unit="deg"),
... phi=apyu.Quantity(3, unit="deg"))
>>> convert(vec, apyu.Quantity)
<Quantity [0.03485167, 0.0018265 , 0.99939084] kpc>
>>> vec = cx.CylindricalPos(rho=Quantity(1, unit="kpc"),
... phi=Quantity(2, unit="deg"),
... z=Quantity(3, unit="pc"))
>>> convert(vec, Quantity)
>>> vec = cx.CylindricalPos(rho=apyu.Quantity(1, unit="kpc"),
... phi=apyu.Quantity(2, unit="deg"),
... z=apyu.Quantity(3, unit="pc"))
>>> convert(vec, apyu.Quantity)
<Quantity [0.99939084, 0.0348995 , 0.003 ] kpc>
"""
return convert(convert(obj, ux.Quantity), u.Quantity)
return convert(convert(obj, u.Quantity), apyu.Quantity)


@conversion_method(cx.CartesianAcc3D, u.Quantity) # type: ignore[misc]
@conversion_method(cx.CartesianVel3D, u.Quantity) # type: ignore[misc]
@conversion_method(cx.CartesianAcc3D, apyu.Quantity) # type: ignore[misc]
@conversion_method(cx.CartesianVel3D, apyu.Quantity) # type: ignore[misc]
def vec_diff_to_q(
obj: cx.CartesianVel3D | cx.CartesianAcc3D, /
) -> Shaped[u.Quantity, "*batch 3"]:
) -> Shaped[apyu.Quantity, "*batch 3"]:
"""`coordinax.CartesianVel3D` -> `astropy.units.Quantity`.
Examples
--------
>>> import coordinax as cx
>>> from plum import convert
>>> from astropy.units import Quantity
>>> from astropy.units import Quantity as AstropyQuantity
>>> dif = cx.CartesianVel3D.from_([1, 2, 3], "km/s")
>>> convert(dif, Quantity)
>>> convert(dif, AstropyQuantity)
<Quantity [1., 2., 3.] km / s>
>>> dif2 = cx.CartesianAcc3D.from_([1, 2, 3], "km/s2")
>>> convert(dif2, Quantity)
>>> convert(dif2, AstropyQuantity)
<Quantity [1., 2., 3.] km / s2>
"""
return convert(convert(obj, ux.Quantity), u.Quantity)
return convert(convert(obj, u.Quantity), apyu.Quantity)


# =====================================
Expand Down Expand Up @@ -100,9 +100,9 @@ def cart3_to_apycart3(obj: cx.CartesianPos3D, /) -> apyc.CartesianRepresentation
"""
return apyc.CartesianRepresentation(
x=convert(obj.x, u.Quantity),
y=convert(obj.y, u.Quantity),
z=convert(obj.z, u.Quantity),
x=convert(obj.x, apyu.Quantity),
y=convert(obj.y, apyu.Quantity),
z=convert(obj.z, apyu.Quantity),
)


Expand All @@ -112,7 +112,6 @@ def apycart3_to_cart3(obj: apyc.CartesianRepresentation, /) -> cx.CartesianPos3D
Examples
--------
>>> import astropy.units as u
>>> import coordinax as cx
>>> from astropy.coordinates import CartesianRepresentation
Expand Down Expand Up @@ -155,9 +154,9 @@ def cyl_to_apycyl(obj: cx.CylindricalPos, /) -> apyc.CylindricalRepresentation:
"""
return apyc.CylindricalRepresentation(
rho=convert(obj.rho, u.Quantity),
phi=convert(obj.phi, u.Quantity),
z=convert(obj.z, u.Quantity),
rho=convert(obj.rho, apyu.Quantity),
phi=convert(obj.phi, apyu.Quantity),
z=convert(obj.z, apyu.Quantity),
)


Expand Down Expand Up @@ -206,9 +205,9 @@ def sph_to_apysph(obj: cx.SphericalPos, /) -> apyc.PhysicsSphericalRepresentatio
"""
return apyc.PhysicsSphericalRepresentation(
r=convert(obj.r, u.Quantity),
phi=convert(obj.phi, u.Quantity),
theta=convert(obj.theta, u.Quantity),
r=convert(obj.r, apyu.Quantity),
phi=convert(obj.phi, apyu.Quantity),
theta=convert(obj.theta, apyu.Quantity),
)


Expand Down Expand Up @@ -258,9 +257,9 @@ def lonlatsph_to_apysph(obj: cx.LonLatSphericalPos, /) -> apyc.SphericalRepresen
"""
return apyc.SphericalRepresentation(
lon=convert(obj.lon, u.Quantity),
lat=convert(obj.lat, u.Quantity),
distance=convert(obj.distance, u.Quantity),
lon=convert(obj.lon, apyu.Quantity),
lat=convert(obj.lat, apyu.Quantity),
distance=convert(obj.distance, apyu.Quantity),
)


Expand Down Expand Up @@ -308,9 +307,9 @@ def diffcart3_to_apycart3(obj: cx.CartesianVel3D, /) -> apyc.CartesianDifferenti
"""
return apyc.CartesianDifferential(
d_x=convert(obj.d_x, u.Quantity),
d_y=convert(obj.d_y, u.Quantity),
d_z=convert(obj.d_z, u.Quantity),
d_x=convert(obj.d_x, apyu.Quantity),
d_y=convert(obj.d_y, apyu.Quantity),
d_z=convert(obj.d_z, apyu.Quantity),
)


Expand All @@ -322,7 +321,6 @@ def apycart3_to_diffcart3(obj: apyc.CartesianDifferential, /) -> cx.CartesianVel
Examples
--------
>>> import astropy.units as u
>>> import coordinax as cx
>>> from astropy.coordinates import CartesianDifferential
Expand Down Expand Up @@ -366,9 +364,9 @@ def diffcyl_to_apycyl(obj: cx.CylindricalVel, /) -> apyc.CylindricalDifferential
"""
return apyc.CylindricalDifferential(
d_rho=convert(obj.d_rho, u.Quantity),
d_phi=convert(obj.d_phi, u.Quantity),
d_z=convert(obj.d_z, u.Quantity),
d_rho=convert(obj.d_rho, apyu.Quantity),
d_phi=convert(obj.d_phi, apyu.Quantity),
d_z=convert(obj.d_z, apyu.Quantity),
)


Expand Down Expand Up @@ -424,9 +422,9 @@ def diffsph_to_apysph(obj: cx.SphericalVel, /) -> apyc.PhysicsSphericalDifferent
"""
return apyc.PhysicsSphericalDifferential(
d_r=convert(obj.d_r, u.Quantity),
d_theta=convert(obj.d_theta, u.Quantity),
d_phi=convert(obj.d_phi, u.Quantity),
d_r=convert(obj.d_r, apyu.Quantity),
d_theta=convert(obj.d_theta, apyu.Quantity),
d_phi=convert(obj.d_phi, apyu.Quantity),
)


Expand Down Expand Up @@ -484,9 +482,9 @@ def difflonlatsph_to_apysph(
"""
return apyc.SphericalDifferential(
d_distance=convert(obj.d_distance, u.Quantity),
d_lon=convert(obj.d_lon, u.Quantity),
d_lat=convert(obj.d_lat, u.Quantity),
d_distance=convert(obj.d_distance, apyu.Quantity),
d_lon=convert(obj.d_lon, apyu.Quantity),
d_lat=convert(obj.d_lat, apyu.Quantity),
)


Expand Down Expand Up @@ -546,9 +544,9 @@ def diffloncoslatsph_to_apysph(
""" # noqa: E501
return apyc.SphericalCosLatDifferential(
d_distance=convert(obj.d_distance, u.Quantity),
d_lon_coslat=convert(obj.d_lon_coslat, u.Quantity),
d_lat=convert(obj.d_lat, u.Quantity),
d_distance=convert(obj.d_distance, apyu.Quantity),
d_lon_coslat=convert(obj.d_lon_coslat, apyu.Quantity),
d_lat=convert(obj.d_lat, apyu.Quantity),
)


Expand Down
7 changes: 3 additions & 4 deletions src/coordinax/_src/angle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

__all__: list[str] = []

import astropy.units as u
from plum import add_promotion_rule, conversion_method

from unxt import Quantity, dimensions_of
from unxt import Quantity, dimension, dimension_of
from unxt.quantity import AbstractQuantity

angle_dimension = u.get_physical_type("angle")
angle_dimension = dimension("angle")


class AbstractAngle(AbstractQuantity): # type: ignore[misc]
Expand Down Expand Up @@ -39,7 +38,7 @@ class AbstractAngle(AbstractQuantity): # type: ignore[misc]

def __check_init__(self) -> None:
"""Check the initialization."""
if dimensions_of(self) != angle_dimension:
if dimension_of(self) != angle_dimension:
msg = "Angle must have dimensions angle."
raise ValueError(msg)

Expand Down
Loading

0 comments on commit d2899f5

Please sign in to comment.