coordinax.angle#

coordinax.angle module.

class coordinax.angle.AbstractAngle#

Bases: AbstractQuantity

Angular quantity.

See also

None

a concrete implementation of this class.

Examples

For this example, we will use the concrete implementation of unxt.AbstractAngle, unxt.Angle.

>>> from unxt import Angle
>>> Angle(90, "deg")
Angle(Array(90, dtype=int32...), unit='deg')

Angles have to have dimensions of angle.

>>> try:
...     Angle(90, "m")
... except ValueError as e:
...     print(e)
Angle must have units with angular dimensions.
property T: AbstractQuantity#

Transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Q([[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.Q([1, 2, 3], "m")
>>> q.argmax()
Array(2, dtype=int32)
Parameters:
Return type:

Array

argmin(*args: Any, **kwargs: Any)#

Return the indices of the minimum value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.argmin()
Array(0, dtype=int32)
Parameters:
Return type:

Array

astype(*args: Any, **kwargs: Any)#

Copy the array and cast to a specified dtype.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.dtype
dtype('int32')
>>> q.astype(float)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property at: _QuantityIndexUpdateHelper#

Helper property for index update functionality.

The at property 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] = y

x = x.at[idx].add(y)

x[idx] += y

x = x.at[idx].subtract(y)

x[idx] -= y

x = x.at[idx].multiply(y)

x[idx] *= y

x = x.at[idx].divide(y)

x[idx] /= y

x = x.at[idx].power(y)

x[idx] **= y

x = 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.at expressions modify the original x; instead they return a modified copy of x. However, inside a jit() compiled function, expressions like x = 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 mode parameter (see below).

Parameters:
  • mode –

    string specifying 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 in get() will be clipped, and out-of-bounds indices in set(), 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 optional fill_value argument specifies the value that will be returned.

    See jax.lax.GatherScatterMode for more details.

  • wrap_negative_indices – If True (default) then negative indices indicate position from the end of the array, similar to Python and NumPy indexing. If False, then negative indices are considered out-of-bounds and behave according to the mode parameter.

  • fill_value – Only applies to the get() method: the fill value to return for out-of-bounds slices when mode is 'fill'. Ignored otherwise. Defaults to NaN for inexact types, the largest negative value for signed types, the largest positive value for unsigned types, and True for booleans.

  • indices_are_sorted – If True, the implementation will assume that the (normalized) indices passed to at[] are sorted in ascending order, which can lead to more efficient execution on some backends. If True but the indices are not actually sorted, the output is undefined.

  • unique_indices – If True, the implementation will assume that the (normalized) indices passed to at[] are unique, which can result in more efficient execution on some backends. If True but the indices are not actually unique, the output is undefined.

Examples

>>> x = jnp.arange(5.0)
>>> x
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[2].get()
Array(2., dtype=float32)
>>> x.at[2].add(10)
Array([ 0.,  1., 12.,  3.,  4.], dtype=float32)

By default, out-of-bound indices are ignored in updates, but this behavior can be controlled with the mode parameter:

>>> x.at[10].add(10)  # dropped
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[20].add(10, mode='clip')  # clipped
Array([ 0.,  1.,  2.,  3., 14.], dtype=float32)

For get(), out-of-bound indices are clipped by default:

>>> 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)

Negative indices count from the end of the array, but this behavior can be disabled by setting wrap_negative_indices = False:

>>> x.at[-1].set(99)
Array([ 0.,  1.,  2.,  3., 99.], dtype=float32)
>>> x.at[-1].set(99, wrap_negative_indices=False, mode='drop')  # dropped!
Array([0., 1., 2., 3., 4.], dtype=float32)
block_until_ready()#

Block until the array is ready.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.block_until_ready() is q
True
decompose(bases: Sequence[UnitBase | FunctionUnitBase | 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[UnitBase | FunctionUnitBase | str])

Return type:

AbstractQuantity

property device: Device#

Device where the array is located.

Examples

>>> import unxt as u
>>> u.Q(1, "m").device
CpuDevice(id=0)
devices()#

Return the devices where the array is located.

Return type:

set[Device]

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.devices()
{CpuDevice(id=0)}
property dtype: dtype#

Data type of the array.

Examples

>>> import unxt as u
>>> u.Q(1, "m").dtype
dtype('int32')
flatten()#

Return a flattened version of the array.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Q([[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:

AbstractQuantity

Construct a unxt.AbstractQuantity from an array-like value and a unit.

Parameters:
  • value – The array-like value.

  • unit – The unit of the value.

  • dtype – The data type of the array (keyword-only).

  • args (Any)

  • kwargs (Any)

Return type:

AbstractQuantity

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.Q.from_(x, "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Q.from_([1.0, 2, 3], "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Q.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:

AbstractQuantity

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.Q.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:

AbstractQuantity

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.Q.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:

AbstractQuantity

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.Q.from_({"value": x, "unit": "m"})
>>> q
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Q.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:

AbstractQuantity

Construct a quantity from another quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> u.Q.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:

AbstractQuantity

Construct a quantity from another quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> u.Q.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:

AbstractQuantity

Construct a quantity from another quantity.

The unit is unchanged.

from_(cls: type[StaticQuantity], 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) → StaticQuantity
Parameters:
Return type:

AbstractQuantity

Construct a StaticQuantity, keeping the value on NumPy dtypes.

The generic AbstractQuantity.from_ routes the value through jnp.asarray, which applies JAX’s x64-disabled dtype rules and silently downcasts int64 / float64 to int32 / float32. A StaticQuantity stores its value verbatim, so hand the value straight to __init__ and let the StaticValue.from_ converter convert it – that preserves the NumPy dtype. Delegating (rather than calling np.asarray here) also keeps .from_ and __init__ under the same policy for JAX inputs, instead of materialising an array the constructor would reject. (The keyword-unit overload delegates here, so it is covered too.)

Examples

>>> import numpy as np
>>> import unxt as u
>>> u.StaticQuantity.from_(
...     np.array([1, 2, 3], dtype=np.int64), "m"
... ).value.array.dtype
dtype('int64')

.from_ applies the same JAX-input policy as __init__ – it delegates rather than converting first, so the two cannot drift:

>>> import jax.numpy as jnp
>>> u.StaticQuantity.from_(jnp.array([1.0, 2.0]), "m")
StaticQuantity(array([1., 2.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], value: Quantity, /, **kwargs: Any) → AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a quantity from an astropy Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Q.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:

AbstractQuantity

Construct a quantity from an astropy Quantity, converting to a target unit.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Q.from_(apyu.Quantity(1, "m"), "cm")
Quantity(Array(100., dtype=float32), unit='cm')
from_(cls: type[Distance], obj: AbstractDistance | Quantity, /, **kw: Any) → Distance
Parameters:
Return type:

AbstractQuantity

Construct a Distance from the inputs.

from_(cls: type[DistanceModulus], dm: AbstractDistance | Quantity, /, **kwargs: Any) → DistanceModulus
Parameters:
Return type:

AbstractQuantity

Construct a DistanceModulus from the input.

from_(cls: type[Parallax], obj: AbstractDistance | Quantity, /, **kwargs: Any) → Parallax
Parameters:
Return type:

AbstractQuantity

Construct a Parallax the input.

Parameters:
Return type:

AbstractQuantity

is_equivalent(other: AbstractQuantity, /)#

Whether self and other are physically equal (unit-aware).

The method form of unxt.equivalent; unlike == (which is unit-blind for StaticValue-backed quantities) this accounts for unit conversion.

Examples

>>> import unxt as u
>>> u.Q(1000.0, "m").is_equivalent(u.Q(1.0, "km"))
Quantity(Array(True, dtype=bool...), unit='')
Parameters:

other (AbstractQuantity)

Return type:

Any

property mT: AbstractQuantity#

Matrix transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Q([[0, 1], [2, 3]], "m")
>>> q.mT
Quantity(Array([[0, 2],
                          [1, 3]], dtype=int32), unit='m')

It also works for a StaticQuantity:

>>> u.StaticQuantity([[0, 1], [2, 3]], "m").mT.value.tolist()
[[0, 2], [1, 3]]
max(*args: Any, **kwargs: Any)#

Return the maximum value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.max()
Quantity(Array(3, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

mean(*args: Any, **kwargs: Any)#

Return the mean value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.mean()
Quantity(Array(2., dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

min(*args: Any, **kwargs: Any)#

Return the minimum value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.min()
Quantity(Array(1, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

property ndim: int#

Number of dimensions.

Examples

>>> import unxt as u
>>> q = u.Q([[1]], "m")
>>> q.ndim
2
ravel()#

Return a flattened version of the array.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Q([[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.Q([1, 2, 3, 4], "m")
>>> q.reshape(2, 2)
Quantity(Array([[1, 2],
                          [3, 4]], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

round(*args: Any, **kwargs: Any)#

Round the array to the given number of decimals.

Examples

>>> import unxt as u
>>> q = u.Q([1.1, 2.2, 3.3], "m")
>>> q.round(0)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property shape: tuple[int, ...]#

Shape of the array.

property sharding: Any#

Return the sharding configuration of the array.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.sharding
SingleDeviceSharding(device=..., memory_kind=...)
property size: int#

Total number of elements.

Examples

>>> import unxt as u
>>> q = u.Q([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.Q([[[1], [2], [3]]], "m")
>>> q.squeeze()
Quantity(Array([1, 2, 3], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

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:

AbstractQuantity

to_device(device: None | Device = None)#

Move the array to a new device.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.to_device(None)
Quantity(Array(1, dtype=int32...), unit='m')
Parameters:

device (None | Device)

Return type:

AbstractQuantity

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)
Parameters:

u (Any)

Return type:

Union[Array, ndarray, bool, number, bool, int, float, complex]

uconvert(u: Any, /)#

Convert the quantity to the given units.

See also

None

convert a quantity to a new unit.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.uconvert("cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

u (Any)

Return type:

AbstractQuantity

ustrip(u: Any, /)#

Return the value in the given units.

See also

None

strip the units from a quantity.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.ustrip("cm")
Array(100., dtype=float32, weak_type=True)
Parameters:

u (Any)

Return type:

Array

wrap_to(min: AbstractQuantity, max: AbstractQuantity)#

Wrap the angle to the range [min, max).

Parameters:
Return type:

AbstractAngle

See also

None

functional version of this method.

Examples

>>> import unxt as u
>>> angle = u.Angle(370, "deg")
>>> angle.wrap_to(min=u.Q(0, "deg"), max=u.Q(360, "deg"))
Angle(Array(10, dtype=int32...), unit='deg')
value: AbstractVar[Union[Shaped[Array, '*shape'], Shaped[StaticValue, '*shape']]]#

The value of the unxt.AbstractQuantity.

unit: AbstractVar[UnitBase | FunctionUnitBase]#

The unit associated with this value.

class coordinax.angle.Angle(value: Any, unit: Any)#

Bases: AbstractAngle

Angular quantity.

Examples

>>> import unxt as u

Create an Angle:

>>> q = u.Angle(1, "rad")
>>> q
Angle(Array(1, dtype=int32...), unit='rad')

Wrap an Angle to a range:

>>> q = u.Angle(370, "deg")
>>> q.wrap_to(u.Q(0, "deg"), u.Q(360, "deg"))
Angle(Array(10, dtype=int32...), unit='deg')

Create an Angle array:

>>> q = u.Angle([1, 2, 3], "deg")
>>> q
Angle(Array([1, 2, 3], dtype=int32), unit='deg')

Do math on an Angle:

>>> 2 * q
Angle(Array([2, 4, 6], dtype=int32), unit='deg')
>>> q % u.Q(4, "deg")
Angle(Array([1, 2, 3], dtype=int32), unit='deg')
Parameters:
property T: AbstractQuantity#

Transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Q([[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.Q([1, 2, 3], "m")
>>> q.argmax()
Array(2, dtype=int32)
Parameters:
Return type:

Array

argmin(*args: Any, **kwargs: Any)#

Return the indices of the minimum value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.argmin()
Array(0, dtype=int32)
Parameters:
Return type:

Array

astype(*args: Any, **kwargs: Any)#

Copy the array and cast to a specified dtype.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.dtype
dtype('int32')
>>> q.astype(float)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property at: _QuantityIndexUpdateHelper#

Helper property for index update functionality.

The at property 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] = y

x = x.at[idx].add(y)

x[idx] += y

x = x.at[idx].subtract(y)

x[idx] -= y

x = x.at[idx].multiply(y)

x[idx] *= y

x = x.at[idx].divide(y)

x[idx] /= y

x = x.at[idx].power(y)

x[idx] **= y

x = 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.at expressions modify the original x; instead they return a modified copy of x. However, inside a jit() compiled function, expressions like x = 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 mode parameter (see below).

Parameters:
  • mode –

    string specifying 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 in get() will be clipped, and out-of-bounds indices in set(), 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 optional fill_value argument specifies the value that will be returned.

    See jax.lax.GatherScatterMode for more details.

  • wrap_negative_indices – If True (default) then negative indices indicate position from the end of the array, similar to Python and NumPy indexing. If False, then negative indices are considered out-of-bounds and behave according to the mode parameter.

  • fill_value – Only applies to the get() method: the fill value to return for out-of-bounds slices when mode is 'fill'. Ignored otherwise. Defaults to NaN for inexact types, the largest negative value for signed types, the largest positive value for unsigned types, and True for booleans.

  • indices_are_sorted – If True, the implementation will assume that the (normalized) indices passed to at[] are sorted in ascending order, which can lead to more efficient execution on some backends. If True but the indices are not actually sorted, the output is undefined.

  • unique_indices – If True, the implementation will assume that the (normalized) indices passed to at[] are unique, which can result in more efficient execution on some backends. If True but the indices are not actually unique, the output is undefined.

Examples

>>> x = jnp.arange(5.0)
>>> x
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[2].get()
Array(2., dtype=float32)
>>> x.at[2].add(10)
Array([ 0.,  1., 12.,  3.,  4.], dtype=float32)

By default, out-of-bound indices are ignored in updates, but this behavior can be controlled with the mode parameter:

>>> x.at[10].add(10)  # dropped
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[20].add(10, mode='clip')  # clipped
Array([ 0.,  1.,  2.,  3., 14.], dtype=float32)

For get(), out-of-bound indices are clipped by default:

>>> 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)

Negative indices count from the end of the array, but this behavior can be disabled by setting wrap_negative_indices = False:

>>> x.at[-1].set(99)
Array([ 0.,  1.,  2.,  3., 99.], dtype=float32)
>>> x.at[-1].set(99, wrap_negative_indices=False, mode='drop')  # dropped!
Array([0., 1., 2., 3., 4.], dtype=float32)
block_until_ready()#

Block until the array is ready.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.block_until_ready() is q
True
decompose(bases: Sequence[UnitBase | FunctionUnitBase | 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[UnitBase | FunctionUnitBase | str])

Return type:

AbstractQuantity

property device: Device#

Device where the array is located.

Examples

>>> import unxt as u
>>> u.Q(1, "m").device
CpuDevice(id=0)
devices()#

Return the devices where the array is located.

Return type:

set[Device]

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.devices()
{CpuDevice(id=0)}
property dtype: dtype#

Data type of the array.

Examples

>>> import unxt as u
>>> u.Q(1, "m").dtype
dtype('int32')
flatten()#

Return a flattened version of the array.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Q([[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:

AbstractQuantity

Construct a unxt.AbstractQuantity from an array-like value and a unit.

Parameters:
  • value – The array-like value.

  • unit – The unit of the value.

  • dtype – The data type of the array (keyword-only).

  • args (Any)

  • kwargs (Any)

Return type:

AbstractQuantity

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.Q.from_(x, "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Q.from_([1.0, 2, 3], "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Q.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:

AbstractQuantity

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.Q.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:

AbstractQuantity

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.Q.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:

AbstractQuantity

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.Q.from_({"value": x, "unit": "m"})
>>> q
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Q.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:

AbstractQuantity

Construct a quantity from another quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> u.Q.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:

AbstractQuantity

Construct a quantity from another quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> u.Q.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:

AbstractQuantity

Construct a quantity from another quantity.

The unit is unchanged.

from_(cls: type[StaticQuantity], 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) → StaticQuantity
Parameters:
Return type:

AbstractQuantity

Construct a StaticQuantity, keeping the value on NumPy dtypes.

The generic AbstractQuantity.from_ routes the value through jnp.asarray, which applies JAX’s x64-disabled dtype rules and silently downcasts int64 / float64 to int32 / float32. A StaticQuantity stores its value verbatim, so hand the value straight to __init__ and let the StaticValue.from_ converter convert it – that preserves the NumPy dtype. Delegating (rather than calling np.asarray here) also keeps .from_ and __init__ under the same policy for JAX inputs, instead of materialising an array the constructor would reject. (The keyword-unit overload delegates here, so it is covered too.)

Examples

>>> import numpy as np
>>> import unxt as u
>>> u.StaticQuantity.from_(
...     np.array([1, 2, 3], dtype=np.int64), "m"
... ).value.array.dtype
dtype('int64')

.from_ applies the same JAX-input policy as __init__ – it delegates rather than converting first, so the two cannot drift:

>>> import jax.numpy as jnp
>>> u.StaticQuantity.from_(jnp.array([1.0, 2.0]), "m")
StaticQuantity(array([1., 2.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], value: Quantity, /, **kwargs: Any) → AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a quantity from an astropy Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Q.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:

AbstractQuantity

Construct a quantity from an astropy Quantity, converting to a target unit.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Q.from_(apyu.Quantity(1, "m"), "cm")
Quantity(Array(100., dtype=float32), unit='cm')
from_(cls: type[Distance], obj: AbstractDistance | Quantity, /, **kw: Any) → Distance
Parameters:
Return type:

AbstractQuantity

Construct a Distance from the inputs.

from_(cls: type[DistanceModulus], dm: AbstractDistance | Quantity, /, **kwargs: Any) → DistanceModulus
Parameters:
Return type:

AbstractQuantity

Construct a DistanceModulus from the input.

from_(cls: type[Parallax], obj: AbstractDistance | Quantity, /, **kwargs: Any) → Parallax
Parameters:
Return type:

AbstractQuantity

Construct a Parallax the input.

Parameters:
Return type:

AbstractQuantity

is_equivalent(other: AbstractQuantity, /)#

Whether self and other are physically equal (unit-aware).

The method form of unxt.equivalent; unlike == (which is unit-blind for StaticValue-backed quantities) this accounts for unit conversion.

Examples

>>> import unxt as u
>>> u.Q(1000.0, "m").is_equivalent(u.Q(1.0, "km"))
Quantity(Array(True, dtype=bool...), unit='')
Parameters:

other (AbstractQuantity)

Return type:

Any

property mT: AbstractQuantity#

Matrix transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Q([[0, 1], [2, 3]], "m")
>>> q.mT
Quantity(Array([[0, 2],
                          [1, 3]], dtype=int32), unit='m')

It also works for a StaticQuantity:

>>> u.StaticQuantity([[0, 1], [2, 3]], "m").mT.value.tolist()
[[0, 2], [1, 3]]
max(*args: Any, **kwargs: Any)#

Return the maximum value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.max()
Quantity(Array(3, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

mean(*args: Any, **kwargs: Any)#

Return the mean value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.mean()
Quantity(Array(2., dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

min(*args: Any, **kwargs: Any)#

Return the minimum value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.min()
Quantity(Array(1, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

property ndim: int#

Number of dimensions.

Examples

>>> import unxt as u
>>> q = u.Q([[1]], "m")
>>> q.ndim
2
ravel()#

Return a flattened version of the array.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Q([[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.Q([1, 2, 3, 4], "m")
>>> q.reshape(2, 2)
Quantity(Array([[1, 2],
                          [3, 4]], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

round(*args: Any, **kwargs: Any)#

Round the array to the given number of decimals.

Examples

>>> import unxt as u
>>> q = u.Q([1.1, 2.2, 3.3], "m")
>>> q.round(0)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property shape: tuple[int, ...]#

Shape of the array.

property sharding: Any#

Return the sharding configuration of the array.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.sharding
SingleDeviceSharding(device=..., memory_kind=...)
property size: int#

Total number of elements.

Examples

>>> import unxt as u
>>> q = u.Q([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.Q([[[1], [2], [3]]], "m")
>>> q.squeeze()
Quantity(Array([1, 2, 3], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

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:

AbstractQuantity

to_device(device: None | Device = None)#

Move the array to a new device.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.to_device(None)
Quantity(Array(1, dtype=int32...), unit='m')
Parameters:

device (None | Device)

Return type:

AbstractQuantity

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)
Parameters:

u (Any)

Return type:

Union[Array, ndarray, bool, number, bool, int, float, complex]

uconvert(u: Any, /)#

Convert the quantity to the given units.

See also

None

convert a quantity to a new unit.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.uconvert("cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

u (Any)

Return type:

AbstractQuantity

ustrip(u: Any, /)#

Return the value in the given units.

See also

None

strip the units from a quantity.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.ustrip("cm")
Array(100., dtype=float32, weak_type=True)
Parameters:

u (Any)

Return type:

Array

wrap_to(min: AbstractQuantity, max: AbstractQuantity)#

Wrap the angle to the range [min, max).

Parameters:
Return type:

AbstractAngle

See also

None

functional version of this method.

Examples

>>> import unxt as u
>>> angle = u.Angle(370, "deg")
>>> angle.wrap_to(min=u.Q(0, "deg"), max=u.Q(360, "deg"))
Angle(Array(10, dtype=int32...), unit='deg')
value: Union[Real[Array, '*shape'], Real[StaticValue, '*shape']]#

The value of the unxt.AbstractQuantity.

unit: UnitBase | FunctionUnitBase#

The unit associated with this value.

coordinax.angle.wrap_to(x: Any, min: Any, max: Any, /)#

Wrap to the range [min, max).

General signature: (x, min, max) -> wrapped_x. Other signatures are defined via method dispatch. See wrap_to.methods for details.

Examples

>>> import unxt as u
>>>
>>> angle = u.Angle(370, "deg")
>>> min, max = u.Q(0, "deg"), u.Q(360, "deg")
>>>
>>> u.quantity.wrap_to(angle, min, max)
Angle(Array(10, dtype=int32...), unit='deg')
>>>
>>> u.quantity.wrap_to(angle, min=min, max=max)
Angle(Array(10, dtype=int32...), unit='deg')
coordinax.angle.wrap_to(x: Any, /, *, min: Any, max: Any) → Any
Parameters:
Return type:

Any

Wrap to the range [min, max).

coordinax.angle.wrap_to(angle: AbstractQuantity, min: AbstractQuantity, max: AbstractQuantity, /) → AbstractQuantity
Parameters:
Return type:

Any

Wrap to the range [min, max).

Examples

>>> import unxt as u
>>> angle = u.Angle(370, "deg")
>>> u.quantity.wrap_to(angle, min=u.Q(0, "deg"), max=u.Q(360, "deg"))
Angle(Array(10, dtype=int32...), unit='deg')
Parameters:
Return type:

Any

final class coordinax.angle.Parallax(value: Any, unit: Any, *, check_negative: bool = True)

Bases: AbstractDistance

Parallax distance quantity.

Examples

>>> from coordinax.distance import Parallax
>>> Parallax(1, "mas")
Parallax(Array(1, dtype=int32, ...), unit='mas')

The units are checked to have angle dimensions.

>>> try: Parallax(1, "pc")
... except ValueError as e: print(e)
Parallax must have angular dimensions.

The parallax is checked to be non-negative by default.

>>> try: Parallax(-1, "mas")
... except Exception: print("negative")
negative

To disable this check, set check_negative=False.

>>> Parallax(-1, "mas", check_negative=False)
Parallax(Array(-1, dtype=int32, weak_type=True), unit='mas', check_negative=False)
Parameters:
property T: AbstractQuantity

Transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Q([[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.Q([1, 2, 3], "m")
>>> q.argmax()
Array(2, dtype=int32)
Parameters:
Return type:

Array

argmin(*args: Any, **kwargs: Any)

Return the indices of the minimum value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.argmin()
Array(0, dtype=int32)
Parameters:
Return type:

Array

astype(*args: Any, **kwargs: Any)

Copy the array and cast to a specified dtype.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.dtype
dtype('int32')
>>> q.astype(float)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property at: _QuantityIndexUpdateHelper

Helper property for index update functionality.

The at property 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] = y

x = x.at[idx].add(y)

x[idx] += y

x = x.at[idx].subtract(y)

x[idx] -= y

x = x.at[idx].multiply(y)

x[idx] *= y

x = x.at[idx].divide(y)

x[idx] /= y

x = x.at[idx].power(y)

x[idx] **= y

x = 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.at expressions modify the original x; instead they return a modified copy of x. However, inside a jit() compiled function, expressions like x = 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 mode parameter (see below).

Parameters:
  • mode –

    string specifying 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 in get() will be clipped, and out-of-bounds indices in set(), 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 optional fill_value argument specifies the value that will be returned.

    See jax.lax.GatherScatterMode for more details.

  • wrap_negative_indices – If True (default) then negative indices indicate position from the end of the array, similar to Python and NumPy indexing. If False, then negative indices are considered out-of-bounds and behave according to the mode parameter.

  • fill_value – Only applies to the get() method: the fill value to return for out-of-bounds slices when mode is 'fill'. Ignored otherwise. Defaults to NaN for inexact types, the largest negative value for signed types, the largest positive value for unsigned types, and True for booleans.

  • indices_are_sorted – If True, the implementation will assume that the (normalized) indices passed to at[] are sorted in ascending order, which can lead to more efficient execution on some backends. If True but the indices are not actually sorted, the output is undefined.

  • unique_indices – If True, the implementation will assume that the (normalized) indices passed to at[] are unique, which can result in more efficient execution on some backends. If True but the indices are not actually unique, the output is undefined.

Examples

>>> x = jnp.arange(5.0)
>>> x
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[2].get()
Array(2., dtype=float32)
>>> x.at[2].add(10)
Array([ 0.,  1., 12.,  3.,  4.], dtype=float32)

By default, out-of-bound indices are ignored in updates, but this behavior can be controlled with the mode parameter:

>>> x.at[10].add(10)  # dropped
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[20].add(10, mode='clip')  # clipped
Array([ 0.,  1.,  2.,  3., 14.], dtype=float32)

For get(), out-of-bound indices are clipped by default:

>>> 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)

Negative indices count from the end of the array, but this behavior can be disabled by setting wrap_negative_indices = False:

>>> x.at[-1].set(99)
Array([ 0.,  1.,  2.,  3., 99.], dtype=float32)
>>> x.at[-1].set(99, wrap_negative_indices=False, mode='drop')  # dropped!
Array([0., 1., 2., 3., 4.], dtype=float32)
block_until_ready()

Block until the array is ready.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.block_until_ready() is q
True
decompose(bases: Sequence[UnitBase | FunctionUnitBase | 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[UnitBase | FunctionUnitBase | str])

Return type:

AbstractQuantity

property device: Device

Device where the array is located.

Examples

>>> import unxt as u
>>> u.Q(1, "m").device
CpuDevice(id=0)
devices()

Return the devices where the array is located.

Return type:

set[Device]

Examples

>>> import unxt as u
>>> q = u.Q(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.Q(1, "m").dtype
dtype('int32')
flatten()

Return a flattened version of the array.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Q([[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:

AbstractQuantity

Construct a unxt.AbstractQuantity from an array-like value and a unit.

Parameters:
  • value – The array-like value.

  • unit – The unit of the value.

  • dtype – The data type of the array (keyword-only).

  • args (Any)

  • kwargs (Any)

Return type:

AbstractQuantity

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.Q.from_(x, "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Q.from_([1.0, 2, 3], "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Q.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:

AbstractQuantity

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.Q.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:

AbstractQuantity

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.Q.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:

AbstractQuantity

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.Q.from_({"value": x, "unit": "m"})
>>> q
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Q.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:

AbstractQuantity

Construct a quantity from another quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> u.Q.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:

AbstractQuantity

Construct a quantity from another quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> u.Q.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:

AbstractQuantity

Construct a quantity from another quantity.

The unit is unchanged.

from_(cls: type[StaticQuantity], 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) → StaticQuantity
Parameters:
Return type:

AbstractQuantity

Construct a StaticQuantity, keeping the value on NumPy dtypes.

The generic AbstractQuantity.from_ routes the value through jnp.asarray, which applies JAX’s x64-disabled dtype rules and silently downcasts int64 / float64 to int32 / float32. A StaticQuantity stores its value verbatim, so hand the value straight to __init__ and let the StaticValue.from_ converter convert it – that preserves the NumPy dtype. Delegating (rather than calling np.asarray here) also keeps .from_ and __init__ under the same policy for JAX inputs, instead of materialising an array the constructor would reject. (The keyword-unit overload delegates here, so it is covered too.)

Examples

>>> import numpy as np
>>> import unxt as u
>>> u.StaticQuantity.from_(
...     np.array([1, 2, 3], dtype=np.int64), "m"
... ).value.array.dtype
dtype('int64')

.from_ applies the same JAX-input policy as __init__ – it delegates rather than converting first, so the two cannot drift:

>>> import jax.numpy as jnp
>>> u.StaticQuantity.from_(jnp.array([1.0, 2.0]), "m")
StaticQuantity(array([1., 2.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], value: Quantity, /, **kwargs: Any) → AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a quantity from an astropy Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Q.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:

AbstractQuantity

Construct a quantity from an astropy Quantity, converting to a target unit.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Q.from_(apyu.Quantity(1, "m"), "cm")
Quantity(Array(100., dtype=float32), unit='cm')
from_(cls: type[Distance], obj: AbstractDistance | Quantity, /, **kw: Any) → Distance
Parameters:
Return type:

AbstractQuantity

Construct a Distance from the inputs.

from_(cls: type[DistanceModulus], dm: AbstractDistance | Quantity, /, **kwargs: Any) → DistanceModulus
Parameters:
Return type:

AbstractQuantity

Construct a DistanceModulus from the input.

from_(cls: type[Parallax], obj: AbstractDistance | Quantity, /, **kwargs: Any) → Parallax
Parameters:
Return type:

AbstractQuantity

Construct a Parallax the input.

Parameters:
Return type:

AbstractQuantity

is_equivalent(other: AbstractQuantity, /)

Whether self and other are physically equal (unit-aware).

The method form of unxt.equivalent; unlike == (which is unit-blind for StaticValue-backed quantities) this accounts for unit conversion.

Examples

>>> import unxt as u
>>> u.Q(1000.0, "m").is_equivalent(u.Q(1.0, "km"))
Quantity(Array(True, dtype=bool...), unit='')
Parameters:

other (AbstractQuantity)

Return type:

Any

property mT: AbstractQuantity

Matrix transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Q([[0, 1], [2, 3]], "m")
>>> q.mT
Quantity(Array([[0, 2],
                          [1, 3]], dtype=int32), unit='m')

It also works for a StaticQuantity:

>>> u.StaticQuantity([[0, 1], [2, 3]], "m").mT.value.tolist()
[[0, 2], [1, 3]]
max(*args: Any, **kwargs: Any)

Return the maximum value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.max()
Quantity(Array(3, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

mean(*args: Any, **kwargs: Any)

Return the mean value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.mean()
Quantity(Array(2., dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

min(*args: Any, **kwargs: Any)

Return the minimum value.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.min()
Quantity(Array(1, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

property ndim: int

Number of dimensions.

Examples

>>> import unxt as u
>>> q = u.Q([[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:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Q([[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.Q([1, 2, 3, 4], "m")
>>> q.reshape(2, 2)
Quantity(Array([[1, 2],
                          [3, 4]], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

round(*args: Any, **kwargs: Any)

Round the array to the given number of decimals.

Examples

>>> import unxt as u
>>> q = u.Q([1.1, 2.2, 3.3], "m")
>>> q.round(0)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property shape: tuple[int, ...]

Shape of the array.

property sharding: Any

Return the sharding configuration of the array.

Examples

>>> import unxt as u
>>> q = u.Q([1, 2, 3], "m")
>>> q.sharding
SingleDeviceSharding(device=..., memory_kind=...)
property size: int

Total number of elements.

Examples

>>> import unxt as u
>>> q = u.Q([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.Q([[[1], [2], [3]]], "m")
>>> q.squeeze()
Quantity(Array([1, 2, 3], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

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:

AbstractQuantity

to_device(device: None | Device = None)

Move the array to a new device.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.to_device(None)
Quantity(Array(1, dtype=int32...), unit='m')
Parameters:

device (None | Device)

Return type:

AbstractQuantity

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)
Parameters:

u (Any)

Return type:

Union[Array, ndarray, bool, number, bool, int, float, complex]

uconvert(u: Any, /)

Convert the quantity to the given units.

See also

None

convert a quantity to a new unit.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.uconvert("cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

u (Any)

Return type:

AbstractQuantity

ustrip(u: Any, /)

Return the value in the given units.

See also

None

strip the units from a quantity.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> q.ustrip("cm")
Array(100., dtype=float32, weak_type=True)
Parameters:

u (Any)

Return type:

Array

value: Shaped[Array, '*shape']

The value of the unxt.AbstractQuantity.

unit: UnitBase | FunctionUnitBase

The unit associated with this value.

check_negative: bool = True

Whether to check that the parallax is strictly non-negative.

Theoretically the parallax must be strictly non-negative (:math:` an(p) = 1 AU / d`), however noisy direct measurements of the parallax can be negative.