cf.Field.setmask

Field.setmask(value, indices=Ellipsis)[source]

Set selected elements of the data array’s mask in place.

Missing entries in the data array are signified by True elements of the data array’s mask.

The value to which the selected elements of the mask will be set may be any object which is broadcastable across the selected elements. The value may be of any data type but will be evaluated as boolean.

The mask may be effectively removed by setting every element to False:

>>> f.setmask(False)

Unmasked elements are set to the field’s fill value.

Note that if and only if the value to be assigned is logically scalar and evaluates to True then f.setmask(value, indices) is equivalent to f.setitem(cf.masked, indices). This is consistent with the behaviour of numpy masked arrays.

Parameters :
value : array-like

The value to which the selected elements of the mask will be set. Must be an object which is broadcastable across the selected elements. value may be of any data type but will be evaluated as boolean. The special case of value being a field is equivalent to providing the field’s cf.Data object, or its array attribute.

indices : optional

Select elements of the mask to be set as indices or coordinate conditions as would be accepted by the field’s subspace attribute. By default the entire mask is set.

Only elements of the mask described by indices are set with value.

Returns :

None

Examples

>>> f.shape
(2, 3, 4)
>>> f.setmask(False)
>>> f.setmask(False, indices=dict(longitude=cf.wo(-30, 30, 'degrees')))
>>> f.setmask([1, 0, 0, 1])
>>> f.setmask([[[False]], [[True]]], indices=(slice(None), 0, 0))
>>> g.shape
(3, 4)
>>> f.setmask(g.mask)
>>> f.setmask(g.mask.subspace[0:2, :], indices=1)

The mask may be inverted as follows:

>>> f.setmask(~f.mask)

Previous topic

cf.Field.setitem

Next topic

cf.Field.setprop

This Page