From 08864e26cb0a6f814ac8c3b5786dea33163ad7bb Mon Sep 17 00:00:00 2001 From: Nathaniel Starkman Date: Mon, 14 Oct 2024 16:05:03 -0400 Subject: [PATCH] refactor: rename constructor to from_ (#205) * refactor: rename constructor to from_ * style: pre-commit fixes Signed-off-by: nstarman Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- pyproject.toml | 2 +- .../coordinax_interop_astropy/constructors.py | 152 +++++++++--------- .../coordinax_interop_astropy/converters.py | 28 ++-- src/coordinax/_src/base/base.py | 90 +++++------ src/coordinax/_src/base/base_acc.py | 12 +- src/coordinax/_src/base/base_pos.py | 28 ++-- src/coordinax/_src/base/base_vel.py | 10 +- src/coordinax/_src/base/compat.py | 32 ++-- src/coordinax/_src/base/mixins.py | 26 +-- .../_src/base/register_primitives.py | 24 +-- src/coordinax/_src/compat.py | 36 ++--- src/coordinax/_src/d1/base.py | 36 ++--- src/coordinax/_src/d1/cartesian.py | 26 +-- src/coordinax/_src/d1/compat.py | 4 +- src/coordinax/_src/d1/radial.py | 6 +- src/coordinax/_src/d1/transform.py | 4 +- src/coordinax/_src/d2/cartesian.py | 48 +++--- src/coordinax/_src/d2/compat.py | 4 +- src/coordinax/_src/d2/polar.py | 12 +- src/coordinax/_src/d2/spherical.py | 12 +- src/coordinax/_src/d2/transform.py | 4 +- src/coordinax/_src/d3/cartesian.py | 54 +++---- src/coordinax/_src/d3/compat.py | 4 +- src/coordinax/_src/d3/constructor.py | 72 ++++----- src/coordinax/_src/d3/cylindrical.py | 18 +-- src/coordinax/_src/d3/generic.py | 16 +- src/coordinax/_src/d3/lonlatspherical.py | 38 ++--- src/coordinax/_src/d3/mathspherical.py | 30 ++-- src/coordinax/_src/d3/spherical.py | 32 ++-- src/coordinax/_src/d3/transform.py | 22 +-- src/coordinax/_src/d4/compat.py | 4 +- src/coordinax/_src/d4/spacetime.py | 22 +-- src/coordinax/_src/dn/base.py | 16 +- src/coordinax/_src/dn/cartesian.py | 52 +++--- src/coordinax/_src/dn/poincare.py | 8 +- src/coordinax/_src/dn/transform.py | 4 +- src/coordinax/_src/exceptions.py | 2 +- src/coordinax/_src/operators/base.py | 10 +- src/coordinax/_src/operators/composite.py | 2 +- .../_src/operators/galilean/boost.py | 12 +- .../_src/operators/galilean/composite.py | 8 +- .../_src/operators/galilean/rotation.py | 6 +- .../_src/operators/galilean/translation.py | 72 ++++----- src/coordinax/_src/operators/identity.py | 14 +- src/coordinax/_src/space.py | 74 ++++----- src/coordinax/_src/transform/accelerations.py | 16 +- src/coordinax/_src/transform/d1.py | 4 +- src/coordinax/_src/transform/d2.py | 12 +- src/coordinax/_src/transform/d3.py | 8 +- src/coordinax/_src/transform/differentials.py | 12 +- src/coordinax/_src/transform/dn.py | 4 +- src/coordinax/_src/transform/space.py | 8 +- tests/test_jax_ops.py | 2 +- 53 files changed, 622 insertions(+), 632 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 568eb068..82a3df5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ "plum-dispatch>=2.5.2", "quax>=0.0.5", "quaxed>=0.6.4", - "unxt>=0.17.0", + "unxt>=0.18.0", "xmmutablemap>=0.1", ] diff --git a/src/coordinax/_interop/coordinax_interop_astropy/constructors.py b/src/coordinax/_interop/coordinax_interop_astropy/constructors.py index 9bb54d45..8f8ad12a 100644 --- a/src/coordinax/_interop/coordinax_interop_astropy/constructors.py +++ b/src/coordinax/_interop/coordinax_interop_astropy/constructors.py @@ -16,8 +16,8 @@ ##################################################################### -@cx.AbstractVector.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.AbstractVector.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.AbstractVector], obj: Mapping[str, u.Quantity], / ) -> cx.AbstractVector: """Construct a vector from a mapping. @@ -36,7 +36,7 @@ def constructor( >>> import coordinax as cx >>> xs = {"x": Quantity(1, "m"), "y": Quantity(2, "m"), "z": Quantity(3, "m")} - >>> vec = cx.CartesianPosition3D.constructor(xs) + >>> vec = cx.CartesianPosition3D.from_(xs) >>> vec CartesianPosition3D( x=Quantity[PhysicalType('length')](value=f32[], unit=Unit("m")), @@ -46,7 +46,7 @@ def constructor( >>> xs = {"x": Quantity([1, 2], "m"), "y": Quantity([3, 4], "m"), ... "z": Quantity([5, 6], "m")} - >>> vec = cx.CartesianPosition3D.constructor(xs) + >>> vec = cx.CartesianPosition3D.from_(xs) >>> vec CartesianPosition3D( x=Quantity[PhysicalType('length')](value=f32[2], unit=Unit("m")), @@ -61,8 +61,8 @@ def constructor( ##################################################################### -@cx.AbstractPosition3D.constructor._f.dispatch(precedence=-1) # noqa: SLF001 -def constructor( +@cx.AbstractPosition3D.from_._f.dispatch(precedence=-1) # noqa: SLF001 +def from_( cls: type[cx.AbstractPosition3D], obj: apyc.CartesianRepresentation, / ) -> cx.CartesianPosition3D: """Construct from a :class:`astropy.coordinates.CartesianRepresentation`. @@ -73,16 +73,16 @@ def constructor( >>> from astropy.coordinates import CartesianRepresentation >>> cart = CartesianRepresentation(1, 2, 3, unit="kpc") - >>> vec = cx.AbstractPosition3D.constructor(cart) + >>> vec = cx.AbstractPosition3D.from_(cart) >>> vec.x Quantity['length'](Array(1., dtype=float32), unit='kpc') """ - return cx.CartesianPosition3D.constructor(obj) + return cx.CartesianPosition3D.from_(obj) -@cx.AbstractPosition3D.constructor._f.dispatch(precedence=-1) # noqa: SLF001 -def constructor( +@cx.AbstractPosition3D.from_._f.dispatch(precedence=-1) # noqa: SLF001 +def from_( cls: type[cx.AbstractPosition3D], obj: apyc.CylindricalRepresentation, / ) -> cx.CylindricalPosition: """Construct from a :class:`astropy.coordinates.CylindricalRepresentation`. @@ -95,16 +95,16 @@ def constructor( >>> cyl = CylindricalRepresentation(rho=1 * u.kpc, phi=2 * u.deg, ... z=30 * u.pc) - >>> vec = cx.AbstractPosition3D.constructor(cyl) + >>> vec = cx.AbstractPosition3D.from_(cyl) >>> vec.rho Quantity['length'](Array(1., dtype=float32), unit='kpc') """ - return cx.CylindricalPosition.constructor(obj) + return cx.CylindricalPosition.from_(obj) -@cx.AbstractPosition3D.constructor._f.dispatch(precedence=-1) # noqa: SLF001 -def constructor( +@cx.AbstractPosition3D.from_._f.dispatch(precedence=-1) # noqa: SLF001 +def from_( cls: type[cx.AbstractPosition3D], obj: apyc.PhysicsSphericalRepresentation, / ) -> cx.SphericalPosition: """Construct from a :class:`astropy.coordinates.PhysicsSphericalRepresentation`. @@ -117,16 +117,16 @@ def constructor( >>> sph = PhysicsSphericalRepresentation(r=1 * u.kpc, theta=2 * u.deg, ... phi=3 * u.deg) - >>> vec = cx.AbstractPosition3D.constructor(sph) + >>> vec = cx.AbstractPosition3D.from_(sph) >>> vec.r Distance(Array(1., dtype=float32), unit='kpc') """ - return cx.SphericalPosition.constructor(obj) + return cx.SphericalPosition.from_(obj) -@cx.AbstractPosition3D.constructor._f.dispatch(precedence=-1) # noqa: SLF001 -def constructor( +@cx.AbstractPosition3D.from_._f.dispatch(precedence=-1) # noqa: SLF001 +def from_( cls: type[cx.AbstractPosition3D], obj: apyc.SphericalRepresentation, / ) -> cx.LonLatSphericalPosition: """Construct from a :class:`astropy.coordinates.SphericalRepresentation`. @@ -139,19 +139,19 @@ def constructor( >>> sph = SphericalRepresentation(lon=3 * u.deg, lat=2 * u.deg, ... distance=1 * u.kpc) - >>> vec = cx.AbstractPosition3D.constructor(sph) + >>> vec = cx.AbstractPosition3D.from_(sph) >>> vec.distance Distance(Array(1., dtype=float32), unit='kpc') """ - return cx.LonLatSphericalPosition.constructor(obj) + return cx.LonLatSphericalPosition.from_(obj) # ------------------------------------------------------------------- -@cx.CartesianPosition3D.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.CartesianPosition3D.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.CartesianPosition3D], obj: apyc.BaseRepresentation, / ) -> cx.CartesianPosition3D: """Construct from a :class:`astropy.coordinates.BaseRepresentation`. @@ -162,7 +162,7 @@ def constructor( >>> from astropy.coordinates import CartesianRepresentation >>> cart = CartesianRepresentation(1, 2, 3, unit="kpc") - >>> vec = cx.CartesianPosition3D.constructor(cart) + >>> vec = cx.CartesianPosition3D.from_(cart) >>> vec.x Quantity['length'](Array(1., dtype=float32), unit='kpc') @@ -171,8 +171,8 @@ def constructor( return cls(x=obj.x, y=obj.y, z=obj.z) -@cx.CylindricalPosition.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.CylindricalPosition.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.CylindricalPosition], obj: apyc.BaseRepresentation, / ) -> cx.CylindricalPosition: """Construct from a :class:`astropy.coordinates.BaseRepresentation`. @@ -185,7 +185,7 @@ def constructor( >>> cyl = CylindricalRepresentation(rho=1 * u.kpc, phi=2 * u.deg, ... z=30 * u.pc) - >>> vec = cx.CylindricalPosition.constructor(cyl) + >>> vec = cx.CylindricalPosition.from_(cyl) >>> vec.rho Quantity['length'](Array(1., dtype=float32), unit='kpc') @@ -194,8 +194,8 @@ def constructor( return cls(rho=obj.rho, phi=obj.phi, z=obj.z) -@cx.SphericalPosition.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.SphericalPosition.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.SphericalPosition], obj: apyc.BaseRepresentation, / ) -> cx.SphericalPosition: """Construct from a :class:`astropy.coordinates.BaseRepresentation`. @@ -208,7 +208,7 @@ def constructor( >>> sph = PhysicsSphericalRepresentation(r=1 * u.kpc, theta=2 * u.deg, ... phi=3 * u.deg) - >>> vec = cx.SphericalPosition.constructor(sph) + >>> vec = cx.SphericalPosition.from_(sph) >>> vec.r Distance(Array(1., dtype=float32), unit='kpc') @@ -217,8 +217,8 @@ def constructor( return cls(r=obj.r, theta=obj.theta, phi=obj.phi) -@cx.LonLatSphericalPosition.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.LonLatSphericalPosition.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.LonLatSphericalPosition], obj: apyc.BaseRepresentation, / ) -> cx.LonLatSphericalPosition: """Construct from a :class:`astropy.coordinates.BaseRepresentation`. @@ -231,7 +231,7 @@ def constructor( >>> sph = SphericalRepresentation(lon=3 * u.deg, lat=2 * u.deg, ... distance=1 * u.kpc) - >>> vec = cx.LonLatSphericalPosition.constructor(sph) + >>> vec = cx.LonLatSphericalPosition.from_(sph) >>> vec.distance Distance(Array(1., dtype=float32), unit='kpc') @@ -243,8 +243,8 @@ def constructor( ##################################################################### -@cx.AbstractVelocity3D.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.AbstractVelocity3D.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.AbstractVelocity3D], obj: apyc.CartesianDifferential, / ) -> cx.CartesianVelocity3D: """Construct from a :class:`astropy.coordinates.CartesianDifferential`. @@ -256,16 +256,16 @@ def constructor( >>> from astropy.coordinates import CartesianDifferential >>> dcart = CartesianDifferential(1, 2, 3, unit="km/s") - >>> dif = cx.AbstractVelocity3D.constructor(dcart) + >>> dif = cx.AbstractVelocity3D.from_(dcart) >>> dif.d_x Quantity['speed'](Array(1., dtype=float32), unit='km / s') """ - return cx.CartesianVelocity3D.constructor(obj) + return cx.CartesianVelocity3D.from_(obj) -@cx.AbstractVelocity3D.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.AbstractVelocity3D.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.AbstractVelocity3D], obj: apyc.CylindricalDifferential, / ) -> cx.CylindricalVelocity: """Construct from a :class:`astropy.coordinates.CylindricalDifferential`. @@ -278,16 +278,16 @@ def constructor( >>> dcyl = apyc.CylindricalDifferential(d_rho=1 * u.km / u.s, d_phi=2 * u.mas/u.yr, ... d_z=2 * u.km / u.s) - >>> dif = cx.AbstractVelocity3D.constructor(dcyl) + >>> dif = cx.AbstractVelocity3D.from_(dcyl) >>> dif.d_rho Quantity['speed'](Array(1., dtype=float32), unit='km / s') """ - return cx.CylindricalVelocity.constructor(obj) + return cx.CylindricalVelocity.from_(obj) -@cx.AbstractVelocity3D.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.AbstractVelocity3D.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.AbstractVelocity3D], obj: apyc.PhysicsSphericalDifferential, / ) -> cx.SphericalVelocity: """Construct from a :class:`astropy.coordinates.PhysicsSphericalDifferential`. @@ -300,16 +300,16 @@ def constructor( >>> dsph = PhysicsSphericalDifferential(d_r=1 * u.km / u.s, d_theta=2 * u.mas/u.yr, ... d_phi=3 * u.mas/u.yr) - >>> dif = cx.AbstractVelocity3D.constructor(dsph) + >>> dif = cx.AbstractVelocity3D.from_(dsph) >>> dif.d_r Quantity['speed'](Array(1., dtype=float32), unit='km / s') """ - return cx.SphericalVelocity.constructor(obj) + return cx.SphericalVelocity.from_(obj) -@cx.AbstractVelocity3D.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.AbstractVelocity3D.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.AbstractVelocity3D], obj: apyc.SphericalDifferential, / ) -> cx.LonLatSphericalVelocity: """Construct from a :class:`astropy.coordinates.SphericalDifferential`. @@ -323,16 +323,16 @@ def constructor( >>> dsph = SphericalDifferential(d_distance=1 * u.km / u.s, ... d_lon=2 * u.mas/u.yr, ... d_lat=3 * u.mas/u.yr) - >>> dif = cx.AbstractVelocity3D.constructor(dsph) + >>> dif = cx.AbstractVelocity3D.from_(dsph) >>> dif.d_distance Quantity['speed'](Array(1., dtype=float32), unit='km / s') """ - return cx.LonLatSphericalVelocity.constructor(obj) + return cx.LonLatSphericalVelocity.from_(obj) -@cx.AbstractVelocity3D.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.AbstractVelocity3D.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.AbstractVelocity3D], obj: apyc.SphericalCosLatDifferential, / ) -> cx.LonCosLatSphericalVelocity: """Construct from a :class:`astropy.coordinates.SphericalCosLatDifferential`. @@ -346,7 +346,7 @@ def constructor( >>> dsph = SphericalCosLatDifferential(d_distance=1 * u.km / u.s, ... d_lon_coslat=2 * u.mas/u.yr, ... d_lat=3 * u.mas/u.yr) - >>> dif = cx.AbstractVelocity3D.constructor(dsph) + >>> dif = cx.AbstractVelocity3D.from_(dsph) >>> dif LonCosLatSphericalVelocity( d_lon_coslat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), @@ -357,14 +357,14 @@ def constructor( Quantity['speed'](Array(1., dtype=float32), unit='km / s') """ - return cx.LonCosLatSphericalVelocity.constructor(obj) + return cx.LonCosLatSphericalVelocity.from_(obj) # ------------------------------------------------------------------- -@cx.CartesianVelocity3D.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.CartesianVelocity3D.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.CartesianVelocity3D], obj: apyc.CartesianDifferential, / ) -> cx.CartesianVelocity3D: """Construct from a :class:`astropy.coordinates.CartesianDifferential`. @@ -376,7 +376,7 @@ def constructor( >>> from astropy.coordinates import CartesianDifferential >>> dcart = CartesianDifferential(1, 2, 3, unit="km/s") - >>> dif = cx.CartesianVelocity3D.constructor(dcart) + >>> dif = cx.CartesianVelocity3D.from_(dcart) >>> dif.d_x Quantity['speed'](Array(1., dtype=float32), unit='km / s') @@ -384,8 +384,8 @@ def constructor( return cls(d_x=obj.d_x, d_y=obj.d_y, d_z=obj.d_z) -@cx.CylindricalVelocity.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.CylindricalVelocity.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.CylindricalVelocity], obj: apyc.CylindricalDifferential, / ) -> cx.CylindricalVelocity: """Construct from a :class:`astropy.coordinates.CylindricalVelocity`. @@ -398,7 +398,7 @@ def constructor( >>> dcyl = apyc.CylindricalDifferential(d_rho=1 * u.km / u.s, d_phi=2 * u.mas/u.yr, ... d_z=2 * u.km / u.s) - >>> dif = cx.CylindricalVelocity.constructor(dcyl) + >>> dif = cx.CylindricalVelocity.from_(dcyl) >>> dif.d_rho Quantity['speed'](Array(1., dtype=float32), unit='km / s') @@ -406,8 +406,8 @@ def constructor( return cls(d_rho=obj.d_rho, d_phi=obj.d_phi, d_z=obj.d_z) -@cx.SphericalVelocity.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.SphericalVelocity.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.SphericalVelocity], obj: apyc.PhysicsSphericalDifferential, / ) -> cx.SphericalVelocity: """Construct from a :class:`astropy.coordinates.PhysicsSphericalDifferential`. @@ -420,7 +420,7 @@ def constructor( >>> dsph = PhysicsSphericalDifferential(d_r=1 * u.km / u.s, d_theta=2 * u.mas/u.yr, ... d_phi=3 * u.mas/u.yr) - >>> dif = cx.SphericalVelocity.constructor(dsph) + >>> dif = cx.SphericalVelocity.from_(dsph) >>> dif.d_r Quantity['speed'](Array(1., dtype=float32), unit='km / s') @@ -428,8 +428,8 @@ def constructor( return cls(d_r=obj.d_r, d_phi=obj.d_phi, d_theta=obj.d_theta) -@cx.LonLatSphericalVelocity.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.LonLatSphericalVelocity.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.LonLatSphericalVelocity], obj: apyc.SphericalDifferential, / ) -> cx.LonLatSphericalVelocity: """Construct from a :class:`astropy.coordinates.SphericalVelocity`. @@ -443,7 +443,7 @@ def constructor( >>> dsph = SphericalDifferential(d_distance=1 * u.km / u.s, ... d_lon=2 * u.mas/u.yr, ... d_lat=3 * u.mas/u.yr) - >>> dif = cx.LonLatSphericalVelocity.constructor(dsph) + >>> dif = cx.LonLatSphericalVelocity.from_(dsph) >>> dif.d_distance Quantity['speed'](Array(1., dtype=float32), unit='km / s') @@ -451,8 +451,8 @@ def constructor( return cls(d_distance=obj.d_distance, d_lon=obj.d_lon, d_lat=obj.d_lat) -@cx.LonCosLatSphericalVelocity.constructor._f.dispatch # noqa: SLF001 -def constructor( +@cx.LonCosLatSphericalVelocity.from_._f.dispatch # noqa: SLF001 +def from_( cls: type[cx.LonCosLatSphericalVelocity], obj: apyc.SphericalCosLatDifferential, / ) -> cx.LonCosLatSphericalVelocity: """Construct from a :class:`astropy.coordinates.SphericalCosLatDifferential`. @@ -466,7 +466,7 @@ def constructor( >>> dsph = SphericalCosLatDifferential(d_distance=1 * u.km / u.s, ... d_lon_coslat=2 * u.mas/u.yr, ... d_lat=3 * u.mas/u.yr) - >>> dif = cx.LonCosLatSphericalVelocity.constructor(dsph) + >>> dif = cx.LonCosLatSphericalVelocity.from_(dsph) >>> dif LonCosLatSphericalVelocity( d_lon_coslat=Quantity[...]( value=f32[], unit=Unit("mas / yr") ), @@ -485,8 +485,8 @@ def constructor( ##################################################################### -@cx.AbstractVector.constructor._f.dispatch # noqa: SLF001 -def constructor(cls: type[cx.AbstractVector], obj: u.Quantity, /) -> cx.AbstractVector: +@cx.AbstractVector.from_._f.dispatch # noqa: SLF001 +def from_(cls: type[cx.AbstractVector], obj: u.Quantity, /) -> cx.AbstractVector: """Construct a vector from an Astropy Quantity array. The array is expected to have the components as the last dimension. @@ -505,7 +505,7 @@ def constructor(cls: type[cx.AbstractVector], obj: u.Quantity, /) -> cx.Abstract >>> import coordinax as cx >>> xs = Quantity([1, 2, 3], "meter") - >>> vec = cx.CartesianPosition3D.constructor(xs) + >>> vec = cx.CartesianPosition3D.from_(xs) >>> vec CartesianPosition3D( x=Quantity[PhysicalType('length')](value=f32[], unit=Unit("m")), @@ -514,7 +514,7 @@ def constructor(cls: type[cx.AbstractVector], obj: u.Quantity, /) -> cx.Abstract ) >>> xs = Quantity(jnp.array([[1, 2, 3], [4, 5, 6]]), "meter") - >>> vec = cx.CartesianPosition3D.constructor(xs) + >>> vec = cx.CartesianPosition3D.from_(xs) >>> vec CartesianPosition3D( x=Quantity[PhysicalType('length')](value=f32[2], unit=Unit("m")), @@ -524,7 +524,7 @@ def constructor(cls: type[cx.AbstractVector], obj: u.Quantity, /) -> cx.Abstract >>> vec.x Quantity['length'](Array([1., 4.], dtype=float32), unit='m') - >>> vec = cx.CartesianVelocity3D.constructor(Quantity([1, 2, 3], "m/s")) + >>> vec = cx.CartesianVelocity3D.from_(Quantity([1, 2, 3], "m/s")) >>> vec CartesianVelocity3D( d_x=Quantity[...]( value=f32[], unit=Unit("m / s") ), @@ -532,7 +532,7 @@ def constructor(cls: type[cx.AbstractVector], obj: u.Quantity, /) -> cx.Abstract d_z=Quantity[...]( value=f32[], unit=Unit("m / s") ) ) - >>> vec = cx.CartesianAcceleration3D.constructor(Quantity([1, 2, 3], "m/s2")) + >>> vec = cx.CartesianAcceleration3D.from_(Quantity([1, 2, 3], "m/s2")) >>> vec CartesianAcceleration3D( d2_x=Quantity[...](value=f32[], unit=Unit("m / s2")), @@ -541,7 +541,7 @@ def constructor(cls: type[cx.AbstractVector], obj: u.Quantity, /) -> cx.Abstract ) >>> xs = Quantity([0, 1, 2, 3], "meter") # [ct, x, y, z] - >>> vec = cx.FourVector.constructor(xs) + >>> vec = cx.FourVector.from_(xs) >>> vec FourVector( t=Quantity[PhysicalType('time')](value=f32[], unit=Unit("m s / km")), @@ -549,7 +549,7 @@ def constructor(cls: type[cx.AbstractVector], obj: u.Quantity, /) -> cx.Abstract ) >>> xs = Quantity(jnp.array([[0, 1, 2, 3], [10, 4, 5, 6]]), "meter") - >>> vec = cx.FourVector.constructor(xs) + >>> vec = cx.FourVector.from_(xs) >>> vec FourVector( t=Quantity[PhysicalType('time')](value=f32[2], unit=Unit("m s / km")), @@ -559,4 +559,4 @@ def constructor(cls: type[cx.AbstractVector], obj: u.Quantity, /) -> cx.Abstract Quantity['length'](Array([1., 4.], dtype=float32), unit='m') """ - return cls.constructor(convert(obj, Quantity)) + return cls.from_(convert(obj, Quantity)) diff --git a/src/coordinax/_interop/coordinax_interop_astropy/converters.py b/src/coordinax/_interop/coordinax_interop_astropy/converters.py index 4a962702..e37b8a2e 100644 --- a/src/coordinax/_interop/coordinax_interop_astropy/converters.py +++ b/src/coordinax/_interop/coordinax_interop_astropy/converters.py @@ -30,7 +30,7 @@ def vec_to_q(obj: cx.AbstractPosition3D, /) -> Shaped[u.Quantity, "*batch 3"]: >>> from plum import convert >>> from astropy.units import Quantity - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> convert(vec, Quantity) @@ -61,11 +61,11 @@ def vec_diff_to_q(obj: cx.CartesianVelocity3D, /) -> Shaped[u.Quantity, "*batch >>> from plum import convert >>> from astropy.units import Quantity - >>> dif = cx.CartesianVelocity3D.constructor([1, 2, 3], "km/s") + >>> dif = cx.CartesianVelocity3D.from_([1, 2, 3], "km/s") >>> convert(dif, Quantity) - >>> dif2 = cx.CartesianAcceleration3D.constructor([1, 2, 3], "km/s2") + >>> dif2 = cx.CartesianAcceleration3D.from_([1, 2, 3], "km/s2") >>> convert(dif2, Quantity) @@ -87,7 +87,7 @@ def cart3_to_apycart3(obj: cx.CartesianPosition3D, /) -> apyc.CartesianRepresent >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> convert(vec, apyc.CartesianRepresentation) @@ -123,7 +123,7 @@ def apycart3_to_cart3(obj: apyc.CartesianRepresentation, /) -> cx.CartesianPosit ) """ - return cx.CartesianPosition3D.constructor(obj) + return cx.CartesianPosition3D.from_(obj) # ===================================== @@ -178,7 +178,7 @@ def apycyl_to_cyl(obj: apyc.CylindricalRepresentation, /) -> cx.CylindricalPosit ) """ - return cx.CylindricalPosition.constructor(obj) + return cx.CylindricalPosition.from_(obj) # ===================================== @@ -230,7 +230,7 @@ def apysph_to_sph(obj: apyc.PhysicsSphericalRepresentation, /) -> cx.SphericalPo ) """ - return cx.SphericalPosition.constructor(obj) + return cx.SphericalPosition.from_(obj) # ===================================== @@ -286,7 +286,7 @@ def apysph_to_lonlatsph( ) """ - return cx.LonLatSphericalPosition.constructor(obj) + return cx.LonLatSphericalPosition.from_(obj) # ===================================== @@ -303,7 +303,7 @@ def diffcart3_to_apycart3(obj: cx.CartesianVelocity3D, /) -> apyc.CartesianDiffe >>> from unxt import Quantity >>> import coordinax as cx - >>> dif = cx.CartesianVelocity3D.constructor([1, 2, 3], "km/s") + >>> dif = cx.CartesianVelocity3D.from_([1, 2, 3], "km/s") >>> convert(dif, apyc.CartesianDifferential) @@ -337,7 +337,7 @@ def apycart3_to_diffcart3(obj: apyc.CartesianDifferential, /) -> cx.CartesianVel ) """ - return cx.CartesianVelocity3D.constructor(obj) + return cx.CartesianVelocity3D.from_(obj) # ===================================== @@ -396,7 +396,7 @@ def apycyl_to_diffcyl(obj: apyc.CylindricalDifferential, /) -> cx.CylindricalVel ) """ - return cx.CylindricalVelocity.constructor(obj) + return cx.CylindricalVelocity.from_(obj) # ===================================== @@ -458,7 +458,7 @@ def apysph_to_diffsph( ) """ - return cx.SphericalVelocity.constructor(obj) + return cx.SphericalVelocity.from_(obj) # ===================================== @@ -520,7 +520,7 @@ def apysph_to_difflonlatsph( ) """ - return cx.LonLatSphericalVelocity.constructor(obj) + return cx.LonLatSphericalVelocity.from_(obj) # ===================================== @@ -583,4 +583,4 @@ def apysph_to_diffloncoslatsph( ) """ - return cx.LonCosLatSphericalVelocity.constructor(obj) + return cx.LonCosLatSphericalVelocity.from_(obj) diff --git a/src/coordinax/_src/base/base.py b/src/coordinax/_src/base/base.py index 43856e7c..9723d5dc 100644 --- a/src/coordinax/_src/base/base.py +++ b/src/coordinax/_src/base/base.py @@ -67,7 +67,7 @@ class AbstractVector(ArrayValue): # type: ignore[misc] @classmethod @dispatch - def constructor( + def from_( cls: "type[AbstractVector]", obj: Mapping[str, AbstractQuantity], / ) -> "AbstractVector": """Construct a vector from a mapping. @@ -84,7 +84,7 @@ def constructor( >>> import coordinax as cx >>> xs = {"x": Quantity(1, "m"), "y": Quantity(2, "m"), "z": Quantity(3, "m")} - >>> vec = cx.CartesianPosition3D.constructor(xs) + >>> vec = cx.CartesianPosition3D.from_(xs) >>> vec CartesianPosition3D( x=Quantity[...](value=f32[], unit=Unit("m")), @@ -94,7 +94,7 @@ def constructor( >>> xs = {"x": Quantity([1, 2], "m"), "y": Quantity([3, 4], "m"), ... "z": Quantity([5, 6], "m")} - >>> vec = cx.CartesianPosition3D.constructor(xs) + >>> vec = cx.CartesianPosition3D.from_(xs) >>> vec CartesianPosition3D( x=Quantity[...](value=f32[2], unit=Unit("m")), @@ -107,7 +107,7 @@ def constructor( @classmethod @dispatch - def constructor( + def from_( cls: "type[AbstractVector]", obj: ArrayLike | list[Any], unit: Unit | str, / ) -> "AbstractVector": """Construct a vector from an array and unit. @@ -127,7 +127,7 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "meter") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "meter") >>> vec CartesianPosition3D( x=Quantity[...](value=f32[], unit=Unit("m")), @@ -136,7 +136,7 @@ def constructor( ) >>> xs = jnp.array([[1, 2, 3], [4, 5, 6]]) - >>> vec = cx.CartesianPosition3D.constructor(xs, "meter") + >>> vec = cx.CartesianPosition3D.from_(xs, "meter") >>> vec CartesianPosition3D( x=Quantity[...](value=f32[2], unit=Unit("m")), @@ -147,8 +147,8 @@ def constructor( Quantity['length'](Array([1., 4.], dtype=float32), unit='m') """ - obj = Quantity.constructor(jnp.asarray(obj), unit) - return cls.constructor(obj) # re-dispatch + obj = Quantity.from_(jnp.asarray(obj), unit) + return cls.from_(obj) # re-dispatch # =============================================================== # Quax @@ -159,7 +159,7 @@ def materialise(self) -> NoReturn: Examples -------- >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> try: vec.materialise() ... except RuntimeError as e: print(e) @@ -216,11 +216,11 @@ def ndim(self) -> int: We can get the number of dimensions of a vector: - >>> vec = cx.CartesianPosition2D.constructor([1, 2], "m") + >>> vec = cx.CartesianPosition2D.from_([1, 2], "m") >>> vec.ndim 0 - >>> vec = cx.CartesianPosition2D.constructor([[1, 2], [3, 4]], "m") + >>> vec = cx.CartesianPosition2D.from_([[1, 2], [3, 4]], "m") >>> vec.ndim 1 @@ -285,11 +285,11 @@ def size(self) -> int: We can get the size of a vector: - >>> vec = cx.CartesianPosition2D.constructor([1, 2], "m") + >>> vec = cx.CartesianPosition2D.from_([1, 2], "m") >>> vec.size 1 - >>> vec = cx.CartesianPosition2D.constructor([[1, 2], [3, 4]], "m") + >>> vec = cx.CartesianPosition2D.from_([[1, 2], [3, 4]], "m") >>> vec.size 2 @@ -371,8 +371,8 @@ def __eq__(self: "AbstractVector", other: object) -> Any: >>> acc1 == acc2 Array([ True, False, True], dtype=bool) - >>> vel1 = cx.CartesianVelocity2D.constructor([[1, 3], [2, 4]], "km/s") - >>> vel2 = cx.CartesianVelocity2D.constructor([[1, 3], [0, 4]], "km/s") + >>> vel1 = cx.CartesianVelocity2D.from_([[1, 3], [2, 4]], "km/s") + >>> vel2 = cx.CartesianVelocity2D.from_([[1, 3], [0, 4]], "km/s") >>> vel1.d_x Quantity['speed'](Array([1., 2.], dtype=float32), unit='km / s') >>> jnp.equal(vel1, vel2) @@ -380,8 +380,8 @@ def __eq__(self: "AbstractVector", other: object) -> Any: >>> vel1 == vel2 Array([ True, False], dtype=bool) - >>> acc1 = cx.CartesianAcceleration2D.constructor([[1, 3], [2, 4]], "km/s2") - >>> acc2 = cx.CartesianAcceleration2D.constructor([[1, 3], [0, 4]], "km/s2") + >>> acc1 = cx.CartesianAcceleration2D.from_([[1, 3], [2, 4]], "km/s2") + >>> acc2 = cx.CartesianAcceleration2D.from_([[1, 3], [0, 4]], "km/s2") >>> acc1.d2_x Quantity['acceleration'](Array([1., 2.], dtype=float32), unit='km / s2') >>> jnp.equal(acc1, acc2) @@ -389,8 +389,8 @@ def __eq__(self: "AbstractVector", other: object) -> Any: >>> acc1 == acc2 Array([ True, False], dtype=bool) - >>> vel1 = cx.CartesianVelocity3D.constructor([[1, 4], [2, 5], [3, 6]], "km/s") - >>> vel2 = cx.CartesianVelocity3D.constructor([[1, 4], [0, 5], [3, 0]], "km/s") + >>> vel1 = cx.CartesianVelocity3D.from_([[1, 4], [2, 5], [3, 6]], "km/s") + >>> vel2 = cx.CartesianVelocity3D.from_([[1, 4], [0, 5], [3, 0]], "km/s") >>> vel1.d_x Quantity['speed'](Array([1., 2., 3.], dtype=float32), unit='km / s') >>> jnp.equal(vel1, vel2) @@ -416,7 +416,7 @@ def __len__(self) -> int: Scalar vectors have length 0: - >>> vec = cx.CartesianPosition1D.constructor([1], "m") + >>> vec = cx.CartesianPosition1D.from_([1], "m") >>> len(vec) 0 @@ -439,7 +439,7 @@ def __abs__(self) -> Quantity: Examples -------- >>> import coordinax as cx - >>> vec = cx.CartesianPosition2D.constructor([3, 4], "m") + >>> vec = cx.CartesianPosition2D.from_([3, 4], "m") >>> abs(vec) Quantity['length'](Array(5., dtype=float32), unit='m') @@ -452,7 +452,7 @@ def __array_namespace__(self) -> "ArrayAPINamespace": Examples -------- >>> import coordinax as cx - >>> vec = cx.CartesianPosition2D.constructor([3, 4], "m") + >>> vec = cx.CartesianPosition2D.from_([3, 4], "m") >>> vec.__array_namespace__() @@ -502,7 +502,7 @@ def __mul__(self: "AbstractVector", other: Any) -> Any: >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor(Quantity([1, 2, 3], "m")) + >>> vec = cx.CartesianPosition3D.from_(Quantity([1, 2, 3], "m")) >>> (vec * 2).x Quantity['length'](Array(2., dtype=float32), unit='m') @@ -521,7 +521,7 @@ def __rmul__(self: "AbstractVector", other: Any) -> Any: >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor(Quantity([1, 2, 3], "m")) + >>> vec = cx.CartesianPosition3D.from_(Quantity([1, 2, 3], "m")) >>> (2 * vec).x Quantity['length'](Array(2., dtype=float32), unit='m') @@ -728,10 +728,10 @@ def sizes(self) -> MappingProxyType[str, int]: -------- >>> import coordinax as cx - >>> cx.CartesianPosition2D.constructor([1, 2], "m").sizes + >>> cx.CartesianPosition2D.from_([1, 2], "m").sizes mappingproxy({'x': 1, 'y': 1}) - >>> cx.CartesianPosition2D.constructor([[1, 2], [1, 2]], "m").sizes + >>> cx.CartesianPosition2D.from_([[1, 2], [1, 2]], "m").sizes mappingproxy({'x': 2, 'y': 2}) """ @@ -763,7 +763,7 @@ def to_units(self, usys: Any, /) -> "AbstractVector": >>> usys = unitsystem(u.m, u.s, u.kg, u.rad) - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "km") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "km") >>> vec.to_units(usys) CartesianPosition3D( x=Quantity[...](value=f32[], unit=Unit("m")), @@ -887,7 +887,7 @@ def __str__(self) -> str: >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> str(vec) '' @@ -910,8 +910,8 @@ def __str__(self) -> str: # Register additional constructors -@AbstractVector.constructor._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor(cls: type[AbstractVector], obj: AbstractVector, /) -> AbstractVector: +@AbstractVector.from_._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_(cls: type[AbstractVector], obj: AbstractVector, /) -> AbstractVector: """Construct a vector from another vector. Parameters @@ -927,9 +927,9 @@ def constructor(cls: type[AbstractVector], obj: AbstractVector, /) -> AbstractVe Positions: - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "km") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "km") - >>> cart = cx.CartesianPosition3D.constructor(q) + >>> cart = cx.CartesianPosition3D.from_(q) >>> cart CartesianPosition3D( x=Quantity[...](value=f32[], unit=Unit("km")), @@ -937,47 +937,47 @@ def constructor(cls: type[AbstractVector], obj: AbstractVector, /) -> AbstractVe z=Quantity[...](value=f32[], unit=Unit("km")) ) - >>> cx.AbstractPosition3D.constructor(cart) is cart + >>> cx.AbstractPosition3D.from_(cart) is cart True >>> sph = cart.represent_as(cx.SphericalPosition) - >>> cx.AbstractPosition3D.constructor(sph) is sph + >>> cx.AbstractPosition3D.from_(sph) is sph True >>> cyl = cart.represent_as(cx.CylindricalPosition) - >>> cx.AbstractPosition3D.constructor(cyl) is cyl + >>> cx.AbstractPosition3D.from_(cyl) is cyl True Velocities: - >>> p = cx.CartesianVelocity3D.constructor([1, 2, 3], "km/s") + >>> p = cx.CartesianVelocity3D.from_([1, 2, 3], "km/s") - >>> cart = cx.CartesianVelocity3D.constructor(p) - >>> cx.AbstractVelocity3D.constructor(cart) is cart + >>> cart = cx.CartesianVelocity3D.from_(p) + >>> cx.AbstractVelocity3D.from_(cart) is cart True >>> sph = cart.represent_as(cx.SphericalVelocity, q) - >>> cx.AbstractVelocity3D.constructor(sph) is sph + >>> cx.AbstractVelocity3D.from_(sph) is sph True >>> cyl = cart.represent_as(cx.CylindricalVelocity, q) - >>> cx.AbstractVelocity3D.constructor(cyl) is cyl + >>> cx.AbstractVelocity3D.from_(cyl) is cyl True Accelerations: - >>> p = cx.CartesianVelocity3D.constructor([1, 1, 1], "km/s") + >>> p = cx.CartesianVelocity3D.from_([1, 1, 1], "km/s") - >>> cart = cx.CartesianAcceleration3D.constructor([1, 2, 3], "km/s2") - >>> cx.AbstractAcceleration3D.constructor(cart) is cart + >>> cart = cx.CartesianAcceleration3D.from_([1, 2, 3], "km/s2") + >>> cx.AbstractAcceleration3D.from_(cart) is cart True >>> sph = cart.represent_as(cx.SphericalAcceleration, p, q) - >>> cx.AbstractAcceleration3D.constructor(sph) is sph + >>> cx.AbstractAcceleration3D.from_(sph) is sph True >>> cyl = cart.represent_as(cx.CylindricalAcceleration, p, q) - >>> cx.AbstractAcceleration3D.constructor(cyl) is cyl + >>> cx.AbstractAcceleration3D.from_(cyl) is cyl True """ diff --git a/src/coordinax/_src/base/base_acc.py b/src/coordinax/_src/base/base_acc.py index 1834d98e..43b10798 100644 --- a/src/coordinax/_src/base/base_acc.py +++ b/src/coordinax/_src/base/base_acc.py @@ -97,7 +97,7 @@ def __neg__(self) -> "Self": >>> from unxt import Quantity >>> import coordinax as cx - >>> d2r = cx.RadialAcceleration.constructor([1], "m/s2") + >>> d2r = cx.RadialAcceleration.from_([1], "m/s2") >>> -d2r RadialAcceleration( d2_r=Quantity[...](value=i32[], unit=Unit("m / s2")) ) @@ -142,9 +142,9 @@ def represent_as(self, target: type[AccT], /, *args: Any, **kwargs: Any) -> AccT Examples -------- >>> import coordinax as cx - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "m") - >>> p = cx.CartesianVelocity3D.constructor([4, 5, 6], "m/s") - >>> a = cx.CartesianAcceleration3D.constructor([7, 8, 9], "m/s2") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "m") + >>> p = cx.CartesianVelocity3D.from_([4, 5, 6], "m/s") + >>> a = cx.CartesianAcceleration3D.from_([7, 8, 9], "m/s2") >>> sph = a.represent_as(cx.SphericalAcceleration, p, q) >>> sph SphericalAcceleration( @@ -191,7 +191,7 @@ def _mul_acc_time(lhs: AbstractAcceleration, rhs: Quantity["time"]) -> AbstractV """ # TODO: better access to corresponding fields - return lhs.integral_cls.constructor( + return lhs.integral_cls.from_( {k.replace("2", ""): jnp.multiply(v, rhs) for k, v in field_items(lhs)} ) @@ -239,7 +239,7 @@ def _mul_acc_time2(lhs: AbstractAcceleration, rhs: Quantity["s2"]) -> AbstractPo """ # TODO: better access to corresponding fields - return lhs.integral_cls.integral_cls.constructor( + return lhs.integral_cls.integral_cls.from_( {k.replace("d2_", ""): v * rhs for k, v in field_items(lhs)} ) diff --git a/src/coordinax/_src/base/base_pos.py b/src/coordinax/_src/base/base_pos.py index 1cd11c82..b14fd1aa 100644 --- a/src/coordinax/_src/base/base_pos.py +++ b/src/coordinax/_src/base/base_pos.py @@ -103,14 +103,14 @@ def __eq__(self: "AbstractPosition", other: object) -> Any: Showing the broadcasting, then element-wise comparison of two vectors: - >>> vec1 = cx.CartesianPosition3D.constructor([[1, 2, 3], [1, 2, 4]], "m") - >>> vec2 = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> vec1 = cx.CartesianPosition3D.from_([[1, 2, 3], [1, 2, 4]], "m") + >>> vec2 = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> jnp.equal(vec1, vec2) Array([ True, False], dtype=bool) Showing the change of representation: - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> vec1 = vec.represent_as(cx.SphericalPosition) >>> vec2 = vec.represent_as(cx.MathSphericalPosition) >>> jnp.equal(vec1, vec2) @@ -118,12 +118,12 @@ def __eq__(self: "AbstractPosition", other: object) -> Any: Quick run-through of each dimensionality: - >>> vec1 = cx.CartesianPosition1D.constructor([1], "m") - >>> vec2 = cx.RadialPosition.constructor([1], "m") + >>> vec1 = cx.CartesianPosition1D.from_([1], "m") + >>> vec2 = cx.RadialPosition.from_([1], "m") >>> jnp.equal(vec1, vec2) Array(True, dtype=bool) - >>> vec1 = cx.CartesianPosition2D.constructor([2, 0], "m") + >>> vec1 = cx.CartesianPosition2D.from_([2, 0], "m") >>> vec2 = cx.PolarPosition(r=Quantity(2, "m"), phi=Quantity(0, "rad")) >>> jnp.equal(vec1, vec2) Array(True, dtype=bool) @@ -160,7 +160,7 @@ def represent_as(self, target: type[PosT], /, *args: Any, **kwargs: Any) -> PosT Examples -------- >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> sph = vec.represent_as(cx.SphericalPosition) >>> sph SphericalPosition( @@ -187,11 +187,11 @@ def norm(self) -> ct.BatchableLength: >>> from unxt import Quantity >>> import coordinax as cx - >>> v = cx.CartesianPosition1D.constructor([-1], "kpc") + >>> v = cx.CartesianPosition1D.from_([-1], "kpc") >>> v.norm() Quantity['length'](Array(1., dtype=float32), unit='kpc') - >>> v = cx.CartesianPosition2D.constructor([3, 4], "kpc") + >>> v = cx.CartesianPosition2D.from_([3, 4], "kpc") >>> v.norm() Quantity['length'](Array(5., dtype=float32), unit='kpc') @@ -199,7 +199,7 @@ def norm(self) -> ct.BatchableLength: >>> v.norm() Quantity['length'](Array(3., dtype=float32), unit='kpc') - >>> v = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> v = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> v.norm() Quantity['length'](Array(3.7416575, dtype=float32), unit='m') @@ -240,7 +240,7 @@ def _div_pos_v(lhs: AbstractPosition, rhs: ArrayLike) -> AbstractPosition: >>> import quaxed.numpy as jnp >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> jnp.divide(vec, 2).x Quantity['length'](Array(0.5, dtype=float32), unit='m') @@ -273,7 +273,7 @@ def _mul_v_pos(lhs: ArrayLike, rhs: AbstractPosition, /) -> AbstractPosition: >>> import coordinax as cx >>> import quaxed.numpy as jnp - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> jnp.multiply(2, vec) CartesianPosition3D( x=Quantity[...](value=f32[], unit=Unit("m")), @@ -366,7 +366,7 @@ def _mul_pos_v(lhs: AbstractPosition, rhs: ArrayLike, /) -> AbstractPosition: >>> import coordinax as cx >>> import quaxed.numpy as jnp - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> jnp.multiply(vec, 2) CartesianPosition3D( x=Quantity[...](value=f32[], unit=Unit("m")), @@ -421,7 +421,7 @@ def _neg_pos(obj: AbstractPosition, /) -> AbstractPosition: Examples -------- >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> -vec CartesianPosition3D( x=Quantity[PhysicalType('length')](value=f32[], unit=Unit("m")), diff --git a/src/coordinax/_src/base/base_vel.py b/src/coordinax/_src/base/base_vel.py index 3829666d..2092b42b 100644 --- a/src/coordinax/_src/base/base_vel.py +++ b/src/coordinax/_src/base/base_vel.py @@ -113,7 +113,7 @@ def __neg__(self) -> "Self": >>> from unxt import Quantity >>> import coordinax as cx - >>> dr = cx.RadialVelocity.constructor([1], "m/s") + >>> dr = cx.RadialVelocity.from_([1], "m/s") >>> -dr RadialVelocity( d_r=Quantity[...]( value=i32[], unit=Unit("m / s") ) ) @@ -163,8 +163,8 @@ def represent_as( Examples -------- >>> import coordinax as cx - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "m") - >>> p = cx.CartesianVelocity3D.constructor([4, 5, 6], "m/s") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "m") + >>> p = cx.CartesianVelocity3D.from_([4, 5, 6], "m/s") >>> sph = p.represent_as(cx.SphericalVelocity, q) >>> sph SphericalVelocity( @@ -210,6 +210,4 @@ def _mul_vel_q(self: AbstractVelocity, other: Quantity["time"]) -> AbstractPosit Distance(Array(2., dtype=float32), unit='m') """ - return self.integral_cls.constructor( - {k[2:]: v * other for k, v in field_items(self)} - ) + return self.integral_cls.from_({k[2:]: v * other for k, v in field_items(self)}) diff --git a/src/coordinax/_src/base/compat.py b/src/coordinax/_src/base/compat.py index 154c15cb..48d0ba31 100644 --- a/src/coordinax/_src/base/compat.py +++ b/src/coordinax/_src/base/compat.py @@ -26,15 +26,15 @@ def convert_pos_to_absquantity(obj: AbstractPosition, /) -> AbstractQuantity: >>> import coordinax as cx >>> from unxt import AbstractQuantity, Quantity - >>> pos = cx.CartesianPosition1D.constructor([1.0], "km") + >>> pos = cx.CartesianPosition1D.from_([1.0], "km") >>> convert(pos, AbstractQuantity) Quantity['length'](Array([1.], dtype=float32), unit='km') - >>> pos = cx.RadialPosition.constructor([1.0], "km") + >>> pos = cx.RadialPosition.from_([1.0], "km") >>> convert(pos, AbstractQuantity) Quantity['length'](Array([1.], dtype=float32), unit='km') - >>> pos = cx.CartesianPosition2D.constructor([1.0, 2.0], "km") + >>> pos = cx.CartesianPosition2D.from_([1.0, 2.0], "km") >>> convert(pos, AbstractQuantity) Quantity['length'](Array([1., 2.], dtype=float32), unit='km') @@ -42,7 +42,7 @@ def convert_pos_to_absquantity(obj: AbstractPosition, /) -> AbstractQuantity: >>> convert(pos, AbstractQuantity) Quantity['length'](Array([1., 0.], dtype=float32), unit='km') - >>> pos = cx.CartesianPosition3D.constructor([1.0, 2.0, 3.0], "km") + >>> pos = cx.CartesianPosition3D.from_([1.0, 2.0, 3.0], "km") >>> convert(pos, AbstractQuantity) Quantity['length'](Array([1., 2., 3.], dtype=float32), unit='km') @@ -68,15 +68,15 @@ def convert_pos_to_q(obj: AbstractPosition, /) -> Quantity["length"]: >>> import coordinax as cx >>> from unxt import AbstractQuantity, Quantity - >>> pos = cx.CartesianPosition1D.constructor([1.0], "km") + >>> pos = cx.CartesianPosition1D.from_([1.0], "km") >>> convert(pos, AbstractQuantity) Quantity['length'](Array([1.], dtype=float32), unit='km') - >>> pos = cx.RadialPosition.constructor([1.0], "km") + >>> pos = cx.RadialPosition.from_([1.0], "km") >>> convert(pos, AbstractQuantity) Quantity['length'](Array([1.], dtype=float32), unit='km') - >>> pos = cx.CartesianPosition2D.constructor([1.0, 2.0], "km") + >>> pos = cx.CartesianPosition2D.from_([1.0, 2.0], "km") >>> convert(pos, AbstractQuantity) Quantity['length'](Array([1., 2.], dtype=float32), unit='km') @@ -84,7 +84,7 @@ def convert_pos_to_q(obj: AbstractPosition, /) -> Quantity["length"]: >>> convert(pos, AbstractQuantity) Quantity['length'](Array([1., 0.], dtype=float32), unit='km') - >>> pos = cx.CartesianPosition3D.constructor([1.0, 2.0, 3.0], "km") + >>> pos = cx.CartesianPosition3D.from_([1.0, 2.0, 3.0], "km") >>> convert(pos, AbstractQuantity) Quantity['length'](Array([1., 2., 3.], dtype=float32), unit='km') @@ -111,15 +111,15 @@ def convert_pos_to_uncheckedq( >>> import coordinax as cx >>> from unxt import AbstractQuantity, Quantity, UncheckedQuantity - >>> pos = cx.CartesianPosition1D.constructor([1.0], "km") + >>> pos = cx.CartesianPosition1D.from_([1.0], "km") >>> convert(pos, UncheckedQuantity) UncheckedQuantity(Array([1.], dtype=float32), unit='km') - >>> pos = cx.RadialPosition.constructor([1.0], "km") + >>> pos = cx.RadialPosition.from_([1.0], "km") >>> convert(pos, UncheckedQuantity) UncheckedQuantity(Array([1.], dtype=float32), unit='km') - >>> pos = cx.CartesianPosition2D.constructor([1.0, 2.0], "km") + >>> pos = cx.CartesianPosition2D.from_([1.0, 2.0], "km") >>> convert(pos, UncheckedQuantity) UncheckedQuantity(Array([1., 2.], dtype=float32), unit='km') @@ -127,7 +127,7 @@ def convert_pos_to_uncheckedq( >>> convert(pos, UncheckedQuantity) UncheckedQuantity(Array([1., 0.], dtype=float32), unit='km') - >>> pos = cx.CartesianPosition3D.constructor([1.0, 2.0, 3.0], "km") + >>> pos = cx.CartesianPosition3D.from_([1.0, 2.0, 3.0], "km") >>> convert(pos, UncheckedQuantity) UncheckedQuantity(Array([1., 2., 3.], dtype=float32), unit='km') @@ -152,15 +152,15 @@ def convert_pos_to_distance(obj: AbstractPosition, /) -> Shaped[Distance, "*batc >>> import coordinax as cx >>> from unxt import AbstractQuantity, Quantity, Distance - >>> pos = cx.CartesianPosition1D.constructor([1.0], "km") + >>> pos = cx.CartesianPosition1D.from_([1.0], "km") >>> convert(pos, Distance) Distance(Array([1.], dtype=float32), unit='km') - >>> pos = cx.RadialPosition.constructor([1.0], "km") + >>> pos = cx.RadialPosition.from_([1.0], "km") >>> convert(pos, Distance) Distance(Array([1.], dtype=float32), unit='km') - >>> pos = cx.CartesianPosition2D.constructor([1.0, 2.0], "km") + >>> pos = cx.CartesianPosition2D.from_([1.0, 2.0], "km") >>> convert(pos, Distance) Distance(Array([1., 2.], dtype=float32), unit='km') @@ -168,7 +168,7 @@ def convert_pos_to_distance(obj: AbstractPosition, /) -> Shaped[Distance, "*batc >>> convert(pos, Distance) Distance(Array([1., 0.], dtype=float32), unit='km') - >>> pos = cx.CartesianPosition3D.constructor([1.0, 2.0, 3.0], "km") + >>> pos = cx.CartesianPosition3D.from_([1.0, 2.0, 3.0], "km") >>> convert(pos, Distance) Distance(Array([1., 2., 3.], dtype=float32), unit='km') diff --git a/src/coordinax/_src/base/mixins.py b/src/coordinax/_src/base/mixins.py index 9675a5ad..9058af0b 100644 --- a/src/coordinax/_src/base/mixins.py +++ b/src/coordinax/_src/base/mixins.py @@ -27,33 +27,33 @@ def aval(self) -> jax.core.ShapedArray: 1 dimensional vectors: - >>> vec = cx.CartesianPosition1D.constructor([1], "m") + >>> vec = cx.CartesianPosition1D.from_([1], "m") >>> vec.aval() ConcreteArray([1.], dtype=float32) - >>> vec = cx.RadialPosition.constructor([1], "m") + >>> vec = cx.RadialPosition.from_([1], "m") >>> vec.aval() ConcreteArray([1.], dtype=float32) - >>> vec = cx.CartesianVelocity1D.constructor([1], "m/s") + >>> vec = cx.CartesianVelocity1D.from_([1], "m/s") >>> vec.aval() ConcreteArray([1], dtype=int32) - >>> vec = cx.RadialVelocity.constructor([1], "m/s") + >>> vec = cx.RadialVelocity.from_([1], "m/s") >>> vec.aval() ConcreteArray([1], dtype=int32) - >>> vec = cx.CartesianAcceleration1D.constructor([1], "m/s2") + >>> vec = cx.CartesianAcceleration1D.from_([1], "m/s2") >>> vec.aval() ConcreteArray([1], dtype=int32) - >>> vec = cx.RadialAcceleration.constructor([1], "m/s2") + >>> vec = cx.RadialAcceleration.from_([1], "m/s2") >>> vec.aval() ConcreteArray([1], dtype=int32) 2 dimensional vectors: - >>> vec = cx.CartesianPosition2D.constructor([1, 2], "m") + >>> vec = cx.CartesianPosition2D.from_([1, 2], "m") >>> vec.aval() ConcreteArray([1. 2.], dtype=float32) @@ -61,7 +61,7 @@ def aval(self) -> jax.core.ShapedArray: >>> vec.aval() ConcreteArray([1. 0.], dtype=float32) - >>> vec = cx.CartesianVelocity2D.constructor([1, 2], "m/s") + >>> vec = cx.CartesianVelocity2D.from_([1, 2], "m/s") >>> vec.aval() ConcreteArray([1. 2.], dtype=float32) @@ -70,7 +70,7 @@ def aval(self) -> jax.core.ShapedArray: ... except NotImplementedError as e: print("nope") nope - >>> vec = cx.CartesianAcceleration2D.constructor([1,2], "m/s2") + >>> vec = cx.CartesianAcceleration2D.from_([1,2], "m/s2") >>> vec.aval() ConcreteArray([1. 2.], dtype=float32) @@ -81,11 +81,11 @@ def aval(self) -> jax.core.ShapedArray: 3 dimensional vectors: - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> vec.aval() ConcreteArray([1. 2. 3.], dtype=float32) - >>> vec = cx.CartesianPosition3D.constructor([[1, 2, 3], [4, 5, 6]], "m") + >>> vec = cx.CartesianPosition3D.from_([[1, 2, 3], [4, 5, 6]], "m") >>> vec.aval() ConcreteArray([[1. 2. 3.] [4. 5. 6.]], dtype=float32) @@ -94,7 +94,7 @@ def aval(self) -> jax.core.ShapedArray: >>> vec.aval() ConcreteArray([0. 0. 1.], dtype=float32) - >>> vec = cx.CartesianVelocity3D.constructor([1,2,3], "m/s") + >>> vec = cx.CartesianVelocity3D.from_([1,2,3], "m/s") >>> vec.aval() ConcreteArray([1. 2. 3.], dtype=float32) @@ -103,7 +103,7 @@ def aval(self) -> jax.core.ShapedArray: ... except NotImplementedError as e: print("nope") nope - >>> vec = cx.CartesianAcceleration3D.constructor([1,2,3], "m/s2") + >>> vec = cx.CartesianAcceleration3D.from_([1,2,3], "m/s2") >>> vec.aval() ConcreteArray([1. 2. 3.], dtype=float32) diff --git a/src/coordinax/_src/base/register_primitives.py b/src/coordinax/_src/base/register_primitives.py index 0cc99d7d..d513e165 100644 --- a/src/coordinax/_src/base/register_primitives.py +++ b/src/coordinax/_src/base/register_primitives.py @@ -37,21 +37,21 @@ def _broadcast_in_dim_p( Cartesian 1D position, velocity, and acceleration: - >>> q = cx.CartesianPosition1D.constructor([1], "m") + >>> q = cx.CartesianPosition1D.from_([1], "m") >>> q.x Quantity['length'](Array(1., dtype=float32), unit='m') >>> jnp.broadcast_to(q, (1, 1)).x Quantity['length'](Array([1.], dtype=float32), unit='m') - >>> p = cx.CartesianVelocity1D.constructor([1], "m/s") + >>> p = cx.CartesianVelocity1D.from_([1], "m/s") >>> p.d_x Quantity['speed'](Array(1, dtype=int32), unit='m / s') >>> jnp.broadcast_to(p, (1, 1)).d_x Quantity['speed'](Array([1], dtype=int32), unit='m / s') - >>> a = cx.CartesianAcceleration1D.constructor([1], "m/s2") + >>> a = cx.CartesianAcceleration1D.from_([1], "m/s2") >>> a.d2_x Quantity['acceleration'](Array(1, dtype=int32), unit='m / s2') @@ -61,21 +61,21 @@ def _broadcast_in_dim_p( Radial 1D position, velocity, and acceleration: - >>> q = cx.RadialPosition.constructor([1], "m") + >>> q = cx.RadialPosition.from_([1], "m") >>> q.r Distance(Array(1., dtype=float32), unit='m') >>> jnp.broadcast_to(q, (1, 1)).r Distance(Array([1.], dtype=float32), unit='m') - >>> p = cx.RadialVelocity.constructor([1], "m/s") + >>> p = cx.RadialVelocity.from_([1], "m/s") >>> p.d_r Quantity['speed'](Array(1, dtype=int32), unit='m / s') >>> jnp.broadcast_to(p, (1, 1)).d_r Quantity['speed'](Array([1], dtype=int32), unit='m / s') - >>> a = cx.RadialAcceleration.constructor([1], "m/s2") + >>> a = cx.RadialAcceleration.from_([1], "m/s2") >>> a.d2_r Quantity['acceleration'](Array(1, dtype=int32), unit='m / s2') @@ -85,21 +85,21 @@ def _broadcast_in_dim_p( Cartesian 2D position, velocity, and acceleration: - >>> q = cx.CartesianPosition2D.constructor([1, 2], "m") + >>> q = cx.CartesianPosition2D.from_([1, 2], "m") >>> q.x Quantity['length'](Array(1., dtype=float32), unit='m') >>> jnp.broadcast_to(q, (1, 2)).x Quantity['length'](Array([1.], dtype=float32), unit='m') - >>> p = cx.CartesianVelocity2D.constructor([1, 2], "m/s") + >>> p = cx.CartesianVelocity2D.from_([1, 2], "m/s") >>> p.d_x Quantity['speed'](Array(1., dtype=float32), unit='m / s') >>> jnp.broadcast_to(p, (1, 2)).d_x Quantity['speed'](Array([1.], dtype=float32), unit='m / s') - >>> a = cx.CartesianAcceleration2D.constructor([1, 2], "m/s2") + >>> a = cx.CartesianAcceleration2D.from_([1, 2], "m/s2") >>> a.d2_x Quantity['acceleration'](Array(1., dtype=float32), unit='m / s2') @@ -109,21 +109,21 @@ def _broadcast_in_dim_p( Cartesian 3D position, velocity, and acceleration: - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> q.x Quantity['length'](Array(1., dtype=float32), unit='m') >>> jnp.broadcast_to(q, (1, 3)).x Quantity['length'](Array([1.], dtype=float32), unit='m') - >>> p = cx.CartesianVelocity3D.constructor([1, 2, 3], "m/s") + >>> p = cx.CartesianVelocity3D.from_([1, 2, 3], "m/s") >>> p.d_x Quantity['speed'](Array(1., dtype=float32), unit='m / s') >>> jnp.broadcast_to(p, (1, 3)).d_x Quantity['speed'](Array([1.], dtype=float32), unit='m / s') - >>> a = cx.CartesianAcceleration3D.constructor([1, 2, 3], "m/s2") + >>> a = cx.CartesianAcceleration3D.from_([1, 2, 3], "m/s2") >>> a.d2_x Quantity['acceleration'](Array(1., dtype=float32), unit='m / s2') diff --git a/src/coordinax/_src/compat.py b/src/coordinax/_src/compat.py index e806e8d1..68383298 100644 --- a/src/coordinax/_src/compat.py +++ b/src/coordinax/_src/compat.py @@ -57,19 +57,19 @@ def vec_diff1d_to_uncheckedq( >>> from unxt import UncheckedQuantity >>> import coordinax as cx - >>> cart_vel = cx.CartesianVelocity1D.constructor([1], "km/s") + >>> cart_vel = cx.CartesianVelocity1D.from_([1], "km/s") >>> convert(cart_vel, UncheckedQuantity) UncheckedQuantity(Array([1], dtype=int32), unit='km / s') - >>> cart_acc = cx.CartesianAcceleration1D.constructor([1], "km/s2") + >>> cart_acc = cx.CartesianAcceleration1D.from_([1], "km/s2") >>> convert(cart_acc, UncheckedQuantity) UncheckedQuantity(Array([1], dtype=int32), unit='km / s2') - >>> rad_vel = cx.RadialVelocity.constructor([1], "km/s") + >>> rad_vel = cx.RadialVelocity.from_([1], "km/s") >>> convert(rad_vel, UncheckedQuantity) UncheckedQuantity(Array([1], dtype=int32), unit='km / s') - >>> rad_acc = cx.RadialAcceleration.constructor([1], "km/s2") + >>> rad_acc = cx.RadialAcceleration.from_([1], "km/s2") >>> convert(rad_acc, UncheckedQuantity) UncheckedQuantity(Array([1], dtype=int32), unit='km / s2') @@ -90,19 +90,19 @@ def vec_diff1d_to_uncheckedq(obj: QConvertible1D, /) -> Shaped[Quantity, "*batch >>> from unxt import Quantity >>> import coordinax as cx - >>> cart_vel = cx.CartesianVelocity1D.constructor([1], "km/s") + >>> cart_vel = cx.CartesianVelocity1D.from_([1], "km/s") >>> convert(cart_vel, Quantity) Quantity['speed'](Array([1], dtype=int32), unit='km / s') - >>> cart_acc = cx.CartesianAcceleration1D.constructor([1], "km/s2") + >>> cart_acc = cx.CartesianAcceleration1D.from_([1], "km/s2") >>> convert(cart_acc, Quantity) Quantity['acceleration'](Array([1], dtype=int32), unit='km / s2') - >>> rad_vel = cx.RadialVelocity.constructor([1], "km/s") + >>> rad_vel = cx.RadialVelocity.from_([1], "km/s") >>> convert(rad_vel, Quantity) Quantity['speed'](Array([1], dtype=int32), unit='km / s') - >>> rad_acc = cx.RadialAcceleration.constructor([1], "km/s2") + >>> rad_acc = cx.RadialAcceleration.from_([1], "km/s2") >>> convert(rad_acc, Quantity) Quantity['acceleration'](Array([1], dtype=int32), unit='km / s2') @@ -127,11 +127,11 @@ def vec_diff_to_q(obj: QConvertible2D, /) -> Shaped[UncheckedQuantity, "*batch 2 >>> from unxt import UncheckedQuantity >>> import coordinax as cx - >>> vel = cx.CartesianVelocity2D.constructor([1, 2], "km/s") + >>> vel = cx.CartesianVelocity2D.from_([1, 2], "km/s") >>> convert(vel, UncheckedQuantity) UncheckedQuantity(Array([1., 2.], dtype=float32), unit='km / s') - >>> acc = cx.CartesianAcceleration2D.constructor([1, 2], "km/s2") + >>> acc = cx.CartesianAcceleration2D.from_([1, 2], "km/s2") >>> convert(acc, UncheckedQuantity) UncheckedQuantity(Array([1., 2.], dtype=float32), unit='km / s2') @@ -150,11 +150,11 @@ def vec_diff_to_q(obj: QConvertible2D, /) -> Shaped[Quantity, "*batch 2"]: >>> from unxt import Quantity >>> import coordinax as cx - >>> vel = cx.CartesianVelocity2D.constructor([1, 2], "km/s") + >>> vel = cx.CartesianVelocity2D.from_([1, 2], "km/s") >>> convert(vel, Quantity) Quantity['speed'](Array([1., 2.], dtype=float32), unit='km / s') - >>> acc = cx.CartesianAcceleration2D.constructor([1, 2], "km/s2") + >>> acc = cx.CartesianAcceleration2D.from_([1, 2], "km/s2") >>> convert(acc, Quantity) Quantity['acceleration'](Array([1., 2.], dtype=float32), unit='km / s2') @@ -179,11 +179,11 @@ def vec_diff_to_q(obj: CartesianVelocity3D, /) -> Shaped[UncheckedQuantity, "*ba >>> from plum import convert >>> from unxt import UncheckedQuantity - >>> vel = cx.CartesianVelocity3D.constructor([1, 2, 3], "km/s") + >>> vel = cx.CartesianVelocity3D.from_([1, 2, 3], "km/s") >>> convert(vel, UncheckedQuantity) UncheckedQuantity(Array([1., 2., 3.], dtype=float32), unit='km / s') - >>> acc = cx.CartesianAcceleration3D.constructor([1, 2, 3], "km/s2") + >>> acc = cx.CartesianAcceleration3D.from_([1, 2, 3], "km/s2") >>> convert(acc, UncheckedQuantity) UncheckedQuantity(Array([1., 2., 3.], dtype=float32), unit='km / s2') @@ -202,11 +202,11 @@ def vec_diff_to_q(obj: CartesianVelocity3D, /) -> Shaped[Quantity, "*batch 3"]: >>> from plum import convert >>> from unxt import Quantity - >>> vel = cx.CartesianVelocity3D.constructor([1, 2, 3], "km/s") + >>> vel = cx.CartesianVelocity3D.from_([1, 2, 3], "km/s") >>> convert(vel, Quantity) Quantity['speed'](Array([1., 2., 3.], dtype=float32), unit='km / s') - >>> acc = cx.CartesianAcceleration3D.constructor([1, 2, 3], "km/s2") + >>> acc = cx.CartesianAcceleration3D.from_([1, 2, 3], "km/s2") >>> convert(acc, Quantity) Quantity['acceleration'](Array([1., 2., 3.], dtype=float32), unit='km / s2') @@ -224,7 +224,7 @@ def vec_diff_to_q(obj: CartesianVelocity3D, /) -> Shaped[Quantity, "*batch 3"]: @op_call_dispatch def call(self: AbstractOperator, x: Q1, /) -> Q1: """Dispatch to the operator's `__call__` method.""" - return self(CartesianPosition1D.constructor(x)) + return self(CartesianPosition1D.from_(x)) @op_call_dispatch @@ -232,5 +232,5 @@ def call( self: AbstractOperator, x: Q1, t: TimeBatchOrScalar, / ) -> tuple[Q1, TimeBatchOrScalar]: """Dispatch to the operator's `__call__` method.""" - vec, t = self(CartesianPosition1D.constructor(x), t) + vec, t = self(CartesianPosition1D.from_(x), t) return convert(vec, Quantity), t diff --git a/src/coordinax/_src/d1/base.py b/src/coordinax/_src/d1/base.py index 55ca369d..f77c4b7a 100644 --- a/src/coordinax/_src/d1/base.py +++ b/src/coordinax/_src/d1/base.py @@ -42,8 +42,8 @@ def differential_cls(cls) -> type["AbstractVelocity1D"]: # ------------------------------------------------------------------- -@AbstractPosition1D.constructor._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@AbstractPosition1D.from_._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[AbstractPosition1D], obj: Shaped[Quantity["length"], "*batch"] | Shaped[Quantity["length"], "*batch 1"], /, @@ -55,16 +55,16 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> cx.CartesianPosition1D.constructor(Quantity(1, "meter")) + >>> cx.CartesianPosition1D.from_(Quantity(1, "meter")) CartesianPosition1D( x=Quantity[...](value=f32[], unit=Unit("m")) ) - >>> cx.CartesianPosition1D.constructor(Quantity([1], "meter")) + >>> cx.CartesianPosition1D.from_(Quantity([1], "meter")) CartesianPosition1D( x=Quantity[...](value=f32[], unit=Unit("m")) ) - >>> cx.RadialPosition.constructor(Quantity(1, "meter")) + >>> cx.RadialPosition.from_(Quantity(1, "meter")) RadialPosition(r=Distance(value=f32[], unit=Unit("m"))) - >>> cx.RadialPosition.constructor(Quantity([1], "meter")) + >>> cx.RadialPosition.from_(Quantity([1], "meter")) RadialPosition(r=Distance(value=f32[], unit=Unit("m"))) """ @@ -101,8 +101,8 @@ def differential_cls(cls) -> type[AbstractAcceleration]: # ------------------------------------------------------------------- -@AbstractVelocity1D.constructor._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@AbstractVelocity1D.from_._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[AbstractVelocity1D], obj: Shaped[Quantity["speed"], "*batch"] | Shaped[Quantity["speed"], "*batch 1"], /, @@ -114,16 +114,16 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> cx.CartesianVelocity1D.constructor(Quantity(1, "m/s")) + >>> cx.CartesianVelocity1D.from_(Quantity(1, "m/s")) CartesianVelocity1D( d_x=Quantity[...]( value=...i32[], unit=Unit("m / s") ) ) - >>> cx.CartesianVelocity1D.constructor(Quantity([1], "m/s")) + >>> cx.CartesianVelocity1D.from_(Quantity([1], "m/s")) CartesianVelocity1D( d_x=Quantity[...]( value=i32[], unit=Unit("m / s") ) ) - >>> cx.RadialVelocity.constructor(Quantity(1, "m/s")) + >>> cx.RadialVelocity.from_(Quantity(1, "m/s")) RadialVelocity( d_r=Quantity[...]( value=...i32[], unit=Unit("m / s") ) ) - >>> cx.RadialVelocity.constructor(Quantity([1], "m/s")) + >>> cx.RadialVelocity.from_(Quantity([1], "m/s")) RadialVelocity( d_r=Quantity[...]( value=i32[], unit=Unit("m / s") ) ) """ @@ -154,8 +154,8 @@ def integral_cls(cls) -> type[AbstractVelocity1D]: # ------------------------------------------------------------------- -@AbstractAcceleration1D.constructor._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@AbstractAcceleration1D.from_._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[AbstractAcceleration1D], obj: Shaped[Quantity["acceleration"], "*batch"] | Shaped[Quantity["acceleration"], "*batch 1"], @@ -168,16 +168,16 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> cx.CartesianAcceleration1D.constructor(Quantity(1, "m/s2")) + >>> cx.CartesianAcceleration1D.from_(Quantity(1, "m/s2")) CartesianAcceleration1D( d2_x=... ) - >>> cx.CartesianAcceleration1D.constructor(Quantity([1], "m/s2")) + >>> cx.CartesianAcceleration1D.from_(Quantity([1], "m/s2")) CartesianAcceleration1D( d2_x=Quantity[...](value=i32[], unit=Unit("m / s2")) ) - >>> cx.RadialAcceleration.constructor(Quantity(1, "m/s2")) + >>> cx.RadialAcceleration.from_(Quantity(1, "m/s2")) RadialAcceleration( d2_r=... ) - >>> cx.RadialAcceleration.constructor(Quantity([1], "m/s2")) + >>> cx.RadialAcceleration.from_(Quantity([1], "m/s2")) RadialAcceleration( d2_r=Quantity[...](value=i32[], unit=Unit("m / s2")) ) """ diff --git a/src/coordinax/_src/d1/cartesian.py b/src/coordinax/_src/d1/cartesian.py index 9f4eb8ac..fecc2a9e 100644 --- a/src/coordinax/_src/d1/cartesian.py +++ b/src/coordinax/_src/d1/cartesian.py @@ -35,7 +35,7 @@ class CartesianPosition1D(AbstractPosition1D): -------- >>> import coordinax as cx - >>> vec = cx.CartesianPosition1D.constructor([2], "m") + >>> vec = cx.CartesianPosition1D.from_([2], "m") >>> vec CartesianPosition1D( x=Quantity[PhysicalType('length')](value=f32[], unit=Unit("m")) @@ -55,7 +55,7 @@ class CartesianPosition1D(AbstractPosition1D): """ x: ct.BatchableLength = eqx.field( - converter=partial(Quantity["length"].constructor, dtype=float) + converter=partial(Quantity["length"].from_, dtype=float) ) r"""X coordinate :math:`x \in (-\infty,+\infty)`.""" @@ -78,8 +78,8 @@ def _add_qq(lhs: CartesianPosition1D, rhs: AbstractPosition, /) -> CartesianPosi >>> import quaxed.numpy as jnp >>> import coordinax as cx - >>> q = cx.CartesianPosition1D.constructor([1], "kpc") - >>> r = cx.RadialPosition.constructor([1], "kpc") + >>> q = cx.CartesianPosition1D.from_([1], "kpc") + >>> r = cx.RadialPosition.from_([1], "kpc") >>> qpr = jnp.add(q, r) >>> qpr @@ -131,7 +131,7 @@ def _neg_p_cart1d_pos(obj: CartesianPosition1D, /) -> CartesianPosition1D: Examples -------- >>> import coordinax as cx - >>> q = cx.CartesianPosition1D.constructor([1], "km") + >>> q = cx.CartesianPosition1D.from_([1], "km") >>> (-q).x Quantity['length'](Array(-1., dtype=float32), unit='km') @@ -151,8 +151,8 @@ def _sub_q1d_pos( >>> from unxt import Quantity >>> import coordinax as cx - >>> q = cx.CartesianPosition1D.constructor(Quantity([1], "kpc")) - >>> r = cx.RadialPosition.constructor(Quantity([1], "kpc")) + >>> q = cx.CartesianPosition1D.from_(Quantity([1], "kpc")) + >>> r = cx.RadialPosition.from_(Quantity([1], "kpc")) >>> qmr = jnp.subtract(q, r) >>> qmr @@ -177,7 +177,7 @@ def _sub_q1d_pos( class CartesianVelocity1D(AvalMixin, AbstractVelocity1D): """Cartesian differential representation.""" - d_x: ct.BatchableSpeed = eqx.field(converter=Quantity["speed"].constructor) + d_x: ct.BatchableSpeed = eqx.field(converter=Quantity["speed"].from_) r"""X differential :math:`dx/dt \in (-\infty,+\infty`)`.""" @override @@ -201,7 +201,7 @@ def norm(self, _: AbstractPosition1D | None = None, /) -> ct.BatchableSpeed: -------- >>> from unxt import Quantity >>> import coordinax as cx - >>> q = cx.CartesianVelocity1D.constructor([-1], "km/s") + >>> q = cx.CartesianVelocity1D.from_([-1], "km/s") >>> q.norm() Quantity['speed'](Array(1, dtype=int32), unit='km / s') @@ -225,7 +225,7 @@ def _add_pp( >>> from unxt import Quantity >>> import coordinax as cx - >>> v = cx.CartesianVelocity1D.constructor([1], "km/s") + >>> v = cx.CartesianVelocity1D.from_([1], "km/s") >>> vec = jnp.add(v, v) >>> vec CartesianVelocity1D( @@ -281,7 +281,7 @@ def _mul_vcart(lhs: ArrayLike, rhs: CartesianVelocity1D, /) -> CartesianVelocity class CartesianAcceleration1D(AvalMixin, AbstractAcceleration1D): """Cartesian differential representation.""" - d2_x: ct.BatchableAcc = eqx.field(converter=Quantity["acceleration"].constructor) + d2_x: ct.BatchableAcc = eqx.field(converter=Quantity["acceleration"].from_) r"""X differential :math:`d^2x/dt^2 \in (-\infty,+\infty`)`.""" @classproperty @@ -301,7 +301,7 @@ def norm(self, _: AbstractPosition1D | None = None, /) -> ct.BatchableAcc: -------- >>> from unxt import Quantity >>> import coordinax as cx - >>> q = cx.CartesianAcceleration1D.constructor([-1], "km/s2") + >>> q = cx.CartesianAcceleration1D.from_([-1], "km/s2") >>> q.norm() Quantity['acceleration'](Array(1, dtype=int32), unit='km / s2') @@ -321,7 +321,7 @@ def _add_aa( >>> from unxt import Quantity >>> import coordinax as cx - >>> v = cx.CartesianAcceleration1D.constructor([1], "km/s2") + >>> v = cx.CartesianAcceleration1D.from_([1], "km/s2") >>> vec = jnp.add(v, v) >>> vec CartesianAcceleration1D( diff --git a/src/coordinax/_src/d1/compat.py b/src/coordinax/_src/d1/compat.py index 1ca5b63c..74318aaa 100644 --- a/src/coordinax/_src/d1/compat.py +++ b/src/coordinax/_src/d1/compat.py @@ -20,7 +20,7 @@ @op_call_dispatch def call(self: AbstractOperator, x: Q1, /) -> Q1: """Dispatch to the operator's `__call__` method.""" - return self(CartesianPosition1D.constructor(x)) + return self(CartesianPosition1D.from_(x)) @op_call_dispatch @@ -28,5 +28,5 @@ def call( self: AbstractOperator, x: Q1, t: TimeBatchOrScalar, / ) -> tuple[Q1, TimeBatchOrScalar]: """Dispatch to the operator's `__call__` method.""" - vec, t = self(CartesianPosition1D.constructor(x), t) + vec, t = self(CartesianPosition1D.from_(x), t) return convert(vec, Quantity), t diff --git a/src/coordinax/_src/d1/radial.py b/src/coordinax/_src/d1/radial.py index 792dc8c1..15008a2d 100644 --- a/src/coordinax/_src/d1/radial.py +++ b/src/coordinax/_src/d1/radial.py @@ -23,7 +23,7 @@ class RadialPosition(AbstractPosition1D): """Radial vector representation.""" r: ct.BatchableDistance = eqx.field( - converter=Unless(AbstractDistance, partial(Distance.constructor, dtype=float)) + converter=Unless(AbstractDistance, partial(Distance.from_, dtype=float)) ) r"""Radial distance :math:`r \in [0,+\infty)`.""" @@ -41,7 +41,7 @@ def differential_cls(cls) -> type["RadialVelocity"]: class RadialVelocity(AbstractVelocity1D): """Radial differential representation.""" - d_r: ct.BatchableSpeed = eqx.field(converter=Quantity["speed"].constructor) + d_r: ct.BatchableSpeed = eqx.field(converter=Quantity["speed"].from_) r"""Radial speed :math:`dr/dt \in (-\infty,+\infty)`.""" @classproperty @@ -64,7 +64,7 @@ def aval(self) -> jax.core.ShapedArray: class RadialAcceleration(AbstractAcceleration1D): """Radial differential representation.""" - d2_r: ct.BatchableAcc = eqx.field(converter=Quantity["acceleration"].constructor) + d2_r: ct.BatchableAcc = eqx.field(converter=Quantity["acceleration"].from_) r"""Radial acceleration :math:`d^2r/dt^2 \in (-\infty,+\infty)`.""" @classproperty diff --git a/src/coordinax/_src/d1/transform.py b/src/coordinax/_src/d1/transform.py index 6ce403b9..8dd0016a 100644 --- a/src/coordinax/_src/d1/transform.py +++ b/src/coordinax/_src/d1/transform.py @@ -158,7 +158,7 @@ def represent_as( Examples -------- >>> import coordinax as cx - >>> v = cx.CartesianVelocity1D.constructor([1], "m/s") + >>> v = cx.CartesianVelocity1D.from_([1], "m/s") >>> cx.represent_as(v, cx.CartesianVelocity1D) is v True @@ -186,7 +186,7 @@ def represent_as( Examples -------- >>> import coordinax as cx - >>> a = cx.CartesianAcceleration1D.constructor([1], "m/s2") + >>> a = cx.CartesianAcceleration1D.from_([1], "m/s2") >>> cx.represent_as(a, cx.CartesianAcceleration1D) is a True diff --git a/src/coordinax/_src/d2/cartesian.py b/src/coordinax/_src/d2/cartesian.py index b679113a..ee46314d 100644 --- a/src/coordinax/_src/d2/cartesian.py +++ b/src/coordinax/_src/d2/cartesian.py @@ -32,12 +32,12 @@ class CartesianPosition2D(AbstractPosition2D): """Cartesian vector representation.""" x: ct.BatchableLength = eqx.field( - converter=partial(Quantity["length"].constructor, dtype=float) + converter=partial(Quantity["length"].from_, dtype=float) ) r"""X coordinate :math:`x \in (-\infty,+\infty)`.""" y: ct.BatchableLength = eqx.field( - converter=partial(Quantity["length"].constructor, dtype=float) + converter=partial(Quantity["length"].from_, dtype=float) ) r"""Y coordinate :math:`y \in (-\infty,+\infty)`.""" @@ -50,8 +50,8 @@ def differential_cls(cls) -> type["CartesianVelocity2D"]: # ----------------------------------------------------- -@CartesianPosition2D.constructor._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@CartesianPosition2D.from_._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[CartesianPosition2D], obj: Shaped[AbstractQuantity, "*batch 2"], / ) -> CartesianPosition2D: """Construct a 2D Cartesian position. @@ -61,7 +61,7 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianPosition2D.constructor(Quantity([1, 2], "m")) + >>> vec = cx.CartesianPosition2D.from_(Quantity([1, 2], "m")) >>> vec CartesianPosition2D( x=Quantity[...](value=f32[], unit=Unit("m")), @@ -88,7 +88,7 @@ def _add_cart2d_pos( >>> from unxt import Quantity >>> import coordinax as cx - >>> cart = cx.CartesianPosition2D.constructor(Quantity([1, 2], "kpc")) + >>> cart = cx.CartesianPosition2D.from_(Quantity([1, 2], "kpc")) >>> polr = cx.PolarPosition(r=Quantity(3, "kpc"), phi=Quantity(90, "deg")) >>> (cart + polr).x Quantity['length'](Array(0.9999999, dtype=float32), unit='kpc') @@ -111,7 +111,7 @@ def _mul_v_cart2d(lhs: ArrayLike, rhs: CartesianPosition2D, /) -> CartesianPosit >>> from unxt import Quantity >>> import coordinax as cx - >>> v = cx.CartesianPosition2D.constructor(Quantity([3, 4], "m")) + >>> v = cx.CartesianPosition2D.from_(Quantity([3, 4], "m")) >>> jnp.multiply(5, v).x Quantity['length'](Array(15., dtype=float32), unit='m') @@ -132,7 +132,7 @@ def _neg_p_cart2d_pos(obj: CartesianPosition2D, /) -> CartesianPosition2D: Examples -------- >>> import coordinax as cx - >>> q = cx.CartesianPosition2D.constructor([1, 2], "km") + >>> q = cx.CartesianPosition2D.from_([1, 2], "km") >>> (-q).x Quantity['length'](Array(-1., dtype=float32), unit='km') @@ -150,7 +150,7 @@ def _sub_cart2d_pos2d( -------- >>> from unxt import Quantity >>> import coordinax as cx - >>> cart = cx.CartesianPosition2D.constructor([1, 2], "kpc") + >>> cart = cx.CartesianPosition2D.from_([1, 2], "kpc") >>> polr = cx.PolarPosition(r=Quantity(3, "kpc"), phi=Quantity(90, "deg")) >>> (cart - polr).x @@ -169,12 +169,12 @@ class CartesianVelocity2D(AvalMixin, AbstractVelocity2D): """Cartesian differential representation.""" d_x: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""X coordinate differential :math:`\dot{x} \in (-\infty,+\infty)`.""" d_y: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Y coordinate differential :math:`\dot{y} \in (-\infty,+\infty)`.""" @@ -192,8 +192,8 @@ def differential_cls(cls) -> type["CartesianAcceleration2D"]: # ----------------------------------------------------- -@CartesianVelocity2D.constructor._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@CartesianVelocity2D.from_._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[CartesianVelocity2D], obj: Shaped[AbstractQuantity, "*batch 2"], / ) -> CartesianVelocity2D: """Construct a 2D Cartesian velocity. @@ -203,7 +203,7 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianVelocity2D.constructor(Quantity([1, 2], "m/s")) + >>> vec = cx.CartesianVelocity2D.from_(Quantity([1, 2], "m/s")) >>> vec CartesianVelocity2D( d_x=Quantity[...]( value=f32[], unit=Unit("m / s") ), @@ -230,7 +230,7 @@ def _add_pp( >>> from unxt import Quantity >>> import coordinax as cx - >>> v = cx.CartesianVelocity2D.constructor(Quantity([1, 2], "km/s")) + >>> v = cx.CartesianVelocity2D.from_(Quantity([1, 2], "km/s")) >>> (v + v).d_x Quantity['speed'](Array(2., dtype=float32), unit='km / s') @@ -251,7 +251,7 @@ def _mul_vp(lhs: ArrayLike, rhts: CartesianVelocity2D, /) -> CartesianVelocity2D >>> from unxt import Quantity >>> import coordinax as cx - >>> v = cx.CartesianVelocity2D.constructor(Quantity([3, 4], "m/s")) + >>> v = cx.CartesianVelocity2D.from_(Quantity([3, 4], "m/s")) >>> (5 * v).d_x Quantity['speed'](Array(15., dtype=float32), unit='m / s') @@ -276,12 +276,12 @@ class CartesianAcceleration2D(AvalMixin, AbstractAcceleration2D): """Cartesian acceleration representation.""" d2_x: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""X coordinate acceleration :math:`\frac{d^2 x}{dt^2} \in (-\infty,+\infty)`.""" d2_y: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""Y coordinate acceleration :math:`\frac{d^2 y}{dt^2} \in (-\infty,+\infty)`.""" @@ -301,7 +301,7 @@ def norm(self, _: AbstractVelocity2D | None = None, /) -> ct.BatchableAcc: -------- >>> from unxt import Quantity >>> import coordinax as cx - >>> v = cx.CartesianAcceleration2D.constructor([3, 4], "km/s2") + >>> v = cx.CartesianAcceleration2D.from_([3, 4], "km/s2") >>> v.norm() Quantity['acceleration'](Array(5., dtype=float32), unit='km / s2') @@ -312,8 +312,8 @@ def norm(self, _: AbstractVelocity2D | None = None, /) -> ct.BatchableAcc: # ----------------------------------------------------- -@CartesianAcceleration2D.constructor._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@CartesianAcceleration2D.from_._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[CartesianAcceleration2D], obj: AbstractQuantity, /, @@ -325,7 +325,7 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianAcceleration2D.constructor(Quantity([1, 2], "m/s2")) + >>> vec = cx.CartesianAcceleration2D.from_(Quantity([1, 2], "m/s2")) >>> vec CartesianAcceleration2D( d2_x=Quantity[...](value=f32[], unit=Unit("m / s2")), @@ -352,7 +352,7 @@ def _add_aa( >>> from unxt import Quantity >>> import coordinax as cx - >>> v = cx.CartesianAcceleration2D.constructor(Quantity([3, 4], "km/s2")) + >>> v = cx.CartesianAcceleration2D.from_(Quantity([3, 4], "km/s2")) >>> (v + v).d2_x Quantity['acceleration'](Array(6., dtype=float32), unit='km / s2') @@ -375,7 +375,7 @@ def _mul_va( >>> from unxt import Quantity >>> import coordinax as cx - >>> v = cx.CartesianAcceleration2D.constructor(Quantity([3, 4], "m/s2")) + >>> v = cx.CartesianAcceleration2D.from_(Quantity([3, 4], "m/s2")) >>> jnp.multiply(5, v).d2_x Quantity['acceleration'](Array(15., dtype=float32), unit='m / s2') diff --git a/src/coordinax/_src/d2/compat.py b/src/coordinax/_src/d2/compat.py index 48b92dfe..37030d6a 100644 --- a/src/coordinax/_src/d2/compat.py +++ b/src/coordinax/_src/d2/compat.py @@ -20,7 +20,7 @@ @op_call_dispatch def call(self: AbstractOperator, x: Q2, /) -> Q2: """Dispatch to the operator's `__call__` method.""" - return self(CartesianPosition2D.constructor(x)) + return self(CartesianPosition2D.from_(x)) @op_call_dispatch @@ -28,5 +28,5 @@ def call( self: AbstractOperator, x: Q2, t: TimeBatchOrScalar, / ) -> tuple[Q2, TimeBatchOrScalar]: """Dispatch to the operator's `__call__` method.""" - vec, t = self(CartesianPosition2D.constructor(x), t) + vec, t = self(CartesianPosition2D.from_(x), t) return convert(vec, Quantity), t diff --git a/src/coordinax/_src/d2/polar.py b/src/coordinax/_src/d2/polar.py index 9dbc4a7c..ae73873f 100644 --- a/src/coordinax/_src/d2/polar.py +++ b/src/coordinax/_src/d2/polar.py @@ -40,13 +40,13 @@ class PolarPosition(AbstractPosition2D): """ r: ct.BatchableDistance = eqx.field( - converter=Unless(AbstractDistance, partial(Distance.constructor, dtype=float)) + converter=Unless(AbstractDistance, partial(Distance.from_, dtype=float)) ) r"""Radial distance :math:`r \in [0,+\infty)`.""" phi: ct.BatchableAngle = eqx.field( converter=lambda x: converter_azimuth_to_range( - Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 + Quantity["angle"].from_(x, dtype=float) # pylint: disable=E1120 ) ) r"""Polar angle :math:`\phi \in [0,2\pi)`.""" @@ -103,12 +103,12 @@ class PolarVelocity(AbstractVelocity2D): """Polar differential representation.""" d_r: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Radial speed :math:`dr/dt \in [-\infty,+\infty]`.""" d_phi: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular speed"].constructor, dtype=float) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) r"""Polar angular speed :math:`d\phi/dt \in [-\infty,+\infty]`.""" @@ -128,12 +128,12 @@ class PolarAcceleration(AbstractAcceleration2D): """Polar acceleration representation.""" d2_r: ct.BatchableAcc = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""Radial acceleration :math:`d^2r/dt^2 \in [-\infty,+\infty]`.""" d2_phi: ct.BatchableAngularAcc = eqx.field( - converter=partial(Quantity["angular acceleration"].constructor, dtype=float) + converter=partial(Quantity["angular acceleration"].from_, dtype=float) ) r"""Polar angular acceleration :math:`d^2\phi/dt^2 \in [-\infty,+\infty]`.""" diff --git a/src/coordinax/_src/d2/spherical.py b/src/coordinax/_src/d2/spherical.py index 7ff7fcbc..203a0404 100644 --- a/src/coordinax/_src/d2/spherical.py +++ b/src/coordinax/_src/d2/spherical.py @@ -66,13 +66,13 @@ class TwoSpherePosition(AbstractPosition2D): """ theta: ct.BatchableAngle = eqx.field( - converter=partial(Quantity["angle"].constructor, dtype=float) + converter=partial(Quantity["angle"].from_, dtype=float) ) r"""Inclination angle :math:`\theta \in [0,180]`.""" phi: ct.BatchableAngle = eqx.field( converter=lambda x: converter_azimuth_to_range( - Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 + Quantity["angle"].from_(x, dtype=float) # pylint: disable=E1120 ) ) r"""Azimuthal angle :math:`\phi \in [0,360)`.""" @@ -140,12 +140,12 @@ class TwoSphereVelocity(AbstractVelocity2D): """ d_theta: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular speed"].constructor, dtype=float) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) r"""Inclination speed :math:`d\theta/dt \in [-\infty, \infty].""" d_phi: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular speed"].constructor, dtype=float) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) r"""Azimuthal speed :math:`d\phi/dt \in [-\infty, \infty].""" @@ -207,12 +207,12 @@ class TwoSphereAcceleration(AbstractAcceleration2D): """ d2_theta: ct.BatchableAngularAcc = eqx.field( - converter=partial(Quantity["angular acceleration"].constructor, dtype=float) + converter=partial(Quantity["angular acceleration"].from_, dtype=float) ) r"""Inclination acceleration :math:`d^2\theta/dt^2 \in [-\infty, \infty].""" d2_phi: ct.BatchableAngularAcc = eqx.field( - converter=partial(Quantity["angular acceleration"].constructor, dtype=float) + converter=partial(Quantity["angular acceleration"].from_, dtype=float) ) r"""Azimuthal acceleration :math:`d^2\phi/dt^2 \in [-\infty, \infty].""" diff --git a/src/coordinax/_src/d2/transform.py b/src/coordinax/_src/d2/transform.py index 52584c1e..ac6667b3 100644 --- a/src/coordinax/_src/d2/transform.py +++ b/src/coordinax/_src/d2/transform.py @@ -103,7 +103,7 @@ def represent_as( Examples -------- >>> import coordinax as cx - >>> v = cx.CartesianVelocity2D.constructor([1, 1], "m/s") + >>> v = cx.CartesianVelocity2D.from_([1, 1], "m/s") >>> cx.represent_as(v, cx.CartesianVelocity2D) is v True @@ -131,7 +131,7 @@ def represent_as( Examples -------- >>> import coordinax as cx - >>> a = cx.CartesianAcceleration2D.constructor([1, 1], "m/s2") + >>> a = cx.CartesianAcceleration2D.from_([1, 1], "m/s2") >>> cx.represent_as(a, cx.CartesianAcceleration2D) is a True diff --git a/src/coordinax/_src/d3/cartesian.py b/src/coordinax/_src/d3/cartesian.py index ea246b79..b1b0f3a8 100644 --- a/src/coordinax/_src/d3/cartesian.py +++ b/src/coordinax/_src/d3/cartesian.py @@ -38,17 +38,17 @@ class CartesianPosition3D(AbstractPosition3D): """Cartesian vector representation.""" x: ct.BatchableLength = eqx.field( - converter=partial(Quantity["length"].constructor, dtype=float) + converter=partial(Quantity["length"].from_, dtype=float) ) r"""X coordinate :math:`x \in (-\infty,+\infty)`.""" y: ct.BatchableLength = eqx.field( - converter=partial(Quantity["length"].constructor, dtype=float) + converter=partial(Quantity["length"].from_, dtype=float) ) r"""Y coordinate :math:`y \in (-\infty,+\infty)`.""" z: ct.BatchableLength = eqx.field( - converter=partial(Quantity["length"].constructor, dtype=float) + converter=partial(Quantity["length"].from_, dtype=float) ) r"""Z coordinate :math:`z \in (-\infty,+\infty)`.""" @@ -64,8 +64,8 @@ def differential_cls(cls) -> type["CartesianVelocity3D"]: # Constructors -@CartesianPosition3D.constructor._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@CartesianPosition3D.from_._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[CartesianPosition3D], obj: AbstractQuantity, # TODO: Shaped[AbstractQuantity, "*batch 3"] /, @@ -77,7 +77,7 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor(Quantity([1, 2, 3], "m")) + >>> vec = cx.CartesianPosition3D.from_(Quantity([1, 2, 3], "m")) >>> vec CartesianPosition3D( x=Quantity[...](value=f32[], unit=Unit("m")), @@ -104,7 +104,7 @@ def _add_cart3d_pos( -------- >>> from unxt import Quantity >>> import coordinax as cx - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> s = cx.SphericalPosition(r=Quantity(1, "kpc"), theta=Quantity(90, "deg"), ... phi=Quantity(0, "deg")) >>> (q + s).x @@ -124,7 +124,7 @@ def _neg_p_cart3d_pos(obj: CartesianPosition3D, /) -> CartesianPosition3D: Examples -------- >>> import coordinax as cx - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> (-q).x Quantity['length'](Array(-1., dtype=float32), unit='kpc') @@ -142,7 +142,7 @@ def _sub_cart3d_pos( -------- >>> from unxt import Quantity >>> import coordinax as cx - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> s = cx.SphericalPosition(r=Quantity(1, "kpc"), theta=Quantity(90, "deg"), ... phi=Quantity(0, "deg")) >>> (q - s).x @@ -179,7 +179,7 @@ def normalize_vector(obj: CartesianPosition3D, /) -> CartesianGeneric3D: Examples -------- >>> import coordinax as cx - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> cx.normalize_vector(q) CartesianGeneric3D( x=Quantity[...]( value=f32[], unit=Unit(dimensionless) ), @@ -201,17 +201,17 @@ class CartesianVelocity3D(AvalMixin, AbstractVelocity3D): """Cartesian differential representation.""" d_x: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""X speed :math:`dx/dt \in [-\infty, \infty].""" d_y: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Y speed :math:`dy/dt \in [-\infty, \infty].""" d_z: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Z speed :math:`dz/dt \in [-\infty, \infty].""" @@ -235,7 +235,7 @@ def norm(self, _: AbstractPosition3D | None = None, /) -> ct.BatchableSpeed: -------- >>> from unxt import Quantity >>> import coordinax as cx - >>> c = cx.CartesianVelocity3D.constructor([1, 2, 3], "km/s") + >>> c = cx.CartesianVelocity3D.from_([1, 2, 3], "km/s") >>> c.norm() Quantity['speed'](Array(3.7416575, dtype=float32), unit='km / s') @@ -246,8 +246,8 @@ def norm(self, _: AbstractPosition3D | None = None, /) -> ct.BatchableSpeed: # ----------------------------------------------------- -@CartesianVelocity3D.constructor._f.dispatch # type: ignore[attr-defined,misc] # noqa: SLF001 -def constructor( +@CartesianVelocity3D.from_._f.dispatch # type: ignore[attr-defined,misc] # noqa: SLF001 +def from_( cls: type[CartesianVelocity3D], obj: AbstractQuantity, # TODO: Shaped[AbstractQuantity, "*batch 3"] /, @@ -259,7 +259,7 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianVelocity3D.constructor(Quantity([1, 2, 3], "m/s")) + >>> vec = cx.CartesianVelocity3D.from_(Quantity([1, 2, 3], "m/s")) >>> vec CartesianVelocity3D( d_x=Quantity[...]( value=f32[], unit=Unit("m / s") ), @@ -285,7 +285,7 @@ def _add_pp( Examples -------- >>> import coordinax as cx - >>> q = cx.CartesianVelocity3D.constructor([1, 2, 3], "km/s") + >>> q = cx.CartesianVelocity3D.from_([1, 2, 3], "km/s") >>> q2 = q + q >>> q2.d_y Quantity['speed'](Array(4., dtype=float32), unit='km / s') @@ -304,7 +304,7 @@ def _sub_v3_v3( -------- >>> from unxt import Quantity >>> from coordinax import CartesianPosition3D, CartesianVelocity3D - >>> q = CartesianVelocity3D.constructor(Quantity([1, 2, 3], "km/s")) + >>> q = CartesianVelocity3D.from_(Quantity([1, 2, 3], "km/s")) >>> q2 = q - q >>> q2.d_y Quantity['speed'](Array(0., dtype=float32), unit='km / s') @@ -322,17 +322,17 @@ class CartesianAcceleration3D(AvalMixin, AbstractAcceleration3D): """Cartesian differential representation.""" d2_x: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""X acceleration :math:`d^2x/dt^2 \in [-\infty, \infty].""" d2_y: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""Y acceleration :math:`d^2y/dt^2 \in [-\infty, \infty].""" d2_z: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""Z acceleration :math:`d^2z/dt^2 \in [-\infty, \infty].""" @@ -353,7 +353,7 @@ def norm(self, _: AbstractVelocity3D | None = None, /) -> ct.BatchableAcc: -------- >>> from unxt import Quantity >>> import coordinax as cx - >>> c = cx.CartesianAcceleration3D.constructor([1, 2, 3], "km/s2") + >>> c = cx.CartesianAcceleration3D.from_([1, 2, 3], "km/s2") >>> c.norm() Quantity['acceleration'](Array(3.7416575, dtype=float32), unit='km / s2') @@ -364,8 +364,8 @@ def norm(self, _: AbstractVelocity3D | None = None, /) -> ct.BatchableAcc: # ----------------------------------------------------- -@CartesianAcceleration3D.constructor._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@CartesianAcceleration3D.from_._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[CartesianAcceleration3D], obj: Shaped[AbstractQuantity, "*batch 3"], / ) -> CartesianAcceleration3D: """Construct a 3D Cartesian acceleration. @@ -375,7 +375,7 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianAcceleration3D.constructor(Quantity([1, 2, 3], "m/s2")) + >>> vec = cx.CartesianAcceleration3D.from_(Quantity([1, 2, 3], "m/s2")) >>> vec CartesianAcceleration3D( d2_x=Quantity[...](value=f32[], unit=Unit("m / s2")), @@ -410,7 +410,7 @@ def _mul_ac3(lhs: ArrayLike, rhs: CartesianPosition3D, /) -> CartesianPosition3D >>> from unxt import Quantity >>> import coordinax as cx - >>> v = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> v = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> jnp.multiply(2, v).x Quantity['length'](Array(2., dtype=float32), unit='kpc') diff --git a/src/coordinax/_src/d3/compat.py b/src/coordinax/_src/d3/compat.py index da282b1f..3eade723 100644 --- a/src/coordinax/_src/d3/compat.py +++ b/src/coordinax/_src/d3/compat.py @@ -53,7 +53,7 @@ def call(self: AbstractOperator, q: Q3, /) -> Q3: Quantity['length'](Array([1., 2., 3.], dtype=float32), unit='kpc') """ - cart = CartesianPosition3D.constructor(q) + cart = CartesianPosition3D.from_(q) result = self(cart) return convert(result.represent_as(CartesianPosition3D), Quantity) @@ -92,5 +92,5 @@ def call( Quantity['time'](Array(0., dtype=float32, ...), unit='Gyr')) """ - vec, t = self(CartesianPosition3D.constructor(x), t) + vec, t = self(CartesianPosition3D.from_(x), t) return convert(vec, Quantity), t diff --git a/src/coordinax/_src/d3/constructor.py b/src/coordinax/_src/d3/constructor.py index afdd4a7f..ffe32f86 100644 --- a/src/coordinax/_src/d3/constructor.py +++ b/src/coordinax/_src/d3/constructor.py @@ -11,8 +11,8 @@ ##################################################################### -@AbstractPosition3D.constructor._f.dispatch(precedence=-1) # noqa: SLF001 -def constructor(cls: type[AbstractPosition3D], obj: Any, /) -> CartesianPosition3D: +@AbstractPosition3D.from_._f.dispatch(precedence=-1) # noqa: SLF001 +def from_(cls: type[AbstractPosition3D], obj: Any, /) -> CartesianPosition3D: """Try to construct a 3D Cartesian position from an object. Examples @@ -21,7 +21,7 @@ def constructor(cls: type[AbstractPosition3D], obj: Any, /) -> CartesianPosition >>> import coordinax as cx >>> x = Quantity([1, 2, 3], "km") - >>> cx.AbstractPosition3D.constructor(x) + >>> cx.AbstractPosition3D.from_(x) CartesianPosition3D( x=Quantity[...](value=f32[], unit=Unit("km")), y=Quantity[...](value=f32[], unit=Unit("km")), @@ -30,14 +30,12 @@ def constructor(cls: type[AbstractPosition3D], obj: Any, /) -> CartesianPosition """ return ( - obj - if isinstance(obj, CartesianPosition3D) - else CartesianPosition3D.constructor(obj) + obj if isinstance(obj, CartesianPosition3D) else CartesianPosition3D.from_(obj) ) -@AbstractPosition3D.constructor._f.dispatch(precedence=1) # noqa: SLF001 -def constructor( +@AbstractPosition3D.from_._f.dispatch(precedence=1) # noqa: SLF001 +def from_( cls: type[AbstractPosition3D], obj: AbstractPosition3D, / ) -> AbstractPosition3D: """Construct from a 3D position. @@ -46,16 +44,16 @@ def constructor( -------- >>> import coordinax as cx - >>> cart = cx.CartesianPosition3D.constructor([1, 2, 3], "km") - >>> cx.AbstractPosition3D.constructor(cart) is cart + >>> cart = cx.CartesianPosition3D.from_([1, 2, 3], "km") + >>> cx.AbstractPosition3D.from_(cart) is cart True >>> sph = cart.represent_as(cx.SphericalPosition) - >>> cx.AbstractPosition3D.constructor(sph) is sph + >>> cx.AbstractPosition3D.from_(sph) is sph True >>> cyl = cart.represent_as(cx.CylindricalPosition) - >>> cx.AbstractPosition3D.constructor(cyl) is cyl + >>> cx.AbstractPosition3D.from_(cyl) is cyl True """ @@ -65,8 +63,8 @@ def constructor( ##################################################################### -@AbstractVelocity3D.constructor._f.dispatch(precedence=-1) # noqa: SLF001 -def constructor(cls: type[AbstractVelocity3D], obj: Any, /) -> CartesianVelocity3D: +@AbstractVelocity3D.from_._f.dispatch(precedence=-1) # noqa: SLF001 +def from_(cls: type[AbstractVelocity3D], obj: Any, /) -> CartesianVelocity3D: """Try to construct a 3D Cartesian velocity from an object. Examples @@ -75,7 +73,7 @@ def constructor(cls: type[AbstractVelocity3D], obj: Any, /) -> CartesianVelocity >>> import coordinax as cx >>> x = Quantity([1, 2, 3], "km / s") - >>> cx.AbstractVelocity3D.constructor(x) + >>> cx.AbstractVelocity3D.from_(x) CartesianVelocity3D( d_x=Quantity[...]( value=f32[], unit=Unit("km / s") ), d_y=Quantity[...]( value=f32[], unit=Unit("km / s") ), @@ -84,14 +82,12 @@ def constructor(cls: type[AbstractVelocity3D], obj: Any, /) -> CartesianVelocity """ return ( - obj - if isinstance(obj, CartesianVelocity3D) - else CartesianVelocity3D.constructor(obj) + obj if isinstance(obj, CartesianVelocity3D) else CartesianVelocity3D.from_(obj) ) -@AbstractVelocity3D.constructor._f.dispatch(precedence=1) # noqa: SLF001 -def constructor( +@AbstractVelocity3D.from_._f.dispatch(precedence=1) # noqa: SLF001 +def from_( cls: type[AbstractVelocity3D], obj: AbstractVelocity3D, / ) -> AbstractVelocity3D: """Construct from a 3D velocity. @@ -100,18 +96,18 @@ def constructor( -------- >>> import coordinax as cx - >>> q = cx.CartesianPosition3D.constructor([1, 1, 1], "km") + >>> q = cx.CartesianPosition3D.from_([1, 1, 1], "km") - >>> cart = cx.CartesianVelocity3D.constructor([1, 2, 3], "km/s") - >>> cx.AbstractVelocity3D.constructor(cart) is cart + >>> cart = cx.CartesianVelocity3D.from_([1, 2, 3], "km/s") + >>> cx.AbstractVelocity3D.from_(cart) is cart True >>> sph = cart.represent_as(cx.SphericalVelocity, q) - >>> cx.AbstractVelocity3D.constructor(sph) is sph + >>> cx.AbstractVelocity3D.from_(sph) is sph True >>> cyl = cart.represent_as(cx.CylindricalVelocity, q) - >>> cx.AbstractVelocity3D.constructor(cyl) is cyl + >>> cx.AbstractVelocity3D.from_(cyl) is cyl True """ @@ -121,10 +117,8 @@ def constructor( ##################################################################### -@AbstractAcceleration3D.constructor._f.dispatch(precedence=-1) # noqa: SLF001 -def constructor( - cls: type[AbstractAcceleration3D], obj: Any, / -) -> CartesianAcceleration3D: +@AbstractAcceleration3D.from_._f.dispatch(precedence=-1) # noqa: SLF001 +def from_(cls: type[AbstractAcceleration3D], obj: Any, /) -> CartesianAcceleration3D: """Try to construct a 3D Cartesian velocity from an object. Examples @@ -133,7 +127,7 @@ def constructor( >>> import coordinax as cx >>> x = Quantity([1, 2, 3], "km / s2") - >>> cx.AbstractAcceleration3D.constructor(x) + >>> cx.AbstractAcceleration3D.from_(x) CartesianAcceleration3D( d2_x=Quantity[...](value=f32[], unit=Unit("km / s2")), d2_y=Quantity[...](value=f32[], unit=Unit("km / s2")), @@ -144,12 +138,12 @@ def constructor( return ( obj if isinstance(obj, CartesianAcceleration3D) - else CartesianAcceleration3D.constructor(obj) + else CartesianAcceleration3D.from_(obj) ) -@AbstractAcceleration3D.constructor._f.dispatch(precedence=1) # noqa: SLF001 -def constructor( +@AbstractAcceleration3D.from_._f.dispatch(precedence=1) # noqa: SLF001 +def from_( cls: type[AbstractAcceleration3D], obj: AbstractAcceleration3D, / ) -> AbstractAcceleration3D: """Construct from a 3D velocity. @@ -158,19 +152,19 @@ def constructor( -------- >>> import coordinax as cx - >>> q = cx.CartesianPosition3D.constructor([1, 1, 1], "km") - >>> p = cx.CartesianVelocity3D.constructor([1, 1, 1], "km/s") + >>> q = cx.CartesianPosition3D.from_([1, 1, 1], "km") + >>> p = cx.CartesianVelocity3D.from_([1, 1, 1], "km/s") - >>> cart = cx.CartesianAcceleration3D.constructor([1, 2, 3], "km/s2") - >>> cx.AbstractAcceleration3D.constructor(cart) is cart + >>> cart = cx.CartesianAcceleration3D.from_([1, 2, 3], "km/s2") + >>> cx.AbstractAcceleration3D.from_(cart) is cart True >>> sph = cart.represent_as(cx.SphericalAcceleration, p, q) - >>> cx.AbstractAcceleration3D.constructor(sph) is sph + >>> cx.AbstractAcceleration3D.from_(sph) is sph True >>> cyl = cart.represent_as(cx.CylindricalAcceleration, p, q) - >>> cx.AbstractAcceleration3D.constructor(cyl) is cyl + >>> cx.AbstractAcceleration3D.from_(cyl) is cyl True """ diff --git a/src/coordinax/_src/d3/cylindrical.py b/src/coordinax/_src/d3/cylindrical.py index 521a2b21..4581fb98 100644 --- a/src/coordinax/_src/d3/cylindrical.py +++ b/src/coordinax/_src/d3/cylindrical.py @@ -31,19 +31,19 @@ class CylindricalPosition(AbstractPosition3D): """ rho: ct.BatchableLength = eqx.field( - converter=partial(Quantity["length"].constructor, dtype=float) + converter=partial(Quantity["length"].from_, dtype=float) ) r"""Cylindrical radial distance :math:`\rho \in [0,+\infty)`.""" phi: ct.BatchableAngle = eqx.field( converter=lambda x: converter_azimuth_to_range( - Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 + Quantity["angle"].from_(x, dtype=float) # pylint: disable=E1120 ) ) r"""Azimuthal angle :math:`\phi \in [0,360)`.""" z: ct.BatchableLength = eqx.field( - converter=partial(Quantity["length"].constructor, dtype=float) + converter=partial(Quantity["length"].from_, dtype=float) ) r"""Height :math:`z \in (-\infty,+\infty)`.""" @@ -81,17 +81,17 @@ class CylindricalVelocity(AbstractVelocity3D): """Cylindrical differential representation.""" d_rho: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Cyindrical radial speed :math:`d\rho/dt \in [-\infty, \infty].""" d_phi: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular speed"].constructor, dtype=float) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) r"""Azimuthal speed :math:`d\phi/dt \in [-\infty, \infty].""" d_z: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Vertical speed :math:`dz/dt \in [-\infty, \infty].""" @@ -111,17 +111,17 @@ class CylindricalAcceleration(AbstractAcceleration3D): """Cylindrical acceleration representation.""" d2_rho: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""Cyindrical radial acceleration :math:`d^2\rho/dt^2 \in [-\infty, \infty].""" d2_phi: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular acceleration"].constructor, dtype=float) + converter=partial(Quantity["angular acceleration"].from_, dtype=float) ) r"""Azimuthal acceleration :math:`d^2\phi/dt^2 \in [-\infty, \infty].""" d2_z: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""Vertical acceleration :math:`d^2z/dt^2 \in [-\infty, \infty].""" diff --git a/src/coordinax/_src/d3/generic.py b/src/coordinax/_src/d3/generic.py index 7625fa8d..268090f0 100644 --- a/src/coordinax/_src/d3/generic.py +++ b/src/coordinax/_src/d3/generic.py @@ -32,7 +32,7 @@ class CartesianGeneric3D(AvalMixin, AbstractVector): >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianGeneric3D.constructor([1, 2, 3], "kg m /s") + >>> vec = cx.CartesianGeneric3D.from_([1, 2, 3], "kg m /s") >>> vec CartesianGeneric3D( x=Quantity[...]( value=f32[], unit=Unit("kg m / s") ), @@ -43,15 +43,15 @@ class CartesianGeneric3D(AvalMixin, AbstractVector): """ x: ct.BatchableFloatScalarQ = eqx.field( - converter=partial(Quantity.constructor, dtype=float) + converter=partial(Quantity.from_, dtype=float) ) y: ct.BatchableFloatScalarQ = eqx.field( - converter=partial(Quantity.constructor, dtype=float) + converter=partial(Quantity.from_, dtype=float) ) z: ct.BatchableFloatScalarQ = eqx.field( - converter=partial(Quantity.constructor, dtype=float) + converter=partial(Quantity.from_, dtype=float) ) # ----------------------------------------------------- @@ -63,7 +63,7 @@ def __neg__(self) -> "CartesianGeneric3D": Examples -------- >>> import coordinax as cx - >>> q = cx.CartesianGeneric3D.constructor([1, 2, 3], "kpc") + >>> q = cx.CartesianGeneric3D.from_([1, 2, 3], "kpc") >>> (-q).x Quantity['length'](Array(-1., dtype=float32), unit='kpc') @@ -82,8 +82,8 @@ def represent_as(self, target: type[VT], /, *args: Any, **kwargs: Any) -> VT: # Constructors -@CartesianGeneric3D.constructor._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@CartesianGeneric3D.from_._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[CartesianGeneric3D], obj: AbstractQuantity, # TODO: Shaped[AbstractQuantity, "*batch 3"] /, @@ -95,7 +95,7 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianGeneric3D.constructor(Quantity([1, 2, 3], "m")) + >>> vec = cx.CartesianGeneric3D.from_(Quantity([1, 2, 3], "m")) >>> vec CartesianGeneric3D( x=Quantity[...](value=f32[], unit=Unit("m")), diff --git a/src/coordinax/_src/d3/lonlatspherical.py b/src/coordinax/_src/d3/lonlatspherical.py index 6181090e..0f8420b2 100644 --- a/src/coordinax/_src/d3/lonlatspherical.py +++ b/src/coordinax/_src/d3/lonlatspherical.py @@ -101,18 +101,18 @@ class LonLatSphericalPosition(AbstractSphericalPosition): lon: ct.BatchableAngle = eqx.field( converter=lambda x: converter_azimuth_to_range( - Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 + Quantity["angle"].from_(x, dtype=float) # pylint: disable=E1120 ) ) r"""Longitude (azimuthal) angle :math:`\in [0,360)`.""" lat: ct.BatchableAngle = eqx.field( - converter=partial(Quantity["angle"].constructor, dtype=float) + converter=partial(Quantity["angle"].from_, dtype=float) ) r"""Latitude (polar) angle :math:`\in [-90,90]`.""" distance: ct.BatchableDistance = eqx.field( - converter=Unless(AbstractDistance, partial(Distance.constructor, dtype=float)) + converter=Unless(AbstractDistance, partial(Distance.from_, dtype=float)) ) r"""Radial distance :math:`r \in [0,+\infty)`.""" @@ -147,8 +147,8 @@ def norm(self) -> ct.BatchableDistance: return self.distance -@LonLatSphericalPosition.constructor._f.register # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@LonLatSphericalPosition.from_._f.register # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[LonLatSphericalPosition], *, lon: Quantity["angle"], @@ -163,7 +163,7 @@ def constructor( Let's start with a valid input: - >>> cx.LonLatSphericalPosition.constructor(lon=Quantity(0, "deg"), + >>> cx.LonLatSphericalPosition.from_(lon=Quantity(0, "deg"), ... lat=Quantity(0, "deg"), ... distance=Quantity(3, "kpc")) LonLatSphericalPosition( @@ -175,7 +175,7 @@ def constructor( The distance can be negative, which wraps the longitude by 180 degrees and flips the latitude: - >>> vec = cx.LonLatSphericalPosition.constructor(lon=Quantity(0, "deg"), + >>> vec = cx.LonLatSphericalPosition.from_(lon=Quantity(0, "deg"), ... lat=Quantity(45, "deg"), ... distance=Quantity(-3, "kpc")) >>> vec.lon @@ -188,7 +188,7 @@ def constructor( The latitude can be outside the [-90, 90] deg range, causing the longitude to be shifted by 180 degrees: - >>> vec = cx.LonLatSphericalPosition.constructor(lon=Quantity(0, "deg"), + >>> vec = cx.LonLatSphericalPosition.from_(lon=Quantity(0, "deg"), ... lat=Quantity(-100, "deg"), ... distance=Quantity(3, "kpc")) >>> vec.lon @@ -198,7 +198,7 @@ def constructor( >>> vec.distance Distance(Array(3., dtype=float32), unit='kpc') - >>> vec = cx.LonLatSphericalPosition.constructor(lon=Quantity(0, "deg"), + >>> vec = cx.LonLatSphericalPosition.from_(lon=Quantity(0, "deg"), ... lat=Quantity(100, "deg"), ... distance=Quantity(3, "kpc")) >>> vec.lon @@ -211,7 +211,7 @@ def constructor( The longitude can be outside the [0, 360) deg range. This is wrapped to the [0, 360) deg range (actually the base constructor does this): - >>> vec = cx.LonLatSphericalPosition.constructor(lon=Quantity(365, "deg"), + >>> vec = cx.LonLatSphericalPosition.from_(lon=Quantity(365, "deg"), ... lat=Quantity(0, "deg"), ... distance=Quantity(3, "kpc")) >>> vec.lon @@ -252,17 +252,17 @@ class LonLatSphericalVelocity(AbstractSphericalVelocity): """Spherical differential representation.""" d_lon: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular speed"].constructor, dtype=float) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) r"""Longitude speed :math:`dlon/dt \in [-\infty, \infty].""" d_lat: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular speed"].constructor, dtype=float) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) r"""Latitude speed :math:`dlat/dt \in [-\infty, \infty].""" d_distance: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Radial speed :math:`dr/dt \in [-\infty, \infty].""" @@ -282,17 +282,17 @@ class LonCosLatSphericalVelocity(AbstractSphericalVelocity): """Spherical differential representation.""" d_lon_coslat: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular speed"].constructor, dtype=float) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) 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) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) r"""Latitude speed :math:`dlat/dt \in [-\infty, \infty].""" d_distance: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Radial speed :math:`dr/dt \in [-\infty, \infty].""" @@ -315,17 +315,17 @@ class LonLatSphericalAcceleration(AbstractSphericalAcceleration): """Spherical acceleration representation.""" d2_lon: ct.BatchableAngularAcc = eqx.field( - converter=partial(Quantity["angular acceleration"].constructor, dtype=float) + converter=partial(Quantity["angular acceleration"].from_, dtype=float) ) r"""Longitude acceleration :math:`d^2lon/dt^2 \in [-\infty, \infty].""" d2_lat: ct.BatchableAngularAcc = eqx.field( - converter=partial(Quantity["angular acceleration"].constructor, dtype=float) + converter=partial(Quantity["angular acceleration"].from_, dtype=float) ) r"""Latitude acceleration :math:`d^2lat/dt^2 \in [-\infty, \infty].""" d2_distance: ct.BatchableAcc = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""Radial acceleration :math:`d^2r/dt^2 \in [-\infty, \infty].""" diff --git a/src/coordinax/_src/d3/mathspherical.py b/src/coordinax/_src/d3/mathspherical.py index 68d24366..2ce041b6 100644 --- a/src/coordinax/_src/d3/mathspherical.py +++ b/src/coordinax/_src/d3/mathspherical.py @@ -58,19 +58,19 @@ class MathSphericalPosition(AbstractSphericalPosition): """ r: ct.BatchableDistance = eqx.field( - converter=Unless(AbstractDistance, partial(Distance.constructor, dtype=float)) + converter=Unless(AbstractDistance, partial(Distance.from_, dtype=float)) ) r"""Radial distance :math:`r \in [0,+\infty)`.""" theta: ct.BatchableAngle = eqx.field( converter=lambda x: converter_azimuth_to_range( - Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 + Quantity["angle"].from_(x, dtype=float) # pylint: disable=E1120 ) ) r"""Azimuthal angle :math:`\theta \in [0,360)`.""" phi: ct.BatchableAngle = eqx.field( - converter=partial(Quantity["angle"].constructor, dtype=float) + converter=partial(Quantity["angle"].from_, dtype=float) ) r"""Inclination angle :math:`\phi \in [0,180]`.""" @@ -104,8 +104,8 @@ def norm(self) -> ct.BatchableDistance: return self.r -@MathSphericalPosition.constructor._f.register # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@MathSphericalPosition.from_._f.register # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[MathSphericalPosition], *, r: AbstractQuantity, @@ -121,7 +121,7 @@ def constructor( Let's start with a valid input: - >>> cx.MathSphericalPosition.constructor(r=Quantity(3, "kpc"), + >>> cx.MathSphericalPosition.from_(r=Quantity(3, "kpc"), ... theta=Quantity(90, "deg"), ... phi=Quantity(0, "deg")) MathSphericalPosition( @@ -133,7 +133,7 @@ def constructor( The radial distance can be negative, which wraps the azimuthal angle by 180 degrees and flips the polar angle: - >>> vec = cx.MathSphericalPosition.constructor(r=Quantity(-3, "kpc"), + >>> vec = cx.MathSphericalPosition.from_(r=Quantity(-3, "kpc"), ... theta=Quantity(100, "deg"), ... phi=Quantity(45, "deg")) >>> vec.r @@ -146,7 +146,7 @@ def constructor( The polar angle can be outside the [0, 180] deg range, causing the azimuthal angle to be shifted by 180 degrees: - >>> vec = cx.MathSphericalPosition.constructor(r=Quantity(3, "kpc"), + >>> vec = cx.MathSphericalPosition.from_(r=Quantity(3, "kpc"), ... theta=Quantity(0, "deg"), ... phi=Quantity(190, "deg")) >>> vec.r @@ -159,7 +159,7 @@ def constructor( The azimuth can be outside the [0, 360) deg range. This is wrapped to the [0, 360) deg range (actually the base constructor does this): - >>> vec = cx.MathSphericalPosition.constructor(r=Quantity(3, "kpc"), + >>> vec = cx.MathSphericalPosition.from_(r=Quantity(3, "kpc"), ... theta=Quantity(365, "deg"), ... phi=Quantity(90, "deg")) >>> vec.theta @@ -234,17 +234,17 @@ class MathSphericalVelocity(AbstractSphericalVelocity): """Spherical differential representation.""" d_r: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Radial speed :math:`dr/dt \in [-\infty, \infty].""" d_theta: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular speed"].constructor, dtype=float) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) r"""Azimuthal speed :math:`d\theta/dt \in [-\infty, \infty].""" d_phi: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular speed"].constructor, dtype=float) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) r"""Inclination speed :math:`d\phi/dt \in [-\infty, \infty].""" @@ -269,17 +269,17 @@ class MathSphericalAcceleration(AbstractSphericalAcceleration): """Spherical acceleration representation.""" d2_r: ct.BatchableAcc = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""Radial acceleration :math:`d^2r/dt^2 \in [-\infty, \infty].""" d2_theta: ct.BatchableAngularAcc = eqx.field( - converter=partial(Quantity["angular acceleration"].constructor, dtype=float) + converter=partial(Quantity["angular acceleration"].from_, dtype=float) ) r"""Azimuthal acceleration :math:`d^2\theta/dt^2 \in [-\infty, \infty].""" d2_phi: ct.BatchableAngularAcc = eqx.field( - converter=partial(Quantity["angular acceleration"].constructor, dtype=float) + converter=partial(Quantity["angular acceleration"].from_, dtype=float) ) r"""Inclination acceleration :math:`d^2\phi/dt^2 \in [-\infty, \infty].""" diff --git a/src/coordinax/_src/d3/spherical.py b/src/coordinax/_src/d3/spherical.py index e96cdedb..28c2161a 100644 --- a/src/coordinax/_src/d3/spherical.py +++ b/src/coordinax/_src/d3/spherical.py @@ -58,18 +58,18 @@ class SphericalPosition(AbstractSphericalPosition): """ r: ct.BatchableDistance = eqx.field( - converter=Unless(AbstractDistance, partial(Distance.constructor, dtype=float)) + converter=Unless(AbstractDistance, partial(Distance.from_, dtype=float)) ) r"""Radial distance :math:`r \in [0,+\infty)`.""" theta: ct.BatchableAngle = eqx.field( - converter=partial(Quantity["angle"].constructor, dtype=float) + converter=partial(Quantity["angle"].from_, dtype=float) ) r"""Inclination angle :math:`\theta \in [0,180]`.""" phi: ct.BatchableAngle = eqx.field( converter=lambda x: converter_azimuth_to_range( - Quantity["angle"].constructor(x, dtype=float) # pylint: disable=E1120 + Quantity["angle"].from_(x, dtype=float) # pylint: disable=E1120 ) ) r"""Azimuthal angle :math:`\phi \in [0,360)`.""" @@ -86,8 +86,8 @@ def differential_cls(cls) -> type["SphericalVelocity"]: return SphericalVelocity -@SphericalPosition.constructor._f.register # type: ignore[attr-defined, misc] # noqa: SLF001 -def constructor( +@SphericalPosition.from_._f.register # type: ignore[attr-defined, misc] # noqa: SLF001 +def from_( cls: type[SphericalPosition], *, r: AbstractQuantity, @@ -103,7 +103,7 @@ def constructor( Let's start with a valid input: - >>> cx.SphericalPosition.constructor(r=Quantity(3, "kpc"), + >>> cx.SphericalPosition.from_(r=Quantity(3, "kpc"), ... theta=Quantity(90, "deg"), ... phi=Quantity(0, "deg")) SphericalPosition( @@ -115,7 +115,7 @@ def constructor( The radial distance can be negative, which wraps the azimuthal angle by 180 degrees and flips the polar angle: - >>> vec = cx.SphericalPosition.constructor(r=Quantity(-3, "kpc"), + >>> vec = cx.SphericalPosition.from_(r=Quantity(-3, "kpc"), ... theta=Quantity(45, "deg"), ... phi=Quantity(0, "deg")) >>> vec.r @@ -128,7 +128,7 @@ def constructor( The polar angle can be outside the [0, 180] deg range, causing the azimuthal angle to be shifted by 180 degrees: - >>> vec = cx.SphericalPosition.constructor(r=Quantity(3, "kpc"), + >>> vec = cx.SphericalPosition.from_(r=Quantity(3, "kpc"), ... theta=Quantity(190, "deg"), ... phi=Quantity(0, "deg")) >>> vec.r @@ -139,9 +139,9 @@ def constructor( Quantity['angle'](Array(180., dtype=float32), unit='deg') The azimuth can be outside the [0, 360) deg range. This is wrapped to the - [0, 360) deg range (actually the base constructor does this): + [0, 360) deg range (actually the base from_ does this): - >>> vec = cx.SphericalPosition.constructor(r=Quantity(3, "kpc"), + >>> vec = cx.SphericalPosition.from_(r=Quantity(3, "kpc"), ... theta=Quantity(90, "deg"), ... phi=Quantity(365, "deg")) >>> vec.phi @@ -178,17 +178,17 @@ class SphericalVelocity(AbstractSphericalVelocity): """Spherical differential representation.""" d_r: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Radial speed :math:`dr/dt \in [-\infty, \infty].""" d_theta: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular speed"].constructor, dtype=float) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) r"""Inclination speed :math:`d\theta/dt \in [-\infty, \infty].""" d_phi: ct.BatchableAngularSpeed = eqx.field( - converter=partial(Quantity["angular speed"].constructor, dtype=float) + converter=partial(Quantity["angular speed"].from_, dtype=float) ) r"""Azimuthal speed :math:`d\phi/dt \in [-\infty, \infty].""" @@ -211,17 +211,17 @@ class SphericalAcceleration(AbstractSphericalAcceleration): """Spherical differential representation.""" d2_r: ct.BatchableAcc = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""Radial acceleration :math:`d^2r/dt^2 \in [-\infty, \infty].""" d2_theta: ct.BatchableAngularAcc = eqx.field( - converter=partial(Quantity["angular acceleration"].constructor, dtype=float) + converter=partial(Quantity["angular acceleration"].from_, dtype=float) ) r"""Inclination acceleration :math:`d^2\theta/dt^2 \in [-\infty, \infty].""" d2_phi: ct.BatchableAngularAcc = eqx.field( - converter=partial(Quantity["angular acceleration"].constructor, dtype=float) + converter=partial(Quantity["angular acceleration"].from_, dtype=float) ) r"""Azimuthal acceleration :math:`d^2\phi/dt^2 \in [-\infty, \infty].""" diff --git a/src/coordinax/_src/d3/transform.py b/src/coordinax/_src/d3/transform.py index 5c14c965..9dc03f4d 100644 --- a/src/coordinax/_src/d3/transform.py +++ b/src/coordinax/_src/d3/transform.py @@ -53,7 +53,7 @@ def represent_as( Cartesian to Cartesian: - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> cx.represent_as(vec, cx.CartesianPosition3D) is vec True @@ -118,11 +118,11 @@ def represent_as( For these transformations the position does not matter since the self-transform returns the velocity unchanged. - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") Cartesian to Cartesian velocity: - >>> dif = cx.CartesianVelocity3D.constructor([1, 2, 3], "km/s") + >>> dif = cx.CartesianVelocity3D.from_([1, 2, 3], "km/s") >>> cx.represent_as(dif, cx.CartesianVelocity3D, vec) is dif True @@ -185,7 +185,7 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "km") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "km") >>> print(cx.represent_as(vec, cx.CylindricalPosition)) @@ -207,7 +207,7 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "km") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "km") >>> print(cx.represent_as(vec, cx.SphericalPosition)) @@ -236,7 +236,7 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "km") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "km") >>> print(cx.represent_as(vec, cx.LonLatSphericalPosition)) CartD - posvec = current.integral_cls._cartesian_cls.constructor( # noqa: SLF001 + posvec = current.integral_cls._cartesian_cls.from_( # noqa: SLF001 position ) @@ -651,7 +651,7 @@ def represent_as( if isinstance(position, AbstractPosition): posvec = position else: # Q -> CartD - posvec = current.integral_cls._cartesian_cls.constructor( # noqa: SLF001 + posvec = current.integral_cls._cartesian_cls.from_( # noqa: SLF001 position ) @@ -679,7 +679,7 @@ def represent_as( if isinstance(position, AbstractPosition): posvec = position else: # Q -> CartD - posvec = current.integral_cls._cartesian_cls.constructor( # noqa: SLF001 + posvec = current.integral_cls._cartesian_cls.from_( # noqa: SLF001 position ) # Transform the differential to LonLatSphericalVelocity @@ -708,7 +708,7 @@ def represent_as( Examples -------- >>> import coordinax as cx - >>> v = cx.CartesianVelocity3D.constructor([1, 1, 1], "m/s") + >>> v = cx.CartesianVelocity3D.from_([1, 1, 1], "m/s") >>> cx.represent_as(v, cx.CartesianVelocity3D) is v True @@ -736,7 +736,7 @@ def represent_as( Examples -------- >>> import coordinax as cx - >>> a = cx.CartesianAcceleration3D.constructor([1, 1, 1], "m/s2") + >>> a = cx.CartesianAcceleration3D.from_([1, 1, 1], "m/s2") >>> cx.represent_as(a, cx.CartesianAcceleration3D) is a True diff --git a/src/coordinax/_src/d4/compat.py b/src/coordinax/_src/d4/compat.py index 4cca772c..96d856b4 100644 --- a/src/coordinax/_src/d4/compat.py +++ b/src/coordinax/_src/d4/compat.py @@ -44,7 +44,7 @@ def call(self: AbstractOperator, v4: FourVector, /) -> FourVector: We can then apply the operator to a position: - >>> pos = cx.FourVector.constructor([0, 1.0, 2.0, 3.0], "kpc") + >>> pos = cx.FourVector.from_([0, 1.0, 2.0, 3.0], "kpc") >>> pos FourVector( t=Quantity[PhysicalType('time')](...), q=CartesianPosition3D( ... ) ) @@ -87,4 +87,4 @@ def call( Quantity['length'](Array([0., 2., 4., 6.], dtype=float32), unit='kpc') """ - return convert(self(FourVector.constructor(x)), Quantity) + return convert(self(FourVector.from_(x)), Quantity) diff --git a/src/coordinax/_src/d4/spacetime.py b/src/coordinax/_src/d4/spacetime.py index c8cd9ad7..929b5679 100644 --- a/src/coordinax/_src/d4/spacetime.py +++ b/src/coordinax/_src/d4/spacetime.py @@ -64,7 +64,7 @@ class FourVector(AbstractPosition4D): Note that we used a shortcut to create the 3D vector by passing a ``(*batch, 3)`` array to the `q` argument. This assumes that `q` is a :class:`coordinax.CartesianPosition3D` and uses the - :meth:`coordinax.CartesianPosition3D.constructor` method to create the 3D vector. + :meth:`coordinax.CartesianPosition3D.from_` method to create the 3D vector. We can also create the 3D vector explicitly: @@ -75,12 +75,12 @@ class FourVector(AbstractPosition4D): """ t: BatchableTime | ScalarTime = eqx.field( - converter=partial(Quantity["time"].constructor, dtype=float) + converter=partial(Quantity["time"].from_, dtype=float) ) """Time coordinate.""" q: AbstractPosition3D = eqx.field( - converter=Unless(AbstractPosition3D, CartesianPosition3D.constructor) + converter=Unless(AbstractPosition3D, CartesianPosition3D.from_) ) """Spatial coordinates.""" @@ -102,8 +102,8 @@ def __check_init__(self) -> None: # Constructors @classmethod - @AbstractPosition4D.constructor._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 - def constructor( + @AbstractPosition4D.from_._f.dispatch # type: ignore[attr-defined, misc] # noqa: SLF001 + def from_( cls: "type[FourVector]", obj: Shaped[Quantity, "*batch 4"], / ) -> "FourVector": """Construct a vector from a Quantity array. @@ -123,7 +123,7 @@ def constructor( >>> import coordinax as cx >>> xs = Quantity([0, 1, 2, 3], "meter") # [ct, x, y, z] - >>> vec = cx.FourVector.constructor(xs) + >>> vec = cx.FourVector.from_(xs) >>> vec FourVector( t=Quantity[PhysicalType('time')](value=f32[], unit=Unit("m s / km")), @@ -131,7 +131,7 @@ def constructor( ) >>> xs = Quantity(jnp.array([[0, 1, 2, 3], [10, 4, 5, 6]]), "meter") - >>> vec = cx.FourVector.constructor(xs) + >>> vec = cx.FourVector.from_(xs) >>> vec FourVector( t=Quantity[PhysicalType('time')](value=f32[2], unit=Unit("m s / km")), @@ -242,11 +242,11 @@ def norm(self) -> BatchableLength: # ----------------------------------------------- -# Register additional constructors +# Register additional from_s -@FourVector.constructor._f.dispatch # type: ignore[misc] # noqa: SLF001 -def constructor( +@FourVector.from_._f.dispatch # type: ignore[misc] # noqa: SLF001 +def from_( cls: type[FourVector], obj: Shaped[AbstractQuantity, "*batch 3"], / ) -> FourVector: """Construct a 3D Cartesian position. @@ -256,7 +256,7 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> vec = cx.FourVector.constructor(Quantity([0, 1, 2, 3], "km")) + >>> vec = cx.FourVector.from_(Quantity([0, 1, 2, 3], "km")) >>> vec FourVector( t=Quantity[...](value=f32[], unit=Unit("s")), diff --git a/src/coordinax/_src/dn/base.py b/src/coordinax/_src/dn/base.py index 6b410b00..79706fa0 100644 --- a/src/coordinax/_src/dn/base.py +++ b/src/coordinax/_src/dn/base.py @@ -84,7 +84,7 @@ def shape(self) -> tuple[int, ...]: -------- >>> import coordinax as cx - >>> vec = cx.CartesianPositionND.constructor([[[1, 2]], [[3, 4]]], "m") + >>> vec = cx.CartesianPositionND.from_([[[1, 2]], [[3, 4]]], "m") >>> vec.shape (2, 1) @@ -99,7 +99,7 @@ def T(self) -> "Self": # noqa: N802 -------- >>> import coordinax as cx - >>> vec = cx.CartesianPositionND.constructor([[[1, 2]], [[3, 4]]], "m") + >>> vec = cx.CartesianPositionND.from_([[[1, 2]], [[3, 4]]], "m") >>> vec.shape (2, 1) @@ -121,7 +121,7 @@ def flatten(self) -> "Self": -------- >>> import coordinax as cx - >>> vec = cx.CartesianPositionND.constructor([[[1, 2]], [[3, 4]]], "m") + >>> vec = cx.CartesianPositionND.from_([[[1, 2]], [[3, 4]]], "m") >>> vec.shape (2, 1) @@ -138,7 +138,7 @@ def reshape(self, *shape: Any, order: str = "C") -> "Self": -------- >>> import coordinax as cx - >>> vec = cx.CartesianPositionND.constructor([[1, 2], [3, 4]], "m") + >>> vec = cx.CartesianPositionND.from_([[1, 2], [3, 4]], "m") >>> vec.shape (2,) @@ -192,7 +192,7 @@ def mT(self) -> "Self": # noqa: N802 -------- >>> import coordinax as cx - >>> vec = cx.CartesianVelocityND.constructor([[[1, 2]], [[3, 4]]], "m/s") + >>> vec = cx.CartesianVelocityND.from_([[[1, 2]], [[3, 4]]], "m/s") >>> vec.shape (2, 1) @@ -220,7 +220,7 @@ def shape(self) -> tuple[int, ...]: -------- >>> import coordinax as cx - >>> vec = cx.CartesianVelocityND.constructor([[1, 2], [3, 4]], "m/s") + >>> vec = cx.CartesianVelocityND.from_([[1, 2], [3, 4]], "m/s") >>> vec.shape (2,) @@ -235,7 +235,7 @@ def T(self) -> "Self": # noqa: N802 -------- >>> import coordinax as cx - >>> vec = cx.CartesianVelocityND.constructor([[[1, 2]], [[3, 4]]], "m/s") + >>> vec = cx.CartesianVelocityND.from_([[[1, 2]], [[3, 4]]], "m/s") >>> vec.shape (2, 1) @@ -257,7 +257,7 @@ def flatten(self) -> "Self": -------- >>> import coordinax as cx - >>> vec = cx.CartesianVelocityND.constructor([[1, 2], [3, 4]], "m/s") + >>> vec = cx.CartesianVelocityND.from_([[1, 2], [3, 4]], "m/s") >>> vec.flatten() CartesianVelocityND( d_q=Quantity[...]( value=f32[2,2], unit=Unit("m / s") ) diff --git a/src/coordinax/_src/dn/cartesian.py b/src/coordinax/_src/dn/cartesian.py index d6e4553c..9306e090 100644 --- a/src/coordinax/_src/dn/cartesian.py +++ b/src/coordinax/_src/dn/cartesian.py @@ -79,7 +79,7 @@ class CartesianPositionND(AbstractPositionND): """ q: ct.BatchableLength = eqx.field( - converter=partial(Quantity["length"].constructor, dtype=float) + converter=partial(Quantity["length"].from_, dtype=float) ) r"""N-D coordinate :math:`\vec{x} \in (-\infty,+\infty)`. @@ -123,8 +123,8 @@ def norm(self) -> ct.BatchableLength: # TODO: move to the class in py3.11+ -@CartesianPositionND.constructor._f.dispatch # type: ignore[attr-defined,misc] # noqa: SLF001 -def constructor( +@CartesianPositionND.from_._f.dispatch # type: ignore[attr-defined,misc] # noqa: SLF001 +def from_( cls: type[CartesianPositionND], x: Shaped[Quantity["length"], ""] | Shaped[Quantity["length"], "*batch N"], /, @@ -138,33 +138,33 @@ def constructor( 1D vector: - >>> cx.CartesianPositionND.constructor(Quantity(1, "kpc")) + >>> cx.CartesianPositionND.from_(Quantity(1, "kpc")) CartesianPositionND( q=Quantity[...](value=f32[1], unit=Unit("kpc")) ) - >>> cx.CartesianPositionND.constructor(Quantity([1], "kpc")) + >>> cx.CartesianPositionND.from_(Quantity([1], "kpc")) CartesianPositionND( q=Quantity[...](value=f32[1], unit=Unit("kpc")) ) 2D vector: - >>> cx.CartesianPositionND.constructor(Quantity([1, 2], "kpc")) + >>> cx.CartesianPositionND.from_(Quantity([1, 2], "kpc")) CartesianPositionND( q=Quantity[...](value=f32[2], unit=Unit("kpc")) ) 3D vector: - >>> cx.CartesianPositionND.constructor(Quantity([1, 2, 3], "kpc")) + >>> cx.CartesianPositionND.from_(Quantity([1, 2, 3], "kpc")) CartesianPositionND( q=Quantity[...](value=f32[3], unit=Unit("kpc")) ) 4D vector: - >>> cx.CartesianPositionND.constructor(Quantity([1, 2, 3, 4], "kpc")) + >>> cx.CartesianPositionND.from_(Quantity([1, 2, 3, 4], "kpc")) CartesianPositionND( q=Quantity[...](value=f32[4], unit=Unit("kpc")) ) @@ -203,8 +203,8 @@ def _add_vcnd( A 3D vector: - >>> q1 = cx.CartesianPositionND.constructor([1, 2, 3], "kpc") - >>> q2 = cx.CartesianPositionND.constructor([2, 3, 4], "kpc") + >>> q1 = cx.CartesianPositionND.from_([1, 2, 3], "kpc") + >>> q2 = cx.CartesianPositionND.from_([2, 3, 4], "kpc") >>> (q1 + q2).q Quantity['length'](Array([3., 5., 7.], dtype=float32), unit='kpc') @@ -335,7 +335,7 @@ class CartesianVelocityND(AvalMixin, AbstractVelocityND): """ d_q: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""N-D speed :math:`d\vec{x}/dt \in (-\infty, \infty). @@ -377,8 +377,8 @@ def norm(self, _: AbstractPositionND | None = None, /) -> ct.BatchableSpeed: # TODO: move to the class in py3.11+ -@CartesianVelocityND.constructor._f.dispatch # type: ignore[attr-defined,misc] # noqa: SLF001 -def constructor( +@CartesianVelocityND.from_._f.dispatch # type: ignore[attr-defined,misc] # noqa: SLF001 +def from_( cls: type[CartesianVelocityND], x: Shaped[Quantity["speed"], ""] | Shaped[Quantity["speed"], "*batch N"], /, @@ -392,33 +392,33 @@ def constructor( 1D vector: - >>> cx.CartesianVelocityND.constructor(Quantity(1, "km/s")) + >>> cx.CartesianVelocityND.from_(Quantity(1, "km/s")) CartesianVelocityND( d_q=Quantity[...]( value=f32[1], unit=Unit("km / s") ) ) - >>> cx.CartesianVelocityND.constructor(Quantity([1], "km/s")) + >>> cx.CartesianVelocityND.from_(Quantity([1], "km/s")) CartesianVelocityND( d_q=Quantity[...]( value=f32[1], unit=Unit("km / s") ) ) 2D vector: - >>> cx.CartesianVelocityND.constructor(Quantity([1, 2], "km/s")) + >>> cx.CartesianVelocityND.from_(Quantity([1, 2], "km/s")) CartesianVelocityND( d_q=Quantity[...]( value=f32[2], unit=Unit("km / s") ) ) 3D vector: - >>> cx.CartesianVelocityND.constructor(Quantity([1, 2, 3], "km/s")) + >>> cx.CartesianVelocityND.from_(Quantity([1, 2, 3], "km/s")) CartesianVelocityND( d_q=Quantity[...]( value=f32[3], unit=Unit("km / s") ) ) 4D vector: - >>> cx.CartesianVelocityND.constructor(Quantity([1, 2, 3, 4], "km/s")) + >>> cx.CartesianVelocityND.from_(Quantity([1, 2, 3, 4], "km/s")) CartesianVelocityND( d_q=Quantity[...]( value=f32[4], unit=Unit("km / s") ) ) @@ -483,7 +483,7 @@ class CartesianAccelerationND(AvalMixin, AbstractAccelerationND): """ d2_q: ct.BatchableAcc = eqx.field( - converter=partial(Quantity["acceleration"].constructor, dtype=float) + converter=partial(Quantity["acceleration"].from_, dtype=float) ) r"""N-D acceleration :math:`d\vec{x}/dt^2 \in (-\infty, \infty). @@ -551,8 +551,8 @@ def norm( # TODO: move to the class in py3.11+ -@CartesianAccelerationND.constructor._f.dispatch # type: ignore[attr-defined,misc] # noqa: SLF001 -def constructor( +@CartesianAccelerationND.from_._f.dispatch # type: ignore[attr-defined,misc] # noqa: SLF001 +def from_( cls: type[CartesianAccelerationND], x: Shaped[Quantity["acceleration"], ""] | Shaped[Quantity["acceleration"], "*batch N"], @@ -567,33 +567,33 @@ def constructor( 1D vector: - >>> cx.CartesianAccelerationND.constructor(Quantity(1, "km/s2")) + >>> cx.CartesianAccelerationND.from_(Quantity(1, "km/s2")) CartesianAccelerationND( d2_q=Quantity[...]( value=f32[1], unit=Unit("km / s2") ) ) - >>> cx.CartesianAccelerationND.constructor(Quantity([1], "km/s2")) + >>> cx.CartesianAccelerationND.from_(Quantity([1], "km/s2")) CartesianAccelerationND( d2_q=Quantity[...]( value=f32[1], unit=Unit("km / s2") ) ) 2D vector: - >>> cx.CartesianAccelerationND.constructor(Quantity([1, 2], "km/s2")) + >>> cx.CartesianAccelerationND.from_(Quantity([1, 2], "km/s2")) CartesianAccelerationND( d2_q=Quantity[...]( value=f32[2], unit=Unit("km / s2") ) ) 3D vector: - >>> cx.CartesianAccelerationND.constructor(Quantity([1, 2, 3], "km/s2")) + >>> cx.CartesianAccelerationND.from_(Quantity([1, 2, 3], "km/s2")) CartesianAccelerationND( d2_q=Quantity[...]( value=f32[3], unit=Unit("km / s2") ) ) 4D vector: - >>> cx.CartesianAccelerationND.constructor(Quantity([1, 2, 3, 4], "km/s2")) + >>> cx.CartesianAccelerationND.from_(Quantity([1, 2, 3, 4], "km/s2")) CartesianAccelerationND( d2_q=Quantity[...]( value=f32[4], unit=Unit("km / s2") ) ) diff --git a/src/coordinax/_src/dn/poincare.py b/src/coordinax/_src/dn/poincare.py index 54ec8974..08653497 100644 --- a/src/coordinax/_src/dn/poincare.py +++ b/src/coordinax/_src/dn/poincare.py @@ -20,7 +20,7 @@ class PoincarePolarVector(AbstractPosition): # TODO: better name """Poincare vector + differential.""" rho: ct.BatchableLength = eqx.field( - converter=partial(Quantity["length"].constructor, dtype=float) + converter=partial(Quantity["length"].from_, dtype=float) ) r"""Cylindrical radial distance :math:`\rho \in [0,+\infty)`.""" @@ -28,12 +28,12 @@ class PoincarePolarVector(AbstractPosition): # TODO: better name r"""Poincare phi-like variable.""" z: ct.BatchableLength = eqx.field( - converter=partial(Quantity["length"].constructor, dtype=float) + converter=partial(Quantity["length"].from_, dtype=float) ) r"""Height :math:`z \in (-\infty,+\infty)`.""" d_rho: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Cyindrical radial speed :math:`d\rho/dt \in [-\infty, \infty].""" @@ -41,7 +41,7 @@ class PoincarePolarVector(AbstractPosition): # TODO: better name r"""Poincare phi-like velocity variable.""" d_z: ct.BatchableSpeed = eqx.field( - converter=partial(Quantity["speed"].constructor, dtype=float) + converter=partial(Quantity["speed"].from_, dtype=float) ) r"""Vertical speed :math:`dz/dt \in [-\infty, \infty].""" diff --git a/src/coordinax/_src/dn/transform.py b/src/coordinax/_src/dn/transform.py index 1e73f12b..608ad70b 100644 --- a/src/coordinax/_src/dn/transform.py +++ b/src/coordinax/_src/dn/transform.py @@ -78,7 +78,7 @@ def represent_as( Examples -------- >>> import coordinax as cx - >>> v = cx.CartesianVelocityND.constructor([1, 1, 1], "m/s") + >>> v = cx.CartesianVelocityND.from_([1, 1, 1], "m/s") >>> cx.represent_as(v, cx.CartesianVelocityND) is v True @@ -106,7 +106,7 @@ def represent_as( Examples -------- >>> import coordinax as cx - >>> a = cx.CartesianAccelerationND.constructor([1, 1, 1], "m/s2") + >>> a = cx.CartesianAccelerationND.from_([1, 1, 1], "m/s2") >>> cx.represent_as(a, cx.CartesianAccelerationND) is a True diff --git a/src/coordinax/_src/exceptions.py b/src/coordinax/_src/exceptions.py index d7aa8d29..677fd8ad 100644 --- a/src/coordinax/_src/exceptions.py +++ b/src/coordinax/_src/exceptions.py @@ -15,7 +15,7 @@ class IrreversibleDimensionChange(UserWarning): >>> import warnings >>> import coordinax as cx - >>> vec = cx.CartesianPosition3D.constructor([1, 2, 3], "m") + >>> vec = cx.CartesianPosition3D.from_([1, 2, 3], "m") >>> with warnings.catch_warnings(record=True) as w: ... warnings.simplefilter("always") ... _ = vec.represent_as(cx.CartesianPosition2D) diff --git a/src/coordinax/_src/operators/base.py b/src/coordinax/_src/operators/base.py index 4fafca4a..023a07e8 100644 --- a/src/coordinax/_src/operators/base.py +++ b/src/coordinax/_src/operators/base.py @@ -26,7 +26,7 @@ class AbstractOperator(eqx.Module): # type: ignore[misc] @classmethod @dispatch # type: ignore[misc] - def constructor( + def from_( cls: "type[AbstractOperator]", obj: Mapping[str, Any], / ) -> "AbstractOperator": """Construct from a mapping. @@ -45,7 +45,7 @@ def constructor( -------- >>> import coordinax.operators as co >>> operators = co.IdentityOperator() | co.IdentityOperator() - >>> co.OperatorSequence.constructor({"operators": operators}) + >>> co.OperatorSequence.from_({"operators": operators}) OperatorSequence(operators=(IdentityOperator(), IdentityOperator())) """ @@ -104,10 +104,8 @@ def __or__(self, other: "AbstractOperator") -> "OperatorSequence": # TODO: move to the class in py3.11+ -@AbstractOperator.constructor._f.dispatch # type: ignore[misc] # noqa: SLF001 -def constructor( - cls: type[AbstractOperator], obj: AbstractOperator, / -) -> AbstractOperator: +@AbstractOperator.from_._f.dispatch # type: ignore[misc] # noqa: SLF001 +def from_(cls: type[AbstractOperator], obj: AbstractOperator, /) -> AbstractOperator: """Construct an operator from another operator. Parameters diff --git a/src/coordinax/_src/operators/composite.py b/src/coordinax/_src/operators/composite.py index 35b1ba2b..5c7b60f4 100644 --- a/src/coordinax/_src/operators/composite.py +++ b/src/coordinax/_src/operators/composite.py @@ -39,7 +39,7 @@ class AbstractCompositeOperator(AbstractOperator): # Operator # TODO: how to have the `operators` attribute in a way that allows for both - # writeable (in the constructor) and read-only (as a property) subclasses. + # writeable (in the from_) and read-only (as a property) subclasses. @op_call_dispatch(precedence=1) def __call__( diff --git a/src/coordinax/_src/operators/galilean/boost.py b/src/coordinax/_src/operators/galilean/boost.py index 6f4f59db..bcc3b240 100644 --- a/src/coordinax/_src/operators/galilean/boost.py +++ b/src/coordinax/_src/operators/galilean/boost.py @@ -39,7 +39,7 @@ class GalileanBoostOperator(AbstractGalileanOperator): ---------- velocity : :class:`vector.CartesianVelocity3D` The boost velocity. This parameters uses - :meth:`vector.CartesianVelocity3D.constructor` to enable a variety + :meth:`vector.CartesianVelocity3D.from_` to enable a variety of more convenient input types. See :class:`vector.CartesianVelocity3D` for details. @@ -59,20 +59,20 @@ class GalileanBoostOperator(AbstractGalileanOperator): Note that the velocity is a :class:`vector.CartesianVelocity3D`, which was constructed from a 1D array, using - :meth:`vector.CartesianVelocity3D.constructor`. We can also construct it + :meth:`vector.CartesianVelocity3D.from_`. We can also construct it directly: - >>> boost = cx.CartesianVelocity3D.constructor([1, 2, 3], "m/s") + >>> boost = cx.CartesianVelocity3D.from_([1, 2, 3], "m/s") >>> op = co.GalileanBoostOperator(boost) >>> op GalileanBoostOperator( velocity=CartesianVelocity3D( ... ) ) """ - velocity: CartesianVelocity3D = eqx.field(converter=CartesianVelocity3D.constructor) + velocity: CartesianVelocity3D = eqx.field(converter=CartesianVelocity3D.from_) """The boost velocity. - This parameters uses :meth:`vector.CartesianVelocity3D.constructor` to + This parameters uses :meth:`vector.CartesianVelocity3D.from_` to enable a variety of more convenient input types. See :class:`vector.CartesianVelocity3D` for details. """ @@ -129,7 +129,7 @@ def __call__( >>> op = GalileanBoostOperator(Quantity([1, 2, 3], "m/s")) - >>> q = cx.CartesianPosition3D.constructor([0, 0, 0], "m") + >>> q = cx.CartesianPosition3D.from_([0, 0, 0], "m") >>> t = Quantity(1, "s") >>> newq, newt = op(q, t) >>> newt diff --git a/src/coordinax/_src/operators/galilean/composite.py b/src/coordinax/_src/operators/galilean/composite.py index 2e96f316..69e7de43 100644 --- a/src/coordinax/_src/operators/galilean/composite.py +++ b/src/coordinax/_src/operators/galilean/composite.py @@ -107,7 +107,7 @@ class GalileanOperator(AbstractCompositeOperator, AbstractGalileanOperator): Galilean operators can be applied to :class:`vector.FourVector`: - >>> w = cx.FourVector.constructor([0, 0, 0, 0], "kpc") + >>> w = cx.FourVector.from_([0, 0, 0, 0], "kpc") >>> new = op(w) >>> new FourVector( @@ -122,7 +122,7 @@ class GalileanOperator(AbstractCompositeOperator, AbstractGalileanOperator): Also the Galilean operators can also be applied to :class:`vector.AbstractPosition3D` and :class:`unxt.Quantity`: - >>> q = cx.CartesianPosition3D.constructor([0, 0, 0], "kpc") + >>> q = cx.CartesianPosition3D.from_([0, 0, 0], "kpc") >>> t = Quantity(0, "Gyr") >>> newq, newt = op(q, t) >>> newq.x @@ -149,7 +149,7 @@ class GalileanOperator(AbstractCompositeOperator, AbstractGalileanOperator): The translation vector [T, Q]. This parameters accetps either a :class:`coordinax.operators.GalileanTranslationOperator` instance or any input that can be used to construct a :meth:`vector.FourVector`, using - :meth:`vector.FourVector.constructor`. See :class:`vector.FourVector` for + :meth:`vector.FourVector.from_`. See :class:`vector.FourVector` for details. """ @@ -163,7 +163,7 @@ class GalileanOperator(AbstractCompositeOperator, AbstractGalileanOperator): :class:`coordinax.operators.GalileanBoostOperator` instance or any input that can be used to construct a :class:`vector.CartesianVelocity3D`, using - :meth:`vector.CartesianVelocity3D.constructor`. See + :meth:`vector.CartesianVelocity3D.from_`. See :class:`vector.CartesianVelocity3D` for details. """ diff --git a/src/coordinax/_src/operators/galilean/rotation.py b/src/coordinax/_src/operators/galilean/rotation.py index 7452b9b1..a8c3da44 100644 --- a/src/coordinax/_src/operators/galilean/rotation.py +++ b/src/coordinax/_src/operators/galilean/rotation.py @@ -112,7 +112,7 @@ class GalileanRotationOperator(AbstractGalileanOperator): Translation operators can be applied to :class:`vector.AbstractPosition3D`: - >>> q = cx.CartesianPosition3D.constructor(q) # from the previous example + >>> q = cx.CartesianPosition3D.from_(q) # from the previous example >>> newq, newt = op(q, t) >>> newq.x Quantity['length'](Array([ 0.70710677, -0.70710677], dtype=float32), unit='m') @@ -238,7 +238,7 @@ def __call__( ... [0, 0, 1]]) >>> op = GalileanRotationOperator(Rz) - >>> q = cx.CartesianPosition3D.constructor([1, 0, 0], "m") + >>> q = cx.CartesianPosition3D.from_([1, 0, 0], "m") >>> t = Quantity(1, "s") >>> newq, newt = op(q, t) >>> newq.x @@ -253,7 +253,7 @@ def __call__( q.represent_as(CartesianPosition3D).to_units(ToUnitsOptions.consistent), Quantity, ) - rcart = CartesianPosition3D.constructor(vec_matmul(self.rotation, vec)) + rcart = CartesianPosition3D.from_(vec_matmul(self.rotation, vec)) return rcart.represent_as(type(q)) @op_call_dispatch(precedence=1) diff --git a/src/coordinax/_src/operators/galilean/translation.py b/src/coordinax/_src/operators/galilean/translation.py index a2ff5344..a93a37f3 100644 --- a/src/coordinax/_src/operators/galilean/translation.py +++ b/src/coordinax/_src/operators/galilean/translation.py @@ -41,11 +41,11 @@ def _converter_spatialtranslation(x: Any) -> AbstractPosition: shape: tuple[int, ...] = x.shape match shape: case (1,): - out = CartesianPosition1D.constructor(x) + out = CartesianPosition1D.from_(x) case (2,): - out = CartesianPosition2D.constructor(x) + out = CartesianPosition2D.from_(x) case (3,): - out = CartesianPosition3D.constructor(x) + out = CartesianPosition3D.from_(x) case _: msg = f"Cannot convert {x} to a spatial translation vector." raise TypeError(msg) @@ -72,7 +72,7 @@ class GalileanSpatialTranslationOperator(AbstractGalileanOperator): translation : :class:`vector.AbstractPosition3D` The spatial translation vector. This parameters accepts either a :class:`vector.AbstractPosition3D` instance or uses - :meth:`vector.CartesianPosition3D.constructor` to enable a variety of more + :meth:`vector.CartesianPosition3D.from_` to enable a variety of more convenient input types to create a Cartesian vector. See :class:`vector.CartesianPosition3D` for details. @@ -93,7 +93,7 @@ class GalileanSpatialTranslationOperator(AbstractGalileanOperator): Note that the translation is a :class:`vector.CartesianPosition3D`, which was constructed from a 1D array, using - :meth:`vector.CartesianPosition3D.constructor`. We can also construct it + :meth:`vector.CartesianPosition3D.from_`. We can also construct it directly, which allows for other vector types. >>> shift = cx.SphericalPosition(r=Quantity(1.0, "kpc"), @@ -105,7 +105,7 @@ class GalileanSpatialTranslationOperator(AbstractGalileanOperator): Translation operators can be applied to :class:`vector.AbstractPosition`: - >>> q = cx.CartesianPosition3D.constructor([0, 0, 0], "kpc") + >>> q = cx.CartesianPosition3D.from_([0, 0, 0], "kpc") >>> op(q) CartesianPosition3D( ... ) @@ -126,7 +126,7 @@ class GalileanSpatialTranslationOperator(AbstractGalileanOperator): >>> op(q) Quantity['length'](Array([1.], dtype=float32), unit='kpc') - >>> vec = cx.CartesianPosition1D.constructor(q).represent_as(cx.RadialPosition) + >>> vec = cx.CartesianPosition1D.from_(q).represent_as(cx.RadialPosition) >>> op(vec) RadialPosition(r=Distance(value=f32[], unit=Unit("kpc"))) @@ -138,7 +138,7 @@ class GalileanSpatialTranslationOperator(AbstractGalileanOperator): >>> op(q) Quantity['length'](Array([1., 2.], dtype=float32), unit='kpc') - >>> vec = cx.CartesianPosition2D.constructor(q).represent_as(cx.PolarPosition) + >>> vec = cx.CartesianPosition2D.from_(q).represent_as(cx.PolarPosition) >>> op(vec) PolarPosition( r=Distance(value=f32[], unit=Unit("kpc")), phi=Quantity[...](value=f32[], unit=Unit("rad")) ) @@ -151,7 +151,7 @@ class GalileanSpatialTranslationOperator(AbstractGalileanOperator): >>> op(q) Quantity['length'](Array([1., 2., 3.], dtype=float32), unit='kpc') - >>> vec = cx.CartesianPosition3D.constructor(q).represent_as(cx.SphericalPosition) + >>> vec = cx.CartesianPosition3D.from_(q).represent_as(cx.SphericalPosition) >>> op(vec) SphericalPosition( r=Distance(value=f32[], unit=Unit("kpc")), theta=Quantity[...](value=f32[], unit=Unit("rad")), @@ -170,9 +170,9 @@ class GalileanSpatialTranslationOperator(AbstractGalileanOperator): """The spatial translation. This parameters accepts either a :class:`vector.AbstracVector` instance or - uses a Cartesian vector constructor to enable a variety of more convenient + uses a Cartesian vector from_ to enable a variety of more convenient input types to create a Cartesian vector. See - :class:`vector.CartesianPosition3D.constructor` for an example when doing a 3D + :class:`vector.CartesianPosition3D.from_` for an example when doing a 3D translation. """ @@ -181,7 +181,7 @@ class GalileanSpatialTranslationOperator(AbstractGalileanOperator): @override @classmethod @dispatch - def constructor( + def from_( cls: "type[GalileanSpatialTranslationOperator]", x: ArrayLike | list[float | int], unit: str, # TODO: support unit object @@ -194,17 +194,17 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> op = cx.operators.GalileanSpatialTranslationOperator.constructor([1, 1, 1], "kpc") + >>> op = cx.operators.GalileanSpatialTranslationOperator.from_([1, 1, 1], "kpc") >>> op.translation.x Quantity['length'](Array(1., dtype=float32), unit='kpc') - """ # noqa: E501 + """ return cls(Quantity(x, unit)) @override @classmethod @dispatch - def constructor( + def from_( cls: "type[GalileanSpatialTranslationOperator]", x: ArrayLike | list[float | int], *, @@ -217,11 +217,11 @@ def constructor( >>> from unxt import Quantity >>> import coordinax as cx - >>> op = cx.operators.GalileanSpatialTranslationOperator.constructor([1, 1, 1], "kpc") + >>> op = cx.operators.GalileanSpatialTranslationOperator.from_([1, 1, 1], "kpc") >>> op.translation.x Quantity['length'](Array(1., dtype=float32), unit='kpc') - """ # noqa: E501 + """ return cls(Quantity(x, unit)) # ------------------------------------------- @@ -236,7 +236,7 @@ def is_inertial(self) -> Literal[True]: >>> import coordinax as cx >>> from coordinax.operators import GalileanSpatialTranslationOperator - >>> shift = cx.CartesianPosition3D.constructor([1, 1, 1], "kpc") + >>> shift = cx.CartesianPosition3D.from_([1, 1, 1], "kpc") >>> op = GalileanSpatialTranslationOperator(shift) >>> op.is_inertial @@ -255,7 +255,7 @@ def inverse(self) -> "GalileanSpatialTranslationOperator": >>> import coordinax as cx >>> from coordinax.operators import GalileanSpatialTranslationOperator - >>> shift = cx.CartesianPosition3D.constructor([1, 1, 1], "kpc") + >>> shift = cx.CartesianPosition3D.from_([1, 1, 1], "kpc") >>> op = GalileanSpatialTranslationOperator(shift) >>> op.inverse @@ -281,10 +281,10 @@ def __call__( >>> import coordinax as cx >>> from coordinax.operators import GalileanSpatialTranslationOperator - >>> shift = cx.CartesianPosition3D.constructor([1, 1, 1], "kpc") + >>> shift = cx.CartesianPosition3D.from_([1, 1, 1], "kpc") >>> op = GalileanSpatialTranslationOperator(shift) - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> t = Quantity(0, "Gyr") >>> newq = op(q) >>> newq.x @@ -308,10 +308,10 @@ def __call__( >>> import coordinax as cx >>> from coordinax.operators import GalileanSpatialTranslationOperator - >>> shift = cx.CartesianPosition3D.constructor([1, 1, 1], "kpc") + >>> shift = cx.CartesianPosition3D.from_([1, 1, 1], "kpc") >>> op = GalileanSpatialTranslationOperator(shift) - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> t = Quantity(0, "Gyr") >>> newq, newt = op(q, t) >>> newq.x @@ -365,7 +365,7 @@ class GalileanTranslationOperator(AbstractGalileanOperator): ---------- translation : :class:`vector.FourVector` The translation vector [T, Q]. This parameters uses - :meth:`vector.FourVector.constructor` to enable a variety of more + :meth:`vector.FourVector.from_` to enable a variety of more convenient input types. See :class:`vector.FourVector` for details. Examples @@ -388,7 +388,7 @@ class GalileanTranslationOperator(AbstractGalileanOperator): ) Note that the translation is a :class:`vector.FourVector`, which was - constructed from a 1D array, using :meth:`vector.FourVector.constructor`. We + constructed from a 1D array, using :meth:`vector.FourVector.from_`. We can also construct it directly, which allows for other vector types. >>> qshift = cx.SphericalPosition(r=Quantity(1.0, "kpc"), @@ -404,7 +404,7 @@ class GalileanTranslationOperator(AbstractGalileanOperator): Translation operators can be applied to :class:`vector.FourVector`: - >>> w = FourVector.constructor([0, 0, 0, 0], "kpc") + >>> w = FourVector.from_([0, 0, 0, 0], "kpc") >>> op(w) FourVector( t=Quantity[PhysicalType('time')](value=f32[], unit=Unit("kpc s / km")), @@ -413,7 +413,7 @@ class GalileanTranslationOperator(AbstractGalileanOperator): Also to :class:`vector.AbstractPosition3D` and :class:`unxt.Quantity`: - >>> q = cx.CartesianPosition3D.constructor([0, 0, 0], "kpc") + >>> q = cx.CartesianPosition3D.from_([0, 0, 0], "kpc") >>> t = Quantity(0, "Gyr") >>> newq, newt = op(q, t) >>> newq.x @@ -423,11 +423,11 @@ class GalileanTranslationOperator(AbstractGalileanOperator): """ - translation: FourVector = eqx.field(converter=FourVector.constructor) + translation: FourVector = eqx.field(converter=FourVector.from_) """The temporal + spatial translation. The translation vector [T, Q]. This parameters uses - :meth:`vector.FourVector.constructor` to enable a variety of more convenient + :meth:`vector.FourVector.from_` to enable a variety of more convenient input types. See :class:`vector.FourVector` for details. """ @@ -443,7 +443,7 @@ def is_inertial(self) -> Literal[True]: >>> import coordinax as cx >>> from coordinax.operators import GalileanTranslationOperator - >>> shift = cx.FourVector.constructor([0, 1, 1, 1], "kpc") + >>> shift = cx.FourVector.from_([0, 1, 1, 1], "kpc") >>> op = GalileanTranslationOperator(shift) >>> op.is_inertial @@ -462,7 +462,7 @@ def inverse(self) -> "GalileanTranslationOperator": >>> import coordinax as cx >>> from coordinax.operators import GalileanSpatialTranslationOperator - >>> qshift = cx.CartesianPosition3D.constructor([1, 1, 1], "kpc") + >>> qshift = cx.CartesianPosition3D.from_([1, 1, 1], "kpc") >>> tshift = Quantity(1, "Gyr") >>> shift = FourVector(tshift, qshift) >>> op = GalileanTranslationOperator(shift) @@ -490,15 +490,15 @@ def __call__(self: "GalileanTranslationOperator", x: FourVector, /) -> FourVecto Explicitly construct the translation operator: - >>> qshift = cx.CartesianPosition3D.constructor([1, 1, 1], "kpc") + >>> qshift = cx.CartesianPosition3D.from_([1, 1, 1], "kpc") >>> tshift = Quantity(1, "Gyr") >>> shift = FourVector(tshift, qshift) >>> op = GalileanTranslationOperator(shift) - Construct a vector to translate, using the convenience constructor (the + Construct a vector to translate, using the convenience from_ (the 0th component is :math:`c * t`, the rest are spatial components): - >>> w = cx.FourVector.constructor([0, 1, 2, 3], "kpc") + >>> w = cx.FourVector.from_([0, 1, 2, 3], "kpc") >>> w.t Quantity['time'](Array(0., dtype=float32), unit='kpc s / km') @@ -531,14 +531,14 @@ def __call__( Explicitly construct the translation operator: - >>> qshift = cx.CartesianPosition3D.constructor([1, 1, 1], "kpc") + >>> qshift = cx.CartesianPosition3D.from_([1, 1, 1], "kpc") >>> tshift = Quantity(1, "Gyr") >>> shift = cx.FourVector(tshift, qshift) >>> op = GalileanTranslationOperator(shift) Construct a vector to translate - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> t = Quantity(1, "Gyr") >>> newq, newt = op(q, t) diff --git a/src/coordinax/_src/operators/identity.py b/src/coordinax/_src/operators/identity.py index 3f960a37..c10de039 100644 --- a/src/coordinax/_src/operators/identity.py +++ b/src/coordinax/_src/operators/identity.py @@ -35,7 +35,7 @@ class IdentityOperator(AbstractOperator): And the common objects we will use: >>> q = Quantity([1, 2, 3], "kpc") - >>> vec = cx.CartesianPosition3D.constructor(q) + >>> vec = cx.CartesianPosition3D.from_(q) The first call signature is for the case where the input is a vector: @@ -52,28 +52,28 @@ class IdentityOperator(AbstractOperator): - 1D: >>> q = Quantity([1], "kpc") - >>> vec = cx.CartesianPosition1D.constructor(q) + >>> vec = cx.CartesianPosition1D.from_(q) >>> op(vec) is vec and op(q) is q True - 2D: >>> q = Quantity([1, 2], "kpc") - >>> vec = cx.CartesianPosition2D.constructor(q) + >>> vec = cx.CartesianPosition2D.from_(q) >>> op(vec) is vec and op(q) is q True - 3D (not using a `~coordinax.CartesianPosition3D` instance): >>> q = Quantity([1, 2, 3], "kpc") - >>> vec = cx.CartesianPosition3D.constructor(q).represent_as(cx.SphericalPosition) + >>> vec = cx.CartesianPosition3D.from_(q).represent_as(cx.SphericalPosition) >>> op(vec) is vec and op(q) is q True - 4D: >>> q = Quantity([1, 2, 3, 4], "kpc") # 0th elt is ct - >>> vec4 = cx.FourVector.constructor(q) + >>> vec4 = cx.FourVector.from_(q) >>> op(vec4) is vec4 and op(q) is q True @@ -100,7 +100,7 @@ def is_inertial(self) -> Literal[True]: >>> import coordinax as cx >>> from coordinax.operators import IdentityOperator - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> t = Quantity(0, "Gyr") >>> op = IdentityOperator() >>> op.is_inertial @@ -143,7 +143,7 @@ def __call__(self: "IdentityOperator", x: AbstractPosition, /) -> AbstractPositi >>> import coordinax as cx >>> from coordinax.operators import IdentityOperator - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") >>> op = IdentityOperator() >>> op(q) is q True diff --git a/src/coordinax/_src/space.py b/src/coordinax/_src/space.py index 7870bcf6..b3071b31 100644 --- a/src/coordinax/_src/space.py +++ b/src/coordinax/_src/space.py @@ -69,9 +69,9 @@ class Space(ImmutableMap[Dimension, AbstractVector], AbstractVector): # type: i >>> import coordinax as cx >>> from unxt import Quantity - >>> x = cx.CartesianPosition3D.constructor([1, 2, 3], "km") - >>> v = cx.CartesianVelocity3D.constructor([4, 5, 6], "km/s") - >>> a = cx.CartesianAcceleration3D.constructor([7, 8, 9], "km/s^2") + >>> x = cx.CartesianPosition3D.from_([1, 2, 3], "km") + >>> v = cx.CartesianVelocity3D.from_([4, 5, 6], "km/s") + >>> a = cx.CartesianAcceleration3D.from_([7, 8, 9], "km/s^2") >>> space = cx.Space(length=x, speed=v, acceleration=a) >>> space @@ -139,8 +139,8 @@ def __getitem__(self, key: Any) -> Any: Examples -------- >>> import coordinax as cx - >>> w = cx.Space(length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s")) + >>> w = cx.Space(length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s")) By number: @@ -211,8 +211,8 @@ def __getitem__(self, key: str | Dimension) -> Any: Examples -------- >>> import coordinax as cx - >>> w = cx.Space(length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s")) + >>> w = cx.Space(length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s")) By string key: @@ -262,8 +262,8 @@ def mT(self) -> "Self": # noqa: N802 >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... ) >>> w.mT Space({ @@ -277,7 +277,7 @@ def mT(self) -> "Self": # noqa: N802 d_z=Quantity[...]( value=f32[2,1], unit=Unit("m / s") ) )} ) - """ # noqa: E501 + """ return super().mT @property @@ -290,13 +290,13 @@ def ndim(self) -> int: >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") ) + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ) >>> w.ndim 2 - """ # noqa: E501 + """ return super().ndim @property @@ -309,14 +309,14 @@ def shape(self) -> tuple[int, ...]: >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... ) >>> w.shape (1, 2) - """ # noqa: E501 + """ return super().shape @property @@ -329,13 +329,13 @@ def size(self) -> int: >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") ) + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ) >>> w.size 2 - """ # noqa: E501 + """ return super().size @property @@ -348,8 +348,8 @@ def T(self) -> "Self": # noqa: N802 >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... ) >>> w.T @@ -365,7 +365,7 @@ def T(self) -> "Self": # noqa: N802 d_z=Quantity[...]( value=f32[2,1], unit=Unit("m / s") ) )} ) - """ # noqa: E501 + """ return super().T # --------------------------------------------------------------- @@ -380,14 +380,14 @@ def __neg__(self) -> "Self": >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... ) >>> (-w)["length"].x Quantity['length'](Array([[-1., -4.]], dtype=float32), unit='m') - """ # noqa: E501 + """ return type(self)(**{k: -v for k, v in self.items()}) def __repr__(self) -> str: @@ -398,8 +398,8 @@ def __repr__(self) -> str: >>> import coordinax as cx >>> from unxt import Quantity - >>> q = cx.CartesianPosition3D.constructor([1, 2, 3], "m") - >>> p = cx.CartesianVelocity3D.constructor([1, 2, 3], "m/s") + >>> q = cx.CartesianPosition3D.from_([1, 2, 3], "m") + >>> p = cx.CartesianVelocity3D.from_([1, 2, 3], "m/s") >>> w = cx.Space(length=q, speed=p) >>> w Space({ @@ -474,8 +474,8 @@ def dtypes(self) -> MappingProxyType[str, MappingProxyType[str, jnp.dtype]]: >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... ) >>> w.dtypes @@ -496,8 +496,8 @@ def devices(self) -> MappingProxyType[str, MappingProxyType[str, Device]]: >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... ) >>> w.devices @@ -518,14 +518,14 @@ def shapes(self) -> MappingProxyType[str, MappingProxyType[str, tuple[int, ...]] >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... ) >>> w.shapes mappingproxy({'length': (1, 2), 'speed': (1, 2)}) - """ # noqa: E501 + """ return MappingProxyType({k: v.shape for k, v in self.items()}) @property @@ -538,14 +538,14 @@ def sizes(self) -> MappingProxyType[str, int]: >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... ) >>> w.sizes mappingproxy({'length': 2, 'speed': 2}) - """ # noqa: E501 + """ return MappingProxyType({k: v.size for k, v in self.items()}) # =============================================================== diff --git a/src/coordinax/_src/transform/accelerations.py b/src/coordinax/_src/transform/accelerations.py index 7a194aee..b03a3c5f 100644 --- a/src/coordinax/_src/transform/accelerations.py +++ b/src/coordinax/_src/transform/accelerations.py @@ -86,9 +86,9 @@ def represent_as( Now in 2D: - >>> q = cx.CartesianPosition2D.constructor([1.0, 2.0], "km") - >>> p = cx.CartesianVelocity2D.constructor([1.0, 2.0], "km/s") - >>> a = cx.CartesianAcceleration2D.constructor([1.0, 2.0], "km/s2") + >>> q = cx.CartesianPosition2D.from_([1.0, 2.0], "km") + >>> p = cx.CartesianVelocity2D.from_([1.0, 2.0], "km/s") + >>> a = cx.CartesianAcceleration2D.from_([1.0, 2.0], "km/s2") >>> cx.represent_as(a, cx.PolarAcceleration, p, q) PolarAcceleration( d2_r=Quantity[...](value=f32[], unit=Unit("km / s2")), @@ -97,9 +97,9 @@ def represent_as( And in 3D: - >>> q = cx.CartesianPosition3D.constructor([1.0, 2.0, 3.0], "km") - >>> p = cx.CartesianVelocity3D.constructor([1.0, 2.0, 3.0], "km/s") - >>> a = cx.CartesianAcceleration3D.constructor([1.0, 2.0, 3.0], "km/s2") + >>> q = cx.CartesianPosition3D.from_([1.0, 2.0, 3.0], "km") + >>> p = cx.CartesianVelocity3D.from_([1.0, 2.0, 3.0], "km/s") + >>> a = cx.CartesianAcceleration3D.from_([1.0, 2.0, 3.0], "km/s2") >>> cx.represent_as(a, cx.SphericalAcceleration, p, q) SphericalAcceleration( d2_r=Quantity[...](value=f32[], unit=Unit("km / s2")), @@ -128,7 +128,7 @@ def represent_as( if isinstance(position, AbstractPosition): posvec = position else: # Q -> CartD - posvec = current.integral_cls.integral_cls._cartesian_cls.constructor( # noqa: SLF001 + posvec = current.integral_cls.integral_cls._cartesian_cls.from_( # noqa: SLF001 position ) @@ -136,7 +136,7 @@ def represent_as( if isinstance(velocity, AbstractVelocity): velvec = velocity else: # Q -> CartD - velvec = current.integral_cls._cartesian_cls.constructor( # noqa: SLF001 + velvec = current.integral_cls._cartesian_cls.from_( # noqa: SLF001 velocity ) diff --git a/src/coordinax/_src/transform/d1.py b/src/coordinax/_src/transform/d1.py index ce7525d6..2c0bf6f1 100644 --- a/src/coordinax/_src/transform/d1.py +++ b/src/coordinax/_src/transform/d1.py @@ -201,7 +201,7 @@ def represent_as( """ x, theta, phi = jnp.broadcast_arrays(current.x, theta, phi) - return target.constructor(r=x, theta=theta, phi=phi) + return target.from_(r=x, theta=theta, phi=phi) @dispatch @@ -427,7 +427,7 @@ def represent_as( """ r, theta, phi = jnp.broadcast_arrays(current.r, theta, phi) - return target.constructor(r=r, theta=theta, phi=phi) + return target.from_(r=r, theta=theta, phi=phi) @dispatch diff --git a/src/coordinax/_src/transform/d2.py b/src/coordinax/_src/transform/d2.py index 697a000b..dd169370 100644 --- a/src/coordinax/_src/transform/d2.py +++ b/src/coordinax/_src/transform/d2.py @@ -46,7 +46,7 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.CartesianPosition2D.constructor([1.0, 2.0], "km") + >>> x = cx.CartesianPosition2D.from_([1.0, 2.0], "km") >>> x2 = cx.represent_as(x, cx.CylindricalPosition, z=Quantity(14, "km")) >>> x2 @@ -136,7 +136,7 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.CartesianPosition2D.constructor([1.0, 2.0], "km") + >>> x = cx.CartesianPosition2D.from_([1.0, 2.0], "km") >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") @@ -164,7 +164,7 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.CartesianPosition2D.constructor([1.0, 2.0], "km") + >>> x = cx.CartesianPosition2D.from_([1.0, 2.0], "km") >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") @@ -202,7 +202,7 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.CartesianPosition2D.constructor([1.0, 2.0], "km") + >>> x = cx.CartesianPosition2D.from_([1.0, 2.0], "km") >>> x2 = cx.represent_as(x, cx.CartesianPosition3D, z=Quantity(14, "km")) >>> x2 @@ -307,7 +307,7 @@ def represent_as( Quantity['angle'](Array(14., dtype=float32), unit='deg') """ - return target.constructor(r=current.r, theta=theta, phi=current.phi) + return target.from_(r=current.r, theta=theta, phi=current.phi) @dispatch @@ -336,7 +336,7 @@ def represent_as( Quantity['angle'](Array(14., dtype=float32), unit='deg') """ - return target.constructor(r=current.r, phi=phi, theta=current.phi) + return target.from_(r=current.r, phi=phi, theta=current.phi) @dispatch diff --git a/src/coordinax/_src/transform/d3.py b/src/coordinax/_src/transform/d3.py index a94e0fbf..a6eb1770 100644 --- a/src/coordinax/_src/transform/d3.py +++ b/src/coordinax/_src/transform/d3.py @@ -42,7 +42,7 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.CartesianPosition3D.constructor([1.0, 2.0, 3.0], "km") + >>> x = cx.CartesianPosition3D.from_([1.0, 2.0, 3.0], "km") >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") @@ -69,7 +69,7 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.CartesianPosition3D.constructor([1.0, 2.0, 3.0], "km") + >>> x = cx.CartesianPosition3D.from_([1.0, 2.0, 3.0], "km") >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") @@ -98,7 +98,7 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.CartesianPosition3D.constructor([1.0, 2.0, 3.0], "km") + >>> x = cx.CartesianPosition3D.from_([1.0, 2.0, 3.0], "km") >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") @@ -126,7 +126,7 @@ def represent_as( >>> from unxt import Quantity >>> import coordinax as cx - >>> x = cx.CartesianPosition3D.constructor([1.0, 2.0, 3.0], "km") + >>> x = cx.CartesianPosition3D.from_([1.0, 2.0, 3.0], "km") >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore") diff --git a/src/coordinax/_src/transform/differentials.py b/src/coordinax/_src/transform/differentials.py index abe9d0aa..24dcf44d 100644 --- a/src/coordinax/_src/transform/differentials.py +++ b/src/coordinax/_src/transform/differentials.py @@ -75,8 +75,8 @@ def represent_as( Now in 2D: - >>> q = cx.CartesianPosition2D.constructor([1.0, 2.0], "km") - >>> p = cx.CartesianVelocity2D.constructor([1.0, 2.0], "km/s") + >>> q = cx.CartesianPosition2D.from_([1.0, 2.0], "km") + >>> p = cx.CartesianVelocity2D.from_([1.0, 2.0], "km/s") >>> cx.represent_as(p, cx.PolarVelocity, q) PolarVelocity( d_r=Quantity[...]( value=f32[], unit=Unit("km / s") ), @@ -85,8 +85,8 @@ def represent_as( And in 3D: - >>> q = cx.CartesianPosition3D.constructor([1.0, 2.0, 3.0], "km") - >>> p = cx.CartesianVelocity3D.constructor([1.0, 2.0, 3.0], "km/s") + >>> q = cx.CartesianPosition3D.from_([1.0, 2.0, 3.0], "km") + >>> p = cx.CartesianVelocity3D.from_([1.0, 2.0, 3.0], "km/s") >>> cx.represent_as(p, cx.SphericalVelocity, q) SphericalVelocity( d_r=Quantity[...]( value=f32[], unit=Unit("km / s") ), @@ -97,7 +97,7 @@ def represent_as( If given a position as a Quantity, it will be converted to the appropriate Cartesian vector: - >>> p = cx.CartesianVelocity3D.constructor([1.0, 2.0, 3.0], "km/s") + >>> p = cx.CartesianVelocity3D.from_([1.0, 2.0, 3.0], "km/s") >>> cx.represent_as(p, cx.SphericalVelocity, Quantity([1.0, 2.0, 3.0], "km")) SphericalVelocity( d_r=Quantity[...]( value=f32[], unit=Unit("km / s") ), @@ -114,7 +114,7 @@ def represent_as( if isinstance(position, AbstractPosition): posvec = position else: # Q -> CartD - posvec = current.integral_cls._cartesian_cls.constructor( # noqa: SLF001 + posvec = current.integral_cls._cartesian_cls.from_( # noqa: SLF001 position ) diff --git a/src/coordinax/_src/transform/dn.py b/src/coordinax/_src/transform/dn.py index 717e0709..03295039 100644 --- a/src/coordinax/_src/transform/dn.py +++ b/src/coordinax/_src/transform/dn.py @@ -25,8 +25,8 @@ def represent_as(w: PoincarePolarVector, target: type[Space], /) -> Space: >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... ) >>> cx.represent_as(w, cx.PoincarePolarVector) diff --git a/src/coordinax/_src/transform/space.py b/src/coordinax/_src/transform/space.py index a1008da8..2f88cf5a 100644 --- a/src/coordinax/_src/transform/space.py +++ b/src/coordinax/_src/transform/space.py @@ -25,8 +25,8 @@ def represent_as(w: Space, target: type[Space]) -> Space: >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... ) >>> cx.represent_as(w, cx.Space) @@ -48,8 +48,8 @@ def represent_as(w: Space, target: type[PoincarePolarVector], /) -> PoincarePola >>> from unxt import Quantity >>> w = cx.Space( - ... length=cx.CartesianPosition3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m"), - ... speed=cx.CartesianVelocity3D.constructor([[[1, 2, 3], [4, 5, 6]]], "m/s") + ... length=cx.CartesianPosition3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), + ... speed=cx.CartesianVelocity3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... ) >>> cx.represent_as(w, cx.PoincarePolarVector) diff --git a/tests/test_jax_ops.py b/tests/test_jax_ops.py index 886c1ee7..6d9062b1 100644 --- a/tests/test_jax_ops.py +++ b/tests/test_jax_ops.py @@ -18,7 +18,7 @@ @pytest.fixture(params=POSITION_CLASSES_3D) def q(request) -> cx.AbstractPosition: """Fixture for 3D Vectors.""" - q = cx.CartesianPosition3D.constructor([1, 2, 3], "kpc") + q = cx.CartesianPosition3D.from_([1, 2, 3], "kpc") return q.represent_as(request.param)