Bases: cf.variable.Variable
A CF coordinate construct.
Refer to the Variable and Field classes and the cf package for details.
Reserved public attributes:
In addition to the reserved public attributes inherited from the Variable class, the following are also reserved public attributes:
Attribute | Description |
---|---|
axis | As in the CF convention. |
positive | As in the CF convention. |
Reserved attributes:
In addition to the reserved attributes inherited from the Variable class, the following attributes have special definitions and it is recommended to set them accordingly.
Attribute | Description |
---|---|
bounds | The coordinate’s CoordinateBounds object. |
climatology | An indicator to specify if the coordinate’s bounds are intervals of climatological time. |
transform | A pointer to the coordinate’s Transform object. |
Initialization
Parameters : |
|
---|
return new variable containing binary mask
Return a deep copy.
Equivalent to copy.deepcopy(c)
Returns : |
|
---|
Examples
>>> d = c.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 coordinate.
Parameters: |
|
---|---|
Returns: | A string containing the description of the coordinate. |
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 : |
|
Return True if a 1-d monotonic coordinate is increasing, otherwise return False.
Examples
>>> c.array
array([ 0 30 60])
>>> c.find_direction()
True
>>> c.array
array([15])
>>> c.bounds.array
array([ 30 0])
>>> c.find_direction()
False
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 : |
|
Set a standard or non-standard CF attribute.
Parameters : |
|
---|---|
Returns : | None |
Examples
>>> f.setattr('standard_name', 'time')
>>> f.setattr('foo', 12.5)
The Data object containing the data array.
Examples
>>> f.Data
<CF Data: >
The Units object containing the units of the data array.
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 coordinate’s bounds object.
The calendar CF attribute.
Indicator of whether or not the coordinate’s bounds represent climatological time intervals.
Examples
>>> c.climatology = True
>>> c.climatology
True
>>> del c.climatology
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 coordinate whose data and bounds are subsetted in a consistent manner.
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
Pointer to coordinate’s transfrom.
The units CF attribute.
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.)
Return a numpy view of the data.
Making changes to elements of the returned view changes the underlying data. Refer to numpy.ndarray.view.
Examples
>>> a = c.varray
>>> type(a)
<type 'numpy.ndarray'>
>>> a
array([0, 1, 2, 3, 4])
>>> a[0] = 999
>>> c.varray
array([999, 1, 2, 3, 4])