Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ from astropy_xarray.coordinates.sky_coord import (
)

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"]),
}
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
```
Expand Down
125 changes: 2 additions & 123 deletions docs/examples/plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"metadata": {},
"source": [
"<div class=\"alert alert-info\">\n",
"<strong>Note:</strong> this example uses the data provided by the <code>xarray.tutorial</code> functions. As such, the <code>units</code> attributes follow the CF conventions, which <code>astropy</code> does not understand by default. To still be able to read them we are using the registry provided by <a href=\"https://github.com/xarray-contrib/cf-xarray\"><tt>cf-xarray</tt></a>.\n",
"<strong>Note:</strong> this example uses the data provided by the <code>xarray.tutorial</code> functions. As such, the <code>units</code> attributes follow the CF conventions, which <code>astropy</code> does not understand by default. To still be able to read them, registry be aliases can be used. For more information, see <a href=\"https://github.com/xarray-contrib/cf-xarray\"><tt>cf-xarray</tt></a>.\n",
"</div>"
]
},
Expand Down Expand Up @@ -107,7 +107,7 @@
"id": "9",
"metadata": {},
"source": [
"Most operations will preserve the units but there are some which will drop them (see the [duck array integration status](https://xarray.pydata.org/en/stable/user-guide/duckarrays.html#missing-features) page). To work around that there are unit-aware versions on the `.pint` accessor. For example, to select data use `.astropy.sel` instead of `.sel`:"
"Most operations will preserve the units but there are some which will drop them (see the [duck array integration status](https://xarray.pydata.org/en/stable/user-guide/duckarrays.html#missing-features) page). To work around that there are unit-aware versions on the `.astropy` accessor. For example, to select data use `.astropy.sel` instead of `.sel`:"
]
},
{
Expand Down Expand Up @@ -142,127 +142,6 @@
"source": [
"monthly_means.astropy.dequantify(format=\"unicode\").plot.imshow(col=\"month\", col_wrap=4)"
]
},
{
"cell_type": "markdown",
"id": "13",
"metadata": {},
"source": [
"## Time\n",
"\n",
"astropy-xarray patches Time and DeltaTime to be recognized xarray, capturing:\n",
"* format\n",
"* timescale\n",
"* precision"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "14",
"metadata": {},
"outputs": [],
"source": [
"from astropy.time import Time, TimeDelta\n",
"\n",
"ds = xr.Dataset(\n",
" data_vars={\n",
" \"f_time\": (\"time_idx\", Time([0, 1, 2], format=\"unix\", scale=\"utc\")),\n",
" \"i_time\": (\n",
" \"time_idx\",\n",
" Time([0, 1, 2], format=\"unix\", scale=\"utc\").copy(\"datetime64\"),\n",
" ),\n",
" \"s_time\": (\n",
" \"time_idx\",\n",
" Time([0, 1, 2], format=\"unix\", scale=\"utc\").copy(\"isot\"),\n",
" ),\n",
" \"interval\": (\"time_idx\", TimeDelta([0.9, 0.9, 0.9], format=\"sec\", scale=\"tai\")),\n",
" \"temp\": (\"time_idx\", u.Quantity([0, 1, 2], \"K\")),\n",
" },\n",
" coords=xr.Coordinates(\n",
" {\n",
" \"time_idx\": [0, 1, 2],\n",
" }\n",
" ),\n",
")\n",
"ds"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "15",
"metadata": {},
"outputs": [],
"source": [
"ds = ds.astropy.dequantify()\n",
"ds.i_time"
]
},
{
"cell_type": "markdown",
"id": "16",
"metadata": {},
"source": [
"## SkyCoord, Frame and Angle\n",
"\n",
"SkyCoord and Frame fully support conversion to datasets preserving:\n",
"* Representation\n",
"* Differential\n",
"* Frame\n",
"* Angle, Longitude, Latitude containers\n",
"\n",
"Conversion optionally requires coords argument for applying named coordinates to data variable axes.\n",
"\n",
"Frame-specific mapped names for data variables coming soon."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "17",
"metadata": {},
"outputs": [],
"source": [
"from astropy.coordinates import SkyCoord\n",
"\n",
"from astropy_xarray.coordinates.sky_coord import (\n",
" dataset_to_skycoord,\n",
" skycoord_to_dataset,\n",
")\n",
"\n",
"sc = SkyCoord(\n",
" ra=[2, 6, 7, 4] * u.deg,\n",
" dec=[4, 7, 4, 3] * u.deg,\n",
" pm_ra_cosdec=[1, 1, 1, 1] * u.mas / u.yr,\n",
" pm_dec=[1, 1, 1, 1] * u.mas / u.yr,\n",
" frame=\"icrs\",\n",
")\n",
"\n",
"\n",
"s = skycoord_to_dataset(sc, coords=[(\"field\", [0, 1, 2, 3])])\n",
"\n",
"display(s)\n",
"s.astropy.dequantify()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18",
"metadata": {},
"outputs": [],
"source": [
"display(dataset_to_skycoord(s))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
30 changes: 0 additions & 30 deletions docs/examples/skycoord.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -304,36 +304,6 @@
"print(\"Dataset:\", ds.ra.data[1].value)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import astropy.units as u\n",
"from astropy.coordinates import SkyCoord\n",
"from astropy.time import Time\n",
"\n",
"from astropy_xarray.coordinates.sky_coord import (\n",
" skycoord_to_dataset,\n",
")\n",
"\n",
"sc = skycoord_to_dataset(\n",
" SkyCoord(\n",
" ra=[[2, 6, 7, 4]] * u.deg,\n",
" dec=[[4, 7, 4, 3]] * u.deg,\n",
" pm_ra_cosdec=[[1, 1, 1, 1]] * u.mas / u.yr,\n",
" pm_dec=[[1, 1, 1, 1]] * u.mas / u.yr,\n",
" frame=\"icrs\",\n",
" ),\n",
" coords={\n",
" \"timestamp\": (\"time\", Time([1.7e9], format=\"unix\")),\n",
" \"field_label\": (\"field\", [\"a\", \"b\", \"c\", \"d\"]),\n",
" },\n",
")\n",
"sc"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Loading
Loading