cf.Field.insert_data

Field.insert_data(data, axes=None, copy=True, replace=True)[source]

Insert a new data array into the field in place.

Note that the data array’s missing data value, if it has one, is not transferred to the field.

Parameters:
data : cf.Data

The new data array.

axes : sequence of str, optional

A list of axis identifiers ('dimN'), stating the axes, in order, of the data array.

The N part of each identifier should be replaced by an integer greater then or equal to zero such that either a) each axis identifier is the same as one in the field’s domain, or b) if the domain has no axes, arbitrary integers greater then or equal to zero may be used, the only restriction being that the resulting identifiers are unique.

If an axis of the data array already exists in the domain then the it must have the same size as the domain axis. If it does not exist in the domain then a new axis will be created.

By default the axes will either be those defined for the data array by the domain or, if these do not exist, the domain axis identifiers whose sizes unambiguously match the data array.

copy : bool, optional

If False then the new data array is not deep copied prior to insertion. By default the new data array is deep copied.

replace : bool, optional

If False then do not replace an existing data array. By default an data array is replaced with data.

Returns:

None

Examples:
>>> f.domain._axes_sizes
{'dim0': 1, 'dim1': 3}
>>> f.insert_data(cf.Data([[0, 1, 2]]))
>>> f.domain._axes_sizes
{'dim0': 1, 'dim1': 3}
>>> f.insert_data(cf.Data([[0, 1, 2]]), axes=['dim0', 'dim1'])
>>> f.domain._axes_sizes
{}
>>> f.insert_data(cf.Data([[0, 1], [2, 3, 4]]))
>>> f.domain._axes_sizes
{'dim0': 2, 'dim1': 3}
>>> f.insert_data(cf.Data(4))
>>> f.insert_data(cf.Data(4), axes=[])
>>> f.domein._axes_sizes
{'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]))