xoa.geo.get_extent

xoa.geo.get_extent(extent, margin=0, square=False, min_extent=None)[source]

Compute the geographic extent in degrees

Parameters:
  • extent (xarray.DataArray, xarray.Dataset, dict, tuple, list) –

    Either:

    • An array or dataset with longitude and latitude coordinates.

    • A dict with lon and lat keys: dict(lon=..., lat=...)

    • A two-element tuple of longitudes and latitudes: (lon, lat)

    • A extent list: [xmin, xmax, ymin, ymax].

  • margin (float) – A relative fraction of the width and height that is used to set margins. For instance, a value of -0.1 shrinks the box of 10% on each side.

  • square (bool) – Force the box to be square in degrees.

  • min_extent (None, float, (float, float)) – Minimal extent along x and y: (dx, dy). If a single floating value is provided, it is valid for both x and y.

Returns:

list[xmin, xmax, ymin, ymax]

Example

In [1]: get_extent([10., 20., 10., 20.], margin=0.1)
Out[1]: [9.0, 21.0, 9.0, 21.0]

In [2]: get_extent({"lon": np.linspace(10, 20, 5), "lat": np.linspace(10, 20, 5)}, square=True)
Out[2]: [9.823619097949585, 20.176380902050415, 10.0, 20.0]

In [3]: get_extent((np.linspace(10, 20, 5), np.linspace(10, 20, 5)), margin=-.1, square=True)
Out[3]: [10.858895278359668, 19.141104721640332, 11.0, 19.0]