cfdm.Data


class cfdm.Data(array=None, units=None, calendar=None, fill_value=None, source=None, copy=True, dtype=None, mask=None, _use_array=True, **kwargs)[source]

Bases: cfdm.mixin.container.Container, cfdm.mixin.netcdf.NetCDFHDF5, cfdm.core.data.data.Data

An orthogonal multidimensional array with masked values and units.

New in version 1.7.0.

Initialization

Parameters:
array: numpy array-like or subclass of Array, optional

The array of values. Ignored if the source parameter is set.

Parameter example:

array=[34.6]

Parameter example:

array=[[1, 2], [3, 4]]

Parameter example:

array=numpy.ma.arange(10).reshape(2, 1, 5)

units: str, optional

The physical units of the data. Ignored if the source parameter is set.

The units may also be set after initialisation with the set_units method.

Parameter example:

units='km hr-1'

Parameter example:

units='days since 2018-12-01'

calendar: str, optional

The calendar for reference time units. Ignored if the source parameter is set.

The calendar may also be set after initialisation with the set_calendar method.

Parameter example:

calendar='360_day'

fill_value: optional

The fill value of the data. By default, or if set to None, the numpy fill value appropriate to the array’s data type will be used (see numpy.ma.default_fill_value). Ignored if the source parameter is set.

The fill value may also be set after initialisation with the set_fill_value method.

Parameter example:

fill_value=-999.

dtype: data-type, optional

The desired data-type for the data. By default the data-type will be inferred form the array parameter.

The data-type may also be set after initialisation with the dtype attribute.

Parameter example:

dtype=float

Parameter example:

dtype='float32'

Parameter example:

dtype=numpy.dtype('i2')

mask: optional

Apply this mask to the data given by the array parameter. By default, or if mask is None, no mask is applied. May be any scalar or array-like object (such as a numpy array or Data instance) that is scalar or has the same shape as array. Masking will be carried out where mask elements evaluate to True.

This mask will applied in addition to any mask already defined by the array parameter.

source: optional

Initialize the array, units, calendar and fill value from those of source.

copy: bool, optional

If False then do not deep copy input parameters prior to initialization. By default arguments are deep copied.

kwargs: ignored

Not used. Present to facilitate subclassing.

Inspection

Methods

first_element Return the first element of the data as a scalar.
second_element Return the second element of the data as a scalar.
last_element Return the last element of the data as a scalar.

Attributes

array Return an independent numpy array containing the data.
datetime_array Return an independent numpy array containing the date-time objects corresponding to time since a reference date.
dtype Data-type of the data elements.
mask The boolean missing data mask of the data array.
ndim Number of data dimensions.
shape Tuple of data dimension sizes.
size Number of elements in the data.

Units

Methods

get_units Return the units.
set_units Set the units.
set_calendar Set the calendar.
get_calendar Return the calendar.

Fill value

Methods

get_fill_value Return the missing data value.
set_fill_value Set the missing data value.

Dimensions

Methods

insert_dimension Expand the shape of the data array.
squeeze Remove size 1 axes from the data.
transpose Permute the axes of the data array.

Calculation

Methods

max Return the maximum of an array or the maximum along axes.
min Return the minimum of an array or minimum along axes.
sum Return the sum of an array or the sum along axes.
unique The unique elements of the data.

Miscellaneous

Methods

copy Return a deep copy.
equals Whether two data arrays are the same.
to_memory
source Return the underlying array object.
uncompress Uncompress the underlying array in-place.

Compression

Methods

get_compression_type Return the type of compression applied to the underlying array.
get_compressed_axes Return the dimensions that have compressed in the underlying array.
get_compressed_dimension Return the position of the compressed dimension in the compressed array.
uncompress Uncompress the underlying array in-place.
get_count Return the count variable for a compressed array.
get_index Return the index variable for a compressed array.
get_list Return the list variable for a compressed array.

Attributes

compressed_array Return an independent numpy array containing the compressed data.

Special

Methods

__array__ The numpy array interface.
__deepcopy__ Called by the copy.deepcopy function.
__getitem__ Return a subspace of the data defined by indices
__repr__ Called by the repr built-in function.
__setitem__ Assign to data elements defined by indices.
__str__ Called by the str built-in function.