cf.Data¶
-
class
cf.
Data
(array=None, units=None, calendar=None, fill_value=None, hardmask=True, chunk=True, loadd=None, loads=None, dt=False, source=None, copy=True, dtype=None, mask=None, _use_array=True)[source]¶ Bases:
cfdm.data.data.Data
An N-dimensional data array with units and masked values.
Contains an N-dimensional, indexable and broadcastable array with many similarities to a
numpy
array.Contains the units of the array elements.
Supports masked arrays, regardless of whether or not it was initialised with a masked array.
Stores and operates on data arrays which are larger then the available memory.
Indexing
A data array is indexable in a similar way to numpy array:
>>> d.shape (12, 19, 73, 96) >>> d[...].shape (12, 19, 73, 96) >>> d[slice(0, 9), 10:0:-2, :, :].shape (9, 5, 73, 96)
There are three extensions to the numpy indexing functionality:
Size 1 dimensions are never removed bi indexing.
An integer index i takes the i-th element but does not reduce the rank of the output array by one:
>>> d.shape (12, 19, 73, 96) >>> d[0, ...].shape (1, 19, 73, 96) >>> d[:, 3, slice(10, 0, -2), 95].shape (12, 1, 5, 1)
Size 1 dimensions may be removed with the
squeeze
method.The indices for each axis work independently.
When more than one dimension’s slice is a 1-d boolean sequence or 1-d sequence of integers, then these indices work independently along each dimension (similar to the way vector subscripts work in Fortran), rather than by their elements:
>>> d.shape (12, 19, 73, 96) >>> d[0, :, [0, 1], [0, 13, 27]].shape (1, 19, 2, 3)
Boolean indices may be any object which exposes the numpy array interface.
>>> d.shape (12, 19, 73, 96) >>> d[..., d[0, 0, 0]>d[0, 0, 0].min()]
Cyclic axes
Miscellaneous
A
Data
object is picklable.A
Data
object is hashable, but note that, since it is mutable, its hash value is only valid whilst the data array is not changed in place.Initialization
- Parameters
- array: optional
The array of values. May be any scalar or array-like object, including another
Data
instance. 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
orUnits
, optional The physical units of the data. if a
Units
object is provided then this an also set the calendar. Ignored if the source parameter is set.The units (without the calendar) 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
, thenumpy
fill value appropriate to the array’s data-type will be used (seenumpy.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 anumpy
array orData
instance) that is broadcastable to the shape of array. Masking will be carried out where the mask elements evaluate toTrue
.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.
- hardmask:
bool
, optional If False then the mask is soft. By default the mask is hard.
- dt:
bool
, optional If True then strings (such as
'1990-12-01 12:00'
) given by the array parameter are re-interpreted as date-time objects. By default they are not.- loadd:
dict
, optional Initialise the data from a dictionary serialization of a
cf.Data
object. All other arguments are ignored. See thedumpd
andloadd
methods.- loads:
str
, optional Initialise the data array from a string serialization of a
Data
object. All other arguments are ignored. See thedumps
andloads
methods.- copy:
bool
, optional If False then do not deep copy input parameters prior to initialization. By default arguments are deep copied.
- chunk:
bool
, optional If False then the data array will be stored in a single partition. By default the data array will be partitioned if it is larger than the chunk size, as returned by the
cf.CHUNKSIZE
function.
Examples:
>>> d = cf.Data(5) >>> d = cf.Data([1,2,3], units='K') >>> import numpy >>> d = cf.Data(numpy.arange(10).reshape(2,5), units=Units('m/s'), fill_value=-999) >>> d = cf.Data(tuple('fly'))
Data attributes¶
A numpy array copy the data array. |
|
A binary (0 and 1) mask of the data array. |
|
The data as an object identity. |
|
The day of each data array element. |
|
An independent numpy array of date-time objects. |
|
The |
|
The data array missing data value. |
|
Whether the mask is hard (True) or soft (False). |
|
The hour of each data array element. |
|
True if the data array has any masked values. |
|
True if the data array is a 0-d scalar array. |
|
The boolean missing data mask of the data array. |
|
The minute of each data array element. |
|
The month of each data array element. |
|
Total number of bytes consumed by the elements of the array. |
|
Number of dimensions in the data array. |
|
The second of each data array element. |
|
Tuple of the data array’s dimension sizes. |
|
Number of elements in the data array. |
|
The |
|
A numpy array view the data array. |
|
The year of each data array element. |
Data methods¶
Add partition boundaries. |
|
Test whether all data array elements evaluate to True. |
|
Returns True if two broadcastable arrays have equal values, False otherwise. |
|
Test whether any data array elements evaluate to True. |
|
Take the inverse hyperbolic sine of the data element-wise. |
|
Take the trigonometric inverse tangent of the data element-wise. |
|
Return the indices of the maximum values along an axis. |
|
Convert the input to a |
|
The ceiling of the data, element-wise. |
|
Change the calendar of the data array elements. |
|
Partition the data array. |
|
Clip (limit) the values in the data array in place. |
|
Close all files referenced by the data array. |
|
Join a sequence of data arrays together. |
|
Concatenates a list of Data objects into a single Data object along the specified access (see cf.Data.concatenate for details). |
|
Return a deep copy. |
|
Take the trigonometric cosine of the data array in place. |
|
Take the hyperbolic cosine of the data array in place. |
|
Count the non-masked elements of the data. |
|
Count the masked elements of the data. |
|
Return the commands that would create the data object. |
|
Return the data cumulatively summed along the given axis. |
|
TODO |
|
Return an element of the data array as a standard Python scalar. |
|
Delete the calendar. |
|
Delete the fill value. |
|
Delete the units. |
|
Return a string containing a full description of the instance. |
|
Return the indices of the bins to which each value belongs. |
|
Return a serialization of the data array. |
|
Return a JSON string serialization of the data array. |
|
Create a new data array without initializing the elements. |
|
True if two data arrays are logically equal, False otherwise. |
|
Take the exponential of the data array. |
|
Expand the shape of the data array in place. |
|
Return the names of files containing parts of the data array. |
|
TODO |
|
Return the first element of the data as a scalar. |
|
Return True if the master array is small enough to be retained in memory. |
|
Return True if the master array is small enough to be retained in memory. |
|
Return a flat iterator over elements of the data array. |
|
Flatten axes of the data |
|
Reverse the direction of axes of the data array. |
|
Return the floor of the data array. |
|
Return a new data array of given shape and type, filled with the given value. |
|
Apply an element-wise array operation to the data array. |
|
Return the calendar. |
|
Return the dimensions that have compressed in the underlying array. |
|
Return the position of the compressed dimension in the compressed array. |
|
Return the type of compression applied to the underlying array. |
|
Return the count variable for a compressed array. |
|
TODO |
|
Return the missing data value. |
|
Return the index variable for a compressed array. |
|
Return the list variable for a compressed array. |
|
Return the units. |
|
TODO Return the units. |
|
TODO Return the units. |
|
TODO Return the units. |
|
Expand the shape of the data array in place. |
|
Inspect the object for debugging. |
|
TODO |
|
Return where data are element-wise equal to other, broadcastable data. |
|
Return the last element of the data as a scalar. |
|
Reset the data array in place from a data array serialization. |
|
TODO |
|
TODO |
|
Masking of floating-point errors in the results of arithmetic operations. |
|
Mask the array where invalid values occur (NaN or inf). |
|
Alias for |
|
Collapse axes with their maximum. |
|
Collapse axes with their maximum absolute value. |
|
Collapse axes with their mean. |
|
Collapse axes with their mean absolute value. |
|
TODO |
|
TODO |
|
Collapse axes with the unweighted average of their maximum and minimum values. |
|
Alias for |
|
Collapse axes with their minimum. |
|
Collapse axes with their minimum absolute value. |
|
TODO |
|
TODO |
|
TODO |
|
Return an iterator over the N-dimensional indices of the data array. |
|
TODO |
|
Compute the outer product with another data array. |
|
Override the calendar of the data array elements. |
|
Override the data array units. |
|
Return the partition boundaries for each partition matrix dimension. |
|
Return parameters for opening and closing array partitions. |
|
Compute percentiles of the data along the specified axes. |
|
Collapse axes with the absolute difference between their maximum and minimum values. |
|
Expects a dictionary of Data objects with ordering information as keys, as output by the section method when called with a Data object. |
|
Round the data to the nearest integer, element-wise. |
|
A lot like |
|
TODO Collapse axes with their weighted mean. |
|
Evenly round elements of the data array to the given number of decimals. |
|
TODO |
|
Alias for |
|
Collapse axes by calculating their standard deviation. |
|
Return the second element of the data as a scalar. |
|
Return a dictionary of Data objects, which are the m dimensional sections of this n dimensional Data object, where m <= n. |
|
Set the calendar. |
|
Set the missing data value. |
|
Set the units. |
|
Set how floating-point errors in the results of arithmetic operations are handled. |
|
Take the trigonometric sine of the data array in place. |
|
Take the hyperbolic sine of the data array in place. |
|
Return the underlying array object. |
|
Remove size 1 axes from the data array. |
|
Collapse axes by calculating their standard deviation. |
|
Calculate statistics of the data. |
|
Collapse axes with their sum. |
|
Collapse axes with the sum of the squares of the values. |
|
TODO |
|
TODO |
|
Interchange two axes of an array. |
|
Take the trigonometric tangent of the data array element-wise. |
|
Take the hyperbolic tangent of the data array. |
|
Store the data array on disk. |
|
Store each partition’s data in memory in place if the master array is smaller than the chunk size. |
|
Return the array as a (possibly nested) list. |
|
Permute the axes of the data array. |
|
Return the truncated values of the data array. |
|
Uncompress the underlying data. |
|
The unique elements of the array. |
|
Alias of |
|
Collapse axes with their weighted variance. |
|
Assign to data elements depending on a condition. |
|
TODO |
Data static methods¶
Masking of floating-point errors in the results of arithmetic operations. |
|
Set how floating-point errors in the results of arithmetic operations are handled. |
Data arithmetic and comparison operations¶
Arithmetic, bitwise and comparison operations are defined as
element-wise data array operations which yield a new cf.Data
object
or, for augmented assignments, modify the data in-place.
Comparison operators
The rich comparison operator |
|
The rich comparison operator |
|
The rich comparison operator |
|
The rich comparison operator |
|
The rich comparison operator |
|
The rich comparison operator |
Truth value of an array
Truth value testing and the built-in operation |
Binary arithmetic operators
The binary arithmetic operation |
|
The binary arithmetic operation |
|
The binary arithmetic operation |
|
The binary arithmetic operation |
|
The binary arithmetic operation |
|
The binary arithmetic operation |
|
The binary arithmetic operations |
|
The binary arithmetic operation |
Binary arithmetic operators with reflected (swapped) operands
The binary arithmetic operation |
|
The binary arithmetic operation |
|
The binary arithmetic operation |
|
The binary arithmetic operation |
|
The binary arithmetic operation |
|
The binary arithmetic operation |
|
The binary arithmetic operations |
|
The binary arithmetic operation |
Augmented arithmetic assignments
The augmented arithmetic assignment |
|
The augmented arithmetic assignment |
|
The augmented arithmetic assignment |
|
The augmented arithmetic assignment |
|
The augmented arithmetic assignment |
|
The augmented arithmetic assignment |
|
The augmented arithmetic assignment |
|
The binary arithmetic operation |
Unary arithmetic operators
The unary arithmetic operation |
|
The unary arithmetic operation |
|
The unary arithmetic operation |
Binary bitwise operators
The binary bitwise operation |
|
The binary bitwise operation |
|
The binary bitwise operation |
|
The binary bitwise operation |
|
The binary bitwise operation |
..rubric:: Binary bitwise operators with reflected (swapped) operands
The binary bitwise operation |
|
The binary bitwise operation |
|
The binary bitwise operation |
|
The binary bitwise operation |
|
The binary bitwise operation |
Augmented bitwise assignments
The augmented bitwise assignment |
|
The augmented bitwise assignment |
|
The augmented bitwise assignment |
|
The augmented bitwise assignment |
|
The augmented bitwise assignment |
Unary bitwise operators
The unary bitwise operation |
Special¶
The numpy array interface. |
|
Membership test operator |
|
Returns a new reference to self. |
|
Called by the |
|
Return a subspace of the data defined by indices. |
|
The built-in function |
|
Called when an iterator is required. |
|
The built-in function |
|
TODO |
|
TODO |
|
TODO |
|
Called by the |
|
Implement indexed assignment. |
|
Called by the |