cf.Field.set_data

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

Set the field construct data.

New in version 3.0.0.

Parameters
data: Data

The data to be inserted.

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 contructs 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 an attempt will be made to assign existing domain axis constructs to the data.

copy: bool, optional

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

Returns

None

Examples:

>>> f.axes()
{'dim0': 1, 'dim1': 3}
>>> f.insert_data(cf.Data([[0, 1, 2]]))
>>> f.axes()
{'dim0': 1, 'dim1': 3}
>>> f.insert_data(cf.Data([[0, 1, 2]]), axes=['dim0', 'dim1'])
>>> f.axes()
{}
>>> f.insert_data(cf.Data([[0, 1], [2, 3, 4]]))
>>> f.axes()
{'dim0': 2, 'dim1': 3}
>>> f.insert_data(cf.Data(4))
>>> f.insert_data(cf.Data(4), axes=[])
>>> f.axes()
{'dim0': 3, 'dim1': 2}
>>> data = cf.Data([[0, 1], [2, 3, 4]])
>>> f.insert_data(data, axes=['dim1', 'dim0'], copy=False)
>>> f.insert_data(cf.Data([0, 1, 2]))
>>> f.insert_data(cf.Data([3, 4, 5]), replace=False)
ValueError: Can't initialize data: Data already exists
>>> f.insert_data(cf.Data([3, 4, 5]))