Repository: Unidata/MetPy

Issue:
gdxarray() should assign units to x and y coordinates
Is there a way to construct the proper `Dataset` with the current MetPy functionality so my attempt to plot wind barbs works?

Here's my attempt:
```python
from datetime import datetime

import xarray as xr
import metpy
from metpy.units import units
from metpy.io import GempakGrid
from metpy.plots.declarative import ContourPlot, FilledContourPlot, BarbPlot, MapPanel, PanelContainer

print(metpy.__version__)

MODEL = '/ldmdata/gempak/model/'
gem_file_name = MODEL + 'nam/21092012_nam211.gem'
gem_file = GempakGrid(gem_file_name)

plot_time = datetime(2021, 9, 20, 12)

u500 = gem_file.gdxarray(parameter='UREL', date_time=plot_time, level=500)[0]
v500 = gem_file.gdxarray(parameter='VREL', date_time=plot_time, level=500)[0]
u500 = u500 * units('m/s')
v500 = v500 * units('m/s')

wind = xr.merge([u500, v500])

barbs = BarbPlot()
barbs.data = wind
barbs.time = plot_time
barbs.field = ['urel', 'vrel']
barbs.earth_relative = False   # I get a plot w/o this line, but obviously the winds aren't rotated correctly
barbs.skip = (3, 3)
barbs.plot_units = 'knot'

panel = MapPanel()
panel.area = [-120, -74, 22, 55]
panel.projection = 'lcc'
panel.layers = ['states', 'coastline', 'borders']
panel.title = f'500-mb Winds at {plot_time}'
panel.plots = [barbs]

pc = PanelContainer()
pc.size = (15, 15)
pc.panels = [panel]
pc.show()
```

The result:
```
1.1.0.post39+gd43d5eb02.d20210825
Traceback (most recent call last):
  File "/home/decker/classes/met433/new_labs/barb_issue.py", line 42, in <module>
    pc.show()
  File "/home/decker/src/git_repos/metpy/src/metpy/plots/declarative.py", line 589, in show
    self.draw()
  File "/home/decker/src/git_repos/metpy/src/metpy/plots/declarative.py", line 576, in draw
    panel.draw()
  File "/home/decker/src/git_repos/metpy/src/metpy/plots/declarative.py", line 846, in draw
    p.draw()
  File "/home/decker/src/git_repos/metpy/src/metpy/plots/declarative.py", line 1480, in draw
    self._build()
  File "/home/decker/src/git_repos/metpy/src/metpy/plots/declarative.py", line 1504, in _build
    x_like, y_like, u, v = self.plotdata
  File "/home/decker/src/git_repos/metpy/src/metpy/plots/declarative.py", line 1465, in plotdata
    if 'degree' in x.units:
  File "/home/decker/local/miniconda3/envs/devel21/lib/python3.9/site-packages/xarray/core/common.py", line 239, in __getattr__
    raise AttributeError(
AttributeError: 'DataArray' object has no attribute 'units'
```

Discussion:

Patch:
diff --git a/src/metpy/io/gempak.py b/src/metpy/io/gempak.py
index bff5f9d292..15c5b0226f 100644
--- a/src/metpy/io/gempak.py
+++ b/src/metpy/io/gempak.py
@@ -1362,6 +1362,9 @@ class GempakGrid(GempakFile):
                             'gempak_grid_type': ftype,
                         }
                     )
+                    xrda = xrda.metpy.assign_latitude_longitude()
+                    xrda['x'].attrs['units'] = 'meters'
+                    xrda['y'].attrs['units'] = 'meters'
                     grids.append(xrda)
 
                 else:


Test patch:
diff --git a/tests/io/test_gempak.py b/tests/io/test_gempak.py
index 1883b71033..3cb09a20d6 100644
--- a/tests/io/test_gempak.py
+++ b/tests/io/test_gempak.py
@@ -249,9 +249,14 @@ def test_coordinates_creation(proj_type):
 def test_metpy_crs_creation(proj_type, proj_attrs):
     """Test grid mapping metadata."""
     grid = GempakGrid(get_test_data(f'gem_{proj_type}.grd'))
-    metpy_crs = grid.gdxarray()[0].metpy.crs
+    arr = grid.gdxarray()[0]
+    metpy_crs = arr.metpy.crs
     for k, v in proj_attrs.items():
         assert metpy_crs[k] == v
+    x_unit = arr['x'].units
+    y_unit = arr['y'].units
+    assert x_unit == 'meters'
+    assert y_unit == 'meters'
 
 
 def test_date_parsing():