diff --git a/src/coordinax/_base.py b/src/coordinax/_base.py index 2527a704..f2ea4117 100644 --- a/src/coordinax/_base.py +++ b/src/coordinax/_base.py @@ -513,7 +513,7 @@ def components(cls) -> tuple[str, ...]: >>> Cartesian2DVector.components ('x', 'y') >>> SphericalVector.components - ('r', 'phi', 'theta') + ('r', 'theta', 'phi') >>> RadialDifferential.components ('d_r',) @@ -608,8 +608,8 @@ def to_units( >>> cart = Cartesian2DVector(x=Quantity(1, "m"), y=Quantity(2, "km")) >>> cart.to_units({"length": "km"}) Cartesian2DVector( - x=Quantity[PhysicalType('length')](value=f32[], unit=Unit("km")), - y=Quantity[PhysicalType('length')](value=f32[], unit=Unit("km")) + x=Quantity[...](value=f32[], unit=Unit("km")), + y=Quantity[...](value=f32[], unit=Unit("km")) ) This also works for vectors with different units: @@ -619,9 +619,8 @@ def to_units( >>> sph.to_units({"length": "km", "angle": "deg"}) SphericalVector( r=Distance(value=f32[], unit=Unit("km")), - phi=Quantity[PhysicalType('angle')](value=f32[], unit=Unit("deg")), - theta=Quantity[PhysicalType('angle')](value=f32[], unit=Unit("deg")) - ) + theta=Quantity[...](value=f32[], unit=Unit("deg")), + phi=Quantity[...](value=f32[], unit=Unit("deg")) ) """ # Ensure `units_` is PT -> Unit @@ -667,9 +666,8 @@ def to_units( >>> sph.to_units(ToUnitsOptions.consistent) SphericalVector( r=Distance(value=f32[], unit=Unit("m")), - phi=Quantity[PhysicalType('angle')](value=f32[], unit=Unit("rad")), - theta=Quantity[PhysicalType('angle')](value=f32[], unit=Unit("rad")) - ) + theta=Quantity[...](value=f32[], unit=Unit("deg")), + phi=Quantity[...](value=f32[], unit=Unit("deg")) ) """ units_ = {} diff --git a/src/coordinax/_base_vec.py b/src/coordinax/_base_vec.py index 7f8bb10b..a8b7da06 100644 --- a/src/coordinax/_base_vec.py +++ b/src/coordinax/_base_vec.py @@ -172,10 +172,9 @@ def represent_as(self, target: type[VT], /, *args: Any, **kwargs: Any) -> VT: >>> sph = vec.represent_as(SphericalVector) >>> sph SphericalVector( - r=Distance(value=f32[], unit=Unit("m")), - phi=Quantity[PhysicalType('angle')](value=f32[], unit=Unit("rad")), - theta=Quantity[PhysicalType('angle')](value=f32[], unit=Unit("rad")) - ) + r=Distance(value=f32[], unit=Unit("m")), + theta=Quantity[...](value=f32[], unit=Unit("rad")), + phi=Quantity[...](value=f32[], unit=Unit("rad")) ) >>> sph.r Distance(Array(3.7416575, dtype=float32), unit='m') diff --git a/src/coordinax/_checks.py b/src/coordinax/_checks.py index 67a78afb..d7ea6c26 100644 --- a/src/coordinax/_checks.py +++ b/src/coordinax/_checks.py @@ -25,7 +25,7 @@ def check_r_non_negative(r: BatchableLength) -> BatchableLength: ) -def check_phi_range(phi: BatchableAngle) -> BatchableAngle: +def check_azimuth_range(phi: BatchableAngle) -> BatchableAngle: """Check that the polar angle is in the range [0, 2pi).""" return eqx.error_if( phi, @@ -34,7 +34,7 @@ def check_phi_range(phi: BatchableAngle) -> BatchableAngle: ) -def check_theta_range(theta: BatchableAngle) -> BatchableAngle: +def check_polar_range(theta: BatchableAngle) -> BatchableAngle: """Check that the inclination angle is in the range [0, pi].""" return eqx.error_if( theta, diff --git a/src/coordinax/_converters.py b/src/coordinax/_converters.py index 67ddda4f..9374ba20 100644 --- a/src/coordinax/_converters.py +++ b/src/coordinax/_converters.py @@ -10,7 +10,7 @@ _2pid = Quantity(360, "deg") -def converter_phi_to_range(phi: BatchableAngle) -> BatchableAngle: +def converter_azimuth_to_range(phi: BatchableAngle) -> BatchableAngle: """Wrap the polar angle to the range [0, 2pi). It's safe to do this conversion since this is a phase cut, unlike `theta`, diff --git a/src/coordinax/_d2/builtin.py b/src/coordinax/_d2/builtin.py index 373738dd..e55f7743 100644 --- a/src/coordinax/_d2/builtin.py +++ b/src/coordinax/_d2/builtin.py @@ -22,8 +22,8 @@ import coordinax._typing as ct from .base import Abstract2DVector, Abstract2DVectorDifferential from coordinax._base_vec import AbstractVector -from coordinax._checks import check_phi_range, check_r_non_negative -from coordinax._converters import converter_phi_to_range +from coordinax._checks import check_azimuth_range, check_r_non_negative +from coordinax._converters import converter_azimuth_to_range from coordinax._utils import classproperty # ============================================================================= @@ -130,9 +130,16 @@ def norm(self) -> ct.BatchableLength: @final class PolarVector(Abstract2DVector): - """Polar vector representation. + r"""Polar vector representation. + + Parameters + ---------- + r : BatchableDistance + Radial distance :math:`r \in [0,+\infty)`. + phi : BatchableAngle + Polar angle :math:`\phi \in [0,2\pi)`. We use the symbol `phi` to + adhere to the ISO standard 31-11. - We use the symbol `phi` instead of `theta` to adhere to the ISO standard. """ r: ct.BatchableDistance = eqx.field( @@ -141,7 +148,7 @@ class PolarVector(Abstract2DVector): r"""Radial distance :math:`r \in [0,+\infty)`.""" phi: ct.BatchableAngle = eqx.field( - converter=lambda x: converter_phi_to_range( + converter=lambda x: converter_azimuth_to_range( Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 ) ) @@ -150,7 +157,7 @@ class PolarVector(Abstract2DVector): def __check_init__(self) -> None: """Check the initialization.""" check_r_non_negative(self.r) - check_phi_range(self.phi) + check_azimuth_range(self.phi) @classproperty @classmethod diff --git a/src/coordinax/_d3/builtin.py b/src/coordinax/_d3/builtin.py index a39fe6c8..168d18eb 100644 --- a/src/coordinax/_d3/builtin.py +++ b/src/coordinax/_d3/builtin.py @@ -22,8 +22,8 @@ import coordinax._typing as ct from .base import Abstract3DVector, Abstract3DVectorDifferential from coordinax._base_vec import AbstractVector -from coordinax._checks import check_phi_range, check_r_non_negative -from coordinax._converters import converter_phi_to_range +from coordinax._checks import check_azimuth_range, check_r_non_negative +from coordinax._converters import converter_azimuth_to_range from coordinax._utils import classproperty ############################################################################## @@ -82,8 +82,8 @@ def __add__(self, other: Any, /) -> "Cartesian3DVector": >>> from unxt import Quantity >>> from coordinax import Cartesian3DVector, SphericalVector >>> q = Cartesian3DVector.constructor(Quantity([1, 2, 3], "kpc")) - >>> s = SphericalVector(r=Quantity(1, "kpc"), phi=Quantity(0, "deg"), - ... theta=Quantity(90, "deg")) + >>> s = SphericalVector(r=Quantity(1, "kpc"), theta=Quantity(90, "deg"), + ... phi=Quantity(0, "deg")) >>> (q + s).x Quantity['length'](Array(2., dtype=float32), unit='kpc') @@ -103,8 +103,8 @@ def __sub__(self, other: Any, /) -> "Cartesian3DVector": >>> from unxt import Quantity >>> from coordinax import Cartesian3DVector, SphericalVector >>> q = Cartesian3DVector.constructor(Quantity([1, 2, 3], "kpc")) - >>> s = SphericalVector(r=Quantity(1, "kpc"), phi=Quantity(0, "deg"), - ... theta=Quantity(90, "deg")) + >>> s = SphericalVector(r=Quantity(1, "kpc"), theta=Quantity(90, "deg"), + ... phi=Quantity(0, "deg")) >>> (q - s).x Quantity['length'](Array(0., dtype=float32), unit='kpc') @@ -134,7 +134,11 @@ def norm(self) -> ct.BatchableLength: @final class CylindricalVector(Abstract3DVector): - """Cylindrical vector representation.""" + """Cylindrical vector representation. + + This adheres to ISO standard 31-11. + + """ rho: ct.BatchableLength = eqx.field( converter=partial(Quantity["length"].constructor, dtype=float) @@ -142,7 +146,7 @@ class CylindricalVector(Abstract3DVector): r"""Cylindrical radial distance :math:`\rho \in [0,+\infty)`.""" phi: ct.BatchableAngle = eqx.field( - converter=lambda x: converter_phi_to_range( + converter=lambda x: converter_azimuth_to_range( Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 ) ) @@ -156,7 +160,7 @@ class CylindricalVector(Abstract3DVector): def __check_init__(self) -> None: """Check the validity of the initialisation.""" check_r_non_negative(self.rho) - check_phi_range(self.phi) + check_azimuth_range(self.phi) @classproperty @classmethod diff --git a/src/coordinax/_d3/compat.py b/src/coordinax/_d3/compat.py index af92c5b3..568d06a1 100644 --- a/src/coordinax/_d3/compat.py +++ b/src/coordinax/_d3/compat.py @@ -95,7 +95,7 @@ def constructor( """ obj = obj.represent_as(apyc.PhysicsSphericalRepresentation) - return cls(r=obj.r, phi=obj.phi, theta=obj.theta) + return cls(r=obj.r, theta=obj.theta, phi=obj.phi) @LonLatSphericalVector.constructor._f.register # noqa: SLF001 @@ -227,9 +227,9 @@ def constructor( >>> dif = cx.LonCosLatSphericalDifferential.constructor(dsph) >>> dif LonCosLatSphericalDifferential( - d_distance=Quantity[...]( value=f32[], unit=Unit("km / s") ), d_lon_coslat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), - d_lat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ) + d_lat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), + d_distance=Quantity[...]( value=f32[], unit=Unit("km / s") ) ) >>> dif.d_distance Quantity['speed'](Array(1., dtype=float32), unit='km / s') @@ -265,8 +265,8 @@ def vec_to_q(obj: Abstract3DVector, /) -> Shaped[Quantity["length"], "*batch 3"] unit='kpc') >>> vec = cx.CylindricalVector(rho=Quantity(1, unit="kpc"), - ... phi=Quantity(2, unit="deg"), - ... z=Quantity(3, unit="pc")) + ... phi=Quantity(2, unit="deg"), + ... z=Quantity(3, unit="pc")) >>> convert(vec, Quantity) Quantity['length'](Array([0.99939084, 0.0348995 , 0.003 ], dtype=float32), unit='kpc') @@ -472,8 +472,8 @@ def apysph_to_sph(obj: apyc.PhysicsSphericalRepresentation, /) -> SphericalVecto >>> convert(sph, cx.SphericalVector) SphericalVector( r=Distance(value=f32[], unit=Unit("kpc")), - phi=Quantity[...](value=f32[], unit=Unit("deg")), - theta=Quantity[...](value=f32[], unit=Unit("deg")) + theta=Quantity[...](value=f32[], unit=Unit("deg")), + phi=Quantity[...](value=f32[], unit=Unit("deg")) ) """ @@ -534,9 +534,9 @@ def apysph_to_lonlatsph(obj: apyc.SphericalRepresentation, /) -> LonLatSpherical ... distance=1 * u.kpc) >>> convert(sph, cx.LonLatSphericalVector) LonLatSphericalVector( - distance=Distance(value=f32[], unit=Unit("kpc")), lon=Quantity[...](value=f32[], unit=Unit("deg")), - lat=Quantity[...](value=f32[], unit=Unit("deg")) + lat=Quantity[...](value=f32[], unit=Unit("deg")), + distance=Distance(value=f32[], unit=Unit("kpc")) ) """ @@ -696,8 +696,8 @@ def diffsph_to_apysph( >>> import coordinax as cx >>> dif = cx.SphericalDifferential(d_r=Quantity(1, unit="km/s"), - ... d_theta=Quantity(2, unit="mas/yr"), - ... d_phi=Quantity(3, unit="mas/yr")) + ... d_theta=Quantity(2, unit="mas/yr"), + ... d_phi=Quantity(3, unit="mas/yr")) >>> convert(dif, apyc.PhysicsSphericalDifferential) <PhysicsSphericalDifferential (d_phi, d_theta, d_r) in (mas / yr, mas / yr, km / s) (3., 2., 1.)> @@ -709,8 +709,8 @@ def diffsph_to_apysph( """ return apyc.PhysicsSphericalDifferential( d_r=convert(obj.d_r, apyu.Quantity), - d_phi=convert(obj.d_phi, apyu.Quantity), d_theta=convert(obj.d_theta, apyu.Quantity), + d_phi=convert(obj.d_phi, apyu.Quantity), ) @@ -740,8 +740,8 @@ def apysph_to_diffsph( >>> convert(dif, cx.SphericalDifferential) SphericalDifferential( d_r=Quantity[...]( value=f32[], unit=Unit("km / s") ), - d_phi=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), - d_theta=Quantity[...]( value=f32[], unit=Unit("mas / yr") ) + d_theta=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), + d_phi=Quantity[...]( value=f32[], unit=Unit("mas / yr") ) ) """ @@ -812,9 +812,9 @@ def apysph_to_difflonlatsph( ... d_lon=3 * u.mas/u.yr) >>> convert(dif, cx.LonLatSphericalDifferential) LonLatSphericalDifferential( - d_distance=Quantity[...]( value=f32[], unit=Unit("km / s") ), d_lon=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), - d_lat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ) + d_lat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), + d_distance=Quantity[...]( value=f32[], unit=Unit("km / s") ) ) """ @@ -888,9 +888,9 @@ def apysph_to_diffloncoslatsph( ... d_lon_coslat=3 * u.mas/u.yr) >>> convert(dif, cx.LonCosLatSphericalDifferential) LonCosLatSphericalDifferential( - d_distance=Quantity[...]( value=f32[], unit=Unit("km / s") ), d_lon_coslat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), - d_lat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ) + d_lat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), + d_distance=Quantity[...]( value=f32[], unit=Unit("km / s") ) ) """ diff --git a/src/coordinax/_d3/sphere.py b/src/coordinax/_d3/sphere.py index 37d1f7d8..de82c051 100644 --- a/src/coordinax/_d3/sphere.py +++ b/src/coordinax/_d3/sphere.py @@ -26,8 +26,12 @@ import coordinax._typing as ct from .base import Abstract3DVector, Abstract3DVectorDifferential -from coordinax._checks import check_phi_range, check_r_non_negative, check_theta_range -from coordinax._converters import converter_phi_to_range +from coordinax._checks import ( + check_azimuth_range, + check_polar_range, + check_r_non_negative, +) +from coordinax._converters import converter_azimuth_to_range from coordinax._utils import classproperty ############################################################################## @@ -55,10 +59,10 @@ class SphericalVector(AbstractSphericalVector): ---------- r : Distance Radial distance r (slant distance to origin), - phi : Quantity['angle'] - Azimuthal angle [0, 360) [deg] where 0 is the x-axis. theta : Quantity['angle'] Polar angle [0, 180] [deg] where 0 is the z-axis. + phi : Quantity['angle'] + Azimuthal angle [0, 360) [deg] where 0 is the x-axis. """ @@ -67,23 +71,23 @@ class SphericalVector(AbstractSphericalVector): ) r"""Radial distance :math:`r \in [0,+\infty)`.""" + theta: ct.BatchableAngle = eqx.field( + converter=partial(Quantity["angle"].constructor, dtype=float) + ) + r"""Inclination angle :math:`\theta \in [0,180]`.""" + phi: ct.BatchableAngle = eqx.field( - converter=lambda x: converter_phi_to_range( + converter=lambda x: converter_azimuth_to_range( Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 ) ) r"""Azimuthal angle :math:`\phi \in [0,360)`.""" - theta: ct.BatchableAngle = eqx.field( - converter=partial(Quantity["angle"].constructor, dtype=float) - ) - r"""Inclination angle :math:`\phi \in [0,180]`.""" - def __check_init__(self) -> None: """Check the validity of the initialization.""" check_r_non_negative(self.r) - check_theta_range(self.theta) - check_phi_range(self.phi) + check_polar_range(self.theta) + check_azimuth_range(self.phi) @classproperty @classmethod @@ -98,8 +102,8 @@ def norm(self) -> ct.BatchableDistance: -------- >>> from unxt import Quantity >>> from coordinax import SphericalVector - >>> s = SphericalVector(r=Quantity(3, "kpc"), phi=Quantity(0, "deg"), - ... theta=Quantity(90, "deg")) + >>> s = SphericalVector(r=Quantity(3, "kpc"), theta=Quantity(90, "deg"), + ... phi=Quantity(0, "deg")) >>> s.norm() Distance(Array(3., dtype=float32), unit='kpc') @@ -132,11 +136,11 @@ class MathSphericalVector(AbstractSphericalVector): r"""Radial distance :math:`r \in [0,+\infty)`.""" theta: ct.BatchableAngle = eqx.field( - converter=lambda x: converter_phi_to_range( + converter=lambda x: converter_azimuth_to_range( Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 ) ) - r"""Azimuthal angle :math:`\phi \in [0,360)`.""" + r"""Azimuthal angle :math:`\theta \in [0,360)`.""" phi: ct.BatchableAngle = eqx.field( converter=partial(Quantity["angle"].constructor, dtype=float) @@ -146,8 +150,8 @@ class MathSphericalVector(AbstractSphericalVector): def __check_init__(self) -> None: """Check the validity of the initialization.""" check_r_non_negative(self.r) - check_theta_range(self.phi) - check_phi_range(self.theta) + check_azimuth_range(self.theta) + check_polar_range(self.phi) @classproperty @classmethod @@ -181,37 +185,37 @@ class LonLatSphericalVector(AbstractSphericalVector): Parameters ---------- - distance : Distance - Radial distance r (slant distance to origin), lon : Quantity['angle'] The longitude (azimuthal) angle [0, 360) [deg] where 0 is the x-axis. lat : Quantity['angle'] The latitude (polar angle) [-90, 90] [deg] where 90 is the z-axis. + distance : Distance + Radial distance r (slant distance to origin), """ - distance: ct.BatchableDistance = eqx.field( - converter=partial(Distance.constructor, dtype=float) - ) - r"""Radial distance :math:`r \in [0,+\infty)`.""" - lon: ct.BatchableAngle = eqx.field( - converter=lambda x: converter_phi_to_range( + converter=lambda x: converter_azimuth_to_range( Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 ) ) - r"""Longitude angle :math:`\phi \in [0,360)`.""" + r"""Longitude (azimuthal) angle :math:`\in [0,360)`.""" lat: ct.BatchableAngle = eqx.field( converter=lambda x: Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 ) - r"""Latitude angle :math:`\phi \in [-90,90]`.""" + r"""Latitude (polar) angle :math:`\in [-90,90]`.""" + + distance: ct.BatchableDistance = eqx.field( + converter=partial(Distance.constructor, dtype=float) + ) + r"""Radial distance :math:`r \in [0,+\infty)`.""" def __check_init__(self) -> None: """Check the validity of the initialization.""" + check_azimuth_range(self.lon) + check_polar_range(self.lat) check_r_non_negative(self.distance) - check_phi_range(self.lon) - check_theta_range(self.lat) @classproperty @classmethod @@ -256,15 +260,15 @@ class SphericalDifferential(Abstract3DVectorDifferential): ) r"""Radial speed :math:`dr/dt \in [-\infty, \infty].""" - d_phi: ct.BatchableAngularSpeed = eqx.field( + d_theta: ct.BatchableAngularSpeed = eqx.field( converter=partial(Quantity["angular speed"].constructor, dtype=float) ) - r"""Azimuthal speed :math:`d\phi/dt \in [-\infty, \infty].""" + r"""Inclination speed :math:`d\theta/dt \in [-\infty, \infty].""" - d_theta: ct.BatchableAngularSpeed = eqx.field( + d_phi: ct.BatchableAngularSpeed = eqx.field( converter=partial(Quantity["angular speed"].constructor, dtype=float) ) - r"""Inclination speed :math:`d\theta/dt \in [-\infty, \infty].""" + r"""Azimuthal speed :math:`d\phi/dt \in [-\infty, \infty].""" @classproperty @classmethod @@ -301,20 +305,20 @@ def integral_cls(cls) -> type[MathSphericalVector]: class LonLatSphericalDifferential(Abstract3DVectorDifferential): """Spherical differential representation.""" - d_distance: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) - ) - r"""Radial speed :math:`dr/dt \in [-\infty, \infty].""" - d_lon: ct.BatchableAngularSpeed = eqx.field( converter=partial(Quantity["angular speed"].constructor, dtype=float) ) - r"""Longitude speed :math:`d\theta/dt \in [-\infty, \infty].""" + r"""Longitude speed :math:`dlon/dt \in [-\infty, \infty].""" d_lat: ct.BatchableAngularSpeed = eqx.field( converter=partial(Quantity["angular speed"].constructor, dtype=float) ) - r"""Latitude speed :math:`d\phi/dt \in [-\infty, \infty].""" + r"""Latitude speed :math:`dlat/dt \in [-\infty, \infty].""" + + d_distance: ct.BatchableSpeed = eqx.field( + converter=partial(Quantity["speed"].constructor, dtype=float) + ) + r"""Radial speed :math:`dr/dt \in [-\infty, \infty].""" @classproperty @classmethod @@ -326,20 +330,20 @@ def integral_cls(cls) -> type[LonLatSphericalVector]: class LonCosLatSphericalDifferential(Abstract3DVectorDifferential): """Spherical differential representation.""" - d_distance: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) - ) - r"""Radial speed :math:`dr/dt \in [-\infty, \infty].""" - d_lon_coslat: ct.BatchableAngularSpeed = eqx.field( converter=partial(Quantity["angular speed"].constructor, dtype=float) ) - r"""Longitude * cos(Latitude) speed :math:`d\theta/dt \in [-\infty, \infty].""" + r"""Longitude * cos(Latitude) speed :math:`dlon/dt \in [-\infty, \infty].""" d_lat: ct.BatchableAngularSpeed = eqx.field( converter=partial(Quantity["angular speed"].constructor, dtype=float) ) - r"""Latitude speed :math:`d\phi/dt \in [-\infty, \infty].""" + r"""Latitude speed :math:`dlat/dt \in [-\infty, \infty].""" + + d_distance: ct.BatchableSpeed = eqx.field( + converter=partial(Quantity["speed"].constructor, dtype=float) + ) + r"""Radial speed :math:`dr/dt \in [-\infty, \infty].""" @classproperty @classmethod diff --git a/src/coordinax/_d3/transform.py b/src/coordinax/_d3/transform.py index 5e8255bb..b26d73c4 100644 --- a/src/coordinax/_d3/transform.py +++ b/src/coordinax/_d3/transform.py @@ -86,8 +86,8 @@ def represent_as( MathSpherical to MathSpherical: - >>> vec = cx.MathSphericalVector(r=Quantity(1, "kpc"), phi=Quantity(2, "deg"), - ... theta=Quantity(3, "deg")) + >>> vec = cx.MathSphericalVector(r=Quantity(1, "kpc"), theta=Quantity(2, "deg"), + ... phi=Quantity(3, "deg")) >>> cx.represent_as(vec, cx.MathSphericalVector) is vec True @@ -143,8 +143,8 @@ def represent_as( Spherical to Spherical differential: >>> dif = cx.SphericalDifferential(d_r=Quantity(1, "km/s"), - ... d_phi=Quantity(2, "mas/yr"), - ... d_theta=Quantity(3, "mas/yr")) + ... d_theta=Quantity(2, "mas/yr"), + ... d_phi=Quantity(3, "mas/yr")) >>> cx.represent_as(dif, cx.SphericalDifferential, vec) is dif True @@ -215,14 +215,14 @@ def represent_as( >>> vec = cx.Cartesian3DVector.constructor(Quantity([1, 2, 3], "km")) >>> print(cx.represent_as(vec, cx.SphericalVector)) - <SphericalVector (r[km], phi[rad], theta[rad]) - [3.742 1.107 0.641]> + <SphericalVector (r[km], theta[rad], phi[rad]) + [3.742 0.641 1.107]> """ r = xp.sqrt(current.x**2 + current.y**2 + current.z**2) - phi = xp.atan2(current.y, current.x) theta = xp.acos(current.z / r) - return target(r=r, phi=phi, theta=theta) + phi = xp.atan2(current.y, current.x) + return target(r=r, theta=theta, phi=phi) @dispatch.multi( @@ -242,8 +242,8 @@ def represent_as( >>> vec = cx.Cartesian3DVector.constructor(Quantity([1, 2, 3], "km")) >>> print(cx.represent_as(vec, cx.LonLatSphericalVector)) - <LonLatSphericalVector (distance[km], lon[rad], lat[deg]) - [ 3.742 1.107 53.301]> + <LonLatSphericalVector (lon[rad], lat[deg], distance[km]) + [ 1.107 53.301 3.742]> >>> print(cx.represent_as(vec, cx.MathSphericalVector)) <MathSphericalVector (r[km], theta[rad], phi[rad]) @@ -295,14 +295,13 @@ def represent_as( >>> vec = cx.CylindricalVector(rho=Quantity(1., "kpc"), phi=Quantity(90, "deg"), ... z=Quantity(1, "kpc")) >>> print(cx.represent_as(vec, cx.SphericalVector)) - <SphericalVector (r[kpc], phi[deg], theta[rad]) - [ 1.414 90. 0.785]> + <SphericalVector (r[kpc], theta[rad], phi[deg]) + [ 1.414 0.785 90. ]> """ r = xp.sqrt(current.rho**2 + current.z**2) theta = xp.acos(current.z / r) - phi = current.phi - return target(r=r, phi=phi, theta=theta) + return target(r=r, theta=theta, phi=current.phi) @dispatch.multi( @@ -323,8 +322,8 @@ def represent_as( ... z=Quantity(1, "kpc")) >>> print(cx.represent_as(vec, cx.LonLatSphericalVector)) - <LonLatSphericalVector (distance[kpc], lon[deg], lat[deg]) - [ 1.414 90. 45. ]> + <LonLatSphericalVector (lon[deg], lat[deg], distance[kpc]) + [90. 45. 1.414]> >>> print(cx.represent_as(vec, cx.MathSphericalVector)) <MathSphericalVector (r[kpc], theta[deg], phi[rad]) @@ -349,8 +348,8 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.SphericalVector(r=Quantity(1., "kpc"), phi=Quantity(90, "deg"), - ... theta=Quantity(90, "deg")) + >>> vec = cx.SphericalVector(r=Quantity(1., "kpc"), theta=Quantity(90, "deg"), + ... phi=Quantity(90, "deg")) >>> print(cx.represent_as(vec, cx.Cartesian3DVector)) <Cartesian3DVector (x[kpc], y[kpc], z[kpc]) [-4.371e-08 1.000e+00 -4.371e-08]> @@ -373,17 +372,16 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.SphericalVector(r=Quantity(1., "kpc"), phi=Quantity(90, "deg"), - ... theta=Quantity(90, "deg")) + >>> vec = cx.SphericalVector(r=Quantity(1., "kpc"), theta=Quantity(90, "deg"), + ... phi=Quantity(90, "deg")) >>> print(cx.represent_as(vec, cx.CylindricalVector)) <CylindricalVector (rho[kpc], phi[deg], z[kpc]) [ 1.000e+00 9.000e+01 -4.371e-08]> """ rho = xp.abs(current.r * xp.sin(current.theta)) - phi = current.phi z = current.r * xp.cos(current.theta) - return target(rho=rho, phi=phi, z=z) + return target(rho=rho, phi=current.phi, z=z) @dispatch @@ -397,17 +395,15 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.SphericalVector(r=Quantity(1., "kpc"), phi=Quantity(90, "deg"), - ... theta=Quantity(90, "deg")) + >>> vec = cx.SphericalVector(r=Quantity(1., "kpc"), theta=Quantity(90, "deg"), + ... phi=Quantity(90, "deg")) >>> print(cx.represent_as(vec, cx.LonLatSphericalVector)) - <LonLatSphericalVector (distance[kpc], lon[deg], lat[deg]) - [ 1. 90. 0.]> + <LonLatSphericalVector (lon[deg], lat[deg], distance[kpc]) + [90. 0. 1.]> """ return target( - distance=current.r, - lon=current.phi, - lat=Quantity(90, "deg") - current.theta, + lon=current.phi, lat=Quantity(90, "deg") - current.theta, distance=current.r ) @@ -422,8 +418,8 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.SphericalVector(r=Quantity(1., "kpc"), phi=Quantity(90, "deg"), - ... theta=Quantity(90, "deg")) + >>> vec = cx.SphericalVector(r=Quantity(1., "kpc"), theta=Quantity(90, "deg"), + ... phi=Quantity(90, "deg")) >>> print(cx.represent_as(vec, cx.MathSphericalVector)) <MathSphericalVector (r[kpc], theta[deg], phi[deg]) [ 1. 90. 90.]> @@ -492,12 +488,12 @@ def represent_as( >>> vec = cx.LonLatSphericalVector(lon=Quantity(90, "deg"), lat=Quantity(0, "deg"), ... distance=Quantity(1., "kpc")) >>> print(cx.represent_as(vec, cx.SphericalVector)) - <SphericalVector (r[kpc], phi[deg], theta[deg]) + <SphericalVector (r[kpc], theta[deg], phi[deg]) [ 1. 90. 90.]> """ return target( - r=current.distance, phi=current.lon, theta=Quantity(90, "deg") - current.lat + r=current.distance, theta=Quantity(90, "deg") - current.lat, phi=current.lon ) @@ -548,9 +544,8 @@ def represent_as( """ rho = xp.abs(current.r * xp.sin(current.phi)) - phi = current.theta z = current.r * xp.cos(current.phi) - return target(rho=rho, phi=phi, z=z) + return target(rho=rho, phi=current.theta, z=z) @dispatch @@ -567,7 +562,7 @@ def represent_as( >>> vec = cx.MathSphericalVector(r=Quantity(1., "kpc"), theta=Quantity(90, "deg"), ... phi=Quantity(90, "deg")) >>> print(cx.represent_as(vec, cx.SphericalVector)) - <SphericalVector (r[kpc], phi[deg], theta[deg]) + <SphericalVector (r[kpc], theta[deg], phi[deg]) [ 1. 90. 90.]> """ @@ -602,9 +597,10 @@ def represent_as( >>> newdif = cx.represent_as(dif, cx.LonCosLatSphericalDifferential, vec) >>> newdif LonCosLatSphericalDifferential( - d_distance=Quantity[...]( value=f32[], unit=Unit("km / s") ), - d_lon_coslat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), - d_lat=Quantity[...]( value=f32[], unit=Unit("deg / Gyr") ) ) + d_lon_coslat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), + d_lat=Quantity[...]( value=f32[], unit=Unit("deg / Gyr") ), + d_distance=Quantity[...]( value=f32[], unit=Unit("km / s") ) + ) >>> newdif.d_lon_coslat / xp.cos(vec.lat) # float32 imprecision Quantity['angular frequency'](Array(6.9999995, dtype=float32), unit='mas / yr') diff --git a/src/coordinax/_transform/d1.py b/src/coordinax/_transform/d1.py index d936d3ca..d730cae2 100644 --- a/src/coordinax/_transform/d1.py +++ b/src/coordinax/_transform/d1.py @@ -163,8 +163,8 @@ def represent_as( >>> x2 = cx.represent_as(x, cx.SphericalVector) >>> x2 SphericalVector( r=Distance(value=f32[], unit=Unit("km")), - phi=Quantity[...](value=f32[], unit=Unit("rad")), - theta=Quantity[...](value=f32[], unit=Unit("rad")) ) + theta=Quantity[...](value=f32[], unit=Unit("rad")), + phi=Quantity[...](value=f32[], unit=Unit("rad")) ) >>> x2.phi Quantity['angle'](Array(0., dtype=float32), unit='rad') >>> x2.theta @@ -388,8 +388,8 @@ def represent_as( >>> x2 = cx.represent_as(x, cx.SphericalVector) >>> x2 SphericalVector( r=Distance(value=f32[], unit=Unit("km")), - phi=Quantity[...](value=f32[], unit=Unit("rad")), - theta=Quantity[...](value=f32[], unit=Unit("rad")) ) + theta=Quantity[...](value=f32[], unit=Unit("rad")), + phi=Quantity[...](value=f32[], unit=Unit("rad")) ) >>> x2.phi Quantity['angle'](Array(0., dtype=float32), unit='rad') >>> x2.theta diff --git a/src/coordinax/_transform/d2.py b/src/coordinax/_transform/d2.py index 7bd7817d..cdbef6b9 100644 --- a/src/coordinax/_transform/d2.py +++ b/src/coordinax/_transform/d2.py @@ -55,8 +55,8 @@ def represent_as( >>> x3 = cx.represent_as(x, cx.SphericalVector, z=Quantity(14, "km")) >>> x3 SphericalVector( r=Distance(value=f32[], unit=Unit("km")), - phi=Quantity[...](value=f32[], unit=Unit("rad")), - theta=Quantity[...](value=f32[], unit=Unit("rad")) ) + theta=Quantity[...](value=f32[], unit=Unit("rad")), + phi=Quantity[...](value=f32[], unit=Unit("rad")) ) >>> x3.r Distance(Array(14.177447, dtype=float32), unit='km') @@ -297,8 +297,8 @@ def represent_as( >>> x2 = cx.represent_as(x, cx.SphericalVector, theta=Quantity(14, "deg")) >>> x2 SphericalVector( r=Distance(value=f32[], unit=Unit("km")), - phi=Quantity[...](value=f32[], unit=Unit("deg")), - theta=Quantity[...](value=f32[], unit=Unit("deg")) ) + theta=Quantity[...](value=f32[], unit=Unit("deg")), + phi=Quantity[...](value=f32[], unit=Unit("deg")) ) >>> x2.theta Quantity['angle'](Array(14., dtype=float32), unit='deg') diff --git a/src/coordinax/_transform/d3.py b/src/coordinax/_transform/d3.py index 2fcfeae6..d770e5e7 100644 --- a/src/coordinax/_transform/d3.py +++ b/src/coordinax/_transform/d3.py @@ -277,8 +277,8 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.SphericalVector(r=Quantity(1.0, "km"), phi=Quantity(10.0, "deg"), - ... theta=Quantity(14, "deg")) + >>> x = cx.SphericalVector(r=Quantity(1.0, "km"), theta=Quantity(14, "deg"), + ... phi=Quantity(10.0, "deg")) >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") @@ -303,8 +303,8 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.SphericalVector(r=Quantity(1.0, "km"), phi=Quantity(10.0, "deg"), - ... theta=Quantity(14, "deg")) + >>> x = cx.SphericalVector(r=Quantity(1.0, "km"), theta=Quantity(14, "deg"), + ... phi=Quantity(10.0, "deg")) >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") @@ -333,8 +333,8 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.SphericalVector(r=Quantity(1.0, "km"), phi=Quantity(10.0, "deg"), - ... theta=Quantity(14, "deg")) + >>> x = cx.SphericalVector(r=Quantity(1.0, "km"), theta=Quantity(14, "deg"), + ... phi=Quantity(10.0, "deg")) >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") @@ -362,8 +362,8 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.SphericalVector(r=Quantity(1.0, "km"), phi=Quantity(10.0, "deg"), - ... theta=Quantity(14, "deg")) + >>> x = cx.SphericalVector(r=Quantity(1.0, "km"), theta=Quantity(14, "deg"), + ... phi=Quantity(10.0, "deg")) >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") diff --git a/src/coordinax/_transform/differentials.py b/src/coordinax/_transform/differentials.py index aee99c92..22ade8e5 100644 --- a/src/coordinax/_transform/differentials.py +++ b/src/coordinax/_transform/differentials.py @@ -89,8 +89,8 @@ def represent_as( >>> cx.represent_as(p, cx.SphericalDifferential, q) SphericalDifferential( d_r=Quantity[...]( value=f32[], unit=Unit("km / s") ), - d_phi=Quantity[...]( value=f32[], unit=Unit("rad / s") ), - d_theta=Quantity[...]( value=f32[], unit=Unit("rad / s") ) + d_theta=Quantity[...]( value=f32[], unit=Unit("rad / s") ), + d_phi=Quantity[...]( value=f32[], unit=Unit("rad / s") ) ) If given a position as a Quantity, it will be converted to the appropriate @@ -100,8 +100,8 @@ def represent_as( >>> cx.represent_as(p, cx.SphericalDifferential, Quantity([1.0, 2.0, 3.0], "km")) SphericalDifferential( d_r=Quantity[...]( value=f32[], unit=Unit("km / s") ), - d_phi=Quantity[...]( value=f32[], unit=Unit("rad / s") ), - d_theta=Quantity[...]( value=f32[], unit=Unit("rad / s") ) + d_theta=Quantity[...]( value=f32[], unit=Unit("rad / s") ), + d_phi=Quantity[...]( value=f32[], unit=Unit("rad / s") ) ) """ diff --git a/src/coordinax/operators/_galilean/translation.py b/src/coordinax/operators/_galilean/translation.py index f9a60f18..71990f12 100644 --- a/src/coordinax/operators/_galilean/translation.py +++ b/src/coordinax/operators/_galilean/translation.py @@ -154,8 +154,8 @@ class GalileanSpatialTranslationOperator(AbstractGalileanOperator): >>> vec = cx.Cartesian3DVector.constructor(q).represent_as(cx.SphericalVector) >>> op(vec) SphericalVector( r=Distance(value=f32[], unit=Unit("kpc")), - phi=Quantity[...](value=f32[], unit=Unit("rad")), - theta=Quantity[...](value=f32[], unit=Unit("rad")) ) + theta=Quantity[...](value=f32[], unit=Unit("rad")), + phi=Quantity[...](value=f32[], unit=Unit("rad")) ) Many operators are time dependent and require a time argument. This operator is time independent and will pass through the time argument: diff --git a/tests/test_d1.py b/tests/test_d1.py index 5a49ec2e..55ea8485 100644 --- a/tests/test_d1.py +++ b/tests/test_d1.py @@ -78,14 +78,14 @@ def test_cartesian1d_to_spherical(self, vector): """Test ``coordinax.represent_as(SphericalVector)``.""" spherical = vector.represent_as( cx.SphericalVector, - phi=Quantity([0, 1, 2, 3], "rad"), theta=Quantity([4, 5, 6, 7], "rad"), + phi=Quantity([0, 1, 2, 3], "rad"), ) assert isinstance(spherical, cx.SphericalVector) assert qnp.array_equal(spherical.r, Quantity([1, 2, 3, 4], "kpc")) - assert qnp.array_equal(spherical.phi, Quantity([0, 1, 2, 3], "rad")) assert qnp.array_equal(spherical.theta, Quantity([4, 5, 6, 7], "rad")) + assert qnp.array_equal(spherical.phi, Quantity([0, 1, 2, 3], "rad")) def test_cartesian1d_to_cylindrical(self, vector): """Test ``coordinax.represent_as(CylindricalVector)``.""" @@ -164,14 +164,14 @@ def test_radial_to_spherical(self, vector): """Test ``coordinax.represent_as(SphericalVector)``.""" spherical = vector.represent_as( cx.SphericalVector, - phi=Quantity([0, 1, 2, 3], "rad"), theta=Quantity([4, 5, 6, 7], "rad"), + phi=Quantity([0, 1, 2, 3], "rad"), ) assert isinstance(spherical, cx.SphericalVector) assert qnp.array_equal(spherical.r, Quantity([1, 2, 3, 4], "kpc")) - assert qnp.array_equal(spherical.phi, Quantity([0, 1, 2, 3], "rad")) assert qnp.array_equal(spherical.theta, Quantity([4, 5, 6, 7], "rad")) + assert qnp.array_equal(spherical.phi, Quantity([0, 1, 2, 3], "rad")) def test_radial_to_cylindrical(self, vector): """Test ``coordinax.represent_as(CylindricalVector)``.""" @@ -273,14 +273,14 @@ def test_cartesian1d_to_spherical(self, difntl, vector): spherical = difntl.represent_as( cx.SphericalDifferential, vector, - d_phi=Quantity([0, 1, 2, 3], "rad"), d_theta=Quantity([4, 5, 6, 7], "rad"), + d_phi=Quantity([0, 1, 2, 3], "rad"), ) assert isinstance(spherical, cx.SphericalDifferential) assert qnp.array_equal(spherical.d_r, Quantity([1, 2, 3, 4], "kpc")) + assert spherical.d_theta == Quantity([4, 5, 6, 7], "rad") assert qnp.array_equal(spherical.d_phi, Quantity([0, 1, 2, 3], "rad")) - assert spherical.dtheta == Quantity([4, 5, 6, 7], "rad") @pytest.mark.xfail(reason="Not implemented") @pytest.mark.filterwarnings("ignore:Explicitly requested dtype") @@ -381,14 +381,14 @@ def test_radial_to_spherical(self, difntl, vector): spherical = difntl.represent_as( cx.SphericalDifferential, vector, + d_theta=Quantity([4, 5, 6, 7], "rad"), d_phi=Quantity([0, 1, 2, 3], "rad"), - dtheta=Quantity([4, 5, 6, 7], "rad"), ) assert isinstance(spherical, cx.SphericalDifferential) assert qnp.array_equal(spherical.d_r, Quantity([1, 2, 3, 4], "kpc")) + assert spherical.d_theta == Quantity([4, 5, 6, 7], "rad") assert qnp.array_equal(spherical.d_phi, Quantity([0, 1, 2, 3], "rad")) - assert spherical.dtheta == Quantity([4, 5, 6, 7], "rad") @pytest.mark.xfail(reason="Not implemented") @pytest.mark.filterwarnings("ignore:Explicitly requested dtype") diff --git a/tests/test_d2.py b/tests/test_d2.py index 75bcfd83..fcdcad79 100644 --- a/tests/test_d2.py +++ b/tests/test_d2.py @@ -200,8 +200,8 @@ def test_polar_to_spherical(self, vector): assert isinstance(spherical, cx.SphericalVector) assert qnp.array_equal(spherical.r, Quantity([1, 2, 3, 4], "kpc")) - assert qnp.array_equal(spherical.phi, Quantity([0, 1, 2, 3], "rad")) assert qnp.array_equal(spherical.theta, Quantity([4, 5, 6, 7], "rad")) + assert qnp.array_equal(spherical.phi, Quantity([0, 1, 2, 3], "rad")) def test_polar_to_cylindrical(self, vector): """Test ``coordinax.represent_as(CylindricalVector)``.""" @@ -304,8 +304,8 @@ def test_cartesian2d_to_spherical(self, difntl, vector): assert isinstance(spherical, cx.SphericalDifferential) assert qnp.array_equal(spherical.d_r, Quantity([1, 2, 3, 4], "km/s")) - assert qnp.array_equal(spherical.d_phi, Quantity([5, 6, 7, 8], "km/s")) assert qnp.array_equal(spherical.d_theta, Quantity([4, 5, 6, 7], "rad")) + assert qnp.array_equal(spherical.d_phi, Quantity([5, 6, 7, 8], "km/s")) @pytest.mark.xfail(reason="Not implemented") @pytest.mark.filterwarnings("ignore:Explicitly requested dtype") @@ -408,8 +408,8 @@ def test_polar_to_spherical(self, difntl, vector): assert isinstance(spherical, cx.SphericalDifferential) assert qnp.array_equal(spherical.d_r, Quantity([1, 2, 3, 4], "km/s")) - assert qnp.array_equal(spherical.d_phi, Quantity([5, 6, 7, 8], "km/s")) assert qnp.array_equal(spherical.d_theta, Quantity([4, 5, 6, 7], "rad")) + assert qnp.array_equal(spherical.d_phi, Quantity([5, 6, 7, 8], "km/s")) @pytest.mark.xfail(reason="Not implemented") @pytest.mark.filterwarnings("ignore:Explicitly requested dtype") diff --git a/tests/test_d3.py b/tests/test_d3.py index a6f84803..84c505ac 100644 --- a/tests/test_d3.py +++ b/tests/test_d3.py @@ -177,8 +177,8 @@ def test_cartesian3d_to_cylindrical_astropy(self, vector, apyvector): apycyl = apyvector.represent_as(apyc.CylindricalRepresentation) assert np.allclose(convert(cyl.rho, APYQuantity), apycyl.rho) - assert np.allclose(convert(cyl.z, APYQuantity), apycyl.z) assert np.allclose(convert(cyl.phi, APYQuantity), apycyl.phi) + assert np.allclose(convert(cyl.z, APYQuantity), apycyl.z) class TestCylindricalVector(Abstract3DVectorTest): @@ -271,8 +271,8 @@ def test_cylindrical_to_spherical(self, vector): assert isinstance(spherical, cx.SphericalVector) assert qnp.array_equal(spherical.r, Quantity([1, 2, 3, 4], "kpc")) - assert qnp.array_equal(spherical.phi, Quantity([0, 1, 2, 3], "rad")) assert qnp.array_equal(spherical.theta, Quantity(xp.full(4, xp.pi / 2), "rad")) + assert qnp.array_equal(spherical.phi, Quantity([0, 1, 2, 3], "rad")) def test_cylindrical_to_spherical_astropy(self, vector, apyvector): """Test Astropy equivalence.""" @@ -298,8 +298,8 @@ def test_cylindrical_to_cylindrical_astropy(self, vector, apyvector): apycyl = apyvector.represent_as(apyc.CylindricalRepresentation) assert np.allclose(convert(cyl.rho, APYQuantity), apycyl.rho) - assert np.allclose(convert(cyl.z, APYQuantity), apycyl.z) assert np.allclose(convert(cyl.phi, APYQuantity), apycyl.phi) + assert np.allclose(convert(cyl.z, APYQuantity), apycyl.z) class TestSphericalVector(Abstract3DVectorTest): @@ -310,8 +310,8 @@ def vector(self) -> cx.SphericalVector: """Return a vector.""" return cx.SphericalVector( r=Quantity([1, 2, 3, 4], "kpc"), - phi=Quantity([0, 65, 135, 270], "deg"), theta=Quantity([0, 36, 142, 180], "deg"), + phi=Quantity([0, 65, 135, 270], "deg"), ) @pytest.fixture(scope="class") @@ -449,8 +449,8 @@ def test_spherical_to_mathspherical(self, vector): """Test ``coordinax.represent_as(MathSphericalVector)``.""" newvec = cx.represent_as(vector, cx.MathSphericalVector) assert qnp.array_equal(newvec.r, vector.r) - assert qnp.array_equal(newvec.phi, vector.theta) assert qnp.array_equal(newvec.theta, vector.phi) + assert qnp.array_equal(newvec.phi, vector.theta) def test_spherical_to_lonlatspherical(self, vector): """Test ``coordinax.represent_as(LonLatSphericalVector)``.""" @@ -459,9 +459,9 @@ def test_spherical_to_lonlatspherical(self, vector): ) assert isinstance(llsph, cx.LonLatSphericalVector) - assert qnp.array_equal(llsph.distance, vector.r) assert qnp.array_equal(llsph.lon, vector.phi) assert qnp.array_equal(llsph.lat, Quantity(90, "deg") - vector.theta) + assert qnp.array_equal(llsph.distance, vector.r) def test_spherical_to_lonlatspherical_astropy(self, vector, apyvector): """Test Astropy equivalence.""" @@ -641,8 +641,8 @@ def test_cartesian3d_to_cylindrical_astropy( cyl = difntl.represent_as(cx.CylindricalDifferential, vector) apycyl = apydifntl.represent_as(apyc.CylindricalDifferential, apyvector) assert np.allclose(convert(cyl.d_rho, APYQuantity), apycyl.d_rho) - assert np.allclose(convert(cyl.d_z, APYQuantity), apycyl.d_z) assert np.allclose(convert(cyl.d_phi, APYQuantity), apycyl.d_phi) + assert np.allclose(convert(cyl.d_z, APYQuantity), apycyl.d_z) class TestCylindricalDifferential(Abstract3DVectorDifferentialTest): @@ -744,10 +744,6 @@ def test_cylindrical_to_spherical(self, difntl, vector): dsph.d_r, Quantity([13.472646, 14.904826, 16.313278, 17.708754], "km/s"), ) - assert qnp.array_equal( - dsph.d_phi, - Quantity([42.664234, 47.404705, 52.145176, 56.885643], "km rad / (kpc s)"), - ) assert qnp.allclose( dsph.d_theta, Quantity( @@ -755,6 +751,10 @@ def test_cylindrical_to_spherical(self, difntl, vector): ), atol=Quantity(5e-7, "km rad / (kpc s)"), ) + assert qnp.array_equal( + dsph.d_phi, + Quantity([42.664234, 47.404705, 52.145176, 56.885643], "km rad / (kpc s)"), + ) def test_cylindrical_to_spherical_astropy( self, difntl, vector, apydifntl, apyvector @@ -781,8 +781,8 @@ def test_cylindrical_to_cylindrical(self, difntl, vector, apydifntl, apyvector): cyl = difntl.represent_as(cx.CylindricalDifferential, vector) apycyl = apydifntl.represent_as(apyc.CylindricalDifferential, apyvector) assert np.allclose(convert(cyl.d_rho, APYQuantity), apycyl.d_rho) - assert np.allclose(convert(cyl.d_z, APYQuantity), apycyl.d_z) assert np.allclose(convert(cyl.d_phi, APYQuantity), apycyl.d_phi) + assert np.allclose(convert(cyl.d_z, APYQuantity), apycyl.d_z) class TestSphericalDifferential(Abstract3DVectorDifferentialTest): @@ -793,8 +793,8 @@ def difntl(self) -> cx.SphericalDifferential: """Return a differential.""" return cx.SphericalDifferential( d_r=Quantity([5, 6, 7, 8], "km/s"), - d_phi=Quantity([9, 10, 11, 12], "mas/yr"), d_theta=Quantity([13, 14, 15, 16], "mas/yr"), + d_phi=Quantity([9, 10, 11, 12], "mas/yr"), ) @pytest.fixture(scope="class") @@ -802,8 +802,8 @@ def vector(self) -> cx.SphericalVector: """Return a vector.""" return cx.SphericalVector( r=Quantity([1, 2, 3, 4], "kpc"), - phi=Quantity([0, 42, 160, 270], "deg"), theta=Quantity([3, 63, 90, 179.5], "deg"), + phi=Quantity([0, 42, 160, 270], "deg"), ) @pytest.fixture(scope="class") @@ -920,8 +920,8 @@ def test_spherical_to_cylindrical_astropy( cyl = difntl.represent_as(cx.CylindricalDifferential, vector) apycyl = apydifntl.represent_as(apyc.CylindricalDifferential, apyvector) assert np.allclose(convert(cyl.d_rho, APYQuantity), apycyl.d_rho) - assert np.allclose(convert(cyl.d_z, APYQuantity), apycyl.d_z) assert np.allclose(convert(cyl.d_phi, APYQuantity), apycyl.d_phi) + assert np.allclose(convert(cyl.d_z, APYQuantity), apycyl.d_z) def test_spherical_to_spherical(self, difntl, vector): """Test ``coordinax.represent_as(SphericalDifferential)``.""" @@ -971,5 +971,5 @@ def test_spherical_to_mathspherical(self, difntl, vector): assert isinstance(llsph, cx.MathSphericalDifferential) assert qnp.array_equal(llsph.d_r, difntl.d_r) - assert qnp.array_equal(llsph.d_theta, difntl.d_phi) assert qnp.array_equal(llsph.d_phi, difntl.d_theta) + assert qnp.array_equal(llsph.d_theta, difntl.d_phi)