cf.Field.insert_data

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

Insert a new data array into the field in place, preserving internal consistency.

Note that the field’s pre-existing Units attribute and _FillValue property will be overwritten with those attached to the new data array.

Parameters :
data : cf.Data

The new data array.

dimensions : sequence of str, optional

A list of dimension identifiers ('dimN'), stating the dimensions, 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 dimension identifier is the same as one in the field’s domain, or b) if the domain has no dimensions, arbitrary integers greater then or equal to zero may be used, the only restriction being that the resulting identifiers are unique.

By default these dimension identifiers will be the sequence of consecutive dimension identifiers 'dim0' up to 'dimM', where M is the number of dimensions of the data array, or an empty sequence if the data array is a scalar.

If the field’s domain has any of the data array’s dimensions, then their sizes must correspond to those of the field’s 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.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]]), dimensions['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), dimensions=[])
>>> f.dimension_sizes
{'dim0': 3, 'dim1': 2}
>>> data = cf.Data([[0, 1], [2, 3, 4]])
>>> f.insert_data(data, dimensions=['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.indices

Next topic

cf.Field.match

This Page