cfdm.Data

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

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

An orthogonal multidimensional array with masking and units.

New in version (cfdm): 1.7.0

Initialisation

Parameters
array: data_like, optional

The array of values.

A data_like object is any object that can be converted to a Data object, i.e. numpy array_like objects, Data objects, and cfdm instances that contain Data objects.

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.

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.

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).

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: data_like, 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 data_like object that broadcasts to array. Masking will be carried out where mask elements evaluate to True.

A data_like object is any object that can be converted to a Data object, i.e. numpy array_like objects, Data objects, and cfdm instances that contain Data objects.

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

mask_value: scalar array_like

Mask array where it is equal to mask_value, using numerically tolerant floating point equality.

New in version (cfdm): 1.11.0.0

source: optional

Convert source, which can be any type of object, to a Data instance.

All other parameters, apart from copy, are ignored and their values are instead inferred from source by assuming that it has the Data API. Any parameters that can not be retrieved from source in this way are assumed to have their default value.

Note that if x is also a Data instance then cfdm.Data(source=x) is equivalent to x.copy().

copy: bool, optional

If True (the default) then deep copy the input parameters prior to initialisation. By default the parameters are not deep copied.

kwargs: ignored

Not used. Present to facilitate subclassing.

Inspection

Attributes

array

Return an independent numpy array containing the data.

sparse_array

Return an independent scipy sparse array of the data.

dtype

Data-type of the data elements.

ndim

Number of data dimensions.

shape

Tuple of data dimension sizes.

size

Number of elements in the data.

Units

del_units

Delete the units.

get_units

Return the units.

has_units

Whether units have been set.

set_units

Set the units.

Date-time support

del_calendar

Delete the calendar.

get_calendar

Return the calendar.

has_calendar

Whether a calendar has been set.

set_calendar

Set the calendar.

Attributes

datetime_array

Returns an independent numpy array of datetimes.

datetime_as_string

Returns an independent numpy array with datetimes as strings.

Data creation routines

Ones and zeros

empty

Create a new data array without initialising the elements.

From existing data

copy

Return a deep copy.

Data manipulation routines

Changing data shape

flatten

Flatten axes of the data.

Transpose-like operations

transpose

Permute the axes of the data array.

Changing number of dimensions

insert_dimension

Expand the shape of the data array.

squeeze

Remove size 1 axes from the data.

Adding and removing elements

unique

The unique elements of the data.

Indexing routines

Single value selection

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.

Logic functions

Truth value testing

any

Test whether any data array elements evaluate to True.

Comparison

equals

Whether two data arrays are the same.

Mask support

apply_masking

Apply masking.

filled

Replace masked elements with the fill value.

masked_values

Mask using floating point equality.

del_fill_value

Delete the fill value.

get_fill_value

Return the missing data value.

has_fill_value

Whether a fill value has been set.

set_fill_value

Set the missing data value.

Attributes

mask

The Boolean missing data mask of the data array.

Mathematical functions

Sums, products, differences

sum

Return the sum of an array or the sum along axes.

Set routines

Making proper sets

unique

The unique elements of the data.

Sorting, searching, and counting

Statistics

Order statistics

maximum

Return the maximum of an array or the maximum along axes.

minimum

Return the minimum of an array or minimum along axes.

max

Alias for maximum.

min

Alias for minimum.

Sums

sum

Return the sum of an array or the sum along axes.

Compression by convention

get_compressed_axes

Returns the dimensions that are compressed in the array.

get_compressed_dimension

Returns the compressed dimension’s array position.

get_compression_type

Returns the type of compression applied to the array.

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.

get_dependent_tie_points

Return the list variable for a compressed array.

get_interpolation_parameters

Return the list variable for a compressed array.

get_tie_point_indices

Return the list variable for a compressed array.

uncompress

Uncompress the underlying array.

Attributes

compressed_array

Returns an independent numpy array of the compressed data.

Miscellaneous

creation_commands

Return the commands that would create the data object.

get_data

Returns the data.

get_filenames

Return the names of any files containing the data array.

get_original_filenames

The names of files containing the original data and metadata.

source

Return the underlying array object.

Attributes

data

The data as an object identity.

Performance

nc_clear_hdf5_chunksizes

Clear the HDF5 chunksizes for the data.

nc_hdf5_chunksizes

Return the HDF5 chunksizes for the data.

nc_set_hdf5_chunksizes

Set the HDF5 chunksizes for the data.

to_memory

Bring data on disk into memory.

Special

__array__

The numpy array interface.

__deepcopy__

Called by the copy.deepcopy function.

__getitem__

Return a subspace of the data defined by indices.

__int__

Called by the int built-in function.

__iter__

Called when an iterator is required.

__repr__

Called by the repr built-in function.

__setitem__

Assign to data elements defined by indices.

__str__

Called by the str built-in function.

Docstring substitutions

Methods

_docstring_special_substitutions

Return the special docstring substitutions.

_docstring_substitutions

Returns the substitutions that apply to methods of the class.

_docstring_package_depth

Returns the class {{package}} substitutions package depth.

_docstring_method_exclusions

Returns method names excluded in the class substitutions.