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.

By default the axes will either be those already defined by the domain for the data array, else the sequence of consecutive axis identifiers 'dim0' up to 'dimM', where M is the number of axes of the data array (or an empty sequence if the data array is a scalar).

If an axis of the data array already exists in the domain then the it must have the same size as the domain axis.

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

Previous topic

cf.Field.insert_cm

Next topic

cf.Field.insert_dim

This Page