sandplover.plan.compute_land_area¶
- sandplover.plan.compute_land_area(land_mask)¶
Compute land (delta) area.
Computes the land area for a LandMask as:
\[\sum_{i=1}^L \sum_{j=1}^W A_{ij}\]where \(L\) and \(W\) are the mask dimensions, and \(A_{ij}\) is the area of each cell where \(A_{ij} =dx^2\) if the mask is True, otherwise \(A_{ij} = 0\).
Will return area with the same base units as the spatial coordinates of input array (i.e., for a
Maskor xarray.DataArray). In the case of a numpy array without coordinates, a unit dimension is assumed for each cell.Note
In implementation, this is a simple 1-liner summation over the mask. It is implemented as a function here for convenience and consistency in the api:
land_area = np.sum(land_mask.integer_mask) * dx * dx
- Parameters:
land_mask (
LandMask,ndarray) – Land mask. Can be aLandMaskobject, or a binarized array.- Returns:
land_area – Land area, computed as described above.
- Return type:
float
Examples
>>> import matplotlib.pyplot as plt >>> from sandplover.mask import LandMask >>> from sandplover.plan import compute_land_area >>> from sandplover.sample_data.sample_data import golf
>>> golf = golf()
>>> lm = LandMask( ... golf["eta"][-1, :, :], ... elevation_threshold=golf.meta["H_SL"][-1], ... elevation_offset=-0.5, ... )
>>> lm.trim_mask(length=golf.meta["L0"].data + 1)
>>> land_area = compute_land_area(lm)
>>> fig, ax = plt.subplots() >>> lm.show(ax=ax, ticks=True) >>> _ = ax.set_title(f"Land area is {land_area/1e6:.1f} km$^2$")
(
Source code,png,hires.png)