coordinax library#
coordinax: Coordinates in JAX.
- class coordinax.Distance(value: Any, unit: Any, *, check_negative: bool = True)
Bases:
AbstractDistanceDistance quantities.
The distance is a quantity with dimensions of length.
Examples
>>> from coordinax.distance import Distance >>> Distance(10, "km") Distance(Array(10, dtype=int32, ...), unit='km')
The units are checked to have length dimensions.
>>> try: Distance(10, "s") ... except ValueError as e: print(e) Distance must have dimensions length.
- property T: AbstractQuantity
Transpose of the array.
Examples
>>> import unxt as u >>> q = u.Quantity([[0, 1], [1, 2]], "m") >>> q.T Quantity(Array([[0, 1], [1, 2]], dtype=int32), unit='m')
- argmax(*args: Any, **kwargs: Any)
Return the indices of the maximum value.
Examples
>>> import unxt as u >>> q = u.Quantity([1, 2, 3], "m") >>> q.argmax() Array(2, dtype=int32)
- argmin(*args: Any, **kwargs: Any)
Return the indices of the minimum value.
Examples
>>> import unxt as u >>> q = u.Quantity([1, 2, 3], "m") >>> q.argmin() Array(0, dtype=int32)
- astype(*args: Any, **kwargs: Any)
Copy the array and cast to a specified dtype.
Examples
>>> import unxt as u >>> q = u.Quantity([1, 2, 3], "m") >>> q.dtype dtype('int32')
>>> q.astype(float) Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
- Parameters:
- Return type:
- property at: _QuantityIndexUpdateHelper
Helper property for index update functionality.
The
atproperty provides a functionally pure equivalent of in-place array modifications.In particular:
Alternate syntax
Equivalent In-place expression
x = x.at[idx].set(y)x[idx] = yx = x.at[idx].add(y)x[idx] += yx = x.at[idx].subtract(y)x[idx] -= yx = x.at[idx].multiply(y)x[idx] *= yx = x.at[idx].divide(y)x[idx] /= yx = x.at[idx].power(y)x[idx] **= yx = x.at[idx].min(y)x[idx] = minimum(x[idx], y)x = x.at[idx].max(y)x[idx] = maximum(x[idx], y)x = x.at[idx].apply(ufunc)ufunc.at(x, idx)x = x.at[idx].get()x = x[idx]None of the
x.atexpressions modify the originalx; instead they return a modified copy ofx. However, inside ajit()compiled function, expressions likex = x.at[idx].set(y)are guaranteed to be applied in-place.Unlike NumPy in-place operations such as
x[idx] += y, if multiple indices refer to the same location, all updates will be applied (NumPy would only apply the last update, rather than applying all updates.) The order in which conflicting updates are applied is implementation-defined and may be nondeterministic (e.g., due to concurrency on some hardware platforms).By default, JAX assumes that all indices are in-bounds. Alternative out-of-bound index semantics can be specified via the
modeparameter (see below).- Parameters:
mode (str) β
Specify out-of-bound indexing mode. Options are:
"promise_in_bounds": (default) The user promises that indices are in bounds. No additional checking will be performed. In practice, this means that out-of-bounds indices inget()will be clipped, and out-of-bounds indices inset(),add(), etc. will be dropped."clip": clamp out of bounds indices into valid range."drop": ignore out-of-bound indices."fill": alias for"drop". For get(), the optionalfill_valueargument specifies the value that will be returned.See
jax.lax.GatherScatterModefor more details.
indices_are_sorted (bool) β If True, the implementation will assume that the indices passed to
at[]are sorted in ascending order, which can lead to more efficient execution on some backends.unique_indices (bool) β If True, the implementation will assume that the indices passed to
at[]are unique, which can result in more efficient execution on some backends.fill_value (Any) β Only applies to the
get()method: the fill value to return for out-of-bounds slices when mode is'fill'. Ignored otherwise. Defaults toNaNfor inexact types, the largest negative value for signed types, the largest positive value for unsigned types, andTruefor booleans.
Examples
>>> x = jnp.arange(5.0) >>> x Array([0., 1., 2., 3., 4.], dtype=float32) >>> x.at[2].add(10) Array([ 0., 1., 12., 3., 4.], dtype=float32) >>> x.at[10].add(10) # out-of-bounds indices are ignored Array([0., 1., 2., 3., 4.], dtype=float32) >>> x.at[20].add(10, mode='clip') Array([ 0., 1., 2., 3., 14.], dtype=float32) >>> x.at[2].get() Array(2., dtype=float32) >>> x.at[20].get() # out-of-bounds indices clipped Array(4., dtype=float32) >>> x.at[20].get(mode='fill') # out-of-bounds indices filled with NaN Array(nan, dtype=float32) >>> x.at[20].get(mode='fill', fill_value=-1) # custom fill value Array(-1., dtype=float32)
- block_until_ready()
Block until the array is ready.
- Return type:
Examples
>>> import unxt as u >>> q = u.Quantity(1, "m") >>> q.block_until_ready() is q True
-
check_negative:
bool= True Whether to check that the distance is strictly non-negative.
- decompose(bases: Sequence[Unit | UnitBase | CompositeUnit | str], /)
Decompose the quantity into the given bases.
Examples
>>> from unxt import Quantity
>>> q = Quantity(1, "m") >>> q.decompose(["cm", "s"]) Quantity(Array(100., dtype=float32, ...), unit='cm')
- Parameters:
bases (
Sequence[Unit|UnitBase|CompositeUnit|str])- Return type:
- property device: Device
Device where the array is located.
Examples
>>> import unxt as u >>> u.Quantity(1, "m").device CpuDevice(id=0)
- devices()
Return the devices where the array is located.
Examples
>>> import unxt as u >>> q = u.Quantity(1, "m") >>> q.devices() {CpuDevice(id=0)}
- property distance: AbstractDistance
The distance.
Examples
>>> from coordinax.distance import Distance >>> d = Distance(10, "km") >>> d.distance is d True
>>> from coordinax.distance import DistanceModulus >>> DistanceModulus(10, "mag").distance Distance(Array(1000., dtype=float32, ...), unit='pc')
>>> from coordinax.distance import Parallax >>> p = Parallax(1, "mas") >>> p.distance.to("kpc") Distance(Array(1., dtype=float32, ...), unit='kpc')
- property distance_modulus: AbstractDistance
The distance modulus.
Examples
>>> from coordinax.distance import Distance >>> d = Distance(1, "pc") >>> d.distance_modulus DistanceModulus(Array(-5., dtype=float32), unit='mag')
>>> from coordinax.distance import DistanceModulus >>> DistanceModulus(10, "mag").distance_modulus DistanceModulus(Array(10, dtype=int32, ...), unit='mag')
>>> from coordinax.distance import Parallax >>> Parallax(1, "mas").distance_modulus DistanceModulus(Array(10., dtype=float32), unit='mag')
- property dtype: dtype
Data type of the array.
Examples
>>> import unxt as u >>> u.Quantity(1, "m").dtype dtype('int32')
- flatten()
Return a flattened version of the array.
- Return type:
Examples
>>> import unxt as u >>> q = u.Quantity([[1, 2], [3, 4]], "m") >>> q.flatten() Quantity(Array([1, 2, 3, 4], dtype=int32), unit='m')
- classmethod from_(cls: type[AbstractQuantity], *args: Any, **kwargs: Any)
- from_(cls: type[AbstractQuantity], value: ArrayLike | list[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex] | tuple[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex, ...], unit: Any, /, *, dtype: Any = None) AbstractQuantity
- Parameters:
- Return type:
Construct a unxt.Quantity from an array-like value and a unit.
- Parameters:
- Return type:
Examples
For this example weβll use the Quantity class. The same applies to any subclass of AbstractQuantity.
>>> import jax.numpy as jnp >>> import unxt as u
>>> x = jnp.array([1.0, 2, 3]) >>> u.Quantity.from_(x, "m") Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_([1.0, 2, 3], "m") Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_((1.0, 2, 3), "m") Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
- from_(cls: type[AbstractQuantity], value: ArrayLike | list[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex] | tuple[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex, ...], /, *, unit: Any, dtype: Any = None) AbstractQuantity
- Parameters:
- Return type:
Make a unxt.AbstractQuantity from an array-like value and a unit kwarg.
Examples
For this example weβll use the unxt.Quantity class. The same applies to any subclass of unxt.AbstractQuantity.
>>> import unxt as u >>> u.Quantity.from_([1.0, 2, 3], unit="m") Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
- from_(cls: type[AbstractQuantity], *, value: Any, unit: Any, dtype: Any = None) AbstractQuantity
- Parameters:
- Return type:
Construct a AbstractQuantity from value and unit kwargs.
Examples
For this example weβll use the Quantity class. The same applies to any subclass of AbstractQuantity.
>>> import unxt as u >>> u.Quantity.from_(value=[1.0, 2, 3], unit="m") Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
- from_(cls: type[AbstractQuantity], mapping: Mapping[str, Any]) AbstractQuantity
- Parameters:
- Return type:
Construct a Quantity from a Mapping.
Examples
For this example weβll use the Quantity class. The same applies to any subclass of AbstractQuantity.
>>> import jax.numpy as jnp >>> import unxt as u
>>> x = jnp.array([1.0, 2, 3]) >>> q = u.Quantity.from_({"value": x, "unit": "m"}) >>> q Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_({"value": q, "unit": "km"}) Quantity(Array([0.001, 0.002, 0.003], dtype=float32), unit='km')
- from_(cls: type[AbstractQuantity], value: AbstractQuantity, unit: Any, /, *, dtype: Any = None) AbstractQuantity
- Parameters:
- Return type:
Construct a Quantity from another Quantity.
The value is converted to the new unit.
Examples
>>> import unxt as u
>>> q = u.Quantity(1, "m") >>> u.Quantity.from_(q, "cm") Quantity(Array(100., dtype=float32, ...), unit='cm')
- from_(cls: type[AbstractQuantity], value: AbstractQuantity, unit: NoneType, /, *, dtype: Any = None) AbstractQuantity
- Parameters:
- Return type:
Construct a Quantity from another Quantity.
The value is converted to the new unit.
Examples
>>> import unxt as u
>>> q = u.Quantity(1, "m") >>> u.Quantity.from_(q, None) Quantity(Array(1, dtype=int32, ...), unit='m')
- from_(cls: type[AbstractQuantity], value: AbstractQuantity, /, *, unit: Any | None = None, dtype: Any = None) AbstractQuantity
- Parameters:
- Return type:
Construct a Quantity from another Quantity, with no unit change.
- from_(cls: type[AbstractQuantity], value: Quantity, /, **kwargs: Any) AbstractQuantity
- Parameters:
- Return type:
Construct a Quantity from another Quantity.
The value is converted to the new unit.
Examples
>>> import unxt as u >>> import astropy.units as apyu
>>> u.Quantity.from_(apyu.Quantity(1, "m")) Quantity(Array(1., dtype=float32), unit='m')
- from_(cls: type[AbstractQuantity], value: Quantity, u: Any, /, **kwargs: Any) AbstractQuantity
- Parameters:
- Return type:
Construct a Quantity from another Quantity.
The value is converted to the new unit.
Examples
>>> import unxt as u >>> import astropy.units as apyu
>>> u.Quantity.from_(apyu.Quantity(1, "m"), "cm") Quantity(Array(100., dtype=float32), unit='cm')
- from_(cls: type[Distance], obj: AbstractDistance | Quantity[PhysicalType('length')] | Quantity[PhysicalType('angle')] | Quantity[PhysicalType('unknown')], /, **kw: Any) Distance
- Parameters:
- Return type:
Construct a Distance from the inputs.
- from_(cls: type[DistanceModulus], dm: AbstractDistance | Quantity[PhysicalType('unknown')] | Quantity[PhysicalType('length')] | Quantity[PhysicalType('angle')], /, **kwargs: Any) DistanceModulus
- Parameters:
- Return type:
Construct a DistanceModulus from the input.
- from_(cls: type[Parallax], obj: AbstractDistance | Quantity[PhysicalType('angle')] | Quantity[PhysicalType('length')] | Quantity[PhysicalType('unknown')], /, **kwargs: Any) Parallax
- Parameters:
- Return type:
Construct a Parallax the input.
- Parameters:
cls (
type[AbstractQuantity])args (
Any)kwargs (
Any)
- Return type:
- property mT: AbstractQuantity
Matrix transpose of the array.
Examples
>>> import unxt as u >>> q = u.Quantity([[0, 1], [1, 2]], "m") >>> q.mT Quantity(Array([[0, 1], [1, 2]], dtype=int32), unit='m')
- max(*args: Any, **kwargs: Any)
Return the maximum value.
Examples
>>> import unxt as u >>> q = u.Quantity([1, 2, 3], "m") >>> q.max() Quantity(Array(3, dtype=int32), unit='m')
- Parameters:
- Return type:
- mean(*args: Any, **kwargs: Any)
Return the mean value.
Examples
>>> import unxt as u >>> q = u.Quantity([1, 2, 3], "m") >>> q.mean() Quantity(Array(2., dtype=float32), unit='m')
- Parameters:
- Return type:
- min(*args: Any, **kwargs: Any)
Return the minimum value.
Examples
>>> import unxt as u >>> q = u.Quantity([1, 2, 3], "m") >>> q.min() Quantity(Array(1, dtype=int32), unit='m')
- Parameters:
- Return type:
- property ndim: int
Number of dimensions.
Examples
>>> import unxt as u >>> q = u.Quantity([[1]], "m") >>> q.ndim 2
- property parallax: AbstractDistance
The parallax from a distance.
The parallax is calculated as \(\arctan(1 AU / d)\).
Examples
>>> import quaxed.numpy as jnp >>> from coordinax.distance import Distance
>>> d = Distance(1, "pc") >>> jnp.round(d.parallax.to("arcsec"), 2) Parallax(Array(1., dtype=float32, ...), unit='arcsec')
>>> from coordinax.distance import DistanceModulus >>> DistanceModulus(10, "mag").parallax.to("mas") Parallax(Array(0.99999994, dtype=float32, ...), unit='mas')
>>> from coordinax.distance import Parallax >>> p = Parallax(1, "mas") >>> p.parallax is p True
- ravel()
Return a flattened version of the array.
- Return type:
Examples
>>> import unxt as u >>> q = u.Quantity([[1, 2], [3, 4]], "m") >>> q.ravel() Quantity(Array([1, 2, 3, 4], dtype=int32), unit='m')
- reshape(*args: Any, order: str = 'C')
Return a reshaped version of the array.
Examples
>>> import unxt as u >>> q = u.Quantity([1, 2, 3, 4], "m") >>> q.reshape(2, 2) Quantity(Array([[1, 2], [3, 4]], dtype=int32), unit='m')
- Parameters:
- Return type:
- round(*args: Any, **kwargs: Any)
Round the array to the given number of decimals.
Examples
>>> import unxt as u >>> q = u.Quantity([1.1, 2.2, 3.3], "m") >>> q.round(0) Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
- Parameters:
- Return type:
- property sharding: Any
Return the sharding configuration of the array.
Examples
>>> import unxt as u >>> q = u.Quantity([1, 2, 3], "m") >>> q.sharding SingleDeviceSharding(device=..., memory_kind=...)
- property size: int
Total number of elements.
Examples
>>> import unxt as u >>> q = u.Quantity([1, 2, 3], "m") >>> q.size 3
- squeeze(*args: Any, **kwargs: Any)
Return the array with all single-dimensional entries removed.
Examples
>>> import unxt as u >>> q = u.Quantity([[[1], [2], [3]]], "m") >>> q.squeeze() Quantity(Array([1, 2, 3], dtype=int32), unit='m')
- Parameters:
- Return type:
- to(u: Any, /)
Convert the quantity to the given units.
See unxt.quantity.AbstractQuantity.uconvert.
Examples
>>> from unxt import Quantity
>>> q = Quantity(1, "m") >>> q.to("cm") Quantity(Array(100., dtype=float32, ...), unit='cm')
- Parameters:
u (
Any)- Return type:
- to_device(device: None | Device = None)
Move the array to a new device.
Examples
>>> import unxt as u >>> q = u.Quantity(1, "m") >>> q.to_device(None) Quantity(Array(1, dtype=int32, weak_type=True), unit='m')
- Parameters:
- Return type:
- to_value(u: Any, /)
Return the value in the given units.
See unxt.AbstractQuantity.ustrip.
Examples
>>> from unxt import Quantity
>>> q = Quantity(1, "m") >>> q.to_value("cm") Array(100., dtype=float32, weak_type=True)
- uconvert(u: Any, /)
Convert the quantity to the given units.
See also
Noneconvert a quantity to a new unit.
Examples
>>> import unxt as u
>>> q = u.Quantity(1, "m") >>> q.uconvert("cm") Quantity(Array(100., dtype=float32, ...), unit='cm')
- Parameters:
u (
Any)- Return type:
- ustrip(u: Any, /)
Return the value in the given units.
See also
Nonestrip the units from a quantity.
Examples
>>> import unxt as u
>>> q = u.Quantity(1, "m") >>> q.ustrip("cm") Array(100., dtype=float32, weak_type=True)
-
value:
Shaped[Array, '*shape'] The value of the unxt.AbstractQuantity.
-
unit:
Unit|UnitBase|CompositeUnit The unit associated with this value.
- coordinax.vector(*args: Any, **kwargs: Any)
Construct a vector given the arguments.
- coordinax.vector(obj: AbstractVector, /) AbstractVector
Construct a vector from a vector.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> cart = cx.vecs.CartesianPos2D.from_([1, 2], "km") >>> cx.vector(cart) is cart True
- coordinax.vector(cls: type[AbstractVector], obj: Mapping[str, Any], /) AbstractVector
Construct a vector from a mapping.
Examples
>>> import jax.numpy as jnp >>> import unxt as u >>> import coordinax as cx
>>> xs = {"x": u.Quantity(1, "m"), "y": u.Quantity(2, "m"), ... "z": u.Quantity(3, "m")} >>> vec = cx.CartesianPos3D.from_(xs) >>> print(vec) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
>>> xs = {"x": u.Quantity([1, 2], "m"), "y": u.Quantity([3, 4], "m"), ... "z": u.Quantity([5, 6], "m")} >>> vec = cx.CartesianPos3D.from_(xs) >>> print(vec) <CartesianPos3D: (x, y, z) [m] [[1 3 5] [2 4 6]]>
- coordinax.vector(cls: type[AbstractVector], obj: AbstractQuantity, /) AbstractVector
Construct a vector from a quantity.
This will fail for most non-position vectors, except Cartesian vectors, since they generally do not have the same dimensions, nor can be converted from a Cartesian vector without additional information.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Mismatch:
>>> try: cxv.CartesianPos1D.from_(u.Quantity([1, 2, 3], "m")) ... except ValueError as e: print(e) Cannot construct <class 'coordinax...CartesianPos1D'> from 3 components.
Pos 1D:
>>> cxv.CartesianPos1D.from_(u.Quantity(1, "meter")) CartesianPos1D(x=Quantity(1, unit='m'))
>>> cxv.CartesianPos1D.from_(u.Quantity([1], "meter")) CartesianPos1D(x=Quantity(1, unit='m'))
>>> cxv.CartesianPos1D.from_(cx.Distance(1, "meter")) CartesianPos1D(x=Quantity(1, unit='m'))
>>> cxv.RadialPos.from_(u.Quantity(1, "meter")) RadialPos(r=Distance(1, unit='m'))
>>> cxv.RadialPos.from_(u.Quantity([1], "meter")) RadialPos(r=Distance(1, unit='m'))
Vel 1D:
>>> cxv.CartesianVel1D.from_(u.Quantity(1, "m/s")) CartesianVel1D(x=Quantity(1, unit='m / s'))
>>> cxv.CartesianVel1D.from_(u.Quantity([1], "m/s")) CartesianVel1D(x=Quantity(1, unit='m / s'))
>>> cxv.RadialVel.from_(u.Quantity(1, "m/s")) RadialVel(r=Quantity(1, unit='m / s'))
>>> cxv.RadialVel.from_(u.Quantity([1], "m/s")) RadialVel(r=Quantity(1, unit='m / s'))
Acc 1D:
>>> cxv.CartesianAcc1D.from_(u.Quantity(1, "m/s2")) CartesianAcc1D(x=Quantity(1, unit='m / s2'))
>>> cxv.CartesianAcc1D.from_(u.Quantity([1], "m/s2")) CartesianAcc1D(x=Quantity(1, unit='m / s2'))
>>> cxv.RadialAcc.from_(u.Quantity(1, "m/s2")) RadialAcc(r=Quantity(1, unit='m / s2'))
>>> cxv.RadialAcc.from_(u.Quantity([1], "m/s2")) RadialAcc(r=Quantity(1, unit='m / s2'))
Pos 2D:
>>> vec = cxv.CartesianPos2D.from_(u.Quantity([1, 2], "m")) >>> print(vec) <CartesianPos2D: (x, y) [m] [1 2]>
Vel 2D:
>>> vec = cxv.CartesianVel2D.from_(u.Quantity([1, 2], "m/s")) >>> print(vec) <CartesianVel2D: (x, y) [m / s] [1 2]>
Acc 2D:
>>> vec = cxv.CartesianAcc2D.from_(u.Quantity([1, 2], "m/s2")) >>> print(vec) <CartesianAcc2D: (x, y) [m / s2] [1 2]>
Pos 3D:
>>> vec = cxv.CartesianPos3D.from_(u.Quantity([1, 2, 3], "m")) >>> print(vec) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
Vel 3D:
>>> vec = cxv.CartesianVel3D.from_(u.Quantity([1, 2, 3], "m/s")) >>> print(vec) <CartesianVel3D: (x, y, z) [m / s] [1 2 3]>
Acc 3D:
>>> vec = cxv.CartesianAcc3D.from_(u.Quantity([1, 2, 3], "m/s2")) >>> print(vec) <CartesianAcc3D: (x, y, z) [m / s2] [1 2 3]>
Generic 3D:
>>> vec = cxv.Cartesian3D.from_(u.Quantity([1, 2, 3], "m")) >>> print(vec) <Cartesian3D: (x, y, z) [m] [1 2 3]>
- coordinax.vector(cls: type[AbstractVector], obj: ArrayLike | list[Any], unit: Unit | UnitBase | CompositeUnit | str, /) AbstractVector
Construct a vector from an array and unit.
The
ArrayLike[Any, (*#batch, N), "..."]is expected to have the components as the last dimension.Examples
>>> import jax.numpy as jnp >>> import coordinax as cx
>>> vec = cx.CartesianPos3D.from_([1, 2, 3], "meter") >>> print(vec) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
>>> xs = jnp.array([[1, 2, 3], [4, 5, 6]]) >>> vec = cx.CartesianPos3D.from_(xs, "meter") >>> print(vec) <CartesianPos3D: (x, y, z) [m] [[1 2 3] [4 5 6]]>
- coordinax.vector(cls: type[AbstractVector], obj: AbstractVector, /) AbstractVector
Construct a vector from another vector.
- Raises:
TypeError β If the object is not an instance of the vector class.
- Parameters:
- Return type:
Examples
>>> import coordinax as cx
Positions:
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "km")
>>> cart = cx.CartesianPos3D.from_(q) >>> print(cart) <CartesianPos3D: (x, y, z) [km] [1 2 3]>
>>> cx.vecs.AbstractPos3D.from_(cart) is cart True
>>> sph = cart.vconvert(cx.SphericalPos) >>> cx.vecs.AbstractPos3D.from_(sph) is sph True
>>> cyl = cart.vconvert(cx.vecs.CylindricalPos) >>> cx.vecs.AbstractPos3D.from_(cyl) is cyl True
Velocities:
>>> p = cx.CartesianVel3D.from_([1, 2, 3], "km/s")
>>> cart = cx.CartesianVel3D.from_(p) >>> cx.vecs.AbstractVel3D.from_(cart) is cart True
>>> sph = cart.vconvert(cx.SphericalVel, q) >>> cx.vecs.AbstractVel3D.from_(sph) is sph True
>>> cyl = cart.vconvert(cx.vecs.CylindricalVel, q) >>> cx.vecs.AbstractVel3D.from_(cyl) is cyl True
Accelerations:
>>> p = cx.CartesianVel3D.from_([1, 1, 1], "km/s")
>>> cart = cx.vecs.CartesianAcc3D.from_([1, 2, 3], "km/s2") >>> cx.vecs.AbstractAcc3D.from_(cart) is cart True
>>> sph = cart.vconvert(cx.vecs.SphericalAcc, p, q) >>> cx.vecs.AbstractAcc3D.from_(sph) is sph True
>>> cyl = cart.vconvert(cx.vecs.CylindricalAcc, p, q) >>> cx.vecs.AbstractAcc3D.from_(cyl) is cyl True
- coordinax.vector(cls: type[AbstractPos3D], obj: AbstractPos3D, /) AbstractPos3D
Construct from a 3D position.
Examples
>>> import coordinax.vecs as cxv
>>> cart = cxv.CartesianPos3D.from_([1, 2, 3], "km") >>> cxv.AbstractPos3D.from_(cart) is cart True
>>> sph = cart.vconvert(cxv.SphericalPos) >>> cxv.AbstractPos3D.from_(sph) is sph True
>>> cyl = cart.vconvert(cxv.CylindricalPos) >>> cxv.AbstractPos3D.from_(cyl) is cyl True
- coordinax.vector(cls: type[AbstractVel3D], obj: AbstractVel3D, /) AbstractVel3D
Construct from a 3D velocity.
Examples
>>> import coordinax.vecs as cxv
>>> q = cxv.CartesianPos3D.from_([1, 1, 1], "km")
>>> cart = cxv.CartesianVel3D.from_([1, 2, 3], "km/s") >>> cxv.AbstractVel3D.from_(cart) is cart True
>>> sph = cart.vconvert(cxv.SphericalVel, q) >>> cxv.AbstractVel3D.from_(sph) is sph True
>>> cyl = cart.vconvert(cxv.CylindricalVel, q) >>> cxv.AbstractVel3D.from_(cyl) is cyl True
- coordinax.vector(cls: type[AbstractAcc3D], obj: AbstractAcc3D, /) AbstractAcc3D
Construct from a 3D velocity.
Examples
>>> import coordinax.vecs as cxv
>>> q = cxv.CartesianPos3D.from_([1, 1, 1], "km") >>> p = cxv.CartesianVel3D.from_([1, 1, 1], "km/s")
>>> cart = cxv.CartesianAcc3D.from_([1, 2, 3], "km/s2") >>> cxv.AbstractAcc3D.from_(cart) is cart True
>>> sph = cart.vconvert(cxv.SphericalAcc, p, q) >>> cxv.AbstractAcc3D.from_(sph) is sph True
>>> cyl = cart.vconvert(cxv.CylindricalAcc, p, q) >>> cxv.AbstractAcc3D.from_(cyl) is cyl True
- coordinax.vector(cls: type[SphericalPos], *, r: AbstractQuantity, theta: AbstractQuantity, phi: AbstractQuantity) SphericalPos
Construct SphericalPos, allowing for out-of-range values.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Letβs start with a valid input:
>>> vec = cxv.SphericalPos.from_(r=u.Quantity(3, "km"), ... theta=u.Quantity(90, "deg"), ... phi=u.Quantity(0, "deg")) >>> print(vec) <SphericalPos: (r[km], theta[deg], phi[deg]) [ 3 90 0]>
The radial distance can be negative, which wraps the azimuthal angle by 180 degrees and flips the polar angle:
>>> vec = cxv.SphericalPos.from_(r=u.Quantity(-3, "km"), ... theta=u.Quantity(45, "deg"), ... phi=u.Quantity(0, "deg")) >>> print(vec) <SphericalPos: (r[km], theta[deg], phi[deg]) [ 3 135 180]>
The polar angle can be outside the [0, 180] deg range, causing the azimuthal angle to be shifted by 180 degrees:
>>> vec = cxv.SphericalPos.from_(r=u.Quantity(3, "km"), ... theta=u.Quantity(190, "deg"), ... phi=u.Quantity(0, "deg")) >>> print(vec) <SphericalPos: (r[km], theta[deg], phi[deg]) [ 3 170 180]>
The azimuth can be outside the [0, 360) deg range. This is wrapped to the [0, 360) deg range (actually the base from_ does this):
>>> vec = cxv.SphericalPos.from_(r=u.Quantity(3, "km"), ... theta=u.Quantity(90, "deg"), ... phi=u.Quantity(365, "deg")) >>> vec.phi Angle(Array(5, dtype=int32, ...), unit='deg')
- coordinax.vector(cls: type[LonLatSphericalPos], *, lon: AbstractQuantity, lat: AbstractQuantity, distance: AbstractQuantity) LonLatSphericalPos
Construct LonLatSphericalPos, allowing for out-of-range values.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Letβs start with a valid input:
>>> vec = cxv.LonLatSphericalPos.from_(lon=u.Quantity(0, "deg"), ... lat=u.Quantity(0, "deg"), ... distance=u.Quantity(3, "km")) >>> print(vec) <LonLatSphericalPos: (lon[deg], lat[deg], distance[km]) [0 0 3]>
The distance can be negative, which wraps the longitude by 180 degrees and flips the latitude:
>>> vec = cxv.LonLatSphericalPos.from_(lon=u.Quantity(0, "deg"), ... lat=u.Quantity(45, "deg"), ... distance=u.Quantity(-3, "km")) >>> print(vec) <LonLatSphericalPos: (lon[deg], lat[deg], distance[km]) [180 -45 3]>
The latitude can be outside the [-90, 90] deg range, causing the longitude to be shifted by 180 degrees:
>>> vec = cxv.LonLatSphericalPos.from_(lon=u.Quantity(0, "deg"), ... lat=u.Quantity(-100, "deg"), ... distance=u.Quantity(3, "km")) >>> print(vec) <LonLatSphericalPos: (lon[deg], lat[deg], distance[km]) [180 -80 3]>
>>> vec = cxv.LonLatSphericalPos.from_(lon=u.Quantity(0, "deg"), ... lat=u.Quantity(100, "deg"), ... distance=u.Quantity(3, "km")) >>> print(vec) <LonLatSphericalPos: (lon[deg], lat[deg], distance[km]) [180 80 3]>
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 = cxv.LonLatSphericalPos.from_(lon=u.Quantity(365, "deg"), ... lat=u.Quantity(0, "deg"), ... distance=u.Quantity(3, "km")) >>> vec.lon Angle(Array(5, dtype=int32, ...), unit='deg')
- coordinax.vector(cls: type[MathSphericalPos], *, r: AbstractQuantity, theta: AbstractQuantity, phi: AbstractQuantity) MathSphericalPos
Construct MathSphericalPos, allowing for out-of-range values.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Letβs start with a valid input:
>>> vec = cxv.MathSphericalPos.from_(r=u.Quantity(3, "km"), ... theta=u.Quantity(90, "deg"), ... phi=u.Quantity(0, "deg")) >>> print(vec) <MathSphericalPos: (r[km], theta[deg], phi[deg]) [ 3 90 0]>
The radial distance can be negative, which wraps the azimuthal angle by 180 degrees and flips the polar angle:
>>> vec = cxv.MathSphericalPos.from_(r=u.Quantity(-3, "km"), ... theta=u.Quantity(100, "deg"), ... phi=u.Quantity(45, "deg")) >>> print(vec) <MathSphericalPos: (r[km], theta[deg], phi[deg]) [ 3 280 135]>
The polar angle can be outside the [0, 180] deg range, causing the azimuthal angle to be shifted by 180 degrees:
>>> vec = cxv.MathSphericalPos.from_(r=u.Quantity(3, "km"), ... theta=u.Quantity(0, "deg"), ... phi=u.Quantity(190, "deg")) >>> print(vec) <MathSphericalPos: (r[km], theta[deg], phi[deg]) [ 3 180 170]>
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 = cxv.MathSphericalPos.from_(r=u.Quantity(3, "km"), ... theta=u.Quantity(365, "deg"), ... phi=u.Quantity(90, "deg")) >>> vec.theta Angle(Array(5, dtype=int32, ...), unit='deg')
- coordinax.vector(cls: type[CartesianPosND] | type[CartesianVelND] | type[CartesianAccND], x: AbstractQuantity, /) CartesianPosND | CartesianVelND | CartesianAccND
Construct an N-dimensional acceleration.
Examples
>>> import unxt as u >>> import coordinax as cx
1D vector:
>>> cx.vecs.CartesianPosND.from_(u.Quantity(1, "km")) CartesianPosND(q=Quantity([1], unit='km'))
>>> cx.vecs.CartesianPosND.from_(u.Quantity([1], "km")) CartesianPosND(q=Quantity([1], unit='km'))
>>> cx.vecs.CartesianVelND.from_(u.Quantity(1, "km/s")) CartesianVelND(q=Quantity([1], unit='km / s'))
>>> cx.vecs.CartesianVelND.from_(u.Quantity([1], "km/s")) CartesianVelND(q=Quantity([1], unit='km / s'))
>>> cx.vecs.CartesianAccND.from_(u.Quantity(1, "km/s2")) CartesianAccND(q=Quantity([1], unit='km / s2'))
>>> cx.vecs.CartesianAccND.from_(u.Quantity([1], "km/s2")) CartesianAccND(q=Quantity([1], unit='km / s2'))
2D vector:
>>> cx.vecs.CartesianPosND.from_(u.Quantity([1, 2], "km")) CartesianPosND(q=Quantity([1, 2], unit='km'))
>>> cx.vecs.CartesianVelND.from_(u.Quantity([1, 2], "km/s")) CartesianVelND(q=Quantity([1, 2], unit='km / s'))
>>> cx.vecs.CartesianAccND.from_(u.Quantity([1, 2], "km/s2")) CartesianAccND(q=Quantity([1, 2], unit='km / s2'))
3D vector:
>>> cx.vecs.CartesianPosND.from_(u.Quantity([1, 2, 3], "km")) CartesianPosND(q=Quantity([1, 2, 3], unit='km'))
>>> cx.vecs.CartesianVelND.from_(u.Quantity([1, 2, 3], "km/s")) CartesianVelND(q=Quantity([1, 2, 3], unit='km / s'))
>>> cx.vecs.CartesianAccND.from_(u.Quantity([1, 2, 3], "km/s2")) CartesianAccND(q=Quantity([1, 2, 3], unit='km / s2'))
4D vector:
>>> cx.vecs.CartesianPosND.from_(u.Quantity([1, 2, 3, 4], "km")) CartesianPosND(q=Quantity([1, 2, 3, 4], unit='km'))
>>> cx.vecs.CartesianVelND.from_(u.Quantity([1, 2, 3, 4], "km/s")) CartesianVelND(q=Quantity([1, 2, 3, 4], unit='km / s'))
>>> cx.vecs.CartesianAccND.from_(u.Quantity([1, 2, 3, 4], "km/s2")) CartesianAccND(q=Quantity([1, 2, 3, 4], unit='km / s2'))
- coordinax.vector(cls: type[FourVector], obj: AbstractQuantity, /) FourVector
Construct a vector from a Quantity array.
The
Quantity[Any, (*#batch, 4), "..."]is expected to have the components as the last dimension. The 4 components are the (c x) time, x, y, z.Examples
>>> import jax.numpy as jnp >>> import unxt as u >>> import coordinax as cx
>>> xs = u.Quantity([0, 1, 2, 3], "meter") # [ct, x, y, z] >>> vec = cx.FourVector.from_(xs) >>> print(vec) <FourVector: (t[m s / km], q=(x, y, z) [m]) [0. 1. 2. 3.]>
>>> xs = u.Quantity(jnp.array([[0, 1, 2, 3], [10, 4, 5, 6]]), "meter") >>> vec = cx.FourVector.from_(xs) >>> print(vec) <FourVector: (t[m s / km], q=(x, y, z) [m]) [[0.000e+00 1.000e+00 2.000e+00 3.000e+00] [3.336e-05 4.000e+00 5.000e+00 6.000e+00]]>
- coordinax.vector(q: AbstractQuantity, /) AbstractVector
Construct a vector from a quantity.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> print(cx.vecs.vector(u.Quantity(1, "km"))) <CartesianPos1D: (x) [km] [1]>
>>> print(cx.vecs.vector(u.Quantity([1], "km"))) <CartesianPos1D: (x) [km] [1]>
>>> print(cx.vecs.vector(u.Quantity(1, "km/s"))) <CartesianVel1D: (x) [km / s] [1]>
>>> print(cx.vecs.vector(u.Quantity([1], "km/s"))) <CartesianVel1D: (x) [km / s] [1]>
>>> print(cx.vecs.vector(u.Quantity(1, "km/s2"))) <CartesianAcc1D: (x) [km / s2] [1]>
>>> print(cx.vecs.vector(u.Quantity([1], "km/s2"))) <CartesianAcc1D: (x) [km / s2] [1]>
>>> print(cx.vecs.vector(u.Quantity([1, 2], "km"))) <CartesianPos2D: (x, y) [km] [1 2]>
>>> print(cx.vecs.vector(u.Quantity([1, 2], "km/s"))) <CartesianVel2D: (x, y) [km / s] [1 2]>
>>> print(cx.vecs.vector(u.Quantity([1, 2], "km/s2"))) <CartesianAcc2D: (x, y) [km / s2] [1 2]>
>>> print(cx.vecs.vector(u.Quantity([1, 2, 3], "km"))) <CartesianPos3D: (x, y, z) [km] [1 2 3]>
>>> print(cx.vecs.vector(u.Quantity([1, 2, 3], "km/s"))) <CartesianVel3D: (x, y, z) [km / s] [1 2 3]>
>>> print(cx.vecs.vector(u.Quantity([1, 2, 3], "km/s2"))) <CartesianAcc3D: (x, y, z) [km / s2] [1 2 3]>
>>> print(cx.vecs.vector(u.Quantity([0, 1, 2, 3], "km"))) <CartesianPosND: (q) [km] [[0] [1] [2] [3]]>
>>> print(cx.vecs.vector(u.Quantity([0, 1, 2, 3], "km/s"))) <CartesianVelND: (q) [km / s] [[0] [1] [2] [3]]>
>>> print(cx.vecs.vector(u.Quantity([0, 1, 2, 3], "km/s2"))) <CartesianAccND: (q) [km / s2] [[0] [1] [2] [3]]>
>>> try: print(cx.vecs.vector(u.Quantity([1], "Msun"))) ... except ValueError as e: print(e) Cannot construct a Cartesian vector from Quantity['mass']([1], unit='solMass').
- coordinax.vector(q: list[float | int], unit: str, /) AbstractVector
Construct a vector from a list and unit.
Examples
>>> import coordinax as cx
>>> print(cx.vecs.vector([1], "km")) <CartesianPos1D: (x) [km] [1]>
>>> print(cx.vecs.vector([1], "km/s")) <CartesianVel1D: (x) [km / s] [1]>
>>> print(cx.vecs.vector([1], "km/s2")) <CartesianAcc1D: (x) [km / s2] [1]>
>>> print(cx.vecs.vector([1, 2], "km")) <CartesianPos2D: (x, y) [km] [1 2]>
>>> print(cx.vecs.vector([1, 2], "km/s")) <CartesianVel2D: (x, y) [km / s] [1 2]>
>>> print(cx.vecs.vector([1, 2], "km/s2")) <CartesianAcc2D: (x, y) [km / s2] [1 2]>
>>> print(cx.vecs.vector([1, 2, 3], "km")) <CartesianPos3D: (x, y, z) [km] [1 2 3]>
>>> print(cx.vecs.vector([1, 2, 3], "km/s")) <CartesianVel3D: (x, y, z) [km / s] [1 2 3]>
>>> print(cx.vecs.vector([1, 2, 3], "km/s2")) <CartesianAcc3D: (x, y, z) [km / s2] [1 2 3]>
- coordinax.vector(cls: type[Coordinate], data: KinematicSpace | AbstractPos, frame: AbstractReferenceFrame, /) Coordinate
Construct a coordinate from data and a frame.
Examples
>>> import coordinax as cx
>>> data = cx.CartesianPos3D.from_([1, 2, 3], "kpc") >>> cx.Coordinate.from_(data, cx.frames.ICRS()) Coordinate( KinematicSpace({ 'length': CartesianPos3D( ... ) }), frame=ICRS() )
- coordinax.vector(cls: type[Coordinate], data: KinematicSpace | AbstractPos, base_frame: AbstractReferenceFrame, ops: AbstractOperator, /) Coordinate
Construct a coordinate from data and a frame.
Examples
>>> import coordinax as cx
>>> data = cx.CartesianPos3D.from_([1, 2, 3], "kpc") >>> cx.Coordinate.from_(data, cx.frames.ICRS(), cx.ops.Identity()) Coordinate( KinematicSpace({ 'length': CartesianPos3D( ... ) }), frame=TransformedReferenceFrame(base_frame=ICRS(), xop=Identity()) )
- coordinax.vector(obj: CartesianRepresentation, /) CartesianPos3D
Construct from a astropy.coordinates.CartesianRepresentation.
This re-dispatches to
coordinax.vecs.CartesianPos3D.from_().Examples
>>> import coordinax as cx >>> from astropy.coordinates import CartesianRepresentation
>>> cart = CartesianRepresentation(1, 2, 3, unit="m") >>> vec = cx.vector(cart) >>> print(vec) <CartesianPos3D: (x, y, z) [m] [1. 2. 3.]>
- coordinax.vector(obj: CylindricalRepresentation, /) CylindricalPos
Construct from a astropy.coordinates.CylindricalRepresentation.
This re-dispatches to
coordinax.vecs.CylindricalPos.from_().Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import CylindricalRepresentation
>>> cyl = CylindricalRepresentation(rho=1 * u.km, phi=2 * u.deg, ... z=30 * u.m) >>> vec = cx.vector(cyl) >>> print(vec) <CylindricalPos: (rho[km], phi[deg], z[m]) [ 1. 2. 30.]>
- coordinax.vector(obj: PhysicsSphericalRepresentation, /) SphericalPos
Construct from a astropy.coordinates.PhysicsSphericalRepresentation.
This re-dispatches to
coordinax.vecs.SphericalPos.from_().Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import PhysicsSphericalRepresentation
>>> sph = PhysicsSphericalRepresentation(r=1 * u.km, theta=2 * u.deg, ... phi=3 * u.deg) >>> vec = cx.vector(sph) >>> print(vec) <SphericalPos: (r[km], theta[deg], phi[deg]) [1. 2. 3.]>
- coordinax.vector(obj: SphericalRepresentation, /) LonLatSphericalPos
Construct from a astropy.coordinates.SphericalRepresentation.
This re-dispatches to
coordinax.vecs.LonLatSphericalPos.from_().Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import SphericalRepresentation
>>> sph = SphericalRepresentation(lon=3 * u.deg, lat=2 * u.deg, ... distance=1 * u.km) >>> vec = cx.vector(sph) >>> print(vec) <LonLatSphericalPos: (lon[deg], lat[deg], distance[km]) [3. 2. 1.]>
- coordinax.vector(obj: UnitSphericalRepresentation) TwoSpherePos
Construct from a astropy.coordinates.UnitSphericalRepresentation.
This re-dispatches to
coordinax.vecs.TwoSpherePos.from_().Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import UnitSphericalRepresentation
>>> sph = UnitSphericalRepresentation(lon=3 * u.deg, lat=2 * u.deg) >>> vec = cx.vector(sph) >>> print(vec) <TwoSpherePos: (theta, phi) [deg] [2. 3.]>
- coordinax.vector(obj: CartesianDifferential, /) CartesianVel3D
Construct from a astropy.coordinates.CartesianDifferential.
This re-dispatches to
coordinax.vecs.CartesianVel3D.from_().Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import CartesianDifferential
>>> dcart = CartesianDifferential(1, 2, 3, unit="km/s") >>> dif = cx.vector(dcart) >>> print(vec) <TwoSpherePos: (theta, phi) [deg] [2. 3.]>
- coordinax.vector(obj: CylindricalDifferential, /) CylindricalVel
Construct from a astropy.coordinates.CylindricalDifferential.
This re-dispatches to
coordinax.vecs.CylindricalVel.from_().Examples
>>> import astropy.units as u >>> import astropy.coordinates as apyc >>> import coordinax as cx
>>> 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.vector(dcyl) >>> print(vec) <TwoSpherePos: (theta, phi) [deg] [2. 3.]>
- coordinax.vector(obj: PhysicsSphericalDifferential, /) SphericalVel
Construct from a astropy.coordinates.PhysicsSphericalDifferential.
This re-dispatches to
coordinax.vecs.SphericalVel.from_().Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import PhysicsSphericalDifferential
>>> 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.vector(dsph) >>> print(vec) <TwoSpherePos: (theta, phi) [deg] [2. 3.]>
- coordinax.vector(obj: SphericalDifferential, /) LonLatSphericalVel
Construct from a astropy.coordinates.SphericalDifferential.
This re-dispatches to
coordinax.vecs.LonLatSphericalVel.from_().Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import SphericalDifferential
>>> 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.vector(dsph) >>> print(vec) <TwoSpherePos: (theta, phi) [deg] [2. 3.]>
- coordinax.vector(obj: SphericalCosLatDifferential, /) LonCosLatSphericalVel
Construct from a astropy.coordinates.SphericalCosLatDifferential.
This re-dispatches to
coordinax.vecs.LonCosLatSphericalVel.from_().Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import SphericalCosLatDifferential
>>> 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.vector(dsph) >>> print(dif) <LonCosLatSphericalVel: (lon_coslat[mas / yr], lat[mas / yr], distance[km / s]) [2. 3. 1.]>
- coordinax.vector(obj: UnitSphericalDifferential) TwoSphereVel
Construct from a astropy.coordinates.UnitSphericalDifferential.
This re-dispatches to
coordinax.vecs.TwoSphereVel.from_().Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import UnitSphericalDifferential
>>> dsph = UnitSphericalDifferential(d_lon=3 * u.deg/u.s, d_lat=2 * u.deg/u.s) >>> vel = cx.vector(dsph) >>> print(vel) <TwoSphereVel: (theta, phi) [deg / s] [2. 3.]>
- coordinax.vector(cls: type[CartesianPos3D], obj: BaseRepresentation, /) CartesianPos3D
Construct from a astropy.coordinates.BaseRepresentation.
Examples
>>> import coordinax as cx >>> from astropy.coordinates import CartesianRepresentation
>>> cart = CartesianRepresentation(1, 2, 3, unit="km") >>> vec = cx.CartesianPos3D.from_(cart) >>> print(vec) <CartesianPos3D: (x, y, z) [km] [1. 2. 3.]>
- coordinax.vector(cls: type[CylindricalPos], obj: BaseRepresentation, /) CylindricalPos
Construct from a astropy.coordinates.BaseRepresentation.
Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import CylindricalRepresentation
>>> cyl = CylindricalRepresentation(rho=1 * u.km, phi=2 * u.deg, ... z=30 * u.m) >>> vec = cx.vecs.CylindricalPos.from_(cyl) >>> print(vec) <CylindricalPos: (rho[km], phi[deg], z[m]) [ 1. 2. 30.]>
- coordinax.vector(cls: type[SphericalPos], obj: BaseRepresentation, /) SphericalPos
Construct from a astropy.coordinates.BaseRepresentation.
Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import PhysicsSphericalRepresentation
>>> sph = PhysicsSphericalRepresentation(r=1 * u.km, theta=2 * u.deg, ... phi=3 * u.deg) >>> vec = cx.SphericalPos.from_(sph) >>> print(vec) <SphericalPos: (r[km], theta[deg], phi[deg]) [1. 2. 3.]>
- coordinax.vector(cls: type[LonLatSphericalPos], obj: BaseRepresentation, /) LonLatSphericalPos
Construct from a astropy.coordinates.BaseRepresentation.
Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import SphericalRepresentation
>>> sph = SphericalRepresentation(lon=3 * u.deg, lat=2 * u.deg, ... distance=1 * u.km) >>> vec = cx.vecs.LonLatSphericalPos.from_(sph) >>> print(vec) <LonLatSphericalPos: (lon[deg], lat[deg], distance[km]) [3. 2. 1.]>
- coordinax.vector(cls: type[TwoSpherePos], obj: BaseRepresentation, /) TwoSpherePos
Construct from a astropy.coordinates.BaseRepresentation.
Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import UnitSphericalRepresentation
>>> sph = UnitSphericalRepresentation(lon=3 * u.deg, lat=2 * u.deg) >>> vec = cx.vecs.TwoSpherePos.from_(sph) >>> print(vec) <TwoSpherePos: (theta, phi) [deg] [2. 3.]>
- coordinax.vector(cls: type[CartesianVel3D], obj: CartesianDifferential, /) CartesianVel3D
Construct from a astropy.coordinates.CartesianDifferential.
Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import CartesianDifferential
>>> dcart = CartesianDifferential(1, 2, 3, unit="km/s") >>> dif = cx.CartesianVel3D.from_(dcart) >>> print(vec) <TwoSpherePos: (theta, phi) [deg] [2. 3.]>
- coordinax.vector(cls: type[CylindricalVel], obj: CylindricalDifferential, /) CylindricalVel
Construct from a astropy.coordinates.CylindricalVel.
Examples
>>> import astropy.units as u >>> import astropy.coordinates as apyc >>> import coordinax as cx
>>> dcyl = apyc.CylindricalDifferential(d_rho=1 * u.km / u.s, d_phi=2 * u.mas/u.yr, ... d_z=2 * u.km / u.s) >>> vec = cx.vecs.CylindricalVel.from_(dcyl) >>> print(vec) <CylindricalVel: (rho[km / s], phi[mas / yr], z[km / s]) [1. 2. 2.]>
- coordinax.vector(cls: type[SphericalVel], obj: PhysicsSphericalDifferential, /) SphericalVel
Construct from a astropy.coordinates.PhysicsSphericalDifferential.
Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import PhysicsSphericalDifferential
>>> dsph = PhysicsSphericalDifferential(d_r=1 * u.km / u.s, d_theta=2 * u.mas/u.yr, ... d_phi=3 * u.mas/u.yr) >>> vec = cx.SphericalVel.from_(dsph) >>> print(vec) <SphericalVel: (r[km / s], theta[mas / yr], phi[mas / yr]) [1. 2. 3.]>
- coordinax.vector(cls: type[LonLatSphericalVel], obj: SphericalDifferential, /) LonLatSphericalVel
Construct from a astropy.coordinates.SphericalVel.
Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import SphericalDifferential
>>> dsph = SphericalDifferential(d_distance=1 * u.km / u.s, ... d_lon=2 * u.mas/u.yr, ... d_lat=3 * u.mas/u.yr) >>> vec = cx.vecs.LonLatSphericalVel.from_(dsph) >>> print(vec) <LonLatSphericalVel: (lon[mas / yr], lat[mas / yr], distance[km / s]) [2. 3. 1.]>
- coordinax.vector(cls: type[LonCosLatSphericalVel], obj: SphericalCosLatDifferential, /) LonCosLatSphericalVel
Construct from a astropy.coordinates.SphericalCosLatDifferential.
Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import SphericalCosLatDifferential
>>> dsph = SphericalCosLatDifferential(d_distance=1 * u.km / u.s, ... d_lon_coslat=2 * u.mas/u.yr, ... d_lat=3 * u.mas/u.yr) >>> vec = cx.vecs.LonCosLatSphericalVel.from_(dsph) >>> print(vec) <LonCosLatSphericalVel: (lon_coslat[mas / yr], lat[mas / yr], distance[km / s]) [2. 3. 1.]>
- coordinax.vector(cls: type[TwoSphereVel], obj: UnitSphericalDifferential, /) TwoSphereVel
Construct from a astropy.coordinates.BaseDifferential.
Examples
>>> import astropy.units as u >>> import coordinax as cx >>> from astropy.coordinates import UnitSphericalDifferential
>>> sph = UnitSphericalDifferential(d_lon=3 * u.deg/u.s, d_lat=2 * u.deg/u.s) >>> vec = cx.vecs.TwoSphereVel.from_(sph) >>> print(vec) <TwoSphereVel: (theta, phi) [deg / s] [2. 3.]>
- coordinax.vector(obj: Quantity, /) AbstractVector
Construct a vector from an Astropy Quantity.
The array is expected to have the components as the last dimension.
Examples
>>> import jax.numpy as jnp >>> from astropy.units import Quantity >>> import coordinax as cx
>>> vec = cx.vector(Quantity([1, 2, 3], "meter")) >>> print(vec) <CartesianPos3D: (x, y, z) [m] [1. 2. 3.]>
- coordinax.vector(cls: type[AbstractVector], obj: Quantity, /) AbstractVector
Construct a vector from an Astropy Quantity array.
The array is expected to have the components as the last dimension.
Examples
>>> import jax.numpy as jnp >>> from astropy.units import Quantity >>> import coordinax as cx
>>> xs = Quantity([1, 2, 3], "meter") >>> vec = cx.CartesianPos3D.from_(xs) >>> print(vec) <CartesianPos3D: (x, y, z) [m] [1. 2. 3.]>
>>> xs = Quantity(jnp.array([[1, 2, 3], [4, 5, 6]]), "meter") >>> vec = cx.CartesianPos3D.from_(xs) >>> print(vec) <CartesianPos3D: (x, y, z) [m] [[1. 2. 3.] [4. 5. 6.]]>
>>> vec = cx.CartesianVel3D.from_(Quantity([1, 2, 3], "m/s")) >>> print(vec) <CartesianVel3D: (x, y, z) [m / s] [1. 2. 3.]>
>>> vec = cx.vecs.CartesianAcc3D.from_(Quantity([1, 2, 3], "m/s2")) >>> print(vec) <CartesianAcc3D: (x, y, z) [m / s2] [1. 2. 3.]>
>>> xs = Quantity([0, 1, 2, 3], "meter") # [ct, x, y, z] >>> vec = cx.FourVector.from_(xs) >>> print(vec) <FourVector: (t[m s / km], q=(x, y, z) [m]) [0. 1. 2. 3.]>
>>> xs = Quantity(jnp.array([[0, 1, 2, 3], [10, 4, 5, 6]]), "meter") >>> vec = cx.FourVector.from_(xs) >>> print(vec) <FourVector: (t[m s / km], q=(x, y, z) [m]) [[0.000e+00 1.000e+00 2.000e+00 3.000e+00] [3.336e-05 4.000e+00 5.000e+00 6.000e+00]]>
- coordinax.vconvert(target: type[Any], /, *args: Any, **kwargs: Any)
Transform the current vector to the target vector.
See the dispatch implementations for more details. Not all transformations result in the target vector type, for example
vconvert(type[Cartesian3DPos], FourVector)will return a coordinax.vecs.FourVector with the spatial part in Cartesian coordinates. Likewise, coordinax.vconvert on coordinax.Coordinate instances will transform the contained vectors to the target type, returning a coordinax.Coordinate instance.Examples
>>> import jax >>> import jax.numpy as jnp >>> import unxt as u >>> import coordinax.vecs as cxv
## 1D:
Array-valued:
>>> params = {"x": jnp.array([1.0, 2.0])} >>> cxv.vconvert(cxv.RadialPos, cxv.CartesianPos1D, params) ({'r': Array([1., 2.], dtype=float32)}, {})
Quantity-valued:
>>> params = {"x": u.Quantity([1.0, 2.0], "m")} >>> cxv.vconvert(cxv.RadialPos, cxv.CartesianPos1D, params) ({'r': Quantity(Array([1., 2.], dtype=float32), unit='m')}, {})
Vector-valued:
>>> x = cxv.CartesianPos1D.from_(1, "km") >>> y = cxv.vconvert(cxv.RadialPos, x) >>> print(y) <RadialPos: (r) [km] [1]>
## 2D:
Array-valued:
Without unit information βphiβ is assumed to be in radians.
>>> params = {"r": jnp.array([1.0, 2.0]), "phi": jnp.array(3)} >>> cxv.vconvert(cxv.CartesianPos2D, cxv.PolarPos, params) ({'x': Array([-0.9899925, -1.979985 ], dtype=float32), 'y': Array([0.14112, 0.28224], dtype=float32)}, {})
We can provide that unit information so that βphiβ is in degrees:
>>> usys = u.unitsystem("kpc", "deg") >>> cxv.vconvert(cxv.CartesianPos2D, cxv.PolarPos, params, units=usys) ({'x': Array([0.9986295, 1.997259 ], dtype=float32), 'y': Array([0.05233596, 0.10467192], dtype=float32)}, {})
Quantity-valued:
>>> params = {"r": u.Quantity([1.0, 2.0], "m"), "phi": u.Quantity(3, "deg")} >>> cxv.vconvert(cxv.CartesianPos2D, cxv.PolarPos, params) ({'x': Quantity(Array([0.9986295, 1.997259 ], dtype=float32), unit='m'), 'y': Quantity(Array([0.05233596, 0.10467192], dtype=float32), unit='m')}, {})
Vector-valued:
>>> x = cxv.CartesianPos2D.from_([3, 4], "km") >>> y = cxv.vconvert(cxv.PolarPos, x) >>> print(y) <PolarPos: (r[km], phi[rad]) [5. 0.927]>
>>> y = cxv.vconvert(cxv.PolarPos, x, units=u.unitsystem("m", "deg")) >>> print(y) <PolarPos: (r[m], phi[deg]) [5000. 53.13]>
## 3D:
Array-valued:
>>> params = {"x": jnp.array([1.0, 2.0]), "y": jnp.array([3.0, 4.0]), ... "z": jnp.array([5.0, 6.0])} >>> params, aux = cxv.vconvert(cxv.SphericalPos, cxv.CartesianPos3D, params) >>> jax.tree.map(lambda x: jnp.round(x, 4), params) {'phi': Array([1.249 , 1.1071], dtype=float32), 'r': Array([5.9161 , 7.4832997], dtype=float32), 'theta': Array([0.5639, 0.6405], dtype=float32)}
Quantity-valued:
>>> params = {"x": u.Quantity([1.0, 2.0], "m"), ... "y": u.Quantity([3.0, 4.0], "m"), ... "z": u.Quantity([5.0, 6.0], "m")} >>> params, aux = cxv.vconvert(cxv.SphericalPos, cxv.CartesianPos3D, params) >>> jax.tree.map(lambda x: jnp.round(x, 4), params) {'phi': Quantity(Array([1.249 , 1.1071], dtype=float32), unit='rad'), 'r': Quantity(Array([5.9161 , 7.4832997], dtype=float32), unit='m'), 'theta': Quantity(Array([0.5639, 0.6405], dtype=float32), unit='rad')}
Vector-valued:
>>> x = cxv.CartesianPos3D.from_([[1, 3, 5], [2, 4, 6]], "km") >>> y = cxv.vconvert(cxv.SphericalPos, x) >>> print(y) <SphericalPos: (r[km], theta[rad], phi[rad]) [[5.916 0.564 1.249] [7.483 0.641 1.107]]>
- coordinax.vconvert(target: type[AbstractPos], current: AbstractPos, space: KinematicSpace, /) AbstractPos
Convert a position to the target type, with a KinematicSpace context.
Examples
>>> import coordinax as cx
>>> space = cx.KinematicSpace(length=cx.CartesianPos3D.from_([1, 2, 3], "m"), ... speed=cx.CartesianVel3D.from_([4, 5, 6], "m/s"))
>>> cx.vconvert(cx.SphericalPos, space["length"], space) SphericalPos( ... )
- coordinax.vconvert(target: type[AbstractVel], current: AbstractVel, space: KinematicSpace, /) AbstractVel
Convert a velocity to the target type, with a KinematicSpace context.
Examples
>>> import coordinax as cx
>>> space = cx.KinematicSpace(length=cx.CartesianPos3D.from_([1, 2, 3], "m"), ... speed=cx.CartesianVel3D.from_([4, 5, 6], "m/s"))
>>> cx.vconvert(cx.SphericalVel, space["speed"], space) SphericalVel( ... )
- coordinax.vconvert(target: type[AbstractAcc], current: AbstractAcc, space: KinematicSpace, /) AbstractAcc
Convert an acceleration to the target type, with a KinematicSpace context.
Examples
>>> import coordinax as cx
>>> space = cx.KinematicSpace(length=cx.CartesianPos3D.from_([1, 2, 3], "m"), ... speed=cx.CartesianVel3D.from_([4, 5, 6], "m/s"), ... acceleration=cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2"))
>>> cx.vconvert(cx.vecs.SphericalAcc, space["acceleration"], space) SphericalAcc( ... )
- coordinax.vconvert(target: type[AbstractPos], space: KinematicSpace, /) KinematicSpace
Represent the current vector to the target vector.
- coordinax.vconvert(to_vector: type[AbstractPos3D], from_vector: type[AbstractPos3D], params: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
AbstractPos -> CartesianPos3D -> AbstractPos.
- coordinax.vconvert(to_vector: type[CylindricalPos], from_vector: type[CartesianPos3D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos3D -> CylindricalPos.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> cart = {"x": 1, "y": 2, "z": 3} >>> cxv.vconvert(cxv.CylindricalPos, cxv.CartesianPos3D, cart) ({'phi': Array(1.1071488, dtype=float32, ...), 'rho': Array(2.236068, dtype=float32, ...), 'z': Array(3, dtype=int32, ...)}, {})
>>> cart = {"x": u.Quantity(1, "km"), "y": u.Quantity(2, "km"), ... "z": u.Quantity(3, "km")} >>> cxv.vconvert(cxv.CylindricalPos, cxv.CartesianPos3D, cart) ({'phi': Quantity(Array(1.1071488, dtype=float32, ...), unit='rad'), 'rho': Quantity(Array(2.236068, dtype=float32, ...), unit='km'), 'z': Quantity(Array(3, dtype=int32, ...), unit='km')}, {})
- coordinax.vconvert(to_vector: type[SphericalPos], from_vector: type[CartesianPos3D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos3D -> SphericalPos.
Examples
>>> import coordinax.vecs as cxv >>> cart = {"x": 1, "y": 2, "z": 3} >>> cxv.vconvert(cxv.SphericalPos, cxv.CartesianPos3D, cart) ({'phi': Array(1.1071488, dtype=float32, ...), 'r': Array(3.7416575, dtype=float32, ...), 'theta': Array(0.64052236, dtype=float32)}, {})
The origin is a special case, where the angles are set to 0 by convention:
>>> cart = {"x": 0, "y": 0, "z": 0} >>> cxv.vconvert(cxv.SphericalPos, cxv.CartesianPos3D, cart) ({'phi': Array(0., dtype=float32, ...), 'r': Array(0., dtype=float32, ...), 'theta': Array(0., dtype=float32)}, {})
- coordinax.vconvert(to_vector: type[AbstractSphericalPos], from_vector: type[CartesianPos3D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos3D -> AbstractSphericalPos.
Examples
>>> import coordinax.vecs as cxv >>> params = {"x": 1, "y": 2, "z": 3} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.LonLatSphericalPos, cxv.CartesianPos3D, ... params, units=usys) ({'distance': Array(3.7416575, dtype=float32, ...), 'lat': Array(53.300774, dtype=float32), 'lon': Array(63.43495, dtype=float32, ...)}, {})
>>> cxv.vconvert(cxv.MathSphericalPos, cxv.CartesianPos3D, ... params, units=usys) ({'phi': Array(36.69923, dtype=float32), 'r': Array(3.7416575, dtype=float32, ...), 'theta': Array(63.43495, dtype=float32, ...)}, {})
- coordinax.vconvert(to_vector: type[CartesianPos3D], from_vector: type[CylindricalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CylindricalPos -> CartesianPos3D.
Examples
>>> import coordinax.vecs as cxv >>> cyl = {"rho": 1, "phi": 90, "z": 1} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.CartesianPos3D, cxv.CylindricalPos, cyl, units=usys) ({'x': Array(-4.371139e-08, dtype=float32, ...), 'y': Array(1., dtype=float32, ...), 'z': Array(1, dtype=int32, ...)}, {})
- coordinax.vconvert(to_vector: type[SphericalPos], from_vector: type[CylindricalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CylindricalPos -> SphericalPos.
Examples
>>> import coordinax.vecs as cxv >>> cyl = {"rho": 1, "phi": 90, "z": 1} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.SphericalPos, cxv.CylindricalPos, cyl, units=usys) ({'phi': Array(90., dtype=float32, ...), 'r': Array(1.4142135, dtype=float32, ...), 'theta': Array(45..., dtype=float32)}, {})
The origin is a special case, where the angles are set to 0 by convention:
>>> cyl = {"rho": 0, "phi": 0, "z": 0} >>> cxv.vconvert(cxv.SphericalPos, cxv.CylindricalPos, cyl, units=usys) ({'phi': Array(0., dtype=float32, ...), 'r': Array(0., dtype=float32, ...), 'theta': Array(0., dtype=float32)}, {})
- coordinax.vconvert(to_vector: type[AbstractSphericalPos], from_vector: type[CylindricalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CylindricalPos -> AbstractSphericalPos.
Examples
>>> import coordinax.vecs as cxv >>> cyl = {"rho": 1, "phi": 90, "z": 1} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.LonLatSphericalPos, cxv.CylindricalPos, cyl, units=usys) ({'distance': Array(1.4142135, dtype=float32, ...), 'lat': Array(45., dtype=float32), 'lon': Array(90., dtype=float32, ...)}, {})
>>> cxv.vconvert(cxv.MathSphericalPos, cxv.CylindricalPos, cyl, units=usys) ({'phi': Array(45..., dtype=float32), 'r': Array(1.4142135, dtype=float32, ...), 'theta': Array(90., dtype=float32, ...)}, {})
- coordinax.vconvert(to_vector: type[CartesianPos3D], from_vector: type[SphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CylindricalPos -> CartesianPos3D.
Examples
>>> import coordinax.vecs as cxv >>> sph = {"r": 1, "theta": 90, "phi": 90} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.CartesianPos3D, cxv.SphericalPos, sph, units=usys) ({'x': Array(-4.371139e-08, dtype=float32, ...), 'y': Array(1., dtype=float32, ...), 'z': Array(-4.371139e-08, dtype=float32, ...)}, {})
- coordinax.vconvert(to_vector: type[CylindricalPos], from_vector: type[SphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
SphericalPos -> CylindricalPos.
Examples
>>> import coordinax.vecs as cxv >>> sph = {"r": 1, "theta": 90, "phi": 90} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.CylindricalPos, cxv.SphericalPos, sph, units=usys) ({'phi': Array(90., dtype=float32, ...), 'rho': Array(1., dtype=float32, ...), 'z': Array(-4.371139e-08, dtype=float32, ...)}, {})
- coordinax.vconvert(to_vector: type[LonLatSphericalPos], from_vector: type[SphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
SphericalPos -> LonLatSphericalPos.
Examples
>>> import coordinax.vecs as cxv >>> sph = {"r": 1, "theta": 90, "phi": 90} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.LonLatSphericalPos, cxv.SphericalPos, sph, units=usys) ({'distance': Array(1, dtype=int32, ...), 'lat': Array(3.2016512e-06, dtype=float32, ...), 'lon': Array(90., dtype=float32, ...)}, {})
- coordinax.vconvert(to_vector: type[AbstractVector], from_vector: type[AbstractVector], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
SphericalVel/Acc -> LonLatSphericalVel/Acc.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> p = {"r": u.Quantity(1, "km/s"), ... "theta": u.Quantity(10, "deg/s"), ... "phi": u.Quantity(20, "deg/s")}
>>> cxv.vconvert(cxv.LonLatSphericalVel, cxv.SphericalVel, p) ({'distance': Quantity(Array(1, dtype=int32, ...), unit='km / s'), 'lat': Quantity(Array(-10, dtype=int32, ...), unit='deg / s'), 'lon': Quantity(Array(20, dtype=int32, ...), unit='deg / s')}, {})
>>> x = cxv.SphericalVel(**p) >>> y = cxv.vconvert(cxv.LonLatSphericalVel, x) >>> print(y) <LonLatSphericalVel: (lon[deg / s], lat[deg / s], distance[km / s]) [ 20 -10 1]>
>>> p = {"r": u.Quantity(1, "km/s2"), ... "theta": u.Quantity(10, "deg/s2"), ... "phi": u.Quantity(20, "deg/s2")}
>>> cxv.vconvert(cxv.LonLatSphericalAcc, cxv.SphericalAcc, p) ({'distance': Quantity(Array(1, dtype=int32, ...), unit='km / s2'), 'lat': Quantity(Array(-10, dtype=int32, ...), unit='deg / s2'), 'lon': Quantity(Array(20, dtype=int32, ...), unit='deg / s2')}, {})
>>> x = cxv.SphericalAcc(**p) >>> y = cxv.vconvert(cxv.LonLatSphericalAcc, x) >>> print(y) <LonLatSphericalAcc: (lon[deg / s2], lat[deg / s2], distance[km / s2]) [ 20 -10 1]>
- coordinax.vconvert(to_vector: type[AbstractVector], from_vector: type[AbstractVector], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
SphericalPos <-> MathSphericalPos.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Position:
>>> p = {"r": 1, "theta": 90, "phi": 90} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.MathSphericalPos, cxv.SphericalPos, p, units=usys) ({'phi': Array(90., dtype=float32, ...), 'r': Array(1, dtype=int32, ...), 'theta': Array(90., dtype=float32, ...)}, {})
>>> cxv.vconvert(cxv.SphericalPos, cxv.MathSphericalPos, p, units=usys) ({'phi': Array(90., dtype=float32, ...), 'r': Array(1, dtype=int32, ...), 'theta': Array(90., dtype=float32, ...)}, {})
Velocity:
>>> p = {"r": u.Quantity(1, "km/s"), ... "theta": u.Quantity(10, "deg/s"), ... "phi": u.Quantity(20, "deg/s")}
>>> p, aux = cxv.vconvert(cxv.MathSphericalVel, cxv.SphericalVel, p) >>> p, aux ({'phi': Quantity(Array(10, dtype=int32, ...), unit='deg / s'), 'r': Quantity(Array(1, dtype=int32, ...), unit='km / s'), 'theta': Quantity(Array(20, dtype=int32, ...), unit='deg / s')}, {})
>>> cxv.vconvert(cxv.SphericalVel, cxv.MathSphericalVel, p) ({'phi': Quantity(Array(20, dtype=int32, ...), unit='deg / s'), 'r': Quantity(Array(1, dtype=int32, ...), unit='km / s'), 'theta': Quantity(Array(10, dtype=int32, ...), unit='deg / s')}, {})
>>> x = cxv.SphericalVel(r=u.Quantity(1, "km/s"), ... theta=u.Quantity(10, "deg/s"), ... phi=u.Quantity(20, "deg/s")) >>> y = cxv.vconvert(cxv.MathSphericalVel, x) >>> print(y) <MathSphericalVel: (r[km / s], theta[deg / s], phi[deg / s]) [ 1 20 10]>
>>> x = cxv.vconvert(cxv.SphericalVel, y) >>> print(x) <SphericalVel: (r[km / s], theta[deg / s], phi[deg / s]) [ 1 10 20]>
Acceleration:
>>> p = {"r": u.Quantity(1, "km/s2"), ... "theta": u.Quantity(10, "deg/s2"), ... "phi": u.Quantity(20, "deg/s2")}
>>> p, aux = cxv.vconvert(cxv.MathSphericalAcc, cxv.SphericalAcc, p) >>> p, aux ({'phi': Quantity(Array(10, dtype=int32, ...), unit='deg / s2'), 'r': Quantity(Array(1, dtype=int32, ...), unit='km / s2'), 'theta': Quantity(Array(20, dtype=int32, ...), unit='deg / s2')}, {})
>>> cxv.vconvert(cxv.SphericalAcc, cxv.MathSphericalAcc, p) ({'phi': Quantity(Array(20, dtype=int32, ...), unit='deg / s2'), 'r': Quantity(Array(1, dtype=int32, ...), unit='km / s2'), 'theta': Quantity(Array(10, dtype=int32, ...), unit='deg / s2')}, {})
>>> x = cxv.SphericalAcc(r=u.Quantity(1, "km/s2"), ... theta=u.Quantity(10, "deg/s2"), ... phi=u.Quantity(20, "deg/s2")) >>> y = cxv.vconvert(cxv.MathSphericalAcc, x) >>> print(y) <MathSphericalAcc: (r[km / s2], theta[deg / s2], phi[deg / s2]) [ 1 20 10]>
>>> x = cxv.vconvert(cxv.SphericalAcc, y) >>> print(x) <SphericalAcc: (r[km / s2], theta[deg / s2], phi[deg / s2]) [ 1 10 20]>
- coordinax.vconvert(to_vector: type[CartesianPos3D], from_vector: type[LonLatSphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
LonLatSphericalPos -> CartesianPos3D.
Examples
>>> import coordinax.vecs as cxv >>> vec = {"lon": 90, "lat": 0, "distance": 1} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.CartesianPos3D, cxv.LonLatSphericalPos, vec, units=usys) ({'x': Array(-4.371139e-08, dtype=float32, ...), 'y': Array(1., dtype=float32, ...), 'z': Array(-4.371139e-08, dtype=float32, ...)}, {})
- coordinax.vconvert(to_vector: type[CylindricalPos], from_vector: type[LonLatSphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
LonLatSphericalPos -> CylindricalPos.
Examples
>>> import coordinax.vecs as cxv >>> sph = {"lon": 90, "lat": 0, "distance": 1} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.CylindricalPos, cxv.LonLatSphericalPos, sph, units=usys) ({'phi': Array(90., dtype=float32, ...), 'rho': Array(1., dtype=float32, ...), 'z': Array(-4.371139e-08, dtype=float32, ...)}, {})
- coordinax.vconvert(to_vector: type[SphericalPos], from_vector: type[LonLatSphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
LonLatSphericalPos -> SphericalPos.
Examples
>>> import coordinax.vecs as cxv >>> vec = {"lon": 90, "lat": 0, "distance": 1} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.SphericalPos, cxv.LonLatSphericalPos, vec, units=usys) ({'phi': Array(90., dtype=float32, ..., 'r': Array(1, dtype=int32, ..., 'theta': Array(90., dtype=float32, ...}, {})
- coordinax.vconvert(to_vector: type[AbstractVector], from_vector: type[AbstractVector], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
LonLatSphericalVel -> SphericalVel.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> p = {"lon": u.Quantity(90, "deg/s"), ... "lat": u.Quantity(0, "deg/s"), ... "distance": u.Quantity(1, "km/s")} >>> cxv.vconvert(cxv.SphericalVel, cxv.LonLatSphericalVel, p) ({'r': Quantity(Array(1, dtype=int32, ...), unit='km / s'), 'theta': Quantity(Array(0, dtype=int32, ...), unit='deg / s'), 'phi': Quantity(Array(90, dtype=int32, ...), unit='deg / s')}, {})
>>> x = cxv.LonLatSphericalVel(**p) >>> y = cxv.vconvert(cxv.SphericalVel, x) >>> print(y) <SphericalVel: (r[km / s], theta[deg / s], phi[deg / s]) [ 1 0 90]>
>>> p = {"lon": u.Quantity(90, "deg/s2"), ... "lat": u.Quantity(0, "deg/s2"), ... "distance": u.Quantity(1, "km/s2")} >>> cxv.vconvert(cxv.SphericalAcc, cxv.LonLatSphericalAcc, p) ({'r': Quantity(Array(1, dtype=int32, ...), unit='km / s2'), 'theta': Quantity(Array(0, dtype=int32, ...), unit='deg / s2'), 'phi': Quantity(Array(90, dtype=int32, ...), unit='deg / s2')}, {})
>>> x = cxv.LonLatSphericalAcc(**p) >>> y = cxv.vconvert(cxv.SphericalAcc, x) >>> print(y) <SphericalAcc: (r[km / s2], theta[deg / s2], phi[deg / s2]) [ 1 0 90]>
- coordinax.vconvert(to_vector: type[CartesianPos3D], from_vector: type[MathSphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
MathSphericalPos -> CartesianPos3D.
Examples
>>> import coordinax.vecs as cxv >>> vec = {"r": 1, "theta": 90, "phi": 90} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.CartesianPos3D, cxv.MathSphericalPos, vec, units=usys) ({'x': Array(-4.371139e-08, dtype=float32, ...), 'y': Array(1., dtype=float32, ...), 'z': Array(-4.371139e-08, dtype=float32, ...)}, {})
- coordinax.vconvert(to_vector: type[CylindricalPos], from_vector: type[MathSphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
MathSphericalPos -> CylindricalPos.
Examples
>>> import coordinax.vecs as cxv >>> vec = {"r": 1, "theta": 90, "phi": 90} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.CylindricalPos, cxv.MathSphericalPos, vec, units=usys) ({'phi': Array(90., dtype=float32, ...), 'rho': Array(1., dtype=float32, ...), 'z': Array(-4.371139e-08, dtype=float32, ...)}, {})
- coordinax.vconvert(to_vector: type[CylindricalPos], from_vector: type[ProlateSpheroidalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
ProlateSpheroidalPos -> CylindricalPos.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv >>> vec = {"mu": 1, "nu": 0.2, "phi": 90} >>> in_aux = {"Delta": 0.5} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.CylindricalPos, cxv.ProlateSpheroidalPos, ... vec, in_aux=in_aux, units=usys) ({'phi': Array(90., dtype=float32, ...), 'rho': Array(0.38729832, dtype=float32, ...), 'z': Array(0.8944272, dtype=float32, ...)}, {})
TODO: example with Delta as a Quantity
- coordinax.vconvert(to_vector: type[ProlateSpheroidalPos], from_vector: type[CylindricalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CylindricalPos -> ProlateSpheroidalPos.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> vec = {"rho": 1, "phi": 90, "z": 1} >>> out_aux = {"Delta": 0.5} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.ProlateSpheroidalPos, cxv.CylindricalPos, ... vec, out_aux=out_aux, units=usys) ({'mu': Array(2.1327822, dtype=float32, ...), 'nu': Array(0.11721778, dtype=float32, ...), 'phi': Array(90., dtype=float32, ...)}, {'Delta': Array(0.5, dtype=float32, ...)})
# <ProlateSpheroidalPos: (mu[km2], nu[km2], phi[deg]) # [ 2.133 0.117 90. ]>
TODO: example with Delta as a Quantity
- coordinax.vconvert(to_vector: type[ProlateSpheroidalPos], from_vector: type[ProlateSpheroidalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any], out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
ProlateSpheroidalPos -> ProlateSpheroidalPos.
Examples
>>> import coordinax.vecs as cxv >>> vec = {"mu": 1, "nu": 0.2, "phi": 90} >>> in_aux = {"Delta": 0.5} >>> usys = u.unitsystem("km", "deg")
Self-transforms can change the focal length:
>>> out_aux = {"Delta": 0.8} >>> cxv.vconvert(cxv.ProlateSpheroidalPos, cxv.ProlateSpheroidalPos, ... vec, in_aux=in_aux, out_aux=out_aux, units=usys) ({'mu': Array(1.1414464, dtype=float32, ...), 'nu': Array(0.44855377, dtype=float32, ...), 'phi': Array(90., dtype=float32, ...)}, {'Delta': Array(0.8, dtype=float32, ...)})
Without changing the focal length, no transform is done:
>>> cxv.vconvert(cxv.ProlateSpheroidalPos, cxv.ProlateSpheroidalPos, ... vec, in_aux=in_aux, units=usys) ({'mu': Array(1, dtype=int32, ...), 'nu': Array(0.2, dtype=float32, ...), 'phi': Array(90, dtype=int32, ...)}, {'Delta': Array(0.5, dtype=float32, ...)})
- coordinax.vconvert(to_vector: type[ProlateSpheroidalPos], from_vector: type[AbstractPos3D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any], units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
AbstractPos3D -> ProlateSpheroidalPos.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> vec = {"x": 1, "y": 2, "z": 3} >>> out_aux = {"Delta": 0.5} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.ProlateSpheroidalPos, cxv.CartesianPos3D, ... vec, out_aux=out_aux, units=usys) ({'mu': Array(14.090316, dtype=float32, ...), 'nu': Array(0.15968415, dtype=float32, ...), 'phi': Array(63.43495, dtype=float32, ...)}, {'Delta': Array(0.5, dtype=float32, ...)})
- coordinax.vconvert(target: type[LonCosLatSphericalVel], current: AbstractVel3D, position: AbstractPos, /, **kwargs: Any) LonCosLatSphericalVel
AbstractVel3D -> LonCosLatSphericalVel.
Examples
>>> import quaxed.numpy as jnp >>> import unxt as u >>> import coordinax.vecs as cxv
>>> q = cxv.LonLatSphericalPos(lon=u.Quantity(15, "deg"), ... lat=u.Quantity(10, "deg"), ... distance=u.Quantity(1.5, "km")) >>> p = cxv.LonLatSphericalVel(lon=u.Quantity(7, "mas/yr"), ... lat=u.Quantity(0, "deg/Gyr"), ... distance=u.Quantity(-5, "km/s")) >>> newp = cxv.vconvert(cxv.LonCosLatSphericalVel, p, q) >>> print(newp) <LonCosLatSphericalVel: (lon_coslat[mas / yr], lat[deg / Gyr], distance[km / s]) [ 6.894 0. -5. ]>
- coordinax.vconvert(target: type[LonLatSphericalVel], current: LonCosLatSphericalVel, position: AbstractPos, /, **kwargs: Any) LonLatSphericalVel
LonCosLatSphericalVel -> LonLatSphericalVel.
- coordinax.vconvert(target: type[AbstractVel3D], current: LonCosLatSphericalVel, position: AbstractPos, /, **kwargs: Any) AbstractVel3D
LonCosLatSphericalVel -> AbstractVel3D.
- coordinax.vconvert(target: type[KinematicSpace], w: KinematicSpace, /) KinematicSpace
Space -> KinematicSpace.
Examples
>>> import coordinax as cx
>>> w = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), ... speed=cx.CartesianVel3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... )
>>> cx.vconvert(cx.KinematicSpace, w) KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ) })
- coordinax.vconvert(target: type[PoincarePolarVector], w: KinematicSpace, /) PoincarePolarVector
Space -> PoincarePolarVector.
Examples
>>> import coordinax as cx
>>> w = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), ... speed=cx.CartesianVel3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... )
>>> cx.vconvert(cx.vecs.PoincarePolarVector, w) PoincarePolarVector( rho=Quantity([[2.23606801, 6.40312433]], unit='m'), pp_phi=Quantity([[0., 0.]], unit='m / s(1/2)'), z=Quantity([[3, 6]], unit='m'), dt_rho=Quantity([[2.23606801, 6.40312433]], unit='m / s'), dt_pp_phi=Quantity([[0., 0.]], unit='m / s(1/2)'), dt_z=Quantity([[3, 6]], unit='m / s') )
- coordinax.vconvert(to_vector: type[CartesianPos1D], from_vector: type[RadialPos], params: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
RadialPos -> CartesianPos1D.
The r coordinate is converted to the x coordinate of the 1D system.
- coordinax.vconvert(to_vector: type[RadialPos], from_vector: type[CartesianPos1D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos1D -> RadialPos.
The x coordinate is converted to the r coordinate of the 1D system.
- coordinax.vconvert(to_vector: type[AbstractPos2D], from_vector: type[AbstractPos2D], params: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
AbstractPos -> CartesianPos1D -> AbstractPos.
- coordinax.vconvert(to_vector: type[PolarPos], from_vector: type[CartesianPos2D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any] | None]
CartesianPos2D -> PolarPos.
The x and y coordinates are converted to the radial coordinate r and the angular coordinate phi.
- coordinax.vconvert(to_vector: type[CartesianPos2D], from_vector: type[PolarPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any] | None]
PolarPos -> CartesianPos2D.
The r and phi coordinates are converted to the x and y coordinates.
- coordinax.vconvert(spatial_target: type[AbstractPos3D], current: FourVector, /, **kwargs: Any) FourVector
Convert the spatial part of a 4-vector to a different 3-vector.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> w = cx.FourVector (t=u.Quantity(1, "s"), q=u.Quantity([1, 2, 3], "m")) >>> print(cx.vconvert(cx.vecs.CylindricalPos, w)) <FourVector: (t[s], q=(rho[m], phi[rad], z[m])) [1. 2.236 1.107 3. ]>
- coordinax.vconvert(target: type[AbstractVector], current: AbstractVector, /, units: AbstractUnitSystem | None = None, **out_aux: Any) AbstractVector
AbstractPos -> vconvert_impl -> AbstractPos.
This is the base case for the transformation of position vectors.
- coordinax.vconvert(to_vector: type[AbstractVector], from_vector: type[AbstractVector], current: AbstractVector, /, **out_aux: Any) AbstractVector
Convert from one position vector to another.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.CartesianPos2D.from_([3, 4], "km") >>> y = cxv.vconvert(cxv.PolarPos, cxv.CartesianPos2D, x) >>> print(y) <PolarPos: (r[km], phi[rad]) [5. 0.927]>
- coordinax.vconvert(to_vector: type[AbstractVector], from_vector: type[AbstractVector], params: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
Self transform.
Examples
>>> import jax.numpy as jnp >>> import unxt as u >>> import coordinax.vecs as cxv
## 1D:
>>> params = {"x": 1} >>> cxv.vconvert(cxv.CartesianPos1D, cxv.CartesianPos1D, params) ({'x': 1}, {})
>>> params = {"r": 1} >>> cxv.vconvert(cxv.RadialPos, cxv.RadialPos, params) ({'r': 1}, {})
## 2D:
>>> params = {"x": 1, "y": 2} >>> cxv.vconvert(cxv.CartesianPos2D, cxv.CartesianPos2D, params) ({'x': 1, 'y': 2}, {})
>>> params = {"r": 1, "phi": 10} >>> cxv.vconvert(cxv.PolarPos, cxv.PolarPos, params) ({'r': 1, 'phi': 10}, {})
>>> params = {"theta": 10, "phi": 14} >>> cxv.vconvert(cxv.TwoSpherePos, cxv.TwoSpherePos, params) ({'theta': 10, 'phi': 14}, {})
## 3D:
>>> params = {"x": 1, "y": 2, "z": 3} >>> cxv.vconvert(cxv.CartesianPos3D, cxv.CartesianPos3D, params) ({'x': 1, 'y': 2, 'z': 3}, {})
>>> params = {"rho": 1, "phi": 2, "z": 3} >>> cxv.vconvert(cxv.CylindricalPos, cxv.CylindricalPos, params) ({'rho': 1, 'phi': 2, 'z': 3}, {})
>>> params = {"r": 1, "theta": 2, "phi": 3} >>> cxv.vconvert(cxv.SphericalPos, cxv.SphericalPos, params) ({'r': 1, 'theta': 2, 'phi': 3}, {})
>>> params = {"lon": 1, "lat": 2, "distance": 3} >>> cxv.vconvert(cxv.LonLatSphericalPos, cxv.LonLatSphericalPos, params) ({'lon': 1, 'lat': 2, 'distance': 3}, {})
>>> params = {"r": 1, "theta": 2, "phi": 3} >>> cxv.vconvert(cxv.MathSphericalPos, cxv.MathSphericalPos, params) ({'r': 1, 'theta': 2, 'phi': 3}, {})
>>> params = {"rho": 1, "pp_phi": 2, "z": 3, "dt_rho": 4, "dt_pp_phi": 5, "dt_z": 6} >>> cxv.vconvert(cxv.PoincarePolarVector, cxv.PoincarePolarVector, params) ({'rho': 1, 'pp_phi': 2, 'z': 3, 'dt_rho': 4, 'dt_pp_phi': 5, 'dt_z': 6}, {})
>>> params = {"q": jnp.array([1, 2, 3, 4])} >>> cxv.vconvert(cxv.CartesianPosND, cxv.CartesianPosND, params) ({'q': Array([1, 2, 3, 4], dtype=int32)}, {})
- coordinax.vconvert(target: type[AbstractVector], current: AbstractVector, /, *args: Any, **kw: Any) AbstractVector
Self transforms.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
## 1D:
>>> q = cxv.CartesianPos1D.from_(1, "m") >>> cxv.vconvert(cxv.CartesianPos1D, q) is q True
>>> q = cxv.RadialPos.from_(1, "m") >>> cxv.vconvert(cxv.RadialPos, q) is q True
>>> p = cxv.CartesianVel1D.from_(1, "m/s") >>> cxv.vconvert(cxv.CartesianVel1D, p) is p True >>> cxv.vconvert(cxv.CartesianVel1D, p, q) is p True
>>> p = cxv.RadialVel.from_(1, "m/s") >>> cxv.vconvert(cxv.RadialVel, p) is p True >>> cxv.vconvert(cxv.RadialVel, p, q) is p True
>>> a = cxv.CartesianAcc1D.from_(1, "m/s2") >>> cxv.vconvert(cxv.CartesianAcc1D, a) is a True >>> cxv.vconvert(cxv.CartesianAcc1D, a, p, q) is a True
>>> a = cxv.RadialAcc.from_(1, "m/s2") >>> cxv.vconvert(cxv.RadialAcc, a) is a True >>> cxv.vconvert(cxv.RadialAcc, a, p, q) is a True
## 2D:
>>> q = cxv.CartesianPos2D.from_([1, 2], "m") >>> cxv.vconvert(cxv.CartesianPos2D, q) is q True
>>> q = cxv.PolarPos(r=u.Quantity(1, "m"), phi=u.Quantity(10, "deg")) >>> cxv.vconvert(cxv.PolarPos, q) is q True
>>> q = cxv.TwoSpherePos(theta=u.Quantity(10, "deg"), phi=u.Quantity(14, "deg")) >>> cxv.vconvert(cxv.TwoSpherePos, q) is q True
>>> p = cxv.CartesianVel2D.from_([1, 2], "m/s") >>> cxv.vconvert(cxv.CartesianVel2D, p) is p True
>>> p = cxv.PolarVel(r=u.Quantity(1, "m/s"), phi=u.Quantity(10, "deg/s")) >>> cxv.vconvert(cxv.PolarVel, p) is p True
>>> a = cxv.CartesianAcc2D.from_([1, 2], "m/s2") >>> cxv.vconvert(cxv.CartesianAcc2D, a) is a True
## 3D:
Cartesian to Cartesian:
>>> vec = cxv.CartesianPos3D.from_([1, 2, 3], "km") >>> cxv.vconvert(cxv.CartesianPos3D, vec) is vec True
Cylindrical to Cylindrical:
>>> vec = cxv.CylindricalPos(rho=u.Quantity(1, "km"), ... phi=u.Quantity(2, "deg"), ... z=u.Quantity(3, "km")) >>> cxv.vconvert(cxv.CylindricalPos, vec) is vec True
Spherical to Spherical:
>>> vec = cxv.SphericalPos(r=u.Quantity(1, "km"), ... theta=u.Quantity(2, "deg"), ... phi=u.Quantity(3, "deg")) >>> cxv.vconvert(cxv.SphericalPos, vec) is vec True
LonLatSpherical to LonLatSpherical:
>>> vec = cxv.LonLatSphericalPos(lon=u.Quantity(1, "deg"), ... lat=u.Quantity(2, "deg"), ... distance=u.Quantity(3, "km")) >>> cxv.vconvert(cxv.LonLatSphericalPos, vec) is vec True
MathSpherical to MathSpherical:
>>> vec = cxv.MathSphericalPos(r=u.Quantity(1, "km"), ... theta=u.Quantity(2, "deg"), ... phi=u.Quantity(3, "deg")) >>> cxv.vconvert(cxv.MathSphericalPos, vec) is vec True
For these transformations the position does not matter since the self-transform returns the velocity unchanged.
>>> vec = cxv.CartesianPos3D.from_([1, 2, 3], "km")
Cartesian to Cartesian velocity:
>>> dif = cxv.CartesianVel3D.from_([1, 2, 3], "km/s") >>> cxv.vconvert(cxv.CartesianVel3D, dif, vec) is dif True
Cylindrical to Cylindrical velocity:
>>> dif = cxv.CylindricalVel(rho=u.Quantity(1, "km/s"), ... phi=u.Quantity(2, "mas/yr"), ... z=u.Quantity(3, "km/s")) >>> cxv.vconvert(cxv.CylindricalVel, dif, vec) is dif True
Spherical to Spherical velocity:
>>> dif = cxv.SphericalVel(r=u.Quantity(1, "km/s"), ... theta=u.Quantity(2, "mas/yr"), ... phi=u.Quantity(3, "mas/yr")) >>> cxv.vconvert(cxv.SphericalVel, dif, vec) is dif True
LonLatSpherical to LonLatSpherical velocity:
>>> dif = cxv.LonLatSphericalVel(lon=u.Quantity(1, "mas/yr"), ... lat=u.Quantity(2, "mas/yr"), ... distance=u.Quantity(3, "km/s")) >>> cxv.vconvert(cxv.LonLatSphericalVel, dif, vec) is dif True
LonCosLatSpherical to LonCosLatSpherical velocity:
>>> dif = cxv.LonCosLatSphericalVel(lon_coslat=u.Quantity(1, "mas/yr"), ... lat=u.Quantity(2, "mas/yr"), ... distance=u.Quantity(3, "km/s")) >>> cxv.vconvert(cxv.LonCosLatSphericalVel, dif, vec) is dif True
MathSpherical to MathSpherical velocity:
>>> dif = cxv.MathSphericalVel(r=u.Quantity(1, "km/s"), ... theta=u.Quantity(2, "mas/yr"), ... phi=u.Quantity(3, "mas/yr")) >>> cxv.vconvert(cxv.MathSphericalVel, dif, vec) is dif True
Similarly for the these accelerations:
>>> a = cxv.CartesianAcc3D.from_([1, 1, 1], "m/s2") >>> cxv.vconvert(cxv.CartesianAcc3D, a) is a True
## N-D:
>>> x = cxv.CartesianPosND.from_([1, 2, 3, 4], "km") >>> cxv.vconvert(cxv.CartesianPosND, x) is x True
>>> v = cxv.CartesianVelND.from_([1, 2, 3, 4], "km/s") >>> cxv.vconvert(cxv.CartesianVelND, v, x) is v True >>> cxv.vconvert(cxv.CartesianVelND, v) is v True
>>> a = cxv.CartesianAccND.from_([1, 2, 3, 4], "m/s2") >>> cxv.vconvert(cxv.CartesianAccND, a, v, x) is a True >>> cxv.vconvert(cxv.CartesianAccND, a) is a True
- coordinax.vconvert(to_vector: type[AbstractPos], from_vector: type[AbstractPos], params: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
AbstractPos -> CartesianPos1D -> AbstractPos.
- coordinax.vconvert(to_vector: type[AbstractPos], from_vector: type[AbstractPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos2D -> CartesianPos1D.
The y and z coordinates are dropped.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
## 2D:
>>> params = {"x": 1, "y": 2}
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.CartesianPos1D, cxv.CartesianPos2D, params) ({'x': 1}, {})
>>> x = cxv.CartesianPos2D.from_([1, 2], "km") >>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.CartesianPos1D, x) >>> print(y) <CartesianPos1D: (x) [km] [1]>
>>> x = cxv.PolarPos(r=u.Quantity(1, "km"), phi=u.Quantity(10, "deg"))
>>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.RadialPos, x) >>> print(y) <RadialPos: (r) [km] [1]>
## 3D:
>>> params = {"x": 1, "y": 2, "z": 3}
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.CartesianPos1D, cxv.CartesianPos3D, params) ({'x': 1}, {})
>>> x = cxv.CartesianPos3D.from_([1.0, 2.0, 3.0], "km") >>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.CartesianPos1D, x) >>> print(y) <CartesianPos1D: (x) [km] [1.]>
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.CartesianPos2D, cxv.CartesianPos3D, params) ({'x': 1, 'y': 2}, {})
>>> x = cxv.CartesianPos3D.from_([1.0, 2.0, 3.0], "km")
>>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.CartesianPos2D, x) >>> print(y) <CartesianPos2D: (x, y) [km] [1. 2.]>
>>> params = {"r": 1, "theta": 14, "phi": 10} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.RadialPos, cxv.SphericalPos, ... params, units=usys) ({'r': Array(1, dtype=int32, ...)}, {})
>>> x = cxv.SphericalPos(r=u.Quantity(1, "km"), ... theta=u.Quantity(14, "deg"), ... phi=u.Quantity(10, "deg")) >>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.RadialPos, x) >>> print(y) <RadialPos: (r) [km] [1]>
>>> params = {"r": 1, "theta": 10, "phi": 14} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.RadialPos, cxv.MathSphericalPos, ... params, units=usys) ({'r': Array(1, dtype=int32, ...)}, {})
>>> x = cxv.MathSphericalPos(r=u.Quantity(1, "km"), ... theta=u.Quantity(10, "deg"), ... phi=u.Quantity(14, "deg"))
>>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.RadialPos, x) >>> print(y) <RadialPos: (r) [km] [1]>
- coordinax.vconvert(to_vector: type[CartesianPos2D], from_vector: type[CartesianPos1D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos1D -> CartesianPos2D.
The x coordinate is converted to the x coordinate of the 2D system. The y coordinate is a keyword argument and defaults to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.CartesianPos1D(x=u.Quantity(1.0, "km")) >>> x2 = cxv.vconvert(cxv.CartesianPos2D, x) >>> print(x2) <CartesianPos2D: (x, y) [km] [1. 0.]>
>>> x3 = cxv.vconvert(cxv.CartesianPos3D, x, y=u.Quantity(14, "km")) >>> print(x3) <CartesianPos3D: (x, y, z) [km] [ 1. 14. 0.]>
- coordinax.vconvert(to_vector: type[PolarPos], from_vector: type[CartesianPos1D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos1D -> PolarPos.
The x coordinate is converted to the radial coordinate r. The phi coordinate is a keyword argument and defaults to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.CartesianPos1D(x=u.Quantity(1.0, "km")) >>> x2 = cxv.vconvert(cxv.PolarPos, x) >>> print(x2) <PolarPos: (r[km], phi[rad]) [1. 0.]>
>>> x3 = cxv.vconvert(cxv.PolarPos, x, phi=u.Quantity(14, "deg")) >>> print(x3) <PolarPos: (r[km], phi[deg]) [ 1. 14.]>
- coordinax.vconvert(to_vector: type[CartesianPos3D], from_vector: type[CartesianPos1D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos1D -> CartesianPos3D.
The x coordinate is converted to the x coordinate of the 3D system. The y and z coordinates are keyword arguments and default to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.CartesianPos1D(x=u.Quantity(1, "km")) >>> x2 = cxv.vconvert(cxv.CartesianPos3D, x) >>> print(x2) <CartesianPos3D: (x, y, z) [km] [1 0 0]>
>>> x3 = cxv.vconvert(cxv.CartesianPos3D, x, y=u.Quantity(14, "km")) >>> print(x3) <CartesianPos3D: (x, y, z) [km] [ 1 14 0]>
- coordinax.vconvert(to_vector: type[AbstractPos3D], from_vector: type[CartesianPos1D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos1D -> SphericalPos | MathSphericalPos.
The x coordinate is converted to the radial coordinate r. The theta and phi coordinates are keyword arguments and default to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
SphericalPos:
>>> x = cxv.CartesianPos1D(x=u.Quantity(1, "km")) >>> x2 = cxv.vconvert(cxv.SphericalPos, x) >>> print(x2) <SphericalPos: (r[km], theta[rad], phi[rad]) [1. 0. 0.]>
>>> x3 = cxv.vconvert(cxv.SphericalPos, x, phi=u.Quantity(14, "deg")) >>> print(x3) <SphericalPos: (r[km], theta[rad], phi[deg]) [ 1 0 14]>
MathSphericalPos: Note that
thetaandphihave different meanings in this context.>>> x2 = cxv.vconvert(cxv.MathSphericalPos, x) >>> print(x2) <MathSphericalPos: (r[km], theta[rad], phi[rad]) [1. 0. 0.]>
>>> x3 = cxv.vconvert(cxv.MathSphericalPos, x, phi=u.Quantity(14, "deg")) >>> print(x3) <MathSphericalPos: (r[km], theta[rad], phi[deg]) [ 1. 0. 14.]>
- coordinax.vconvert(to_vector: type[CylindricalPos], from_vector: type[CartesianPos1D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
RadialPos -> CartesianPos2D.
The x coordinate is converted to the radial coordinate rho. The phi and z coordinates are keyword arguments and default to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.CartesianPos1D(x=u.Quantity(1, "km")) >>> x2 = cxv.vconvert(cxv.CylindricalPos, x) >>> print(x2) <CylindricalPos: (rho[km], phi[rad], z[km]) [1. 0. 0.]>
>>> x3 = cxv.vconvert(cxv.CylindricalPos, x, phi=u.Quantity(14, "deg")) >>> print(x3) <CylindricalPos: (rho[km], phi[deg], z[km]) [ 1 14 0]>
- coordinax.vconvert(to_vector: type[CartesianPos2D], from_vector: type[RadialPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
RadialPos -> CartesianPos2D.
The r coordinate is converted to the cartesian coordinate x. The y coordinate is a keyword argument and defaults to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.RadialPos(r=u.Quantity(1, "km")) >>> x2 = cxv.vconvert(cxv.CartesianPos2D, x) >>> print(x2) <CartesianPos2D: (x, y) [km] [1 0]>
>>> x3 = cxv.vconvert(cxv.CartesianPos2D, x, y=u.Quantity(14, "km")) >>> print(x3) <CartesianPos2D: (x, y) [km] [ 1 14]>
- coordinax.vconvert(to_vector: type[PolarPos], from_vector: type[RadialPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
RadialPos -> PolarPos.
The r coordinate is converted to the radial coordinate r. The phi coordinate is a keyword argument and defaults to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.RadialPos(r=u.Quantity(1, "km")) >>> x2 = cxv.vconvert(cxv.PolarPos, x) >>> print(x2) <PolarPos: (r[km], phi[rad]) [1. 0.]>
>>> x3 = cxv.vconvert(cxv.PolarPos, x, phi=u.Quantity(14, "deg")) >>> print(x3) <PolarPos: (r[km], phi[deg]) [ 1 14]>
- coordinax.vconvert(to_vector: type[CartesianPos3D], from_vector: type[RadialPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
RadialPos -> CartesianPos3D.
The r coordinate is converted to the x coordinate of the 3D system. The y and z coordinates are keyword arguments and default to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.RadialPos(r=u.Quantity(1.0, "km")) >>> y = cxv.vconvert(cxv.CartesianPos3D, x) >>> print(y) <CartesianPos3D: (x, y, z) [km] [1. 0. 0.]>
>>> y = cxv.vconvert(cxv.CartesianPos3D, x, y=u.Quantity(14, "km")) >>> print(y) <CartesianPos3D: (x, y, z) [km] [ 1. 14. 0.]>
- coordinax.vconvert(to_vector: type[AbstractPos3D], from_vector: type[RadialPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
RadialPos -> SphericalPos | MathSphericalPos.
The r coordinate is converted to the radial coordinate r. The theta and phi coordinates are keyword arguments and default to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.RadialPos(r=u.Quantity(1, "km"))
SphericalPos:
>>> y = cxv.vconvert(cxv.SphericalPos, x) >>> print(y) <SphericalPos: (r[km], theta[rad], phi[rad]) [1. 0. 0.]>
>>> y = cxv.vconvert(cxv.SphericalPos, x, phi=u.Quantity(14, "deg")) >>> print(y) <SphericalPos: (r[km], theta[rad], phi[deg]) [ 1 0 14]>
MathSphericalPos:
>>> y = cxv.vconvert(cxv.MathSphericalPos, x) >>> print(y) <MathSphericalPos: (r[km], theta[rad], phi[rad]) [1. 0. 0.]>
>>> y = cxv.vconvert(cxv.MathSphericalPos, x, phi=u.Quantity(14, "deg")) >>> print(y) <MathSphericalPos: (r[km], theta[rad], phi[deg]) [ 1. 0. 14.]>
- coordinax.vconvert(to_vector: type[CylindricalPos], from_vector: type[RadialPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
RadialPos -> CylindricalPos.
The r coordinate is converted to the radial coordinate rho. The phi and z coordinates are keyword arguments and default to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.RadialPos(r=u.Quantity(1.0, "km")) >>> y = cxv.vconvert(cxv.CylindricalPos, x) >>> print(y) <CylindricalPos: (rho[km], phi[rad], z[km]) [1. 0. 0.]>
>>> y = cxv.vconvert(cxv.CylindricalPos, x, phi=u.Quantity(14, "deg")) >>> print(y) <CylindricalPos: (rho[km], phi[deg], z[km]) [ 1. 14. 0.]>
- coordinax.vconvert(to_vector: type[AbstractPos3D], from_vector: type[CartesianPos2D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
AbstractPos2D -> Cartesian2D -> Cartesian3D -> AbstractPos3D.
The 2D vector is in the xy plane. The z coordinate is a keyword argument and defaults to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.CartesianPos2D.from_([1, 2], "km")
>>> y = cxv.vconvert(cxv.CylindricalPos, x, z=u.Quantity(14, "km")) >>> print(y) <CylindricalPos: (rho[km], phi[rad], z[km]) [ 2.236 1.107 14. ]>
>>> y = cxv.vconvert(cxv.SphericalPos, x, z=u.Quantity(14, "km")) >>> print(y) <SphericalPos: (r[km], theta[rad], phi[rad]) [14.177 0.158 1.107]>
>>> y = cxv.vconvert(cxv.MathSphericalPos, x, z=u.Quantity(14, "km")) >>> print(y) <MathSphericalPos: (r[km], theta[rad], phi[rad]) [14.177 1.107 0.158]>
- coordinax.vconvert(to_vector: type[CartesianPos3D], from_vector: type[PolarPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
AbstractPos2D -> PolarPos -> Cylindrical -> AbstractPos3D.
The 2D vector is in the xy plane. The z coordinate is a keyword argument and defaults to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.PolarPos(r=u.Quantity(1, "km"), phi=u.Quantity(10, "deg"))
>>> x2 = cxv.vconvert(cxv.CartesianPos3D, x, z=u.Quantity(14, "km")) >>> print(x2) <CartesianPos3D: (x, y, z) [km] [ 0.985 0.174 14. ]>
- coordinax.vconvert(to_vector: type[RadialPos], from_vector: type[CartesianPos2D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos2D -> RadialPos.
The x and y coordinates are converted to the radial coordinate r.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.CartesianPos2D.from_([1, 2], "km")
>>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.RadialPos, x) >>> print(y) <RadialPos: (r) [km] [2.236]>
- coordinax.vconvert(to_vector: type[CartesianPos3D], from_vector: type[CartesianPos2D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos2D -> CartesianPos3D.
The x and y coordinates are converted to the x and y coordinates of the 3D system. The z coordinate is a keyword argument and defaults to 0.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.CartesianPos2D.from_([1, 2], "km")
>>> x2 = cxv.vconvert(cxv.CartesianPos3D, x, z=u.Quantity(14, "km")) >>> print(x2) <CartesianPos3D: (x, y, z) [km] [ 1 2 14]>
- coordinax.vconvert(to_vector: type[CartesianPos1D], from_vector: type[PolarPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
PolarPos -> CartesianPos1D.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.PolarPos(r=u.Quantity(1, "km"), phi=u.Quantity(10, "deg"))
>>> with warnings.catch_warnings(action="ignore"): ... x2 = cxv.vconvert(cxv.CartesianPos1D, x) >>> print(x2) <CartesianPos1D: (x) [km] [0.985]>
- coordinax.vconvert(to_vector: type[SphericalPos], from_vector: type[PolarPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
PolarPos -> SphericalPos.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.PolarPos(r=u.Quantity(1, "km"), phi=u.Quantity(10, "deg"))
>>> x2 = cxv.vconvert(cxv.SphericalPos, x, theta=u.Quantity(14, "deg")) >>> print(x2) <SphericalPos: (r[km], theta[deg], phi[deg]) [ 1 14 10]>
- coordinax.vconvert(to_vector: type[MathSphericalPos], from_vector: type[PolarPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
PolarPos -> MathSphericalPos.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.PolarPos(r=u.Quantity(1, "km"), phi=u.Quantity(10, "deg"))
>>> y = cxv.vconvert(cxv.MathSphericalPos, x, theta=u.Quantity(14, "deg")) >>> print(y) <MathSphericalPos: (r[km], theta[deg], phi[deg]) [ 1 10 14]>
- coordinax.vconvert(to_vector: type[CylindricalPos], from_vector: type[PolarPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
PolarPos -> CylindricalPos.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
>>> x = cxv.PolarPos(r=u.Quantity(1, "km"), phi=u.Quantity(10, "deg"))
>>> x2 = cxv.vconvert(cxv.CylindricalPos, x, z=u.Quantity(14, "km")) >>> print(x2) <CylindricalPos: (rho[km], phi[deg], z[km]) [ 1 10 14]>
>>> x2 = cxv.vconvert(cxv.CylindricalPos, x) >>> print(x2) <CylindricalPos: (rho[km], phi[deg], z[km]) [ 1 10 0]>
- coordinax.vconvert(to_vector: type[RadialPos], from_vector: type[CartesianPos3D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos3D -> RadialPos.
Examples
>>> import warnings >>> import coordinax.vecs as cxv
>>> params = {"x": 1, "y": 2, "z": 3}
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.RadialPos, cxv.CartesianPos3D, params) ({'r': Array(3.7416575, dtype=float32, ...)}, {})
>>> x = cxv.CartesianPos3D.from_([1.0, 2.0, 3.0], "km") >>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.RadialPos, x) >>> print(y) <RadialPos: (r) [km] [3.742]>
- coordinax.vconvert(to_vector: type[PolarPos], from_vector: type[CartesianPos3D], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CartesianPos3D -> Cartesian2D -> AbstractPos2D.
Examples
>>> import warnings >>> import coordinax as cx
>>> params = {"x": 1, "y": 2, "z": 3} >>> with warnings.catch_warnings(action="ignore"): ... cx.vecs.vconvert(cx.vecs.PolarPos, cx.vecs.CartesianPos3D, params) ({'r': Array(2.236068, dtype=float32, ...), 'phi': Array(1.1071488, dtype=float32, ...)}, {})
>>> x = cx.CartesianPos3D.from_([1.0, 2.0, 3.0], "km") >>> with warnings.catch_warnings(action="ignore"): ... y = cx.vconvert(cx.vecs.PolarPos, x) >>> print(y) <PolarPos: (r[km], phi[rad]) [2.236 1.107]>
- coordinax.vconvert(to_vector: type[CartesianPos1D], from_vector: type[CylindricalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CylindricalPos -> CartesianPos1D.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> params = {"rho": 1, "phi": 10, "z": 14} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.CartesianPos1D, cxv.CylindricalPos, ... params, units=usys) ({'x': Array(0.9848077, dtype=float32, ...)}, {})
>>> x = cx.vecs.CylindricalPos(rho=u.Quantity(1.0, "km"), ... phi=u.Quantity(10.0, "deg"), ... z=u.Quantity(14, "km")) >>> with warnings.catch_warnings(action="ignore"): ... y = cx.vconvert(cx.vecs.CartesianPos1D, x) >>> print(y) <CartesianPos1D: (x) [km] [0.985]>
- coordinax.vconvert(to_vector: type[RadialPos], from_vector: type[CylindricalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CylindricalPos -> RadialPos.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> params = {"rho": 1, "phi": 10, "z": 14} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.RadialPos, cxv.CylindricalPos, params, units=usys) ({'r': Array(1, dtype=int32, ...)}, {})
>>> x = cxv.CylindricalPos(rho=u.Quantity(1, "km"), ... phi=u.Quantity(10, "deg"), ... z=u.Quantity(14, "km")) >>> with warnings.catch_warnings(action="ignore"): ... y = cx.vconvert(cxv.RadialPos, x) >>> print(y) <RadialPos: (r) [km] [1]>
- coordinax.vconvert(to_vector: type[CartesianPos2D], from_vector: type[CylindricalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CylindricalPos -> CartesianPos2D.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> params = {"rho": 1, "phi": 10, "z": 14} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.CartesianPos2D, cxv.CylindricalPos, ... params, units=usys) ({'x': Array(0.9848077, dtype=float32, ...), 'y': Array(0.17364818, dtype=float32, ...)}, {})
>>> x = cxv.CylindricalPos(rho=u.Quantity(1, "km"), ... phi=u.Quantity(10, "deg"), ... z=u.Quantity(14, "km")) >>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.CartesianPos2D, x) >>> print(y) <CartesianPos2D: (x, y) [km] [0.985 0.174]>
- coordinax.vconvert(to_vector: type[PolarPos], from_vector: type[CylindricalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
CylindricalPos -> PolarPos.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> params = {"rho": 1, "phi": 10, "z": 14} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.PolarPos, cxv.CylindricalPos, ... params, units=usys) ({'r': Array(1, dtype=int32, ...), 'phi': Array(10., dtype=float32, ...)}, {})
>>> x = cxv.CylindricalPos(rho=u.Quantity(1, "km"), ... phi=u.Quantity(10, "deg"), ... z=u.Quantity(14, "km")) >>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.PolarPos, x) >>> print(y) <PolarPos: (r[km], phi[deg]) [ 1 10]>
- coordinax.vconvert(to_vector: type[CartesianPos1D], from_vector: type[SphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
SphericalPos -> CartesianPos1D.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> params = {"r": 1, "theta": 14, "phi": 10} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.CartesianPos1D, cxv.SphericalPos, ... params, units=usys) ({'x': Array(0.23824656, dtype=float32, ...)}, {})
>>> x = cxv.SphericalPos(r=u.Quantity(1, "km"), ... theta=u.Quantity(14, "deg"), ... phi=u.Quantity(10, "deg")) >>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.CartesianPos1D, x) >>> print(y) <CartesianPos1D: (x) [km] [0.238]>
- coordinax.vconvert(to_vector: type[CartesianPos2D], from_vector: type[SphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
SphericalPos -> CartesianPos2D.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> params = {"r": 1, "theta": 14, "phi": 10} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.CartesianPos2D, cxv.SphericalPos, ... params, units=usys) ({'x': Array(0.23824656, dtype=float32, ...), 'y': Array(0.0420093, dtype=float32, ...)}, {})
>>> x = cxv.SphericalPos(r=u.Quantity(1, "km"), ... theta=u.Quantity(14, "deg"), ... phi=u.Quantity(10, "deg")) >>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.CartesianPos2D, x) >>> print(y) <CartesianPos2D: (x, y) [km] [0.238 0.042]>
- coordinax.vconvert(to_vector: type[PolarPos], from_vector: type[SphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
SphericalPos -> PolarPos.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> params = {"r": 1, "theta": 14, "phi": 10} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.PolarPos, cxv.SphericalPos, ... params, units=usys) ({'r': Array(0.2419219, dtype=float32, ...), 'phi': Array(10., dtype=float32, ...)}, {})
>>> x = cxv.SphericalPos(r=u.Quantity(1, "km"), ... theta=u.Quantity(14, "deg"), ... phi=u.Quantity(10, "deg")) >>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.PolarPos, x) >>> print(y) <PolarPos: (r[km], phi[deg]) [ 0.242 10. ]>
- coordinax.vconvert(to_vector: type[CartesianPos1D], from_vector: type[MathSphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
MathSphericalPos -> CartesianPos1D.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> params = {"r": 1, "theta": 10, "phi": 14} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.CartesianPos1D, cxv.MathSphericalPos, ... params, units=usys) ({'x': Array(0.23824656, dtype=float32, ...)}, {})
>>> x = cx.vecs.MathSphericalPos(r=u.Quantity(1, "km"), ... theta=u.Quantity(10, "deg"), ... phi=u.Quantity(14, "deg"))
>>> with warnings.catch_warnings(action="ignore"): ... y = cx.vconvert(cx.vecs.CartesianPos1D, x) >>> print(y) <CartesianPos1D: (x) [km] [0.238]>
- coordinax.vconvert(to_vector: type[CartesianPos2D], from_vector: type[MathSphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
MathSphericalPos -> CartesianPos2D.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> params = {"r": 1, "theta": 10, "phi": 14} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.CartesianPos2D, cxv.MathSphericalPos, ... params, units=usys) ({'x': Array(0.23824656, dtype=float32, ...), 'y': Array(0.0420093, dtype=float32, ...)}, {})
>>> x = cx.vecs.MathSphericalPos(r=u.Quantity(1, "km"), ... theta=u.Quantity(10, "deg"), ... phi=u.Quantity(14, "deg"))
>>> with warnings.catch_warnings(action="ignore"): ... y = cx.vconvert(cx.vecs.CartesianPos2D, x) >>> print(y) <CartesianPos2D: (x, y) [km] [0.238 0.042]>
- coordinax.vconvert(to_vector: type[PolarPos], from_vector: type[MathSphericalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
MathSphericalPos -> PolarPos.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax.vecs as cxv
>>> params = {"r": 1, "theta": 10, "phi": 14} >>> usys = u.unitsystem("km", "deg")
>>> with warnings.catch_warnings(action="ignore"): ... cxv.vconvert(cxv.PolarPos, cxv.MathSphericalPos, ... params, units=usys) ({'r': Array(0.2419219, dtype=float32, ...), 'phi': Array(10., dtype=float32, ...)}, {})
>>> x = cxv.MathSphericalPos(r=u.Quantity(1, "km"), ... theta=u.Quantity(10, "deg"), ... phi=u.Quantity(14, "deg")) >>> with warnings.catch_warnings(action="ignore"): ... y = cxv.vconvert(cxv.PolarPos, x) >>> print(y) <PolarPos: (r[km], phi[deg]) [ 0.242 10. ]>
- coordinax.vconvert(to_vector: type[AbstractPos], from_vector: type[ProlateSpheroidalPos], p: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None, units: AbstractUnitSystem | None = None) tuple[dict[str, Any], dict[str, Any]]
ProlateSpheroidalPos -> AbstractPos.
Examples
>>> import warnings >>> import unxt as u >>> import coordinax as cx
>>> x = cx.vecs.ProlateSpheroidalPos( ... mu=u.Quantity(2, "km2"), ... nu=u.Quantity(0.5, "km2"), ... phi=u.Quantity(0.5, "rad"), ... Delta=u.Quantity(1, "km"), ... )
>>> with warnings.catch_warnings(action="ignore"): ... y = cx.vconvert(cx.vecs.CartesianPos1D, x) >>> print(y) <CartesianPos1D: (x) [km] [0.621]>
>>> with warnings.catch_warnings(action="ignore"): ... y = cx.vconvert(cx.vecs.RadialPos, x) >>> print(y) <RadialPos: (r) [km] [0.707]>
>>> with warnings.catch_warnings(action="ignore"): ... x2 = cx.vconvert(cx.vecs.CartesianPos2D, x) >>> print(x2) <CartesianPos2D: (x, y) [km] [0.621 0.339]>
>>> with warnings.catch_warnings(action="ignore"): ... x2 = cx.vconvert(cx.vecs.PolarPos, x) >>> print(x2) <PolarPos: (r[km], phi[rad]) [0.707 0.5 ]>
>>> import coordinax.vecs as cxv >>> vec = {"mu": 1, "nu": 0.2, "phi": 90} >>> in_aux = {"Delta": 0.5} >>> usys = u.unitsystem("km", "deg")
>>> cxv.vconvert(cxv.CylindricalPos, cxv.ProlateSpheroidalPos, ... vec, in_aux=in_aux, units=usys) ({'phi': Array(90., dtype=float32, ...), 'rho': Array(0.38729832, dtype=float32, ...), 'z': Array(0.8944272, dtype=float32, ...)}, {})
>>> cxv.vconvert(cxv.CartesianPos3D, cxv.ProlateSpheroidalPos, ... vec, in_aux=in_aux, units=usys) ({'x': Array(-1.6929347e-08, dtype=float32, ...), 'y': Array(0.38729832, dtype=float32, ...), 'z': Array(0.8944272, dtype=float32, ...)}, {})
- coordinax.vconvert(target: type[KinematicSpace], w: PoincarePolarVector, /) KinematicSpace
Space -> PoincarePolarVector.
Examples
>>> import coordinax as cx
>>> w = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), ... speed=cx.CartesianVel3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... )
>>> cx.vconvert(cx.vecs.PoincarePolarVector, w) PoincarePolarVector( rho=Quantity([[2.23606801, 6.40312433]], unit='m'), pp_phi=Quantity([[0., 0.]], unit='m / s(1/2)'), z=Quantity([[3, 6]], unit='m'), dt_rho=Quantity([[2.23606801, 6.40312433]], unit='m / s'), dt_pp_phi=Quantity([[0., 0.]], unit='m / s(1/2)'), dt_z=Quantity([[3, 6]], unit='m / s') )
>>> cx.vconvert(cx.KinematicSpace, w) KinematicSpace({ 'length': CartesianPos3D( x=Quantity([[1, 4]], unit='m'), y=Quantity([[2, 5]], unit='m'), z=Quantity([[3, 6]], unit='m') ), 'speed': CartesianVel3D( x=Quantity([[1, 4]], unit='m / s'), y=Quantity([[2, 5]], unit='m / s'), z=Quantity([[3, 6]], unit='m / s') ) })
- coordinax.vconvert(to_dif_cls: type[AbstractVector], from_dif_cls: type[AbstractVector], p_dif: dict[str, Any], p_pos: dict[str, Any], /, *, in_aux: dict[str, Any] | None = None, out_aux: dict[str, Any] | None = None) tuple[dict[str, Any], dict[str, Any] | None]
AbstractVel1D -> AbstractVel1D.
- Parameters:
to_dif_cls β The target type of the vector differential.
from_dif_cls β The type of the vector differential to transform.
p_dif β The data of the vector differential to transform.
p_pos β The data of the position vector used to transform the differential.
in_aux β The input auxiliary data to the transform.
out_aux β THe output auxiliary data to the transform.
args (Any)
kwargs (Any)
- Return type:
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Letβs start in 1D:
>>> q = {"x": u.Quantity([1.0], "km")} >>> p = {"x": u.Quantity([1.0], "km/s")} >>> newp = cxv.vconvert(cxv.RadialVel, cxv.CartesianVel1D, p, q) >>> print(newp) ({'r': Quantity(Array([1.], dtype=float32), unit='km / s')}, {})
>>> q = {"x": u.Quantity([1.0], "km")} >>> a = {"x": u.Quantity([1.0], "km/s2")} >>> newa = cxv.vconvert(cxv.RadialAcc, cxv.CartesianAcc1D, a, q) >>> print(newa) ({'r': Quantity(Array([1.], dtype=float32), unit='km / s2')}, {})
- coordinax.vconvert(to_dif_cls: type[AbstractVector], from_dif: AbstractVector, from_pos: AbstractPos, /, **kwargs: Any) AbstractVector
Differential -> Differential.
This is the base case for the transformation of vector differentials.
- Parameters:
- Return type:
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Letβs start in 1D:
>>> q = cxv.CartesianPos1D.from_(1.0, "km") >>> p = cxv.CartesianVel1D.from_(1.0, "km/s") >>> newp = cxv.vconvert(cxv.RadialVel, p, q) >>> print(newp) <RadialVel: (r) [km / s] [1.]>
>>> a = cxv.CartesianAcc1D(x=u.Quantity(1.0, "km/s2")) >>> print(cxv.vconvert(cxv.RadialAcc, a, p, q)) <RadialAcc: (r) [km / s2] [1.]>
Now in 2D:
>>> q = cxv.CartesianPos2D.from_([1.0, 2.0], "km") >>> p = cxv.CartesianVel2D.from_([1.0, 2.0], "km/s") >>> newp = cxv.vconvert(cxv.PolarVel, p, q) >>> print(newp) <PolarVel: (r[km / s], phi[rad / s]) [2.236 0. ]>
>>> a = cxv.CartesianAcc2D.from_([1.0, 2.0], "km/s2") >>> print(cxv.vconvert(cxv.PolarAcc, a, p, q)) <PolarAcc: (r[km / s2], phi[rad / s2]) [2.236 0. ]>
And in 3D:
>>> q = cxv.CartesianPos3D.from_([1.0, 2.0, 3.0], "km") >>> p = cxv.CartesianVel3D.from_([1.0, 2.0, 3.0], "km/s") >>> newp = cxv.vconvert(cxv.SphericalVel, p, q) >>> print(newp.round(2)) <SphericalVel: (r[km / s], theta[rad / s], phi[rad / s]) [ 3.74 -0. 0. ]>
>>> a = cxv.CartesianAcc3D.from_([1.0, 2.0, 3.0], "km/s2") >>> print(cxv.vconvert(cxv.SphericalAcc, a, p, q).round(2)) <SphericalAcc: (r[km / s2], theta[rad / s2], phi[rad / s2]) [ 3.74 -0. 0. ]>
- coordinax.vconvert(to_acc_cls: type[AbstractAcc], from_acc: AbstractAcc, from_vel: AbstractVel, from_pos: AbstractPos, /, **kwargs: Any) AbstractAcc
AbstractAcc -> Cartesian -> AbstractAcc.
This is the base case for the transformation of accelerations.
Let $mathbf{x}$ be a position vector in one representation $mathbf{y}$ a position vector in another representation related by:
$$ mathbf{y} = f(mathbf{x}) $$
where $f$ is a differentiable function mapping between the coordinate systems.
The Jacobian matrix $J$ of the transformation is:
$$ J = frac{partial mathbf{y}}{partial mathbf{x}}$$
The coordinate transformation of the acceleration is given by the chain rule:
$$ ddot{mathbf{y}} = dot{J} dot{mathbf{x}} + J ddot{mathbf{x}}$$
where $dot{J}$ is the time derivative of the Jacobian matrix. This function assumes that the representation conversion is time-invariant, so $dot{J} = 0$. Thus, the transformation simplifies to:
$$ ddot{mathbf{y}} = J ddot{mathbf{x}}$$
This function implements this transformation.
- Parameters:
to_acc_cls β The target type of the vector acceleration.
from_acc β The vector acceleration to transform.
from_vel β The velocity vector used to transform the acceleration.
from_pos β The position vector used to transform the acceleration.
**kwargs (Any) β Additional keyword arguments.
args (Any)
**kwargs
- Return type:
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Letβs start in 1D:
>>> q = cxv.CartesianPos1D(x=u.Quantity(1.0, "km")) >>> p = cxv.CartesianVel1D(x=u.Quantity(1.0, "km/s")) >>> a = cxv.CartesianAcc1D(x=u.Quantity(1.0, "km/s2")) >>> print(cxv.vconvert(cxv.RadialAcc, a, p, q)) <RadialAcc: (r) [km / s2] [1.]>
Now in 2D:
>>> q = cxv.CartesianPos2D.from_([1.0, 2.0], "km") >>> p = cxv.CartesianVel2D.from_([1.0, 2.0], "km/s") >>> a = cxv.CartesianAcc2D.from_([1.0, 2.0], "km/s2") >>> print(cxv.vconvert(cxv.PolarAcc, a, p, q)) <PolarAcc: (r[km / s2], phi[rad / s2]) [2.236 0. ]>
And in 3D:
>>> q = cxv.CartesianPos3D.from_([1.0, 2.0, 3.0], "km") >>> p = cxv.CartesianVel3D.from_([1.0, 2.0, 3.0], "km/s") >>> a = cxv.CartesianAcc3D.from_([1.0, 2.0, 3.0], "km/s2") >>> print(cxv.vconvert(cxv.SphericalAcc, a, p, q).round(2)) <SphericalAcc: (r[km / s2], theta[rad / s2], phi[rad / s2]) [ 3.74 -0. 0. ]>
- coordinax.vconvert(target: type[AbstractPos], w: Coordinate, /) Coordinate
Transform the vector representation of a coordinate.
Examples
>>> import coordinax as cx
>>> frame = cx.frames.NoFrame() >>> data = cx.CartesianPos3D.from_([1, 2, 3], "kpc") >>> w = cx.Coordinate(data, frame)
>>> cx.vconvert(cx.SphericalPos, w) Coordinate( KinematicSpace({ 'length': SphericalPos( ... ) }), frame=NoFrame() )
- class coordinax.CartesianPos3D(x: Any, y: Any, z: Any)
Bases:
AbstractCartesian,AbstractPos3DCartesian 3D Position.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.CartesianPos3D.from_(u.Quantity([1, 2, 3], "m")) >>> print(vec) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
- property T: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.T.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- asdict(*, dict_factory: ~collections.abc.Callable[[~typing.Any], ~collections.abc.Mapping[str, ~unxt._src.quantity.base.AbstractQuantity]] = <class 'dict'>)
Return the vector as a Mapping.
- Parameters:
dict_factory (
Callable[[Any],Mapping[str,AbstractQuantity]]) β The type of the mapping to return.- Returns:
The vector as a mapping.
- Return type:
Mapping[str, Quantity]
See also
NoneThis applies recursively to the components of the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the vector as a mapping:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.asdict() {'x': Quantity(Array([[1, 2], [3, 4]], dtype=int32), unit='m'), 'y': Quantity(Array(0, dtype=int32, ...), unit='m')}
- cartesian_type
alias of
CartesianPos3D
- components = ('x', 'y', 'z')
- copy()
Return a copy of the vector.
- Return type:
Self
Examples
>>> import coordinax as cx
>>> vec = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> print(vec.copy()) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
- property devices: MappingProxyType
Get the devices of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.devices mappingproxy({'x': CpuDevice(id=0), 'y': CpuDevice(id=0), 'z': CpuDevice(id=0)})
- dimensions = {'x': PhysicalType('length'), 'y': PhysicalType('length'), 'z': PhysicalType('length')}
- property dtype
- property dtypes: MappingProxyType
Get the dtypes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.dtypes mappingproxy({'x': dtype('int32'), 'y': dtype('int32'), 'z': dtype('int32')})
- flatten()
Flatten the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.flatten().shape (4,)
- classmethod from_(cls: type[AbstractVectorLike], *args: Any, **kwargs: Any)
Create a vector-like object from arguments.
Examples
>>> import coordinax.vecs as cxv
>>> q = cxv.CartesianPos3D.from_([1, 2, 3], "m") >>> print(q) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
>>> v = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> print(v) <CartesianVel3D: (x, y, z) [m / s] [1 2 3]>
>>> space = cxv.KinematicSpace.from_(q) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- from_(cls: type[AbstractVector], *args: Any, **kwargs: Any) AbstractVector
- Parameters:
- Return type:
Create a vector from arguments.
See coordinax.vector for more information.
- from_(cls: type[KinematicSpace], obj: KinematicSpace, /) KinematicSpace
- Parameters:
- Return type:
Construct a Space, returning the KinematicSpace.
Examples
>>> import coordinax as cx
>>> q = cx.KinematicSpace.from_(cx.CartesianPos3D.from_([1, 2, 3], "m")) >>> cx.KinematicSpace.from_(q) is q True
- from_(cls: type[KinematicSpace], obj: AbstractPos, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> w = cx.KinematicSpace.from_(q) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.CartesianVel3D.from_([4, 5, 6], "m/s") >>> w = cx.KinematicSpace.from_(q, p) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, a: AbstractAcc, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.vecs.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.vecs.CartesianVel3D.from_([4, 5, 6], "m/s") >>> a = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> w = cx.KinematicSpace.from_(q, p, a) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ), 'acceleration': CartesianAcc3D( ... ) })
- from_(cls: type[KinematicSpace], obj: Mapping[str, Any]) KinematicSpace
- Parameters:
- Return type:
Construct a KinematicSpace from a Mapping.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> space = cx.KinematicSpace.from_({ 'length': u.Quantity([1, 2, 3], "m") }) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- Parameters:
cls (
type[AbstractVectorLike])args (
Any)kwargs (
Any)
- Return type:
- property mT: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.mT.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- property ndim: int
Number of array dimensions (axes).
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the number of dimensions of a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([1, 2], "m") >>> vec.ndim 0
>>> vec = cx.vecs.CartesianPos2D.from_([[1, 2], [3, 4]], "m") >>> vec.ndim 1
ndimis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.ndim 2
- norm()
Return the norm of the vector.
- Returns:
The norm of the vector.
- Return type:
Quantity
Examples
>>> import unxt as u >>> import coordinax as cx
>>> v = cx.vecs.CartesianPos1D.from_([-1], "km") >>> v.norm() BareQuantity(Array(1., dtype=float32), unit='km')
>>> v = cx.vecs.CartesianPos2D.from_([3, 4], "km") >>> v.norm() BareQuantity(Array(5., dtype=float32), unit='km')
>>> v = cx.vecs.PolarPos(r=u.Quantity(3, "km"), phi=u.Quantity(90, "deg")) >>> v.norm() Distance(Array(3, dtype=int32, ...), unit='km')
>>> v = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> v.norm() BareQuantity(Array(3.7416575, dtype=float32), unit='m')
- ravel()
Ravel the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.ravel().shape (4,)
- represent_as(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVel]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.
- Return type:
Examples
>>> import coordinax as cx
Transforming a Position:
>>> q_cart = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> q_sph = q_cart.represent_as(cx.SphericalPos) >>> q_sph SphericalPos( ... ) >>> q_sph.r Distance(Array(3.7416575, dtype=float32), unit='m')
Transforming a Velocity:
>>> v_cart = cx.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.represent_as(cx.SphericalVel, q_cart) >>> v_sph SphericalVel( ... )
Transforming an Acceleration:
>>> a_cart = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.represent_as(cx.vecs.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- reshape(*shape: Any, order: str = 'C')
Reshape the components of the vector.
- Parameters:
- Return type:
Self
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can reshape a vector:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m"))
>>> vec.reshape(4) CartesianPos2D(x=Quantity([1, 2, 3, 4], unit='m'), y=Quantity([0, 0, 0, 0], unit='m'))
- round(decimals: int = 0)
Round the components of the vector.
- Parameters:
decimals (
int) β The number of decimals to round to.- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
We can round a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([[1.1, 2.2], [3.3, 4.4]], "m") >>> vec.round(0) CartesianPos2D(x=Quantity([1., 3.], unit='m'), y=Quantity([2., 4.], unit='m'))
- property shape: tuple[int, ...]
Return the shape of the vector.
Examples
>>> import unxt as u >>> import coordinax as cx
We can get the shape of a vector:
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([1, 2], "m")) >>> vec.shape (2,)
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([[1, 2], [3, 4]], "m")) >>> vec.shape (2, 2)
shapeis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> space = cx.KinematicSpace(length=vec) >>> space.shape (2, 2)
- property shapes: MappingProxyType
Get the shapes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.shapes mappingproxy({'x': (), 'y': (), 'z': ()})
- property size
- property sizes: MappingProxyType
Get the sizes of the vectorβs components.
Examples
>>> import coordinax as cx
>>> cx.vecs.CartesianPos2D.from_([1, 2], "m").sizes mappingproxy({'x': 1, 'y': 1})
>>> cx.vecs.CartesianPos2D.from_([[1, 2], [1, 2]], "m").sizes mappingproxy({'x': 2, 'y': 2})
- time_derivative_cls
alias of
CartesianVel3D
- classmethod time_nth_derivative_cls(n: int)
Return the corresponding time nth derivative class.
- Parameters:
n (
int)- Return type:
- to_device(device: None | Device = None)
Move the vector to a new device.
Examples
>>> from jax import devices >>> import unxt as u >>> import coordinax as cx
We can move a vector to a new device:
>>> vec = cx.vecs.CartesianPos1D(u.Quantity([1, 2], "m")) >>> vec.to_device(devices()[0]) CartesianPos1D(x=Quantity([1, 2], unit='m'))
- uconvert(*args: Any, **kw: Any)
Convert the vector to the given units.
This just forwards to unxt.uconvert, reversing the order of the arguments to match the unxt API.
Examples
>>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos3D.from_([1, 2, 3], "km")
>>> vec.uconvert({"length": "km"}) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> vec.uconvert(cx.vecs.ToUnitsOptions.consistent) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> usys = u.unitsystem("m", "s", "kg", "rad")
>>> print(vec.uconvert(usys)) <CartesianPos3D: (x, y, z) [m] [1000. 2000. 3000.]>
>>> print(vec.uconvert("galactic")) <CartesianPos3D: (x, y, z) [kpc] [3.241e-17 6.482e-17 9.722e-17]>
- property units: MappingProxyType
Get the units of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.units mappingproxy({'x': Unit("km"), 'y': Unit("km"), 'z': Unit("km")})
- vconvert(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVectorLike]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.self (AbstractVectorLike)
- Return type:
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- vconvert(self: AbstractVectorLike, target: type, *args: Any, **kwargs: Any) AbstractVectorLike
- Parameters:
self (AbstractVectorLike)
target (type)
args (Any)
kwargs (Any)
- Return type:
Represent the vector as another type, forwarding to coordinax.vconvert.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- Parameters:
self (
AbstractVectorLike)target (type)
args (Any)
kwargs (Any)
- Return type:
-
x:
Shaped[Quantity[PhysicalType('length')], '*#batch'] X coordinate \(x \in (-\infty,+\infty)\).
-
y:
Shaped[Quantity[PhysicalType('length')], '*#batch'] Y coordinate \(y \in (-\infty,+\infty)\).
-
z:
Shaped[Quantity[PhysicalType('length')], '*#batch'] Z coordinate \(z \in (-\infty,+\infty)\).
- class coordinax.CartesianVel3D(x: Any, y: Any, z: Any)
Bases:
AbstractCartesian,AbstractVel3DCartesian 3D Velocity.
Examples
>>> import coordinax as cx
>>> vec = cx.CartesianVel3D.from_([1, 2, 3], "m/s") >>> print(vec) <CartesianVel3D: (x, y, z) [m / s] [1 2 3]>
- property T: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.T.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- asdict(*, dict_factory: ~collections.abc.Callable[[~typing.Any], ~collections.abc.Mapping[str, ~unxt._src.quantity.base.AbstractQuantity]] = <class 'dict'>)
Return the vector as a Mapping.
- Parameters:
dict_factory (
Callable[[Any],Mapping[str,AbstractQuantity]]) β The type of the mapping to return.- Returns:
The vector as a mapping.
- Return type:
Mapping[str, Quantity]
See also
NoneThis applies recursively to the components of the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the vector as a mapping:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.asdict() {'x': Quantity(Array([[1, 2], [3, 4]], dtype=int32), unit='m'), 'y': Quantity(Array(0, dtype=int32, ...), unit='m')}
- cartesian_type
alias of
CartesianVel3D
- components = ('x', 'y', 'z')
- copy()
Return a copy of the vector.
- Return type:
Self
Examples
>>> import coordinax as cx
>>> vec = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> print(vec.copy()) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
- property devices: MappingProxyType
Get the devices of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.devices mappingproxy({'x': CpuDevice(id=0), 'y': CpuDevice(id=0), 'z': CpuDevice(id=0)})
- dimensions = {'x': PhysicalType({'speed', 'velocity'}), 'y': PhysicalType({'speed', 'velocity'}), 'z': PhysicalType({'speed', 'velocity'})}
- property dtype
- property dtypes: MappingProxyType
Get the dtypes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.dtypes mappingproxy({'x': dtype('int32'), 'y': dtype('int32'), 'z': dtype('int32')})
- flatten()
Flatten the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.flatten().shape (4,)
- classmethod from_(cls: type[AbstractVectorLike], *args: Any, **kwargs: Any)
Create a vector-like object from arguments.
Examples
>>> import coordinax.vecs as cxv
>>> q = cxv.CartesianPos3D.from_([1, 2, 3], "m") >>> print(q) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
>>> v = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> print(v) <CartesianVel3D: (x, y, z) [m / s] [1 2 3]>
>>> space = cxv.KinematicSpace.from_(q) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- from_(cls: type[AbstractVector], *args: Any, **kwargs: Any) AbstractVector
- Parameters:
- Return type:
Create a vector from arguments.
See coordinax.vector for more information.
- from_(cls: type[KinematicSpace], obj: KinematicSpace, /) KinematicSpace
- Parameters:
- Return type:
Construct a Space, returning the KinematicSpace.
Examples
>>> import coordinax as cx
>>> q = cx.KinematicSpace.from_(cx.CartesianPos3D.from_([1, 2, 3], "m")) >>> cx.KinematicSpace.from_(q) is q True
- from_(cls: type[KinematicSpace], obj: AbstractPos, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> w = cx.KinematicSpace.from_(q) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.CartesianVel3D.from_([4, 5, 6], "m/s") >>> w = cx.KinematicSpace.from_(q, p) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, a: AbstractAcc, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.vecs.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.vecs.CartesianVel3D.from_([4, 5, 6], "m/s") >>> a = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> w = cx.KinematicSpace.from_(q, p, a) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ), 'acceleration': CartesianAcc3D( ... ) })
- from_(cls: type[KinematicSpace], obj: Mapping[str, Any]) KinematicSpace
- Parameters:
- Return type:
Construct a KinematicSpace from a Mapping.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> space = cx.KinematicSpace.from_({ 'length': u.Quantity([1, 2, 3], "m") }) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- Parameters:
cls (
type[AbstractVectorLike])args (
Any)kwargs (
Any)
- Return type:
- property mT: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.mT.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- property ndim: int
Number of array dimensions (axes).
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the number of dimensions of a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([1, 2], "m") >>> vec.ndim 0
>>> vec = cx.vecs.CartesianPos2D.from_([[1, 2], [3, 4]], "m") >>> vec.ndim 1
ndimis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.ndim 2
- norm(_: AbstractPos3D | None = None, /)
Return the norm of the vector.
Examples
>>> import coordinax as cx >>> c = cx.CartesianVel3D.from_([1, 2, 3], "km/s") >>> c.norm() Quantity(Array(3.7416575, dtype=float32), unit='km / s')
- Parameters:
_ (
AbstractPos3D|None)- Return type:
Real[Quantity[PhysicalType({'speed', 'velocity'})], '*#batch']
- ravel()
Ravel the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.ravel().shape (4,)
- represent_as(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVel]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.
- Return type:
Examples
>>> import coordinax as cx
Transforming a Position:
>>> q_cart = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> q_sph = q_cart.represent_as(cx.SphericalPos) >>> q_sph SphericalPos( ... ) >>> q_sph.r Distance(Array(3.7416575, dtype=float32), unit='m')
Transforming a Velocity:
>>> v_cart = cx.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.represent_as(cx.SphericalVel, q_cart) >>> v_sph SphericalVel( ... )
Transforming an Acceleration:
>>> a_cart = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.represent_as(cx.vecs.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- reshape(*shape: Any, order: str = 'C')
Reshape the components of the vector.
- Parameters:
- Return type:
Self
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can reshape a vector:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m"))
>>> vec.reshape(4) CartesianPos2D(x=Quantity([1, 2, 3, 4], unit='m'), y=Quantity([0, 0, 0, 0], unit='m'))
- round(decimals: int = 0)
Round the components of the vector.
- Parameters:
decimals (
int) β The number of decimals to round to.- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
We can round a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([[1.1, 2.2], [3.3, 4.4]], "m") >>> vec.round(0) CartesianPos2D(x=Quantity([1., 3.], unit='m'), y=Quantity([2., 4.], unit='m'))
- property shape: tuple[int, ...]
Return the shape of the vector.
Examples
>>> import unxt as u >>> import coordinax as cx
We can get the shape of a vector:
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([1, 2], "m")) >>> vec.shape (2,)
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([[1, 2], [3, 4]], "m")) >>> vec.shape (2, 2)
shapeis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> space = cx.KinematicSpace(length=vec) >>> space.shape (2, 2)
- property shapes: MappingProxyType
Get the shapes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.shapes mappingproxy({'x': (), 'y': (), 'z': ()})
- property size
- property sizes: MappingProxyType
Get the sizes of the vectorβs components.
Examples
>>> import coordinax as cx
>>> cx.vecs.CartesianPos2D.from_([1, 2], "m").sizes mappingproxy({'x': 1, 'y': 1})
>>> cx.vecs.CartesianPos2D.from_([[1, 2], [1, 2]], "m").sizes mappingproxy({'x': 2, 'y': 2})
- time_antiderivative_cls
alias of
CartesianPos3D
- time_derivative_cls
alias of
CartesianAcc3D
- classmethod time_nth_derivative_cls(*, n: int)
Return the corresponding time nth derivative class.
- Parameters:
n (
int)- Return type:
- to_device(device: None | Device = None)
Move the vector to a new device.
Examples
>>> from jax import devices >>> import unxt as u >>> import coordinax as cx
We can move a vector to a new device:
>>> vec = cx.vecs.CartesianPos1D(u.Quantity([1, 2], "m")) >>> vec.to_device(devices()[0]) CartesianPos1D(x=Quantity([1, 2], unit='m'))
- uconvert(*args: Any, **kw: Any)
Convert the vector to the given units.
This just forwards to unxt.uconvert, reversing the order of the arguments to match the unxt API.
Examples
>>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos3D.from_([1, 2, 3], "km")
>>> vec.uconvert({"length": "km"}) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> vec.uconvert(cx.vecs.ToUnitsOptions.consistent) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> usys = u.unitsystem("m", "s", "kg", "rad")
>>> print(vec.uconvert(usys)) <CartesianPos3D: (x, y, z) [m] [1000. 2000. 3000.]>
>>> print(vec.uconvert("galactic")) <CartesianPos3D: (x, y, z) [kpc] [3.241e-17 6.482e-17 9.722e-17]>
- property units: MappingProxyType
Get the units of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.units mappingproxy({'x': Unit("km"), 'y': Unit("km"), 'z': Unit("km")})
- vconvert(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVectorLike]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.self (AbstractVectorLike)
- Return type:
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- vconvert(self: AbstractVectorLike, target: type, *args: Any, **kwargs: Any) AbstractVectorLike
- Parameters:
self (AbstractVectorLike)
target (type)
args (Any)
kwargs (Any)
- Return type:
Represent the vector as another type, forwarding to coordinax.vconvert.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- Parameters:
self (
AbstractVectorLike)target (type)
args (Any)
kwargs (Any)
- Return type:
-
x:
Real[Quantity[PhysicalType({'speed', 'velocity'})], '*#batch'] `dx/dt in [-infty, infty].
- Type:
X speed
- Type:
math
-
y:
Real[Quantity[PhysicalType({'speed', 'velocity'})], '*#batch'] `dy/dt in [-infty, infty].
- Type:
Y speed
- Type:
math
-
z:
Real[Quantity[PhysicalType({'speed', 'velocity'})], '*#batch'] `dz/dt in [-infty, infty].
- Type:
Z speed
- Type:
math
- class coordinax.SphericalPos(r: ArgT | PassThroughTs, theta: Any, phi: ArgT | PassThroughTs)
Bases:
AbstractSphericalPosSpherical-Polar coordinates.
Note
This class follows the Physics conventions (ISO 80000-2:2019).
- Parameters:
- property T: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.T.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- asdict(*, dict_factory: ~collections.abc.Callable[[~typing.Any], ~collections.abc.Mapping[str, ~unxt._src.quantity.base.AbstractQuantity]] = <class 'dict'>)
Return the vector as a Mapping.
- Parameters:
dict_factory (
Callable[[Any],Mapping[str,AbstractQuantity]]) β The type of the mapping to return.- Returns:
The vector as a mapping.
- Return type:
Mapping[str, Quantity]
See also
NoneThis applies recursively to the components of the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the vector as a mapping:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.asdict() {'x': Quantity(Array([[1, 2], [3, 4]], dtype=int32), unit='m'), 'y': Quantity(Array(0, dtype=int32, ...), unit='m')}
- cartesian_type
alias of
CartesianPos3D
- components = ('r', 'theta', 'phi')
- copy()
Return a copy of the vector.
- Return type:
Self
Examples
>>> import coordinax as cx
>>> vec = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> print(vec.copy()) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
- property devices: MappingProxyType
Get the devices of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.devices mappingproxy({'x': CpuDevice(id=0), 'y': CpuDevice(id=0), 'z': CpuDevice(id=0)})
- dimensions = {'phi': PhysicalType('angle'), 'r': PhysicalType('length'), 'theta': PhysicalType('angle')}
- property dtype
- property dtypes: MappingProxyType
Get the dtypes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.dtypes mappingproxy({'x': dtype('int32'), 'y': dtype('int32'), 'z': dtype('int32')})
- flatten()
Flatten the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.flatten().shape (4,)
- classmethod from_(cls: type[AbstractVectorLike], *args: Any, **kwargs: Any)
Create a vector-like object from arguments.
Examples
>>> import coordinax.vecs as cxv
>>> q = cxv.CartesianPos3D.from_([1, 2, 3], "m") >>> print(q) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
>>> v = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> print(v) <CartesianVel3D: (x, y, z) [m / s] [1 2 3]>
>>> space = cxv.KinematicSpace.from_(q) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- from_(cls: type[AbstractVector], *args: Any, **kwargs: Any) AbstractVector
- Parameters:
- Return type:
Create a vector from arguments.
See coordinax.vector for more information.
- from_(cls: type[KinematicSpace], obj: KinematicSpace, /) KinematicSpace
- Parameters:
- Return type:
Construct a Space, returning the KinematicSpace.
Examples
>>> import coordinax as cx
>>> q = cx.KinematicSpace.from_(cx.CartesianPos3D.from_([1, 2, 3], "m")) >>> cx.KinematicSpace.from_(q) is q True
- from_(cls: type[KinematicSpace], obj: AbstractPos, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> w = cx.KinematicSpace.from_(q) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.CartesianVel3D.from_([4, 5, 6], "m/s") >>> w = cx.KinematicSpace.from_(q, p) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, a: AbstractAcc, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.vecs.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.vecs.CartesianVel3D.from_([4, 5, 6], "m/s") >>> a = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> w = cx.KinematicSpace.from_(q, p, a) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ), 'acceleration': CartesianAcc3D( ... ) })
- from_(cls: type[KinematicSpace], obj: Mapping[str, Any]) KinematicSpace
- Parameters:
- Return type:
Construct a KinematicSpace from a Mapping.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> space = cx.KinematicSpace.from_({ 'length': u.Quantity([1, 2, 3], "m") }) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- Parameters:
cls (
type[AbstractVectorLike])args (
Any)kwargs (
Any)
- Return type:
- property mT: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.mT.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- property ndim: int
Number of array dimensions (axes).
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the number of dimensions of a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([1, 2], "m") >>> vec.ndim 0
>>> vec = cx.vecs.CartesianPos2D.from_([[1, 2], [3, 4]], "m") >>> vec.ndim 1
ndimis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.ndim 2
- norm()
Return the norm of the vector.
- Returns:
The norm of the vector.
- Return type:
Quantity
Examples
>>> import unxt as u >>> import coordinax as cx
>>> v = cx.vecs.CartesianPos1D.from_([-1], "km") >>> v.norm() BareQuantity(Array(1., dtype=float32), unit='km')
>>> v = cx.vecs.CartesianPos2D.from_([3, 4], "km") >>> v.norm() BareQuantity(Array(5., dtype=float32), unit='km')
>>> v = cx.vecs.PolarPos(r=u.Quantity(3, "km"), phi=u.Quantity(90, "deg")) >>> v.norm() Distance(Array(3, dtype=int32, ...), unit='km')
>>> v = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> v.norm() BareQuantity(Array(3.7416575, dtype=float32), unit='m')
- ravel()
Ravel the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.ravel().shape (4,)
- represent_as(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVel]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.
- Return type:
Examples
>>> import coordinax as cx
Transforming a Position:
>>> q_cart = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> q_sph = q_cart.represent_as(cx.SphericalPos) >>> q_sph SphericalPos( ... ) >>> q_sph.r Distance(Array(3.7416575, dtype=float32), unit='m')
Transforming a Velocity:
>>> v_cart = cx.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.represent_as(cx.SphericalVel, q_cart) >>> v_sph SphericalVel( ... )
Transforming an Acceleration:
>>> a_cart = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.represent_as(cx.vecs.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- reshape(*shape: Any, order: str = 'C')
Reshape the components of the vector.
- Parameters:
- Return type:
Self
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can reshape a vector:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m"))
>>> vec.reshape(4) CartesianPos2D(x=Quantity([1, 2, 3, 4], unit='m'), y=Quantity([0, 0, 0, 0], unit='m'))
- round(decimals: int = 0)
Round the components of the vector.
- Parameters:
decimals (
int) β The number of decimals to round to.- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
We can round a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([[1.1, 2.2], [3.3, 4.4]], "m") >>> vec.round(0) CartesianPos2D(x=Quantity([1., 3.], unit='m'), y=Quantity([2., 4.], unit='m'))
- property shape: tuple[int, ...]
Return the shape of the vector.
Examples
>>> import unxt as u >>> import coordinax as cx
We can get the shape of a vector:
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([1, 2], "m")) >>> vec.shape (2,)
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([[1, 2], [3, 4]], "m")) >>> vec.shape (2, 2)
shapeis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> space = cx.KinematicSpace(length=vec) >>> space.shape (2, 2)
- property shapes: MappingProxyType
Get the shapes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.shapes mappingproxy({'x': (), 'y': (), 'z': ()})
- property size
- property sizes: MappingProxyType
Get the sizes of the vectorβs components.
Examples
>>> import coordinax as cx
>>> cx.vecs.CartesianPos2D.from_([1, 2], "m").sizes mappingproxy({'x': 1, 'y': 1})
>>> cx.vecs.CartesianPos2D.from_([[1, 2], [1, 2]], "m").sizes mappingproxy({'x': 2, 'y': 2})
- time_derivative_cls
alias of
SphericalVel
- classmethod time_nth_derivative_cls(n: int)
Return the corresponding time nth derivative class.
- Parameters:
n (
int)- Return type:
- to_device(device: None | Device = None)
Move the vector to a new device.
Examples
>>> from jax import devices >>> import unxt as u >>> import coordinax as cx
We can move a vector to a new device:
>>> vec = cx.vecs.CartesianPos1D(u.Quantity([1, 2], "m")) >>> vec.to_device(devices()[0]) CartesianPos1D(x=Quantity([1, 2], unit='m'))
- uconvert(*args: Any, **kw: Any)
Convert the vector to the given units.
This just forwards to unxt.uconvert, reversing the order of the arguments to match the unxt API.
Examples
>>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos3D.from_([1, 2, 3], "km")
>>> vec.uconvert({"length": "km"}) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> vec.uconvert(cx.vecs.ToUnitsOptions.consistent) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> usys = u.unitsystem("m", "s", "kg", "rad")
>>> print(vec.uconvert(usys)) <CartesianPos3D: (x, y, z) [m] [1000. 2000. 3000.]>
>>> print(vec.uconvert("galactic")) <CartesianPos3D: (x, y, z) [kpc] [3.241e-17 6.482e-17 9.722e-17]>
- property units: MappingProxyType
Get the units of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.units mappingproxy({'x': Unit("km"), 'y': Unit("km"), 'z': Unit("km")})
- vconvert(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVectorLike]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.self (AbstractVectorLike)
- Return type:
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- vconvert(self: AbstractVectorLike, target: type, *args: Any, **kwargs: Any) AbstractVectorLike
- Parameters:
self (AbstractVectorLike)
target (type)
args (Any)
kwargs (Any)
- Return type:
Represent the vector as another type, forwarding to coordinax.vconvert.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- Parameters:
self (
AbstractVectorLike)target (type)
args (Any)
kwargs (Any)
- Return type:
-
r:
Shaped[AbstractDistance, '*#batch'] Radial distance \(r \in [0,+\infty)\).
-
theta:
Shaped[AbstractAngle, '*#batch'] Inclination angle \(\theta \in [0,180]\).
-
phi:
Shaped[AbstractAngle, '*#batch'] Azimuthal angle, generally \(\phi \in [0,360)\).
- class coordinax.SphericalVel(r: Any, theta: Any, phi: Any)
Bases:
AbstractSphericalVelSpherical velocity.
- property T: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.T.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- asdict(*, dict_factory: ~collections.abc.Callable[[~typing.Any], ~collections.abc.Mapping[str, ~unxt._src.quantity.base.AbstractQuantity]] = <class 'dict'>)
Return the vector as a Mapping.
- Parameters:
dict_factory (
Callable[[Any],Mapping[str,AbstractQuantity]]) β The type of the mapping to return.- Returns:
The vector as a mapping.
- Return type:
Mapping[str, Quantity]
See also
NoneThis applies recursively to the components of the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the vector as a mapping:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.asdict() {'x': Quantity(Array([[1, 2], [3, 4]], dtype=int32), unit='m'), 'y': Quantity(Array(0, dtype=int32, ...), unit='m')}
- cartesian_type
alias of
CartesianVel3D
- components = ('r', 'theta', 'phi')
- copy()
Return a copy of the vector.
- Return type:
Self
Examples
>>> import coordinax as cx
>>> vec = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> print(vec.copy()) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
- property devices: MappingProxyType
Get the devices of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.devices mappingproxy({'x': CpuDevice(id=0), 'y': CpuDevice(id=0), 'z': CpuDevice(id=0)})
- dimensions = {'phi': PhysicalType({'angular frequency', 'angular speed', 'angular velocity'}), 'r': PhysicalType({'speed', 'velocity'}), 'theta': PhysicalType({'angular frequency', 'angular speed', 'angular velocity'})}
- property dtype
- property dtypes: MappingProxyType
Get the dtypes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.dtypes mappingproxy({'x': dtype('int32'), 'y': dtype('int32'), 'z': dtype('int32')})
- flatten()
Flatten the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.flatten().shape (4,)
- classmethod from_(cls: type[AbstractVectorLike], *args: Any, **kwargs: Any)
Create a vector-like object from arguments.
Examples
>>> import coordinax.vecs as cxv
>>> q = cxv.CartesianPos3D.from_([1, 2, 3], "m") >>> print(q) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
>>> v = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> print(v) <CartesianVel3D: (x, y, z) [m / s] [1 2 3]>
>>> space = cxv.KinematicSpace.from_(q) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- from_(cls: type[AbstractVector], *args: Any, **kwargs: Any) AbstractVector
- Parameters:
- Return type:
Create a vector from arguments.
See coordinax.vector for more information.
- from_(cls: type[KinematicSpace], obj: KinematicSpace, /) KinematicSpace
- Parameters:
- Return type:
Construct a Space, returning the KinematicSpace.
Examples
>>> import coordinax as cx
>>> q = cx.KinematicSpace.from_(cx.CartesianPos3D.from_([1, 2, 3], "m")) >>> cx.KinematicSpace.from_(q) is q True
- from_(cls: type[KinematicSpace], obj: AbstractPos, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> w = cx.KinematicSpace.from_(q) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.CartesianVel3D.from_([4, 5, 6], "m/s") >>> w = cx.KinematicSpace.from_(q, p) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, a: AbstractAcc, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.vecs.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.vecs.CartesianVel3D.from_([4, 5, 6], "m/s") >>> a = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> w = cx.KinematicSpace.from_(q, p, a) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ), 'acceleration': CartesianAcc3D( ... ) })
- from_(cls: type[KinematicSpace], obj: Mapping[str, Any]) KinematicSpace
- Parameters:
- Return type:
Construct a KinematicSpace from a Mapping.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> space = cx.KinematicSpace.from_({ 'length': u.Quantity([1, 2, 3], "m") }) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- Parameters:
cls (
type[AbstractVectorLike])args (
Any)kwargs (
Any)
- Return type:
- property mT: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.mT.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- property ndim: int
Number of array dimensions (axes).
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the number of dimensions of a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([1, 2], "m") >>> vec.ndim 0
>>> vec = cx.vecs.CartesianPos2D.from_([[1, 2], [3, 4]], "m") >>> vec.ndim 1
ndimis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.ndim 2
- norm(q: AbstractPos, /)
Return the norm of the vector.
Examples
>>> import coordinax as cx
>>> q = cx.vecs.CartesianPos2D.from_([1, 1], "km") >>> p = cx.vecs.PolarVel(r=u.Quantity(1, "km/s"), phi=u.Quantity(1, "deg/s"))
>>> p.norm(q).uconvert('km / s') Quantity(Array(1.0003046, dtype=float32), unit='km / s')
- Parameters:
q (
AbstractPos)- Return type:
Quantity[PhysicalType({'speed', 'velocity'})]
- ravel()
Ravel the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.ravel().shape (4,)
- represent_as(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVel]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.
- Return type:
Examples
>>> import coordinax as cx
Transforming a Position:
>>> q_cart = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> q_sph = q_cart.represent_as(cx.SphericalPos) >>> q_sph SphericalPos( ... ) >>> q_sph.r Distance(Array(3.7416575, dtype=float32), unit='m')
Transforming a Velocity:
>>> v_cart = cx.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.represent_as(cx.SphericalVel, q_cart) >>> v_sph SphericalVel( ... )
Transforming an Acceleration:
>>> a_cart = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.represent_as(cx.vecs.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- reshape(*shape: Any, order: str = 'C')
Reshape the components of the vector.
- Parameters:
- Return type:
Self
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can reshape a vector:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m"))
>>> vec.reshape(4) CartesianPos2D(x=Quantity([1, 2, 3, 4], unit='m'), y=Quantity([0, 0, 0, 0], unit='m'))
- round(decimals: int = 0)
Round the components of the vector.
- Parameters:
decimals (
int) β The number of decimals to round to.- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
We can round a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([[1.1, 2.2], [3.3, 4.4]], "m") >>> vec.round(0) CartesianPos2D(x=Quantity([1., 3.], unit='m'), y=Quantity([2., 4.], unit='m'))
- property shape: tuple[int, ...]
Return the shape of the vector.
Examples
>>> import unxt as u >>> import coordinax as cx
We can get the shape of a vector:
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([1, 2], "m")) >>> vec.shape (2,)
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([[1, 2], [3, 4]], "m")) >>> vec.shape (2, 2)
shapeis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> space = cx.KinematicSpace(length=vec) >>> space.shape (2, 2)
- property shapes: MappingProxyType
Get the shapes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.shapes mappingproxy({'x': (), 'y': (), 'z': ()})
- property size
- property sizes: MappingProxyType
Get the sizes of the vectorβs components.
Examples
>>> import coordinax as cx
>>> cx.vecs.CartesianPos2D.from_([1, 2], "m").sizes mappingproxy({'x': 1, 'y': 1})
>>> cx.vecs.CartesianPos2D.from_([[1, 2], [1, 2]], "m").sizes mappingproxy({'x': 2, 'y': 2})
- time_antiderivative_cls
alias of
SphericalPos
- time_derivative_cls
alias of
SphericalAcc
- classmethod time_nth_derivative_cls(*, n: int)
Return the corresponding time nth derivative class.
- Parameters:
n (
int)- Return type:
- to_device(device: None | Device = None)
Move the vector to a new device.
Examples
>>> from jax import devices >>> import unxt as u >>> import coordinax as cx
We can move a vector to a new device:
>>> vec = cx.vecs.CartesianPos1D(u.Quantity([1, 2], "m")) >>> vec.to_device(devices()[0]) CartesianPos1D(x=Quantity([1, 2], unit='m'))
- uconvert(*args: Any, **kw: Any)
Convert the vector to the given units.
This just forwards to unxt.uconvert, reversing the order of the arguments to match the unxt API.
Examples
>>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos3D.from_([1, 2, 3], "km")
>>> vec.uconvert({"length": "km"}) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> vec.uconvert(cx.vecs.ToUnitsOptions.consistent) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> usys = u.unitsystem("m", "s", "kg", "rad")
>>> print(vec.uconvert(usys)) <CartesianPos3D: (x, y, z) [m] [1000. 2000. 3000.]>
>>> print(vec.uconvert("galactic")) <CartesianPos3D: (x, y, z) [kpc] [3.241e-17 6.482e-17 9.722e-17]>
- property units: MappingProxyType
Get the units of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.units mappingproxy({'x': Unit("km"), 'y': Unit("km"), 'z': Unit("km")})
- vconvert(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVectorLike]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.self (AbstractVectorLike)
- Return type:
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- vconvert(self: AbstractVectorLike, target: type, *args: Any, **kwargs: Any) AbstractVectorLike
- Parameters:
self (AbstractVectorLike)
target (type)
args (Any)
kwargs (Any)
- Return type:
Represent the vector as another type, forwarding to coordinax.vconvert.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- Parameters:
self (
AbstractVectorLike)target (type)
args (Any)
kwargs (Any)
- Return type:
-
r:
Real[Quantity[PhysicalType({'speed', 'velocity'})], '*#batch'] `dr/dt in [-infty, infty].
- Type:
Radial speed
- Type:
math
-
theta:
Real[Quantity[PhysicalType({'angular frequency', 'angular speed', 'angular velocity'})], '*#batch'] `dtheta/dt in [-infty, infty].
- Type:
Inclination speed
- Type:
math
-
phi:
Real[Quantity[PhysicalType({'angular frequency', 'angular speed', 'angular velocity'})], '*#batch'] `dphi/dt in [-infty, infty].
- Type:
Azimuthal speed
- Type:
math
- class coordinax.FourVector(t: ~typing.Any, q: ~dataclassish._src.converters.ArgT | ~dataclassish._src.converters.PassThroughTs, *, c: ~jaxtyping.Shaped[Quantity[PhysicalType({'speed', 'velocity'})], ''] = VectorAttribute(default=Quantity(Array(299792.47, dtype=float32, weak_type=True), unit='km / s'), converter=<function identity>))
Bases:
AbstractPos4D3+1 vector representation.
The 3+1 vector representation is a 4-vector with 3 spatial coordinates and 1 time coordinate.
- Parameters:
Examples
>>> import unxt as u >>> import coordinax as cx
Create a 3+1 vector with a time and 3 spatial coordinates:
>>> w = cx.FourVector (t=u.Quantity(1, "s"), q=u.Quantity([1, 2, 3], "m")) >>> print(w) <FourVector: (t[s], q=(x, y, z) [m]) [1 1 2 3]>
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 coordinax.CartesianPos3D and uses thecoordinax.CartesianPos3D.from_()method to create the 3D vector.We can also create a 3D vector explicitly:
>>> q = cx.SphericalPos(theta=u.Quantity(1, "deg"), phi=u.Quantity(2, "deg"), ... r=u.Quantity(3, "m")) >>> w = cx.FourVector (t=u.Quantity(1, "s"), q=q) >>> print(w) <FourVector: (t[s], q=(r[m], theta[deg], phi[deg])) [1 3 1 2]>
- property T: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.T.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- asdict(*, dict_factory: ~collections.abc.Callable[[~typing.Any], ~collections.abc.Mapping[str, ~unxt._src.quantity.base.AbstractQuantity]] = <class 'dict'>)
Return the vector as a Mapping.
- Parameters:
dict_factory (
Callable[[Any],Mapping[str,AbstractQuantity]]) β The type of the mapping to return.- Returns:
The vector as a mapping.
- Return type:
Mapping[str, Quantity]
See also
NoneThis applies recursively to the components of the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the vector as a mapping:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.asdict() {'x': Quantity(Array([[1, 2], [3, 4]], dtype=int32), unit='m'), 'y': Quantity(Array(0, dtype=int32, ...), unit='m')}
-
c:
Shaped[Quantity[PhysicalType({'speed', 'velocity'})], ''] Speed of light, by default
Quantity(299_792.458, "km/s").
- cartesian_type
alias of
CartesianPos3D
- components = ('t', 'q')
- copy()
Return a copy of the vector.
- Return type:
Self
Examples
>>> import coordinax as cx
>>> vec = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> print(vec.copy()) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
- property devices: MappingProxyType
Get the devices of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.devices mappingproxy({'x': CpuDevice(id=0), 'y': CpuDevice(id=0), 'z': CpuDevice(id=0)})
- property dimensions: dict[str, PhysicalType]
Vector physical dimensions.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> cx.FourVector.dimensions <property object at ...>
>>> w = cx.FourVector (t=u.Quantity(1, "s"), q=u.Quantity([1, 2, 3], "m")) >>> w.dimensions {'t': PhysicalType('time'), 'q': {'x': PhysicalType('length'), 'y': PhysicalType('length'), 'z': PhysicalType('length')}}
- property dtype
- property dtypes: MappingProxyType
Get the dtypes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.dtypes mappingproxy({'x': dtype('int32'), 'y': dtype('int32'), 'z': dtype('int32')})
- flatten()
Flatten the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.flatten().shape (4,)
- classmethod from_(cls: type[AbstractVectorLike], *args: Any, **kwargs: Any)
Create a vector-like object from arguments.
Examples
>>> import coordinax.vecs as cxv
>>> q = cxv.CartesianPos3D.from_([1, 2, 3], "m") >>> print(q) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
>>> v = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> print(v) <CartesianVel3D: (x, y, z) [m / s] [1 2 3]>
>>> space = cxv.KinematicSpace.from_(q) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- from_(cls: type[AbstractVector], *args: Any, **kwargs: Any) AbstractVector
- Parameters:
- Return type:
Create a vector from arguments.
See coordinax.vector for more information.
- from_(cls: type[KinematicSpace], obj: KinematicSpace, /) KinematicSpace
- Parameters:
- Return type:
Construct a Space, returning the KinematicSpace.
Examples
>>> import coordinax as cx
>>> q = cx.KinematicSpace.from_(cx.CartesianPos3D.from_([1, 2, 3], "m")) >>> cx.KinematicSpace.from_(q) is q True
- from_(cls: type[KinematicSpace], obj: AbstractPos, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> w = cx.KinematicSpace.from_(q) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.CartesianVel3D.from_([4, 5, 6], "m/s") >>> w = cx.KinematicSpace.from_(q, p) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, a: AbstractAcc, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.vecs.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.vecs.CartesianVel3D.from_([4, 5, 6], "m/s") >>> a = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> w = cx.KinematicSpace.from_(q, p, a) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ), 'acceleration': CartesianAcc3D( ... ) })
- from_(cls: type[KinematicSpace], obj: Mapping[str, Any]) KinematicSpace
- Parameters:
- Return type:
Construct a KinematicSpace from a Mapping.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> space = cx.KinematicSpace.from_({ 'length': u.Quantity([1, 2, 3], "m") }) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- Parameters:
cls (
type[AbstractVectorLike])args (
Any)kwargs (
Any)
- Return type:
- property mT: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.mT.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- property ndim: int
Number of array dimensions (axes).
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the number of dimensions of a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([1, 2], "m") >>> vec.ndim 0
>>> vec = cx.vecs.CartesianPos2D.from_([[1, 2], [3, 4]], "m") >>> vec.ndim 1
ndimis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.ndim 2
- norm()
Return the vector norm \(\sqrt{(ct)^2 - (x^2 + y^2 + z^2)}\).
- Return type:
Shaped[Quantity[PhysicalType('length')], '*#batch']
Examples
>>> import unxt as u >>> import coordinax as cx
>>> w = cx.FourVector (t=u.Quantity(1, "s"), q=u.Quantity([1, 2, 3], "m")) >>> w.norm() Quantity(Array(299792.47+0.j, dtype=complex64), unit='km')
- ravel()
Ravel the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.ravel().shape (4,)
- represent_as(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVel]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.
- Return type:
Examples
>>> import coordinax as cx
Transforming a Position:
>>> q_cart = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> q_sph = q_cart.represent_as(cx.SphericalPos) >>> q_sph SphericalPos( ... ) >>> q_sph.r Distance(Array(3.7416575, dtype=float32), unit='m')
Transforming a Velocity:
>>> v_cart = cx.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.represent_as(cx.SphericalVel, q_cart) >>> v_sph SphericalVel( ... )
Transforming an Acceleration:
>>> a_cart = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.represent_as(cx.vecs.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- reshape(*shape: Any, order: str = 'C')
Reshape the components of the vector.
- Parameters:
- Return type:
Self
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can reshape a vector:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m"))
>>> vec.reshape(4) CartesianPos2D(x=Quantity([1, 2, 3, 4], unit='m'), y=Quantity([0, 0, 0, 0], unit='m'))
- round(decimals: int = 0)
Round the components of the vector.
- Parameters:
decimals (
int) β The number of decimals to round to.- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
We can round a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([[1.1, 2.2], [3.3, 4.4]], "m") >>> vec.round(0) CartesianPos2D(x=Quantity([1., 3.], unit='m'), y=Quantity([2., 4.], unit='m'))
- property shape: tuple[int, ...]
Return the shape of the vector.
Examples
>>> import unxt as u >>> import coordinax as cx
We can get the shape of a vector:
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([1, 2], "m")) >>> vec.shape (2,)
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([[1, 2], [3, 4]], "m")) >>> vec.shape (2, 2)
shapeis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> space = cx.KinematicSpace(length=vec) >>> space.shape (2, 2)
- property shapes: MappingProxyType
Get the shapes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.shapes mappingproxy({'x': (), 'y': (), 'z': ()})
- property size
- property sizes: MappingProxyType
Get the sizes of the vectorβs components.
Examples
>>> import coordinax as cx
>>> cx.vecs.CartesianPos2D.from_([1, 2], "m").sizes mappingproxy({'x': 1, 'y': 1})
>>> cx.vecs.CartesianPos2D.from_([[1, 2], [1, 2]], "m").sizes mappingproxy({'x': 2, 'y': 2})
- classmethod time_nth_derivative_cls(n: int)
Return the corresponding time nth derivative class.
- Parameters:
n (
int)- Return type:
- to_device(device: None | Device = None)
Move the vector to a new device.
Examples
>>> from jax import devices >>> import unxt as u >>> import coordinax as cx
We can move a vector to a new device:
>>> vec = cx.vecs.CartesianPos1D(u.Quantity([1, 2], "m")) >>> vec.to_device(devices()[0]) CartesianPos1D(x=Quantity([1, 2], unit='m'))
- uconvert(*args: Any, **kw: Any)
Convert the vector to the given units.
This just forwards to unxt.uconvert, reversing the order of the arguments to match the unxt API.
Examples
>>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos3D.from_([1, 2, 3], "km")
>>> vec.uconvert({"length": "km"}) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> vec.uconvert(cx.vecs.ToUnitsOptions.consistent) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> usys = u.unitsystem("m", "s", "kg", "rad")
>>> print(vec.uconvert(usys)) <CartesianPos3D: (x, y, z) [m] [1000. 2000. 3000.]>
>>> print(vec.uconvert("galactic")) <CartesianPos3D: (x, y, z) [kpc] [3.241e-17 6.482e-17 9.722e-17]>
- property units: MappingProxyType
Get the units of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.units mappingproxy({'x': Unit("km"), 'y': Unit("km"), 'z': Unit("km")})
- vconvert(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVectorLike]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.self (AbstractVectorLike)
- Return type:
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- vconvert(self: AbstractVectorLike, target: type, *args: Any, **kwargs: Any) AbstractVectorLike
- Parameters:
self (AbstractVectorLike)
target (type)
args (Any)
kwargs (Any)
- Return type:
Represent the vector as another type, forwarding to coordinax.vconvert.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- Parameters:
self (
AbstractVectorLike)target (type)
args (Any)
kwargs (Any)
- Return type:
-
t:
Real[Quantity[PhysicalType('time')], '*#batch']|Real[Quantity[PhysicalType('time')], ''] Time coordinate.
-
q:
AbstractPos3D Spatial coordinates.
- class coordinax.KinematicSpace(*args: Mapping[PhysicalType | str, Any] | tuple[PhysicalType | str, Any] | Iterable[tuple[PhysicalType | str, Any]], **kwargs: Any)
Bases:
AbstractVectorLike,ImmutableMap[str,AbstractVector],Generic[PosT]A collection of vectors that acts like the primary vector.
- Parameters:
*args (
Mapping[PhysicalType|str,Any] |tuple[PhysicalType|str,Any] |Iterable[tuple[PhysicalType|str,Any]]) β See input to dict for the input data.**kwargs (
Any) β See input to dict for the input data.
Examples
>>> import coordinax as cx
>>> x = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> v = cx.CartesianVel3D.from_([4, 5, 6], "km/s") >>> a = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "km/s^2")
All the vectors can be brought together into a space:
>>> space = cx.KinematicSpace(length=x, speed=v, acceleration=a) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [km] [1 2 3]>, 'speed': <CartesianVel3D: (x, y, z) [km / s] [4 5 6]>, 'acceleration': <CartesianAcc3D: (x, y, z) [km / s2] [7 8 9]> })
The vectors can initialized from unxt.Quantity objects and can have (brodcastable) batch shapes:
>>> w = cx.KinematicSpace( ... length=u.Quantity([[8.5, 0, 0], [10, 0, 0]], "kpc"), ... speed=u.Quantity([0, 200, 0], "km/s")) >>> print(w) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [kpc] [[ 8.5 0. 0. ] [10. 0. 0. ]]>, 'speed': <CartesianVel3D: (x, y, z) [km / s] [ 0 200 0]> })
The vectors can then be accessed by key:
>>> space["length"] CartesianPos3D( ... )
The space can also be converted to different representations. If the conversion is on the primary vector, the other vectors will be correspondingly converted.
>>> space.vconvert(cx.SphericalPos) KinematicSpace({ 'length': SphericalPos( ... ), 'speed': SphericalVel( ... ), 'acceleration': SphericalAcc( ... ) })
>>> cx.vconvert(cx.SphericalPos, space) KinematicSpace({ 'length': SphericalPos( ... ), 'speed': SphericalVel( ... ), 'acceleration': SphericalAcc( ... ) })
Actions on the space are done on the contained vectors.
>>> w = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), ... speed=cx.CartesianVel3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... )
>>> w.ndim 2
>>> w.shape (1, 2)
>>> w.shapes mappingproxy({'length': (1, 2), 'speed': (1, 2)})
>>> w.mT.shapes mappingproxy({'length': (2, 1), 'speed': (2, 1)})
There are convenience ways to initialize the vectors in the space:
>>> space = cx.KinematicSpace.from_({"length": u.Quantity([1, 2, 3], "km"), ... "speed": u.Quantity([4, 5, 6], "km/s")}) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [km] [1 2 3]>, 'speed': <CartesianVel3D: (x, y, z) [km / s] [4 5 6]> })
- property T: Self
Transpose each vector in the space.
Examples
>>> import coordinax as cx
>>> w = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), ... speed=cx.CartesianVel3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... )
>>> w.T.shapes mappingproxy({'length': (2, 1), 'speed': (2, 1)})
- asdict(*, dict_factory: ~collections.abc.Callable[[~typing.Any], ~collections.abc.Mapping[str, ~coordinax._src.vectors.base.vector.AbstractVector]] = <class 'dict'>)
Return the vector collection as a Mapping.
See also
NoneThis applies recursively to the components of the vector.
- Parameters:
dict_factory (
Callable[[Any],Mapping[str,AbstractVector]])- Return type:
- components
Descriptor for class properties.
- Parameters:
fget (classmethod | staticmethod) β The class/staticmethod wrapped function to be used as the getter for the class-level property.
Examples
>>> from coordinax._src.utils import classproperty >>> class MyConstants: ... @classproperty ... def pau(cls) -> float: ... return 4.71 >>> MyConstants.pau 4.71
- copy()
Return a copy of the vector.
- Return type:
Self
Examples
>>> import coordinax as cx
>>> vec = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> print(vec.copy()) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
- property devices: MappingProxyType
Get the devices of the vectorβs components.
Examples
>>> import coordinax as cx
>>> w = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), ... speed=cx.CartesianVel3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... )
>>> w.devices mappingproxy({'length': mappingproxy({'x': CpuDevice(id=0), 'y': CpuDevice(id=0), 'z': CpuDevice(id=0)}), 'speed': mappingproxy({'x': CpuDevice(id=0), 'y': CpuDevice(id=0), 'z': CpuDevice(id=0)})})
- property dtype
- property dtypes: MappingProxyType
Get the dtypes of the vectorβs components.
Examples
>>> import coordinax as cx
>>> w = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), ... speed=cx.CartesianVel3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... )
>>> w.dtypes mappingproxy({'length': mappingproxy({'x': dtype('int32'), 'y': dtype('int32'), 'z': dtype('int32')}), 'speed': mappingproxy({'x': dtype('int32'), 'y': dtype('int32'), 'z': dtype('int32')})})
- flatten()
Flatten the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.flatten().shape (4,)
- classmethod from_(cls: type[AbstractVectorLike], *args: Any, **kwargs: Any)
Create a vector-like object from arguments.
Examples
>>> import coordinax.vecs as cxv
>>> q = cxv.CartesianPos3D.from_([1, 2, 3], "m") >>> print(q) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
>>> v = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> print(v) <CartesianVel3D: (x, y, z) [m / s] [1 2 3]>
>>> space = cxv.KinematicSpace.from_(q) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- from_(cls: type[AbstractVector], *args: Any, **kwargs: Any) AbstractVector
- Parameters:
- Return type:
Create a vector from arguments.
See coordinax.vector for more information.
- from_(cls: type[KinematicSpace], obj: KinematicSpace, /) KinematicSpace
- Parameters:
- Return type:
Construct a Space, returning the KinematicSpace.
Examples
>>> import coordinax as cx
>>> q = cx.KinematicSpace.from_(cx.CartesianPos3D.from_([1, 2, 3], "m")) >>> cx.KinematicSpace.from_(q) is q True
- from_(cls: type[KinematicSpace], obj: AbstractPos, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> w = cx.KinematicSpace.from_(q) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.CartesianVel3D.from_([4, 5, 6], "m/s") >>> w = cx.KinematicSpace.from_(q, p) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, a: AbstractAcc, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.vecs.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.vecs.CartesianVel3D.from_([4, 5, 6], "m/s") >>> a = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> w = cx.KinematicSpace.from_(q, p, a) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ), 'acceleration': CartesianAcc3D( ... ) })
- from_(cls: type[KinematicSpace], obj: Mapping[str, Any]) KinematicSpace
- Parameters:
- Return type:
Construct a KinematicSpace from a Mapping.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> space = cx.KinematicSpace.from_({ 'length': u.Quantity([1, 2, 3], "m") }) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- Parameters:
cls (
type[AbstractVectorLike])args (
Any)kwargs (
Any)
- Return type:
- get(key: K, /, default: V | _T | None = None)
Get an item by key.
Examples
>>> from xmmutablemap import ImmutableMap >>> d = ImmutableMap(a=1, b=2) >>> d.get("a") 1 >>> d.get("c") >>> d.get("c", 3) 3
- items()
Return the items.
- Return type:
Examples
>>> from xmmutablemap import ImmutableMap >>> d = ImmutableMap(a=1, b=2) >>> d.items() dict_items([('a', 1), ('b', 2)])
- keys()
Return the keys.
Examples
>>> from xmmutablemap import ImmutableMap >>> d = ImmutableMap(a=1, b=2) >>> d.keys() dict_keys(['a', 'b'])
- property mT: Self
Transpose each vector in the space.
- property ndim: int
Get the number of dimensions of the vector.
When represented as a single array, the vector has an additional dimension at the end for the components.
Examples
>>> import coordinax as cx
>>> w = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), ... speed=cx.CartesianVel3D.from_([7, 8, 9], "m/s") ... )
>>> w.ndim 2
- property q: PosT
Get the position vector of the space.
- ravel()
Ravel the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.ravel().shape (4,)
- reshape(*shape: Any, order: str = 'C')
Reshape the components of the vector.
- Parameters:
- Return type:
Self
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can reshape a vector:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m"))
>>> vec.reshape(4) CartesianPos2D(x=Quantity([1, 2, 3, 4], unit='m'), y=Quantity([0, 0, 0, 0], unit='m'))
- round(decimals: int = 0)
Round the components of the vector.
- Parameters:
decimals (
int) β The number of decimals to round to.- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
We can round a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([[1.1, 2.2], [3.3, 4.4]], "m") >>> vec.round(0) CartesianPos2D(x=Quantity([1., 3.], unit='m'), y=Quantity([2., 4.], unit='m'))
- property shape: tuple[int, ...]
Get the shape of the vectorβs components.
When represented as a single array, the vector has an additional dimension at the end for the components.
- property shapes: MappingProxyType
Get the shapes of the spacesβs fields.
Examples
>>> import coordinax as cx
>>> w = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), ... speed=cx.CartesianVel3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... )
>>> w.shapes mappingproxy({'length': (1, 2), 'speed': (1, 2)})
- property size: int
Total number of elements in the vector.
Examples
>>> import coordinax as cx
>>> w = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), ... speed=cx.CartesianVel3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") )
>>> w.size 2
- property sizes: MappingProxyType
Get the sizes of the vectorβs components.
Examples
>>> import coordinax as cx
>>> w = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([[[1, 2, 3], [4, 5, 6]]], "m"), ... speed=cx.CartesianVel3D.from_([[[1, 2, 3], [4, 5, 6]]], "m/s") ... )
>>> w.sizes mappingproxy({'length': 6, 'speed': 6})
- to_device(device: None | Device = None)
Move the vector to a new device.
Examples
>>> from jax import devices >>> import unxt as u >>> import coordinax as cx
We can move a vector to a new device:
>>> vec = cx.vecs.CartesianPos1D(u.Quantity([1, 2], "m")) >>> vec.to_device(devices()[0]) CartesianPos1D(x=Quantity([1, 2], unit='m'))
- tree_flatten()
Flatten dict to the values (and keys).
This is used for JAXβs tree flattening.
Examples
>>> import jax >>> from xmmutablemap import ImmutableMap >>> d = ImmutableMap(a=1, b=2) >>> d.tree_flatten() ((1, 2), ('a', 'b'))
>>> jax.tree.flatten(d) ([1, 2], PyTreeDef(CustomNode(ImmutableMap[('a', 'b')], [*, *])))
- classmethod tree_unflatten(aux_data: Annotated[tuple[K, ...], Doc('The keys.')], children: Annotated[tuple[V, ...], Doc('The values.')])
Unflatten into an ImmutableMap from the keys and values.
This is used for JAXβs tree un-flattening.
Examples
>>> import jax >>> from xmmutablemap import ImmutableMap >>> d = ImmutableMap(a=1, b=2) >>> flat = d.tree_flatten() >>> ImmutableMap.tree_unflatten(*flat) ImmutableMap({1: 'a', 2: 'b'})
>>> jax.tree.unflatten(jax.tree.structure(d), flat) ImmutableMap({'a': (1, 2), 'b': ('a', 'b')})
- uconvert(*args: Any, **kw: Any)
Convert the vector to the given units.
This just forwards to unxt.uconvert, reversing the order of the arguments to match the unxt API.
Examples
>>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos3D.from_([1, 2, 3], "km")
>>> vec.uconvert({"length": "km"}) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> vec.uconvert(cx.vecs.ToUnitsOptions.consistent) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> usys = u.unitsystem("m", "s", "kg", "rad")
>>> print(vec.uconvert(usys)) <CartesianPos3D: (x, y, z) [m] [1000. 2000. 3000.]>
>>> print(vec.uconvert("galactic")) <CartesianPos3D: (x, y, z) [kpc] [3.241e-17 6.482e-17 9.722e-17]>
- property units: MappingProxyType
Get the units of the vectorβs components.
- values()
Return the values.
- Return type:
Examples
>>> from xmmutablemap import ImmutableMap >>> d = ImmutableMap(a=1, b=2) >>> d.values() dict_values([1, 2])
- vconvert(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVectorLike]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.self (AbstractVectorLike)
- Return type:
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- vconvert(self: AbstractVectorLike, target: type, *args: Any, **kwargs: Any) AbstractVectorLike
- Parameters:
self (AbstractVectorLike)
target (type)
args (Any)
kwargs (Any)
- Return type:
Represent the vector as another type, forwarding to coordinax.vconvert.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- Parameters:
self (
AbstractVectorLike)target (type)
args (Any)
kwargs (Any)
- Return type:
- class coordinax.Coordinate(data: ArgT | PassThroughTs, frame: ArgT | PassThroughTs)
Bases:
AbstractCoordinateCoordinates are vectors in a reference frame.
Examples
>>> import coordinax as cx
>>> coord = cx.Coordinate(cx.CartesianPos3D.from_([1, 2, 3], "kpc"), ... cx.frames.ICRS()) >>> coord Coordinate( KinematicSpace({ 'length': CartesianPos3D( ... ) }), frame=ICRS() )
Alternative Construction:
>>> frame = cx.frames.ICRS() >>> data = cx.CartesianPos3D.from_([1, 2, 3], "kpc") >>> cx.Coordinate.from_({"data": data, "frame": frame}) Coordinate( KinematicSpace({ 'length': CartesianPos3D( ... ) }), frame=ICRS() )
Changing Representation:
>>> frame = cx.frames.ICRS() >>> data = cx.CartesianPos3D.from_([1, 2, 3], "kpc") >>> coord = cx.Coordinate(data, frame)
>>> coord.vconvert(cx.SphericalPos) Coordinate( KinematicSpace({ 'length': SphericalPos( ... ) }), frame=ICRS() )
Showing Frame Transformation:
>>> space = cx.KinematicSpace( ... length=cx.CartesianPos3D.from_([1.0, 0, 0], "pc"), ... speed=cx.CartesianVel3D.from_([1.0, 0, 0], "km/s"))
>>> w=cx.Coordinate( ... data=space, ... frame=cx.frames.TransformedReferenceFrame( ... cx.frames.Galactocentric(), ... cx.ops.GalileanSpatialTranslation.from_([20, 0, 0], "kpc"), ... ), ... )
>>> w.to_frame(cx.frames.ICRS()) Coordinate( KinematicSpace({ 'length': CartesianPos3D(...), 'speed': CartesianVel3D(...) }), frame=ICRS() )
>>> w.to_frame(cx.frames.ICRS()).data["length"] CartesianPos3D( x=Quantity(-1587.6683, unit='pc'), y=Quantity(-24573.762, unit='pc'), z=Quantity(-13583.504, unit='pc') )
- Parameters:
- property T: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.T.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- asdict(*, dict_factory: ~collections.abc.Callable[[~typing.Any], ~collections.abc.Mapping[str, ~unxt._src.quantity.base.AbstractQuantity]] = <class 'dict'>)
Return the vector as a Mapping.
- Parameters:
dict_factory (
Callable[[Any],Mapping[str,AbstractQuantity]]) β The type of the mapping to return.- Returns:
The vector as a mapping.
- Return type:
Mapping[str, Quantity]
See also
NoneThis applies recursively to the components of the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the vector as a mapping:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.asdict() {'x': Quantity(Array([[1, 2], [3, 4]], dtype=int32), unit='m'), 'y': Quantity(Array(0, dtype=int32, ...), unit='m')}
- components = ('data', 'frame')
- copy()
Return a copy of the vector.
- Return type:
Self
Examples
>>> import coordinax as cx
>>> vec = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> print(vec.copy()) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
- property devices: MappingProxyType
Get the devices of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.devices mappingproxy({'x': CpuDevice(id=0), 'y': CpuDevice(id=0), 'z': CpuDevice(id=0)})
- property dtype
- property dtypes: MappingProxyType
Get the dtypes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.dtypes mappingproxy({'x': dtype('int32'), 'y': dtype('int32'), 'z': dtype('int32')})
- flatten()
Flatten the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.flatten().shape (4,)
- classmethod from_(cls: type[AbstractVectorLike], *args: Any, **kwargs: Any)
Create a vector-like object from arguments.
Examples
>>> import coordinax.vecs as cxv
>>> q = cxv.CartesianPos3D.from_([1, 2, 3], "m") >>> print(q) <CartesianPos3D: (x, y, z) [m] [1 2 3]>
>>> v = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> print(v) <CartesianVel3D: (x, y, z) [m / s] [1 2 3]>
>>> space = cxv.KinematicSpace.from_(q) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- from_(cls: type[AbstractVector], *args: Any, **kwargs: Any) AbstractVector
- Parameters:
- Return type:
Create a vector from arguments.
See coordinax.vector for more information.
- from_(cls: type[KinematicSpace], obj: KinematicSpace, /) KinematicSpace
- Parameters:
- Return type:
Construct a Space, returning the KinematicSpace.
Examples
>>> import coordinax as cx
>>> q = cx.KinematicSpace.from_(cx.CartesianPos3D.from_([1, 2, 3], "m")) >>> cx.KinematicSpace.from_(q) is q True
- from_(cls: type[KinematicSpace], obj: AbstractPos, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> w = cx.KinematicSpace.from_(q) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.CartesianVel3D.from_([4, 5, 6], "m/s") >>> w = cx.KinematicSpace.from_(q, p) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ) })
- from_(cls: type[KinematicSpace], q: AbstractPos, p: AbstractVel, a: AbstractAcc, /) KinematicSpace
- Parameters:
- Return type:
Construct a coordinax.KinematicSpace from a coordinax.AbstractPos.
Examples
>>> import coordinax as cx
>>> q = cx.vecs.CartesianPos3D.from_([1, 2, 3], "m") >>> p = cx.vecs.CartesianVel3D.from_([4, 5, 6], "m/s") >>> a = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> w = cx.KinematicSpace.from_(q, p, a) >>> w KinematicSpace({ 'length': CartesianPos3D( ... ), 'speed': CartesianVel3D( ... ), 'acceleration': CartesianAcc3D( ... ) })
- from_(cls: type[KinematicSpace], obj: Mapping[str, Any]) KinematicSpace
- Parameters:
- Return type:
Construct a KinematicSpace from a Mapping.
Examples
>>> import unxt as u >>> import coordinax as cx
>>> space = cx.KinematicSpace.from_({ 'length': u.Quantity([1, 2, 3], "m") }) >>> print(space) KinematicSpace({ 'length': <CartesianPos3D: (x, y, z) [m] [1 2 3]> })
- Parameters:
cls (
type[AbstractVectorLike])args (
Any)kwargs (
Any)
- Return type:
- property mT: Self
Transpose the vector.
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can transpose a vector:
>>> vec = cx.CartesianPos3D(x=u.Quantity([[0, 1], [2, 3]], "m"), ... y=u.Quantity([[0, 1], [2, 3]], "m"), ... z=u.Quantity([[0, 1], [2, 3]], "m")) >>> vec.mT.x Quantity(Array([[0, 2], [1, 3]], dtype=int32), unit='m')
- property ndim: int
Number of array dimensions (axes).
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can get the number of dimensions of a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([1, 2], "m") >>> vec.ndim 0
>>> vec = cx.vecs.CartesianPos2D.from_([[1, 2], [3, 4]], "m") >>> vec.ndim 1
ndimis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.ndim 2
- ravel()
Ravel the vector.
- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> vec.ravel().shape (4,)
- represent_as(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVel]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.
- Return type:
Examples
>>> import coordinax as cx
Transforming a Position:
>>> q_cart = cx.CartesianPos3D.from_([1, 2, 3], "m") >>> q_sph = q_cart.represent_as(cx.SphericalPos) >>> q_sph SphericalPos( ... ) >>> q_sph.r Distance(Array(3.7416575, dtype=float32), unit='m')
Transforming a Velocity:
>>> v_cart = cx.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.represent_as(cx.SphericalVel, q_cart) >>> v_sph SphericalVel( ... )
Transforming an Acceleration:
>>> a_cart = cx.vecs.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.represent_as(cx.vecs.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- reshape(*shape: Any, order: str = 'C')
Reshape the components of the vector.
- Parameters:
- Return type:
Self
Examples
We assume the following imports:
>>> import unxt as u >>> import coordinax as cx
We can reshape a vector:
>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m"))
>>> vec.reshape(4) CartesianPos2D(x=Quantity([1, 2, 3, 4], unit='m'), y=Quantity([0, 0, 0, 0], unit='m'))
- round(decimals: int = 0)
Round the components of the vector.
- Parameters:
decimals (
int) β The number of decimals to round to.- Return type:
Self
Examples
>>> import unxt as u >>> import coordinax as cx
We can round a vector:
>>> vec = cx.vecs.CartesianPos2D.from_([[1.1, 2.2], [3.3, 4.4]], "m") >>> vec.round(0) CartesianPos2D(x=Quantity([1., 3.], unit='m'), y=Quantity([2., 4.], unit='m'))
- property shape: tuple[int, ...]
Return the shape of the vector.
Examples
>>> import unxt as u >>> import coordinax as cx
We can get the shape of a vector:
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([1, 2], "m")) >>> vec.shape (2,)
>>> vec = cx.vecs.CartesianPos1D(x=u.Quantity([[1, 2], [3, 4]], "m")) >>> vec.shape (2, 2)
shapeis calculated from the broadcasted shape. We can see this by creating a 2D vector in which the components have different shapes:>>> vec = cx.vecs.CartesianPos2D(x=u.Quantity([[1, 2], [3, 4]], "m"), ... y=u.Quantity(0, "m")) >>> vec.shape (2, 2)
>>> space = cx.KinematicSpace(length=vec) >>> space.shape (2, 2)
- property shapes: MappingProxyType
Get the shapes of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.shapes mappingproxy({'x': (), 'y': (), 'z': ()})
- property size
- property sizes: MappingProxyType
Get the sizes of the vectorβs components.
Examples
>>> import coordinax as cx
>>> cx.vecs.CartesianPos2D.from_([1, 2], "m").sizes mappingproxy({'x': 1, 'y': 1})
>>> cx.vecs.CartesianPos2D.from_([[1, 2], [1, 2]], "m").sizes mappingproxy({'x': 2, 'y': 2})
- to_device(device: None | Device = None)
Move the vector to a new device.
Examples
>>> from jax import devices >>> import unxt as u >>> import coordinax as cx
We can move a vector to a new device:
>>> vec = cx.vecs.CartesianPos1D(u.Quantity([1, 2], "m")) >>> vec.to_device(devices()[0]) CartesianPos1D(x=Quantity([1, 2], unit='m'))
- to_frame(toframe: AbstractReferenceFrame, /, t: Quantity | None = None)
Transform the coordinate to a specified frame.
Examples
>>> import coordinax as cx
>>> cicrs = cx.Coordinate(cx.CartesianPos3D.from_([1, 2, 3], "kpc"), ... cx.frames.ICRS())
>>> cicrs.to_frame(cx.frames.ICRS()) is cicrs True
>>> cgcf = cicrs.to_frame(cx.frames.Galactocentric()) >>> cgcf Coordinate( KinematicSpace({ 'length': CartesianPos3D( ... ) }), frame=Galactocentric( ... ) )
- Parameters:
toframe (
AbstractReferenceFrame)
- Return type:
- uconvert(*args: Any, **kw: Any)
Convert the vector to the given units.
This just forwards to unxt.uconvert, reversing the order of the arguments to match the unxt API.
Examples
>>> import coordinax as cx
>>> vec = cx.vecs.CartesianPos3D.from_([1, 2, 3], "km")
>>> vec.uconvert({"length": "km"}) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> vec.uconvert(cx.vecs.ToUnitsOptions.consistent) CartesianPos3D( x=Quantity(1, unit='km'), y=Quantity(2, unit='km'), z=Quantity(3, unit='km') )
>>> usys = u.unitsystem("m", "s", "kg", "rad")
>>> print(vec.uconvert(usys)) <CartesianPos3D: (x, y, z) [m] [1000. 2000. 3000.]>
>>> print(vec.uconvert("galactic")) <CartesianPos3D: (x, y, z) [kpc] [3.241e-17 6.482e-17 9.722e-17]>
- property units: MappingProxyType
Get the units of the vectorβs components.
Examples
>>> import coordinax as cx >>> vec = cx.CartesianPos3D.from_([1, 2, 3], "km") >>> vec.units mappingproxy({'x': Unit("km"), 'y': Unit("km"), 'z': Unit("km")})
- vconvert(target: type, *args: Any, **kwargs: Any)
Represent the vector as another type.
This just forwards to coordinax.vconvert.
- Parameters:
target (type[coordinax.AbstractVectorLike]) β The type to represent the vector as.
*args (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.**kwargs (
Any) β Extra arguments. These are passed to coordinax.vconvert and might be used, depending on the dispatched method. E.g. for transforming an acceleration, generally the first argument is the velocity (coordinax.AbstractVel) followed by the position (coordinax.AbstractPos) at which the acceleration is defined. In general this is a required argument, though it is not for Cartesian-to-Cartesian transforms β see https://en.wikipedia.org/wiki/Tensors_in_curvilinear_coordinates for more information.self (AbstractVectorLike)
- Return type:
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- vconvert(self: AbstractVectorLike, target: type, *args: Any, **kwargs: Any) AbstractVectorLike
- Parameters:
self (AbstractVectorLike)
target (type)
args (Any)
kwargs (Any)
- Return type:
Represent the vector as another type, forwarding to coordinax.vconvert.
Examples
>>> import unxt as u >>> import coordinax.vecs as cxv
Transforming a Position:
>>> q_cart = cxv.CartesianPos3D.from_([1, 2, 3], "m")
>>> q_sph = q_cart.vconvert(cxv.SphericalPos) >>> print(q_sph) <SphericalPos: (r[m], theta[rad], phi[rad]) [3.742 0.641 1.107]>
>>> q_ps = q_cart.vconvert(cxv.ProlateSpheroidalPos, Delta=u.Quantity(1.5, "m")) >>> print(q_ps) <ProlateSpheroidalPos: (mu[m2], nu[m2], phi[rad]) Delta=Quantity(1.5, unit='m') [14.89 1.36 1.107]>
>>> print((q_ps.vconvert(cxv.CartesianPos3D) - q_cart).round(3)) <CartesianPos3D: (x, y, z) [m] [-0. 0. 0.]>
Transforming a Velocity:
>>> v_cart = cxv.CartesianVel3D.from_([1, 2, 3], "m/s") >>> v_sph = v_cart.vconvert(cxv.SphericalVel, q_cart) >>> print(v_sph) <SphericalVel: (r[m / s], theta[rad / s], phi[rad / s]) [ 3.742e+00 -8.941e-08 0.000e+00]>
Transforming an Acceleration:
>>> a_cart = cxv.CartesianAcc3D.from_([7, 8, 9], "m/s2") >>> a_sph = a_cart.vconvert(cxv.SphericalAcc, v_cart, q_cart) >>> print(a_sph) <SphericalAcc: (r[m / s2], theta[rad / s2], phi[rad / s2]) [13.363 0.767 -1.2 ]>
- Parameters:
self (
AbstractVectorLike)target (type)
args (Any)
kwargs (Any)
- Return type:
-
data:
KinematicSpace The data of the coordinate. This is a coordinax.KinematicSpace object, which is a collection of vectors.
-
frame:
AbstractReferenceFrame The reference frame of the coordinate as a coordinax.frames.AbstractReferenceFrame object. This can be from a reference frame object, or any input that can construct a coordinax.frames.TransformedReferenceFrame via coordinax.frames.AbstractReferenceFrame.from_.