MCPcopy Create free account
hub / github.com/NCAR/wrf-python / latlon_coords

Function latlon_coords

src/wrf/util.py:3422–3464  ·  view source on GitHub ↗

Return the latitude and longitude coordinates from a :class:`xarray.DataArray` object. Args: var (:class:`xarray.DataArray`): A variable. as_np (:obj:`bool`): Set to True to return the coordinates as :class:`numpy.ndarray` objects instead of :class

(var, as_np=False)

Source from the content-addressed store, hash-verified

3420
3421
3422def latlon_coords(var, as_np=False):
3423 """Return the latitude and longitude coordinates from a
3424 :class:`xarray.DataArray` object.
3425
3426 Args:
3427
3428 var (:class:`xarray.DataArray`): A variable.
3429
3430 as_np (:obj:`bool`): Set to True to return the coordinates as
3431 :class:`numpy.ndarray` objects instead of
3432 :class:`xarray.DataArray` objects.
3433
3434 Returns:
3435
3436 :obj:`tuple`: The latitude and longitude coordinate variables.
3437
3438 """
3439
3440 if not xarray_enabled():
3441 raise ValueError("xarray is not installed or is disabled")
3442
3443 try:
3444 var_coords = var.coords
3445 except AttributeError:
3446 raise ValueError("'var' object does not contain coordinate "
3447 "attributes")
3448
3449 latname, lonname, _ = _find_coord_names(var_coords)
3450 try:
3451 lats = var_coords[latname]
3452 except KeyError:
3453 raise ValueError("'var' object does not contain a latitude "
3454 "coordinate")
3455 try:
3456 lons = var_coords[lonname]
3457 except KeyError:
3458 raise ValueError("'var' object does not contain a longitude "
3459 "coordinate")
3460
3461 if as_np:
3462 return to_np(lats), to_np(lons)
3463
3464 return lats, lons
3465
3466
3467def get_cartopy(var=None, wrfin=None, varname=None, timeidx=0, method="cat",

Callers 2

ctt_test.pyFile · 0.90
quiver_test.pyFile · 0.90

Calls 3

xarray_enabledFunction · 0.85
_find_coord_namesFunction · 0.85
to_npFunction · 0.85

Tested by

no test coverage detected