Bases: cf.variable.Variable
A CF dimension or auxiliary coordinate construct.
The coordinate array’s bounds (if present) are stored in the bounds attribute. The climatology attribute indicates if the bounds are intervals of climatological time.
If the coordinate is connected to a transform construct then a pointer to the transformation is stored in the transform attribute.
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 : |
|
Examples
>>> x = c.dump()
>>> print c.dump()
>>> print c.dump(id='time_coord')
>>> print c.dump(omit=('long_name',))
True if two variables are logically equal, False otherwise.
Parameters : |
|
---|---|
Returns : |
|
Examples
>>> f.equals(f)
True
>>> g = f + 1
>>> f.equals(g)
False
>>> g -= 1
>>> f.equals(g)
True
>>> f.setattr('name', 'name0')
>>> g.setattr('name', 'name1')
>>> f.equals(g)
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 : |
|
Override the data array units in place.
Not to be confused with setting the Units attribute to units which are equivalent to the original units.
This is different to setting the Units attribute, as the new units need not be equivalent to the original ones and the data array elements will not be changed to reflect the new units.
Parameters : |
|
---|---|
Returns : | None |
Examples
>>> f.Units
<CF Units: hPa>
>>> f.first_datum
100000.0
>>> f.override_units('km')
>>> f.Units
<CF Units: km>
>>> f.first_datum
100000.0
>>> f.override_units(cf.Units('watts'))
>>> f.Units
<CF Units: watts>
>>> f.first_datum
100000.0
Set a standard or non-standard CF attribute.
Parameters : |
|
---|---|
Returns : | None |
Examples
>>> f.setattr('standard_name', 'time')
>>> f.setattr('foo', 12.5)
Remove size 1 dimensions from the coordinate’s data array and bounds in place.
Parameters : |
|
---|---|
Returns : | None |
Examples
>>> c.squeeze()
>>> c.squeeze(1)
>>> c.squeeze([1, 2])
Permute the dimensions of the coordinate’s data array and bounds in place.
Parameters : |
|
---|---|
Returns : | None |
Examples
>>> c.transpose()
>>> c.ndim
3
>>> c.transpose([1, 2, 0])
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
>>> c.axis = 'Y'
>>> c.axis
'Y'
>>> del c.axis
The CoordinateBounds object containing the coordinate array’s cell bounds.
Examples
>>> c.bounds
<CF CoordinateBounds: >
The calendar CF attribute.
This attribute is a mirror of the calendar stored in the Units attribute.
Examples
>>> c.calendar = 'noleap'
>>> c.calendar
'noleap'
>>> del c.calendar
Indicator for the coordinate array’s bounds representing climatological time intervals.
If not set then bounds are assumed to not represent climatological time intervals.
Examples
>>> c.climatology = True
>>> c.climatology
True
>>> del c.climatology
The comment CF attribute.
Examples
>>> f.comment = 'a comment'
>>> f.comment
'a comment'
>>> del f.comment
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
The history CF attribute.
Examples
>>> f.history = 'created on 2012/10/01'
>>> f.history
'created on 2012/10/01'
>>> del f.history
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
>>> f.missing_value
1e30
>>> f._FillValue
1e30
>>> del f.missing_value
>>> f._FillValue
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
>>> c.positive = 'up'
>>> c.positive
'up'
>>> del c.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 transform.
The units CF attribute.
This attribute is a mirror of the units stored in the Units attribute.
Examples
>>> c.units = 'degrees_east'
>>> c.units
'degree_east'
>>> del c.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.)
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])