unifhy.LatLonGrid.land_sea_mask

LatLonGrid.land_sea_mask

The land-sea mask for the Grid of boolean/binary values (i.e. True/1 for land, False/0 for sea) given as a cf.Field and returned as a processed numpy.ndarray.

Parameters
mask: cf.Field

The field containing the land-sea information. The shape of the data array must be the same as the Grid. The field data must contain boolean/binary values (True/1 for land, False/0 for sea).

Returns
numpy.ndarray

The array containing the land-sea information as boolean values (True for land, False for sea). The shape of the array is the same as of the Grid. If not set, return None.

Examples

Assigning land sea mask to grid using binary values:

>>> import numpy
>>> grid = LatLonGrid.from_extent_and_resolution(
...     latitude_extent=(51, 55),
...     latitude_resolution=1,
...     longitude_extent=(-2, 1),
...     longitude_resolution=1
... )
>>> print(grid.land_sea_mask)
None
>>> mask = grid.to_field()
>>> mask.set_data(numpy.array([[0, 1, 1],
...                            [1, 1, 0],
...                            [0, 1, 0],
...                            [0, 0, 0]]))
>>> grid.land_sea_mask = mask
>>> print(grid.land_sea_mask)
[[False  True  True]
 [ True  True False]
 [False  True False]
 [False False False]]
>>> print(grid)
LatLonGrid(
    shape {Y, X}: (4, 3)
    Y, latitude (4,): [51.5, ..., 54.5] degrees_north
    X, longitude (3,): [-1.5, -0.5, 0.5] degrees_east
    Y_bounds (4, 2): [[51.0, ..., 55.0]] degrees_north
    X_bounds (3, 2): [[-2.0, ..., 1.0]] degrees_east
    land_sea_mask (4, 3): [[False, ..., False]]
)

Assigning land sea mask to grid using boolean values:

>>> mask.set_data(numpy.array([[False, True, True],
...                            [True, True, False],
...                            [False, True, False],
...                            [False, False, False]]))
>>> grid.land_sea_mask = mask
>>> print(grid.land_sea_mask)
[[False  True  True]
 [ True  True False]
 [False  True False]
 [False False False]]