Bases: object
Base class for storing a data array with metadata.
A variable contains a data array and metadata comprising properties to describe the physical nature of the data.
All components of a variable are optional.
Initialization
Parameters : |
|
---|
return new variable containing binary mask
Partition the data array using Large Amounts of Massive Arrays (LAMA) functionality.
Parameters : | chunksize : int extra_boundaries : list adim : list |
---|---|
Returns : | extra_boundaries, adim : {list, list} |
Return a deep copy.
Equivalent to copy.deepcopy(f)
Returns : |
|
---|
Examples
>>> g = f.copy()
Delete a standard or non-standard CF attribute.
Parameters : |
|
---|---|
Returns : | None |
Raises : |
|
Examples
>>> f.delattr('standard_name')
>>> f.delattr('foo')
Return a string containing a full description of the variable.
Parameters: |
|
---|---|
Returns: | A string containing the description of the variable. |
See also
Return True if the variable is congruent to another variable in that
- They have identical data. Pointers to data on disk may be converted to numpy arrays in memory if required.
- They have identical reserved public attributes.
- They have identical public attributes.
Equality of numbers is to within a tolerance. Refer to cf for details.
Parameters: |
|
---|---|
Returns: | True if the two objects are congruent, False otherwise. |
Examples
>>> y = x
>>> x.equals(y)
True
>>> y = x + 1
>>> x.equals(y)
False
>>> y -= 1
>>> x.equals(y)
True
>>> x.setattr('name', 'name0')
>>> y.setattr('name', 'name1')
>>> x.equals(y)
False
axis is an integer dim is a string direction is a boolean
Return the instance if it matches the given conditions.
Equivalent to:
def extract(f, *args, **kwargs):
if f.match(*args, **kwargs):
return f
raise ValueError``
Parameters : | |
---|---|
Returns : |
|
Raises : |
|
Get a standard or non-standard CF attribute.
Parameters : |
|
---|---|
Returns : |
|
Raises : |
|
Examples
>>> f.getattr('standard_name')
>>> f.getattr('standard_name', None)
>>> f.getattr('foo')
Return True if the variable has standard or non-standard CF attribute.
Parameters : |
|
---|---|
Returns : |
|
Examples
>>> f.hasattr('standard_name')
>>> f.hasattr('foo')
Determine whether or not a variable matches conditions on its attributes.
Parameters : |
|
---|---|
Returns : |
|
Examples
Return a name for the variable.
Returns the standard_name, long_name (if requested) or netCDF variable name (if requested), whichever it finds first, otherwise returns a default name.
Parameters : | long_name : bool, optional
ncvar : bool, optional
default : str, optional
|
---|---|
Returns : |
|
axes are integers
Set a standard or non-standard CF attribute.
Parameters : |
|
---|---|
Returns : | None |
Examples
>>> f.setattr('standard_name', 'time')
>>> f.setattr('foo', 12.5)
axes are integers
axes are integers
The Data object containing the data array.
Examples
>>> f.Data
<CF Data: >
The Units object containing the units of the data array.
Stores the units and calendar CF attributes in an internally consistent manner. These attributes are mirrored by the units and calendar attributes respectively.
Examples
>>> f.Units
<CF Units: K>
The add_offset CF attribute.
This attribute is only used when writing to a file on disk.
Examples
>>> f.add_offset = -4.0
>>> f.add_offset
-4.0
>>> del f.add_offset
A numpy array deep copy of the data array.
Changing the returned numpy array does not change the data array.
Examples
>>> a = f.array
>>> type(a)
<type 'numpy.ndarray'>
>>> a
array([0, 1, 2, 3, 4])
>>> a[0] = 999
>>> f.array
array([0, 1, 2, 3, 4])
A dictionary of the standard and non-standard CF attributes.
Note that modifying the returned dictionary will not change the attributes.
Examples
>>> f.attributes
{'Conventions': 'CF-1.0',
'_FillValue': 1e+20,
'cell_methods': <CF CellMethods: time: mean>,
'experiment_id': 'stabilization experiment (SRES A1B)',
'long_name': 'Surface Air Temperature',
'standard_name': 'AIR_TEMP',
'title': 'SRES A1B',
'units': 'K'}
The axis CF attribute.
Examples
>>> f.axis = 'Y'
>>> f.axis
'Y'
>>> del f.axis
The calendar CF attribute.
This attribute is a mirror of the calendar stored in the Units attribute.
Examples
>>> f.calendar = 'noleap'
>>> f.calendar
'noleap'
>>> del f.calendar
Numpy data-type of the data array.
Examples
>>> f.dtype
dtype('float64')
The first element of the data array.
Equivalent to f.subset[(0,)*f.ndim].array.item()
Examples
>>> f.array
array([[1, 2],
[3, 4]])
>>> f.first_datum
1
True if and only if the data array is a scalar array.
Examples
>>> f.array
array(2)
>>> f.is_scalar
True
>>> f.array
array([2])
>>> f.is_scalar
False
The last element of the data array.
Equivalent to f.subset[(-1,)*f.ndim].array.item()
Examples
>>> f.array
array([[1, 2],
[3, 4]])
>>> f.first_datum
4
The leap_month CF attribute.
Examples
>>> f.leap_month = 2
>>> f.leap_month
2
>>> del f.leap_month
The leap_year CF attribute.
Examples
>>> f.leap_year = 1984
>>> f.leap_year
1984
>>> del f.leap_year
The long_name CF attribute.
Examples
>>> f.long_name = 'zonal_wind'
>>> f.long_name
'zonal_wind'
>>> del f.long_name
The boolean missing data mask of the data array.
Returned as a Data object. The mask may be set to ‘no missing data’ by deleting the attribute.
Examples
>>> f.shape
(12, 73, 96)
>>> m = f.mask
>>> type(m)
<cf.data.Data>
>>> m.dtype
dtype('bool')
>>> m.shape
[12, 73, 96]
>>> m.array.shape
(12, 73, 96)
>>> del f.mask
>>> f.array.mask
False
>>> import numpy
>>> f.array.mask is numpy.ma.nomask
True
The missing_value CF attribute.
This attribute is forced to be consistent with the _FillValue attribute as follows:
- Assigning a value to the missing_value attribute also assigns the same value to the _FillValue attribute whether the latter has been previously set or not.
- Assigning a value to the _FillValue attribute also assigns the same value to the missing_value attribute, but only if the latter has previously been defined.
Examples
>>> f.missing_value = 1e30
The month_lengths CF attribute.
Number of dimensions in the data array.
Examples
>>> f.shape
(73, 96)
>>> f.ndim
2
The positive CF attribute.
Examples
>>> f.positive = 'up'
>>> f.positive
'up'
>>> del f.positive
The scale_factor CF attribute.
This attribute is only used when writing to a file on disk.
Examples
>>> f.scale_factor = 10.0
>>> f.scale_factor
10.0
>>> del f.scale_factor
Tuple of the data array’s dimension sizes.
Examples
>>> f.shape
(73, 96)
Number of elements in the data array.
Examples
>>> f.shape
(73, 96)
>>> f.size
7008
The standard_name CF attribute.
Examples
>>> f.standard_name = 'time'
>>> f.standard_name
'time'
>>> del f.standard_name
Return a new variable whose data is subsetted.
This attribute may be indexed to select a subset from dimension index values.
Subsetting by indexing
Subsetting by dimension indices uses an extended Python slicing syntax, which is similar numpy array indexing. There are two extensions to the numpy indexing functionality:
Size 1 dimensions are never removed.
An integer index i takes the i-th element but does not reduce the rank of the output array by one.
When advanced indexing is used on more than one dimension, the advanced indices work independently.
When more than one dimension’s slice is a 1-d boolean array 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.
Examples
The units CF attribute.
This attribute is a mirror of the units stored in the Units attribute.
Examples
>>> f.units = 'K'
>>> f.units
'K'
>>> del f.units
The valid_max CF attribute.
Examples
>>> f.valid_max = 100.0
>>> f.valid_max
100.0
>>> del f.valid_max
The valid_min CF attribute.
Examples
>>> f.valid_min = 100.0
>>> f.valid_min
100.0
>>> del f.valid_min
The valid_range CF attribute.
May be set as a numpy array, a list or a tuple. Always returned as a tuple.
Examples
>>> f.valid_range = array([100., 400.])
>>> f.valid_range
(100.0, 400.0)
>>> del f.valid_range
>>> f.valid_range = (50., 450.)
A numpy array view of the data array.
Changing the elements of the returned view changes the data array.
Examples
>>> a = f.varray
>>> type(a)
<type 'numpy.ndarray'>
>>> a
array([0, 1, 2, 3, 4])
>>> a[0] = 999
>>> f.varray
array([999, 1, 2, 3, 4])