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)
| 3420 | |
| 3421 | |
| 3422 | def 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 | |
| 3467 | def get_cartopy(var=None, wrfin=None, varname=None, timeidx=0, method="cat", |
no test coverage detected