lair.geo.round_latlon#

lair.geo.round_latlon(data, lat_deci, lon_deci, lat_dim='lat', lon_dim='lon')[source]#

Round latitude and longitude values to a specified number of decimal places.

Parameters:
  • data (xr.DataArray | xr.Dataset) – The data with lat/lon coordinates to round.

  • lat_deci (int) – Number of decimal places to round latitude values to.

  • lon_deci (int) – Number of decimal places to round longitude values to.

  • lat_dim (str, optional) – Name of the latitude dimension, by default ‘lat’.

  • lon_dim (str, optional) – Name of the longitude dimension, by default ‘lon’.

Returns:

xr.DataArray | xr.Dataset – The data with rounded lat/lon coordinates.

Return type:

_XarrayT

See also

wrap_lons

Puts longitudes in one range.

Examples

Float noise in a file’s coordinates, rounded away so two grids align:

>>> import xarray as xr
>>> from lair.geo import round_latlon
>>> data = xr.DataArray(
...     [[1.0]],
...     coords={"lat": [40.749999999], "lon": [-111.850000001]},
...     dims=("lat", "lon"),
... )
>>> rounded = round_latlon(data, 2, 2)
>>> float(rounded.lat[0]), float(rounded.lon[0])
(40.75, -111.85)