API Reference

Contents

API Reference#

Complete API documentation for coordinax.astro.

import coordinax.astro as cxastro — Frames for Astronomy.

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

Bases: AbstractDistance

Parallax distance quantity.

Examples

>>> from coordinax.astro import Parallax
>>> Parallax(1, "mas")
Parallax(1, '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(-1, 'mas', check_negative=False)
Parameters:
value: Shaped[Array, '*shape']#

The value of the unxt.AbstractQuantity.

unit: Unit | UnitBase | CompositeUnit#

The unit associated with this value.

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

Array

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)
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.Quantity([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)
aval()#

All concrete subclasses must implement this method, specifying the abstract value seen by JAX.

Arguments:

Nothing.

Returns:

Any subclass of jax.core.AbstractValue. Typically a jax.core.ShapedArray.

Return type:

ShapedArray

block_until_ready()#

Block until the array is ready.

Return type:

AbstractQuantity

Examples

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

AbstractQuantity

static default(primitive: Primitive, values: Sequence[Array | ndarray | bool | number | bool | int | float | complex | Value], params)#

This is the default rule for when no rule has been [quax.register][]’d for a primitive.

When performing multiple dispatch primitive.bind(value1, value2, value3), then:

  1. If there is a dispatch rule matching the types of value1, value2, and

    value3, then that will be used.

  2. If precisely one of the types of value{1,2,3} overloads this method, then

    that default rule will be used.

  3. If precisely zero of the types of value{1,2,3} overloads this method, then

    all values are [quax.Value.materialise][]d, and the usual JAX implementation is called.

  4. If multiple of the types of value{1,2,3} overload this method, then a

    trace-time error will be raised.

Arguments:

  • primitive: the jax.extend.core.Primitive being considered.

  • values: a sequence of what values this primitive is being called with. Each

    value can either be [quax.Value][]s, or a normal JAX arraylike (i.e. bool/int/float/complex/NumPy scalar/NumPy array/JAX array).

  • params: the keyword parameters to the primitive.

Returns:

The result of binding this primitive against these types. If primitive.multiple_results is False then this should be a single quax.Value or JAX arraylike. If primitive.multiple_results is True, then this should be a tuple/list of such values.

!!! Example

The default implementation discussed above performs the following: ```python @staticmethod def default(primitive, values, params):

arrays = [

x if equinox.is_array_like(x) else x.materialise() for x in values

] return primitive.bind(*arrays, **params)

``` (Using the [Equinox](patrick-kidger/equinox) library that underlies much of the JAX ecosystem.)

Parameters:
Return type:

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

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.

Return type:

set[Device]

Examples

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

The distance.

Examples

>>> import coordinax.distances as cxd
>>> d = cxd.Distance(10, "km")
>>> d.distance is d
True
>>> import coordinax.astro as cxastro
>>> cxastro.DistanceModulus(10, "mag").distance
Distance(1000., 'pc')
>>> p = cxastro.Parallax(1, "mas")
>>> p.distance.to("kpc")
Distance(1., 'kpc')
property dtype: dtype#

Data type of the array.

Examples

>>> import unxt as u
>>> u.Quantity(1, "m").dtype
dtype('int32')
enable_materialise(_: bool = True)#
Parameters:

_ (bool)

Return type:

Self

flatten()#

Return a flattened version of the array.

Return type:

AbstractQuantity

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:

AbstractQuantity

Construct a unxt.Quantity 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.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:

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

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

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

AbstractQuantity

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:

AbstractQuantity

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:

AbstractQuantity

Construct a Quantity from another Quantity, with no unit change.

from_(cls: type[AbstractQuantity], value: Quantity, /, **kwargs: Any) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

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:

AbstractQuantity

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], value: ArrayLike, unit: Any, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> cxd.Distance.from_(1, "kpc")
Distance(1, 'kpc')
from_(cls: type[Distance], d: Distance, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> d = cxd.Distance(1, "kpc")
>>> cxd.Distance.from_(d) is d
True
>>> cxd.Distance.from_(d, dtype=float)
Distance(1., 'kpc')
from_(cls: type[Distance], d: Quantity[PhysicalType('length')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(1, "kpc")
>>> cxd.Distance.from_(q, dtype=float)
Distance(1., 'kpc')
from_(cls: type[Distance], p: Quantity[PhysicalType('angle')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from parallax.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(1, "mas")
>>> cxd.Distance.from_(q).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[Distance], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance modulus.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(10, "mag")
>>> cxd.Distance.from_(q).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[DistanceModulus], value: ArrayLike, unit: Any, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> DistanceModulus.from_(1, "mag")
DistanceModulus(1, 'mag')
from_(cls: type[DistanceModulus], dm: DistanceModulus, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance modulus.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> dm = DistanceModulus(1, "mag")
>>> DistanceModulus.from_(dm) is dm
True
>>> DistanceModulus.from_(dm, dtype=float)
DistanceModulus(1., 'mag')
from_(cls: type[DistanceModulus], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "mag")
>>> DistanceModulus.from_(q)
DistanceModulus(1, 'mag')
from_(cls: type[DistanceModulus], d: Distance, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import DistanceModulus
>>> d = cxd.Distance(1, "pc")
>>> DistanceModulus.from_(d)
DistanceModulus(-5., 'mag')
from_(cls: type[DistanceModulus], d: Quantity[PhysicalType('length')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "pc")
>>> DistanceModulus.from_(q)
DistanceModulus(-5., 'mag')
from_(cls: type[DistanceModulus], p: Quantity[PhysicalType('angle')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "mas")
>>> DistanceModulus.from_(q)
DistanceModulus(10., 'mag')
from_(cls: type[Distance], dm: DistanceModulus, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance modulus.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import DistanceModulus
>>> dm = DistanceModulus(10, "mag")
>>> cxd.Distance.from_(dm).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[Parallax], value: ArrayLike, unit: Any, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> Parallax.from_(1, "mas")
Parallax(1, 'mas')
from_(cls: type[Parallax], p: Parallax, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> p = Parallax(1, "mas")
>>> Parallax.from_(p) is p
True
>>> Parallax.from_(p, dtype=float)
Parallax(1., 'mas')
from_(cls: type[Parallax], p: Quantity[PhysicalType('angle')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> q = u.Q(1, "mas")
>>> Parallax.from_(q, dtype=float)
Parallax(1., 'mas')
from_(cls: type[Parallax], d: Distance | Quantity[PhysicalType('length')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from distance.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> d = cxd.Distance(10, "pc")
>>> Parallax.from_(d).uconvert("mas").round(2)
Parallax(100., 'mas')
>>> q = u.Q(10, "pc")
>>> Parallax.from_(q).uconvert("mas").round(2)
Parallax(100., 'mas')
from_(cls: type[Parallax], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Convert distance modulus to parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> dm = u.Q(10, "mag")
>>> Parallax.from_(dm).uconvert("mas").round(2)
Parallax(1., 'mas')
from_(cls: type[Distance], p: Parallax, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from parallax.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import Parallax
>>> p = Parallax(1, "mas")
>>> cxd.Distance.from_(p).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[DistanceModulus], p: Parallax, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from parallax.

>>> from coordinax.astro import DistanceModulus, Parallax
>>> p = Parallax(1, "mas")
>>> DistanceModulus.from_(p)
DistanceModulus(10., 'mag')
from_(cls: type[Parallax], dm: DistanceModulus, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Convert distance modulus to parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus, Parallax
>>> dm = DistanceModulus(10, "mag")
>>> Parallax.from_(dm).uconvert("mas").round(2)
Parallax(1., 'mas')
Parameters:
Return type:

AbstractQuantity

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')
materialise()#

All concrete subclasses must implement this method, specifying how to materialise this object into a JAX type (i.e. almost always a JAX array, unless you’re doing something obscure using tokens or refs).

!!! Example

For example, a LoRA array consists of three arrays (W, A, B), combined as W + AB. [quax.examples.lora.LoraArray] leaves these as three separate arrays for efficiency, but calling lora_array.materialise() will evaluate W + AB and return a normal JAX array.

This is so that the usual JAX primitive implementations can be applied as a fallback: the array-ish object is materialised, and then the usual JAX implementation called on it. (See [quax.Value.default][].)

!!! Info

It is acceptable for this function to just raise an error – in this case the error will be surfaced to the end user, indicating that an operation is not supported for this array-ish object.

Arguments:

Nothing.

Returns:

A JAX type; typically a JAX array.

Return type:

NoReturn

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:

AbstractQuantity

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:

AbstractQuantity

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:

AbstractQuantity

property ndim: int#

Number of dimensions.

Examples

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

Return a flattened version of the array.

Return type:

AbstractQuantity

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:

AbstractQuantity

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:

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

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.Quantity(1, "m")
>>> q.to_device(None)
Quantity(Array(1, dtype=int32, weak_type=True), 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.Quantity(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.Quantity(1, "m")
>>> q.ustrip("cm")
Array(100., dtype=float32, weak_type=True)
Parameters:

u (Any)

Return type:

Array

check_negative: bool = True#

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

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

final class coordinax.astro.DistanceModulus(value: Any, unit: Any)#

Bases: AbstractDistance

Distance modulus quantity.

Examples

>>> from coordinax.astro import DistanceModulus
>>> DistanceModulus(10, "mag")
DistanceModulus(10, 'mag')

The units are checked to have magnitude dimensions.

>>> try: DistanceModulus(10, "pc")
... except ValueError as e: print(e)
Distance modulus must have units of magnitude.
Parameters:
value: Shaped[Array, '*shape']#

The value of the unxt.AbstractQuantity.

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

Array

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)
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.Quantity([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)
aval()#

All concrete subclasses must implement this method, specifying the abstract value seen by JAX.

Arguments:

Nothing.

Returns:

Any subclass of jax.core.AbstractValue. Typically a jax.core.ShapedArray.

Return type:

ShapedArray

block_until_ready()#

Block until the array is ready.

Return type:

AbstractQuantity

Examples

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

AbstractQuantity

static default(primitive: Primitive, values: Sequence[Array | ndarray | bool | number | bool | int | float | complex | Value], params)#

This is the default rule for when no rule has been [quax.register][]’d for a primitive.

When performing multiple dispatch primitive.bind(value1, value2, value3), then:

  1. If there is a dispatch rule matching the types of value1, value2, and

    value3, then that will be used.

  2. If precisely one of the types of value{1,2,3} overloads this method, then

    that default rule will be used.

  3. If precisely zero of the types of value{1,2,3} overloads this method, then

    all values are [quax.Value.materialise][]d, and the usual JAX implementation is called.

  4. If multiple of the types of value{1,2,3} overload this method, then a

    trace-time error will be raised.

Arguments:

  • primitive: the jax.extend.core.Primitive being considered.

  • values: a sequence of what values this primitive is being called with. Each

    value can either be [quax.Value][]s, or a normal JAX arraylike (i.e. bool/int/float/complex/NumPy scalar/NumPy array/JAX array).

  • params: the keyword parameters to the primitive.

Returns:

The result of binding this primitive against these types. If primitive.multiple_results is False then this should be a single quax.Value or JAX arraylike. If primitive.multiple_results is True, then this should be a tuple/list of such values.

!!! Example

The default implementation discussed above performs the following: ```python @staticmethod def default(primitive, values, params):

arrays = [

x if equinox.is_array_like(x) else x.materialise() for x in values

] return primitive.bind(*arrays, **params)

``` (Using the [Equinox](patrick-kidger/equinox) library that underlies much of the JAX ecosystem.)

Parameters:
Return type:

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

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.

Return type:

set[Device]

Examples

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

The distance.

Examples

>>> import coordinax.distances as cxd
>>> d = cxd.Distance(10, "km")
>>> d.distance is d
True
>>> import coordinax.astro as cxastro
>>> cxastro.DistanceModulus(10, "mag").distance
Distance(1000., 'pc')
>>> p = cxastro.Parallax(1, "mas")
>>> p.distance.to("kpc")
Distance(1., 'kpc')
property dtype: dtype#

Data type of the array.

Examples

>>> import unxt as u
>>> u.Quantity(1, "m").dtype
dtype('int32')
enable_materialise(_: bool = True)#
Parameters:

_ (bool)

Return type:

Self

flatten()#

Return a flattened version of the array.

Return type:

AbstractQuantity

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:

AbstractQuantity

Construct a unxt.Quantity 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.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:

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

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

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

AbstractQuantity

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:

AbstractQuantity

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:

AbstractQuantity

Construct a Quantity from another Quantity, with no unit change.

from_(cls: type[AbstractQuantity], value: Quantity, /, **kwargs: Any) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

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:

AbstractQuantity

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], value: ArrayLike, unit: Any, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> cxd.Distance.from_(1, "kpc")
Distance(1, 'kpc')
from_(cls: type[Distance], d: Distance, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> d = cxd.Distance(1, "kpc")
>>> cxd.Distance.from_(d) is d
True
>>> cxd.Distance.from_(d, dtype=float)
Distance(1., 'kpc')
from_(cls: type[Distance], d: Quantity[PhysicalType('length')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(1, "kpc")
>>> cxd.Distance.from_(q, dtype=float)
Distance(1., 'kpc')
from_(cls: type[Distance], p: Quantity[PhysicalType('angle')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from parallax.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(1, "mas")
>>> cxd.Distance.from_(q).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[Distance], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance modulus.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(10, "mag")
>>> cxd.Distance.from_(q).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[DistanceModulus], value: ArrayLike, unit: Any, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> DistanceModulus.from_(1, "mag")
DistanceModulus(1, 'mag')
from_(cls: type[DistanceModulus], dm: DistanceModulus, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance modulus.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> dm = DistanceModulus(1, "mag")
>>> DistanceModulus.from_(dm) is dm
True
>>> DistanceModulus.from_(dm, dtype=float)
DistanceModulus(1., 'mag')
from_(cls: type[DistanceModulus], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "mag")
>>> DistanceModulus.from_(q)
DistanceModulus(1, 'mag')
from_(cls: type[DistanceModulus], d: Distance, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import DistanceModulus
>>> d = cxd.Distance(1, "pc")
>>> DistanceModulus.from_(d)
DistanceModulus(-5., 'mag')
from_(cls: type[DistanceModulus], d: Quantity[PhysicalType('length')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "pc")
>>> DistanceModulus.from_(q)
DistanceModulus(-5., 'mag')
from_(cls: type[DistanceModulus], p: Quantity[PhysicalType('angle')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "mas")
>>> DistanceModulus.from_(q)
DistanceModulus(10., 'mag')
from_(cls: type[Distance], dm: DistanceModulus, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance modulus.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import DistanceModulus
>>> dm = DistanceModulus(10, "mag")
>>> cxd.Distance.from_(dm).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[Parallax], value: ArrayLike, unit: Any, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> Parallax.from_(1, "mas")
Parallax(1, 'mas')
from_(cls: type[Parallax], p: Parallax, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> p = Parallax(1, "mas")
>>> Parallax.from_(p) is p
True
>>> Parallax.from_(p, dtype=float)
Parallax(1., 'mas')
from_(cls: type[Parallax], p: Quantity[PhysicalType('angle')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> q = u.Q(1, "mas")
>>> Parallax.from_(q, dtype=float)
Parallax(1., 'mas')
from_(cls: type[Parallax], d: Distance | Quantity[PhysicalType('length')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from distance.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> d = cxd.Distance(10, "pc")
>>> Parallax.from_(d).uconvert("mas").round(2)
Parallax(100., 'mas')
>>> q = u.Q(10, "pc")
>>> Parallax.from_(q).uconvert("mas").round(2)
Parallax(100., 'mas')
from_(cls: type[Parallax], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Convert distance modulus to parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> dm = u.Q(10, "mag")
>>> Parallax.from_(dm).uconvert("mas").round(2)
Parallax(1., 'mas')
from_(cls: type[Distance], p: Parallax, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from parallax.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import Parallax
>>> p = Parallax(1, "mas")
>>> cxd.Distance.from_(p).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[DistanceModulus], p: Parallax, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from parallax.

>>> from coordinax.astro import DistanceModulus, Parallax
>>> p = Parallax(1, "mas")
>>> DistanceModulus.from_(p)
DistanceModulus(10., 'mag')
from_(cls: type[Parallax], dm: DistanceModulus, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Convert distance modulus to parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus, Parallax
>>> dm = DistanceModulus(10, "mag")
>>> Parallax.from_(dm).uconvert("mas").round(2)
Parallax(1., 'mas')
Parameters:
Return type:

AbstractQuantity

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')
materialise()#

All concrete subclasses must implement this method, specifying how to materialise this object into a JAX type (i.e. almost always a JAX array, unless you’re doing something obscure using tokens or refs).

!!! Example

For example, a LoRA array consists of three arrays (W, A, B), combined as W + AB. [quax.examples.lora.LoraArray] leaves these as three separate arrays for efficiency, but calling lora_array.materialise() will evaluate W + AB and return a normal JAX array.

This is so that the usual JAX primitive implementations can be applied as a fallback: the array-ish object is materialised, and then the usual JAX implementation called on it. (See [quax.Value.default][].)

!!! Info

It is acceptable for this function to just raise an error – in this case the error will be surfaced to the end user, indicating that an operation is not supported for this array-ish object.

Arguments:

Nothing.

Returns:

A JAX type; typically a JAX array.

Return type:

NoReturn

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:

AbstractQuantity

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:

AbstractQuantity

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:

AbstractQuantity

property ndim: int#

Number of dimensions.

Examples

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

Return a flattened version of the array.

Return type:

AbstractQuantity

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:

AbstractQuantity

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:

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

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.Quantity(1, "m")
>>> q.to_device(None)
Quantity(Array(1, dtype=int32, weak_type=True), 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.Quantity(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.Quantity(1, "m")
>>> q.ustrip("cm")
Array(100., dtype=float32, weak_type=True)
Parameters:

u (Any)

Return type:

Array

unit: Unit | UnitBase | CompositeUnit#

The unit associated with this value.

class coordinax.astro.AbstractSpaceFrame#

Bases: AbstractReferenceFrame

Abstract base class for astronomy-oriented spatial reference frames.

This class specializes {class}`coordinax.frames.AbstractReferenceFrame` for frames that act on spatial coordinates (for example, {class}`coordinax.astro.ICRS` and {class}`coordinax.astro.Galactocentric`). In the terminology of the coordinax specification, frame changes are interpreted as active transformations: operators act directly on points and move them on the same manifold.

Conceptually, a frame transition corresponds to a smooth map $F : M to M$ on the same spatial manifold, with chart-level formulas supplied by registered frame_transition dispatches.

Notes

  • AbstractSpaceFrame is a typing and dispatch category; concrete frames

    should subclass it and define the parameters that characterize that frame.

  • Transform operators are produced via

    {func}`coordinax.frames.frame_transition`.

  • The generic astronomy-space fallback composes transformations through

    ICRS, so custom spatial frames should typically register at least one transformation path to or from ICRS.

  • This class is for 3D spatial frame semantics; spacetime coordinate models

    (for example, where ct is part of the point itself) are represented separately from this spatial frame category.

Examples

>>> import plum
>>> import coordinax.frames as cxf
>>> import coordinax.transforms as cxfm
>>> import coordinax.astro as cxastro
>>> class MySpaceFrame(cxastro.AbstractSpaceFrame):
...     pass
>>> @plum.dispatch
... def frame_transition(
...     from_frame: MySpaceFrame, to_frame: cxastro.ICRS, /
... ) -> cxfm.Identity:
...     return cxfm.identity
>>> op = cxf.frame_transition(MySpaceFrame(), cxastro.ICRS())
>>> op
Identity()
frame_transition(to_frame: AbstractReferenceFrame, /)#

Backward-compatible alias for {meth}`transform_to`.

Parameters:

to_frame (AbstractReferenceFrame)

Return type:

AbstractTransform

classmethod from_(cls: type[AbstractReferenceFrame], obj: Any, /)#

Construct a reference frame.

from_(cls: type[AbstractReferenceFrame], obj: Mapping[str, Any], /) AbstractReferenceFrame
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct a reference frame from a mapping.

>>> import coordinax.frames as cxf
>>> alice = cxf.Alice.from_({})
>>> alice
Alice()
>>> alex = cxf.Alex.from_({})
>>> print(alex)
Alex()
from_(cls: type[AbstractReferenceFrame], obj: AbstractReferenceFrame, /) AbstractReferenceFrame
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct a reference frame from another reference frame.

Raises:

TypeError – If the input object is not a subclass of the target class.

Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Examples

>>> import coordinax.frames as cxf
>>> cxf.AbstractReferenceFrame.from_(cxf.alice) is cxf.alice
True
>>> import coordinax.astro as cxastro
>>> try:
...     cxastro.Galactocentric.from_(cxf.alice)
... except TypeError as e:
...     print(e)
Cannot construct 'Galactocentric' from Alice()
from_(cls: type[ICRS], obj: ICRS, /) ICRS
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct from a astropy.coordinates.ICRS.

>>> import coordinax.astro as cxastro
>>> from plum import convert
>>> import astropy.coordinates as apyc
>>> apy_frame = apyc.ICRS()
>>> cx_frame = convert(apy_frame, cxastro.ICRS)
>>> isinstance(cx_frame, cxastro.ICRS)
True
>>> cxastro.ICRS.from_(apy_frame)
ICRS()
from_(cls: type[Galactocentric], frame: Galactocentric, /) Galactocentric
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct from a astropy.coordinates.Galactocentric.

>>> import astropy.coordinates as apyc
>>> import coordinax.frames as cxf
>>> apy_gcf = apyc.Galactocentric()
>>> apy_gcf
<Galactocentric Frame (galcen_coord=<ICRS Coordinate: (ra, dec) in deg
(266.4051, -28.936175)>, galcen_distance=8.122 kpc, galcen_v_sun=(12.9, 245.6, 7.78) km / s, z_sun=20.8 pc, roll=0.0 deg)>
>>> gcf = cxf.Galactocentric.from_(apy_gcf)
>>> gcf
Galactocentric(
  galcen=Point(
    { 'lon': Q(f64[], 'deg'), 'lat': Q(f64[], 'deg'), 'distance': Q(f64[], 'kpc') },
    chart=LonLatSpherical3D(M=Rn(3)), frame=ICRS()
  ),
  roll=Angle(f64[], 'deg'),
  z_sun=Quantity(f64[], 'pc')
)

Checking equality

>>> (gcf.galcen["lon"].ustrip("deg") == apy_gcf.galcen_coord.ra.to_value("deg")
...  and gcf.galcen["lat"].ustrip("deg") == apy_gcf.galcen_coord.dec.to_value("deg")
...  and gcf.galcen["distance"].ustrip("kpc") == apy_gcf.galcen_distance.to_value("kpc") )
Array(True, dtype=bool)
Parameters:
Return type:

AbstractReferenceFrame

transform_to(to_frame: AbstractReferenceFrame, /)#

Make a frame transform operator.

Parameters:

to_frame (AbstractReferenceFrame) – The reference frame to transform to.

Returns:

The operator that transforms coordinates from this frame to to_frame.

Return type:

AbstractTransform

Examples

>>> import coordinax.frames as cxf
>>> op = cxf.alice.transform_to(cxf.alex)
>>> op
Composed(( ... ))
>>> op = cxf.alex.transform_to(cxf.alice)
>>> op
Composed(( ... ))
final class coordinax.astro.ICRS#

Bases: AbstractSpaceFrame

The International Celestial Reference System (ICRS).

Examples

>>> import coordinax.astro as cxastro
>>> frame = cxastro.ICRS()
>>> frame
ICRS()
frame_transition(to_frame: AbstractReferenceFrame, /)#

Backward-compatible alias for {meth}`transform_to`.

Parameters:

to_frame (AbstractReferenceFrame)

Return type:

AbstractTransform

classmethod from_(cls: type[AbstractReferenceFrame], obj: Any, /)#

Construct a reference frame.

from_(cls: type[AbstractReferenceFrame], obj: Mapping[str, Any], /) AbstractReferenceFrame
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct a reference frame from a mapping.

>>> import coordinax.frames as cxf
>>> alice = cxf.Alice.from_({})
>>> alice
Alice()
>>> alex = cxf.Alex.from_({})
>>> print(alex)
Alex()
from_(cls: type[AbstractReferenceFrame], obj: AbstractReferenceFrame, /) AbstractReferenceFrame
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct a reference frame from another reference frame.

Raises:

TypeError – If the input object is not a subclass of the target class.

Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Examples

>>> import coordinax.frames as cxf
>>> cxf.AbstractReferenceFrame.from_(cxf.alice) is cxf.alice
True
>>> import coordinax.astro as cxastro
>>> try:
...     cxastro.Galactocentric.from_(cxf.alice)
... except TypeError as e:
...     print(e)
Cannot construct 'Galactocentric' from Alice()
from_(cls: type[ICRS], obj: ICRS, /) ICRS
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct from a astropy.coordinates.ICRS.

>>> import coordinax.astro as cxastro
>>> from plum import convert
>>> import astropy.coordinates as apyc
>>> apy_frame = apyc.ICRS()
>>> cx_frame = convert(apy_frame, cxastro.ICRS)
>>> isinstance(cx_frame, cxastro.ICRS)
True
>>> cxastro.ICRS.from_(apy_frame)
ICRS()
from_(cls: type[Galactocentric], frame: Galactocentric, /) Galactocentric
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct from a astropy.coordinates.Galactocentric.

>>> import astropy.coordinates as apyc
>>> import coordinax.frames as cxf
>>> apy_gcf = apyc.Galactocentric()
>>> apy_gcf
<Galactocentric Frame (galcen_coord=<ICRS Coordinate: (ra, dec) in deg
(266.4051, -28.936175)>, galcen_distance=8.122 kpc, galcen_v_sun=(12.9, 245.6, 7.78) km / s, z_sun=20.8 pc, roll=0.0 deg)>
>>> gcf = cxf.Galactocentric.from_(apy_gcf)
>>> gcf
Galactocentric(
  galcen=Point(
    { 'lon': Q(f64[], 'deg'), 'lat': Q(f64[], 'deg'), 'distance': Q(f64[], 'kpc') },
    chart=LonLatSpherical3D(M=Rn(3)), frame=ICRS()
  ),
  roll=Angle(f64[], 'deg'),
  z_sun=Quantity(f64[], 'pc')
)

Checking equality

>>> (gcf.galcen["lon"].ustrip("deg") == apy_gcf.galcen_coord.ra.to_value("deg")
...  and gcf.galcen["lat"].ustrip("deg") == apy_gcf.galcen_coord.dec.to_value("deg")
...  and gcf.galcen["distance"].ustrip("kpc") == apy_gcf.galcen_distance.to_value("kpc") )
Array(True, dtype=bool)
Parameters:
Return type:

AbstractReferenceFrame

transform_to(to_frame: AbstractReferenceFrame, /)#

Make a frame transform operator.

Parameters:

to_frame (AbstractReferenceFrame) – The reference frame to transform to.

Returns:

The operator that transforms coordinates from this frame to to_frame.

Return type:

AbstractTransform

Examples

>>> import coordinax.frames as cxf
>>> op = cxf.alice.transform_to(cxf.alex)
>>> op
Composed(( ... ))
>>> op = cxf.alex.transform_to(cxf.alice)
>>> op
Composed(( ... ))
final class coordinax.astro.Galactocentric(galcen: Any = Point({'lon': Angle(266.4051, 'deg'), 'lat': Angle(-28.936174, 'deg'), 'distance': Distance(8.122, 'kpc')}, chart=LonLatSpherical3D(M=Rn(3))), roll: ArgT | PassThroughTs = Angle(0, 'deg'), z_sun: ArgT | PassThroughTs = Q(20.8, 'pc'))#

Bases: AbstractSpaceFrame

Reference frame centered at the Galactic center.

Based on the Astropy implementation of the Galactocentric frame.

Examples

>>> import coordinax.astro as cxastro
>>> frame = cxastro.Galactocentric()
>>> frame
Galactocentric()
Parameters:
galcen: Point[LonLatSpherical3D, Any] = Point(   {     'lon': Angle(266.4051, 'deg'),     'lat': Angle(-28.936174, 'deg'),     'distance': Distance(8.122, 'kpc')   },   chart=LonLatSpherical3D(M=Rn(3)) )#

RA, Dec, and distance of the Galactic center from an ICRS origin. ra, dec: https://ui.adsabs.harvard.edu/abs/2004ApJ…616..872R distance: https://ui.adsabs.harvard.edu/abs/2018A%26A…615L..15G

roll: Shaped[Quantity[PhysicalType('angle')], ''] | Shaped[Angle, ''] = Angle(0, 'deg')#

Rotation angle of the Galactic center from the ICRS x-axis.

z_sun: Quantity[PhysicalType('length')] = Q(20.8, 'pc')#

Distance from the Sun to the Galactic midplane. https://ui.adsabs.harvard.edu/abs/2019MNRAS.482.1417B

roll0: ClassVar[Shaped[Quantity[PhysicalType('angle')], ''] | Shaped[Angle, '']] = Angle(58.598633, 'deg')#

The angle between the Galactic center and the ICRS x-axis.

frame_transition(to_frame: AbstractReferenceFrame, /)#

Backward-compatible alias for {meth}`transform_to`.

Parameters:

to_frame (AbstractReferenceFrame)

Return type:

AbstractTransform

classmethod from_(cls: type[AbstractReferenceFrame], obj: Any, /)#

Construct a reference frame.

from_(cls: type[AbstractReferenceFrame], obj: Mapping[str, Any], /) AbstractReferenceFrame
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct a reference frame from a mapping.

>>> import coordinax.frames as cxf
>>> alice = cxf.Alice.from_({})
>>> alice
Alice()
>>> alex = cxf.Alex.from_({})
>>> print(alex)
Alex()
from_(cls: type[AbstractReferenceFrame], obj: AbstractReferenceFrame, /) AbstractReferenceFrame
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct a reference frame from another reference frame.

Raises:

TypeError – If the input object is not a subclass of the target class.

Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Examples

>>> import coordinax.frames as cxf
>>> cxf.AbstractReferenceFrame.from_(cxf.alice) is cxf.alice
True
>>> import coordinax.astro as cxastro
>>> try:
...     cxastro.Galactocentric.from_(cxf.alice)
... except TypeError as e:
...     print(e)
Cannot construct 'Galactocentric' from Alice()
from_(cls: type[ICRS], obj: ICRS, /) ICRS
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct from a astropy.coordinates.ICRS.

>>> import coordinax.astro as cxastro
>>> from plum import convert
>>> import astropy.coordinates as apyc
>>> apy_frame = apyc.ICRS()
>>> cx_frame = convert(apy_frame, cxastro.ICRS)
>>> isinstance(cx_frame, cxastro.ICRS)
True
>>> cxastro.ICRS.from_(apy_frame)
ICRS()
from_(cls: type[Galactocentric], frame: Galactocentric, /) Galactocentric
Parameters:

obj (Any)

Return type:

AbstractReferenceFrame

Construct from a astropy.coordinates.Galactocentric.

>>> import astropy.coordinates as apyc
>>> import coordinax.frames as cxf
>>> apy_gcf = apyc.Galactocentric()
>>> apy_gcf
<Galactocentric Frame (galcen_coord=<ICRS Coordinate: (ra, dec) in deg
(266.4051, -28.936175)>, galcen_distance=8.122 kpc, galcen_v_sun=(12.9, 245.6, 7.78) km / s, z_sun=20.8 pc, roll=0.0 deg)>
>>> gcf = cxf.Galactocentric.from_(apy_gcf)
>>> gcf
Galactocentric(
  galcen=Point(
    { 'lon': Q(f64[], 'deg'), 'lat': Q(f64[], 'deg'), 'distance': Q(f64[], 'kpc') },
    chart=LonLatSpherical3D(M=Rn(3)), frame=ICRS()
  ),
  roll=Angle(f64[], 'deg'),
  z_sun=Quantity(f64[], 'pc')
)

Checking equality

>>> (gcf.galcen["lon"].ustrip("deg") == apy_gcf.galcen_coord.ra.to_value("deg")
...  and gcf.galcen["lat"].ustrip("deg") == apy_gcf.galcen_coord.dec.to_value("deg")
...  and gcf.galcen["distance"].ustrip("kpc") == apy_gcf.galcen_distance.to_value("kpc") )
Array(True, dtype=bool)
Parameters:
Return type:

AbstractReferenceFrame

transform_to(to_frame: AbstractReferenceFrame, /)#

Make a frame transform operator.

Parameters:

to_frame (AbstractReferenceFrame) – The reference frame to transform to.

Returns:

The operator that transforms coordinates from this frame to to_frame.

Return type:

AbstractTransform

Examples

>>> import coordinax.frames as cxf
>>> op = cxf.alice.transform_to(cxf.alex)
>>> op
Composed(( ... ))
>>> op = cxf.alex.transform_to(cxf.alice)
>>> op
Composed(( ... ))