# Grid.to\_xarray() issue with lat/lon

**URL:** <https://openradar.discourse.group/t/grid-to-xarray-issue-with-lat-lon/377>\
**Category:** General\
**Tags:** py-art\
**Created:** [January 3, 2024, 7:38pm UTC](https://openradar.discourse.group/t/grid-to-xarray-issue-with-lat-lon/377 "2024-01-03T19:38:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wxwolff1](https://avatars.discourse-cdn.com/v4/letter/w/85f322/32.png) [@wxwolff1](https://openradar.discourse.group/u/wxwolff1)\
**Post date:** [January 3, 2024, 7:38pm UTC](https://openradar.discourse.group/t/grid-to-xarray-issue-with-lat-lon/377/1 "2024-01-03T19:38:50Z")

</div>

Hello,

Latest versions of pyart (e.g. 1.16) now sets 2d lat and lon as coordinates, but 1d x, y coordinates. This makes using ds.swap\_dims({“x”: “lon”, “y”: 'lat"}) fail and has broken a lot of code that uses Xarray downstream of pyart. Is there a way to specify a return of 1d lat/lon as Xarray coordinates?

**Pyart Version 1.12**

Dimensions: (time: 1, z: 20, y: 201, x: 201)  
Coordinates:

- time (time) object 2023-12-18 05:00:21.321000
- z (z) float64 500.0 1e+03 1.5e+03 2e+03 … 9e+03 9.5e+03 1e+04  
lat (y) float64 37.81 37.82 37.82 37.83 37.83 … 38.7 38.7 38.71 38.71  
lon (x) float64 -75.91 -75.91 -75.9 -75.89 … -74.78 -74.78 -74.77
- y (y) float64 -5e+04 -4.95e+04 -4.9e+04 … 4.9e+04 4.95e+04 5e+04
- x (x) float64 -5e+04 -4.95e+04 -4.9e+04 … 4.9e+04 4.95e+04 5e+04

pyART Version: 1.16.1

\<xarray.Dataset\>  
Dimensions: (time: 1, z: 20, y: 201, x: 201)  
Coordinates:

- time (time) object 2023-12-18 05:00:21.321000
- z (z) float64 500.0 1e+03 1.5e+03 2e+03 … 9e+03 9.5e+03 1e+04  
lat (y, x) float64 37.81 37.81 37.81 37.81 … 38.71 38.71 38.71 38.71  
lon (y, x) float64 -75.91 -75.91 -75.9 -75.89 … -74.78 -74.77 -74.77
- y (y) float64 -5e+04 -4.95e+04 -4.9e+04 … 4.9e+04 4.95e+04 5e+04
- x (x) float64 -5e+04 -4.95e+04 -4.9e+04 … 4.9e+04 4.95e+04 5e+04  
Traceback (most recent call last):  
File “/Users/wolff/Desktop/Test/test\_grid.py”, line 97, in   
ds = ds.swap\_dims({“x”: “lon”, “y”: “lat”})  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/Users/wolff/anaconda3/lib/python3.11/site-packages/xarray/core/dataset.py”, line 3909, in swap\_dims  
raise ValueError(  
ValueError: replacement dimension ‘lon’ is not a 1D variable along the old dimension ‘x’

Thanks,

Dave

---

<div class="post-metadata">

**Author:** ![mgrover1](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/mgrover1/32/7_2.png) [@mgrover1](https://openradar.discourse.group/u/mgrover1)\
**Post date:** [January 4, 2024, 6:38pm UTC](https://openradar.discourse.group/t/grid-to-xarray-issue-with-lat-lon/377/2 "2024-01-04T18:38:41Z")

</div>

Thanks for raising this discussion - Py-ART previously dealt with this incorrectly, assuming equal spacing between latitude and longitude, but it varies since we are using an Azimuthal equidistant projection (see the discussion on this issue [pyart.core.Grid.to\_xarray returns 1-dimensional lon-lat instead of 2-dimensional · Issue #1389 · ARM-DOE/pyart · GitHub](https://github.com/ARM-DOE/pyart/issues/1389#issue-1595077158))

---

<div class="post-metadata">

**Author:** ![mgrover1](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/mgrover1/32/7_2.png) [@mgrover1](https://openradar.discourse.group/u/mgrover1)\
**Post date:** [January 16, 2024, 7:05pm UTC](https://openradar.discourse.group/t/grid-to-xarray-issue-with-lat-lon/377/3 "2024-01-16T19:05:06Z")

</div>

@wxwolff1 does that make sense? Do you think we should roll back changes until Py-ART 2.0 (to be released later this year)? Open to discussion here!
