Skip to main content

Coordinates in JAX

Project description

coordinax

Coordinates in JAX

PyPI: coordinax PyPI versions: coordinax ReadTheDocs coordinax license

CI status ReadTheDocs codecov ruff ruff pre-commit


Coordinax enables calculations with coordinates in JAX. Built on Equinox and Quax.

Installation

PyPI platforms PyPI version

pip install coordinax

Documentation

Read The Docs

Quick example

import jax.numpy as jnp
import unxt as u
import coordinax as cx

q = cx.CartesianPos3D(
    x=u.Quantity(jnp.arange(0, 10.0), "kpc"),
    y=u.Quantity(jnp.arange(5, 15.0), "kpc"),
    z=u.Quantity(jnp.arange(10, 20.0), "kpc"),
)
print(q)
# <CartesianPos3D: (x, y, z) [kpc]
#     [[ 0.  5. 10.]
#      [ 1.  6. 11.]
#      ...
#      [ 8. 13. 18.]
#      [ 9. 14. 19.]]>

q2 = cx.vconvert(cx.SphericalPos, q)
print(q2)
# <SphericalPos: (r[kpc], theta[rad], phi[rad])
#     [[11.18   0.464  1.571]
#      [12.57   0.505  1.406]
#      ...
#      [23.601  0.703  1.019]
#      [25.259  0.719  0.999]]>

p = cx.CartesianVel3D(
    x=u.Quantity(jnp.arange(0, 10.0), "km/s"),
    y=u.Quantity(jnp.arange(5, 15.0), "km/s"),
    z=u.Quantity(jnp.arange(10, 20.0), "km/s"),
)
print(p)
# <CartesianVel3D: (x, y, z) [km / s]
#     [[ 0.  5. 10.]
#      [ 1.  6. 11.]
#      ...
#      [ 8. 13. 18.]
#      [ 9. 14. 19.]]>

p2 = cx.vconvert(cx.SphericalVel, p, q)
print(p2)
# <SphericalVel: (r[km / s], theta[km rad / (km s)], phi[km rad / (km s)])
#     [[ 1.118e+01 -3.886e-16  0.000e+00]
#      [ 1.257e+01 -1.110e-16  0.000e+00]
#      ...
#      [ 2.360e+01  0.000e+00  0.000e+00]
#      [ 2.526e+01 -2.776e-16  0.000e+00]]>


# Transforming between frames
icrs_frame = cx.frames.ICRS()
gc_frame = cx.frames.Galactocentric()
op = cxf.frame_transform_op(icrs_frame, gc_frame)
q_gc, p_gc = op(q, p)
print(q_gc, p_gc, sep="\n")
# <CartesianPos3D: (x, y, z) [kpc]
#     [[-1.732e+01  5.246e+00  3.614e+00]
#      ...
#      [-3.004e+01  1.241e+01 -1.841e+00]]>
# <CartesianVel3D: (x, y, z) [km / s]
#      [[  3.704 250.846  11.373]
#       ...
#       [ -9.02  258.012   5.918]]>

coord = cx.Coordinate({"length": q, "speed": p}, frame=icrs_frame)
print(coord)
# Coordinate(
#     KinematicSpace({
#        'length': <CartesianPos3D: (x, y, z) [kpc]
#             [[ 0.  5. 10.]
#              ...
#              [ 9. 14. 19.]]>,
#        'speed': <CartesianVel3D: (x, y, z) [km / s]
#             [[ 0.  5. 10.]
#              ...
#              [ 9. 14. 19.]]>
#     }),
#     frame=ICRS()
# )

print(coord.to_frame(gc_frame))
# Coordinate(
#     KinematicSpace({
#        'length': <CartesianPos3D: (x, y, z) [kpc]
#             [[-1.732e+01  5.246e+00  3.614e+00]
#              ...
#              [-3.004e+01  1.241e+01 -1.841e+00]]>,
#        'speed': <CartesianVel3D: (x, y, z) [km / s]
#             [[  3.704 250.846  11.373]
#              ...
#              [ -9.02  258.012   5.918]]>
#     }),
#     frame=Galactocentric( ... )
# )

Citation

DOI

If you found this library to be useful in academic work, then please cite.

Development

Actions Status Documentation Status codecov SPEC 0 — Minimum Supported Dependencies pre-commit ruff

We welcome contributions!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coordinax-0.23.2.tar.gz (742.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coordinax-0.23.2-py3-none-any.whl (194.7 kB view details)

Uploaded Python 3

File details

Details for the file coordinax-0.23.2.tar.gz.

File metadata

  • Download URL: coordinax-0.23.2.tar.gz
  • Upload date:
  • Size: 742.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for coordinax-0.23.2.tar.gz
Algorithm Hash digest
SHA256 8e44e9e148275a2bbd3da8470b37d0c4c441a02452d6b830c1cf3e173a39034e
MD5 cd8ff8d84d73cf879ad3823f2aa26752
BLAKE2b-256 d3534cf963f6d87b26fea3d4e1b1c8308fc28fc6e3466d4e68cfcd6d4516abd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for coordinax-0.23.2.tar.gz:

Publisher: cd.yml on GalacticDynamics/coordinax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file coordinax-0.23.2-py3-none-any.whl.

File metadata

  • Download URL: coordinax-0.23.2-py3-none-any.whl
  • Upload date:
  • Size: 194.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for coordinax-0.23.2-py3-none-any.whl
Algorithm Hash digest
SHA256 402a0330f6f77b763b4729c8adef76e86cba2c154690e315afbdea62d9e9b126
MD5 44679a6f2c62f011384f7904db58a3f4
BLAKE2b-256 0a770c41522a7a9e18571e9532602ac2cb8524bca2b6e47d5b54ac8c449035f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for coordinax-0.23.2-py3-none-any.whl:

Publisher: cd.yml on GalacticDynamics/coordinax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page