Skip to main content

astropy-xarray

CI code coverage docs PyPI version codestyle conda-forge

Seamless interoperability between astropy and xarray.

Simple Usage

import astropy_xarray
import xarray as xr

ds = xr.Dataset({"a": ("x", [0, 1, 2]), "b": ("y", [-3, 5, 1], {"units": "m"})})
ds

output:

<xarray.Dataset> Size: 48B
Dimensions:  (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
    a        (x) int64 24B 0 1 2
    b        (y) int64 24B -3 5 1

To convert the variables of a Dataset to quantities, use accessor .astropy.quantify():

q = ds.astropy.quantify(a="s")
q

output:

<xarray.Dataset> Size: 48B
Dimensions:  (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
    a        (x) float64 24B [s] 0.0 1.0 2.0
    b        (y) float64 24B [m] -3.0 5.0 1.0

to convert to different units, use accessor .astropy.to():

c = q.astropy.to({"a": "ms", "b": "km"})
c

output:

<xarray.Dataset> Size: 48B
Dimensions:  (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
    a        (x) float64 24B [ms] 0.0 1e+03 2e+03
    b        (y) float64 24B [km] -0.003 0.005 0.001

to convert back to non-quantities for portability, use accessor .astropy.dequantify():

d = c.astropy.dequantify()
d

output:

<xarray.Dataset> Size: 48B
Dimensions:  (x: 3, y: 3)
Dimensions without coordinates: x, y
Data variables:
    a        (x) float64 24B 0.0 1e+03 2e+03
    b        (y) float64 24B -0.003 0.005 0.001

SkyCoord Usage

To convert a astropy.skyCoord to a Dataset, use skycoord_to_dataset().

import astropy.units as u
from astropy.coordinates import ICRS, SkyCoord
from astropy.time import Time

from astropy_xarray.coordinates.sky_coord import (
    skycoord_to_dataset,
)

sc = skycoord_to_dataset(
    SkyCoord(
        ra=[[2, 6, 7, 4]] * u.deg,
        dec=[[4, 7, 4, 3]] * u.deg,
        pm_ra_cosdec=[[1, 1, 1, 1]] * u.mas / u.yr,
        pm_dec=[[1, 1, 1, 1]] * u.mas / u.yr,
        frame="icrs",
    ),
    coords={
        "timestamp": ("time", Time([1.7e9], format="unix")),
        "field_label": ("field", ["a", "b", "c", "d"]),
    },
)
sc

output:

<xarray.Dataset> Size: 152B
Dimensions:       (time: 1, field: 4)
Coordinates:
    timestamp     (time) float64 8B [utc unix] 2023-11-14T22:13:20.000000000
    field_label   (field) <U1 16B 'a' 'b' 'c' 'd'
Dimensions without coordinates: time, field
Data variables:
    ra            (time, field) float64 32B [°] 2.0 6.0 7.0 4.0
    dec           (time, field) float64 32B [°] 4.0 7.0 4.0 3.0
    pm_ra_cosdec  (time, field) float64 32B [mas yr⁻¹] 1.0 1.0 1.0 1.0
    pm_dec        (time, field) float64 32B [mas yr⁻¹] 1.0 1.0 1.0 1.0
Attributes:
    frame:    {'name': 'icrs', 'representation_type': 'spherical', 'different...

To convert SkyCoord-like datasets back to astropy types, use .astropy.to_skycoord():

sc.astropy.to_skycoord()

output:

<SkyCoord (ICRS): (ra, dec) in deg
    [[(2., 4.), (6., 7.), (7., 4.), (4., 3.)]]
 (pm_ra_cosdec, pm_dec) in mas / yr
    [[(1., 1.), (1., 1.), (1., 1.), (1., 1.)]]>

For more, see the documentation

Metadata

Release files for astropy-xarray 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for astropy-xarray 0.2.1
File Size Uploaded Provenance
astropy_xarray-0.2.1.tar.gz 302.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for astropy-xarray 0.2.1
File Interpreter ABI Platform
astropy_xarray-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 359.6 kB

Release files / astropy_xarray-0.2.1.tar.gz

Download URL astropy_xarray-0.2.1.tar.gz
Size 302.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0ac8f63d9b25d0c8798d91068c045bfb31201b7cacb4e3357248139a86c6aab5
BLAKE2b-256 checksum
How to use checksums
8f4efdd98e2c5fdd798980caad8376a8fa3f8f72d0d53c5c73ba65972a01f82c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 18, 2026.

Transparency log

Release files / astropy_xarray-0.2.1-py3-none-any.whl

Download URL astropy_xarray-0.2.1-py3-none-any.whl
Size 57.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c80db050e86d59d0b6a3247f24955ea57e4f91e723c319f56a8e6bc0b9267d83
BLAKE2b-256 checksum
How to use checksums
def1f1668daf62696cfec095db59cc018daaffd8c2dab16ef379872e6401b23a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 18, 2026.

Transparency log

Security for astropy-xarray 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for astropy_xarray-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page