cf.Field.set_data

Field.set_data(data, axes=None, set_axes=True, copy=True, inplace=True)[source]

Set the field construct data.

New in version 3.0.0.

Parameters
data: Data

The data to be inserted.

A data_like object is any object that can be converted to a Data object, i.e. numpy array_like objects, Data objects, and cf instances that contain Data objects.

axes: (sequence of) str or int, optional

Set the domain axes constructs that are spanned by the data. If unset, and the set_axes parameter is True, then an attempt will be made to assign existing domain axis constructs to the data.

The contents of the axes parameter is mapped to domain axis constructs by translating each element into a domain axis construct key via the domain_axis method.

Parameter example:

axes='domainaxis1'

Parameter example:

axes='X'

Parameter example:

axes=['latitude']

Parameter example:

axes=['X', 'longitude']

Parameter example:

axes=[1, 0]

set_axes: bool, optional

If False then do not set the domain axes constructs that are spanned by the data, even if the axes parameter has been set. By default the axes are set either according to the axes parameter, or if any domain axis constructs exist then an attempt will be made to assign existing domain axis constructs to the data.

If the axes parameter is None and no domain axis constructs exist then no attempt is made to assign domain axes constructs to the data, regardless of the value of set_axes.

copy: bool, optional

If True then set a copy of the data. By default the data are copied.

inplace: bool, optional:

If True (the default) then do the operation in-place and return None. If False a new, modified Field instance is returned.

New in version 3.7.0.

Returns
None or Field

If the operation was in-place then None is returned, otherwise return a new Field instance containing the new data.

Examples

>>> f = cf.Field()
>>> f.set_data([1, 2, 3])
>>> f.has_data()
True
>>> f.get_data()
<CF Data(3): [1, 2, 3]>
>>> f.data
<CF Data(3): [1, 2, 3]>
>>> f.del_data()
<CF Data(3): [1, 2, 3]>
>>> g = f.set_data([4, 5, 6], inplace=False)
>>> g.data
<CF Data(3): [4, 5, 6]>
>>> f.has_data()
False
>>> print(f.get_data(None))
None
>>> print(f.del_data(None))
None