code: def distances_from_cross_section(cross):
      
      if (CFConventionHandler.check_axis(cross.metpy.x, 'lon')
              and CFConventionHandler.check_axis(cross.metpy.y, 'lat')):
          # Use pyproj to obtain x and y distances
          from pyproj import Geod
  
          g = Geod(cross.metpy.cartopy_crs.proj4_init)
          lon = cross.metpy.x
          lat = cross.metpy.y
  
          forward_az, _, distance = g.inv(lon[0].values * np.ones_like(lon),
                                          lat[0].values * np.ones_like(lat),
                                          lon.values,
                                          lat.values)
          x = distance * np.sin(np.deg2rad(forward_az))
          y = distance * np.cos(np.deg2rad(forward_az))
  
          # Build into DataArrays
          x = xr.DataArray(x, coords=lon.coords, dims=lon.dims, attrs={'units': 'meters'})
          y = xr.DataArray(y, coords=lat.coords, dims=lat.dims, attrs={'units': 'meters'})
  
      elif (CFConventionHandler.check_axis(cross.metpy.x, 'x')
              and CFConventionHandler.check_axis(cross.metpy.y, 'y')):
  
          # Simply return what we have
          x = cross.metpy.x
          y = cross.metpy.y
  
      else:
          raise AttributeError('Sufficient horizontal coordinates not defined.')
  
      return x, y
docs: Calculate the distances in the x and y directions along a cross-section.
  
      Parameters
      ----------
      cross : `xarray.DataArray`
          The input DataArray of a cross-section from which to obtain geometeric distances in
          the x and y directions.
  
      Returns
      -------
      x, y : tuple of `xarray.DataArray`
          A tuple of the x and y distances as DataArrays