cf.CoordinateReference

class cf.CoordinateReference(name=None, crtype=None, coords=None, coord_terms=None, **kwargs)[source]

Bases: cf.utils.Dict

A CF coordinate reference construct.

A coordinate reference construct relates the field’s coordinate values to locations in a planetary reference frame.

The coordinate reference object is associated with a coordinate system and contains links to the dimension or auxiliary coordinate constructs to which it applies; and any additional terms, such as parameter values and field objects which define a datum and coordinate conversion, i.e. a formula for converting coordinate values taken from the dimension or auxiliary coordinate objects to a different coordinate system.

Accessing terms

The coordinate reference object behaves like a dictionary when it comes to accessing its terms and their values: For example:

>>> c = cf.CoordinateReference('azimuthal_equidistant', 
...                             longitude_of_projection_origin=80.5,
...                             latitude_of_projection_origin=5, 
...                             false_easting=cf.Data(-200, 'km'),
...                             false_northing=cf.Data(-100, 'km'))
>>> c.keys()
['false_easting',
 'latitude_of_projection_origin',
 'false_northing',
 'longitude_of_projection_origin']
>>> c.items()
[('false_easting', <CF Data: -200 km>),
 ('latitude_of_projection_origin', 5),
 ('false_northing', <CF Data: -100 km>),
 ('longitude_of_projection_origin', 80.5)]
>>> c['latitude_of_projection_origin']
5
>>> c['latitude_of_projection_origin'] = -75.25
>>> c['latitude_of_projection_origin']
-75.25

Attributes

Attribute Description
name The identity of the coordinate reference.
type The CF type of the coordinate reference.
coords The identities of the dimension and auxiliary coordinate objects of the which apply to this coordinate reference.
coord_terms The terms of the coordinate conversion which refer to dimension or auxiliary coordinate objects.

Initialization

Parameters:
name : str, optional

A name which describes the nature of the coordinate conversion. This is usually a CF grid_mapping name or the standard name of a CF dimensionless vertical coordinate, but is not restricted to these.

Example: To create a polar stereographic coordinate reference: name='polar_stereographic'. To create coordinate reference for an ocean sigma over z coordinate: name='ocean_sigma_z_coordinate'. To create new type of coordinate reference: name='my_new_type'.

crtype : str, optional

The CF type of the coordinate reference. This is either 'grid_mapping' or 'formula_terms'. By default the type is inferred from the name, if possible. For example:

>>> c = cf.CoordinateReference('transverse_mercator')
>>> c.type
'grid_mapping'
>>> c = cf.CoordinateReference('my_new_type')
>>> print c.type
None
>>> c = cf.CoordinateReference('my_new_type', crtype='formula_terms')
>>> c.type
'formula_terms'
coords : sequence of str, optional

Identify the dimension and auxiliary coordinate objects which apply to this coordinate reference. By default the standard names of those expected by the CF conventions are used. For example:

>>> c = cf.CoordinateReference('transverse_mercator')
>>> c.coords
{'latitude', 'longitude', 'projection_x_coordinate', 'projection_y_coordinate'}
>>> c = cf.CoordinateReference('transverse_mercator', coords=['ncvar:lat'])
>>> c.coords
{'ncvar:lat'}
coord_terms : sequence of str, optional

The terms of the coordinate conversion which refer to dimension or auxiliary coordinate objects. For example:

>>> c = cf.CoordinateReference('lambert_conformal_conic')
>>> c.coord_terms
set()
>>> c = cf.CoordinateReference('atmosphere_hybrid_height_coordinate',
...                            coord_terms=['a', 'b'])
>>> c.coord_terms
{'a', 'b'}
kwargs : optional

The terms of the coordinate conversion and their values. A term’s values may be one of the following:

  • A number or size one numeric array.
  • A string containing a coordinate object’s identity.
  • A Field.
  • None, indicating that the term exists but is unset.

For example:

>>> c = cf.CoordinateReference('orthographic', 
...                            grid_north_pole_latitude=70,
...                            grid_north_pole_longitude=cf.Data(120, 'degreesE'))
>>> c['grid_north_pole_longitude']
<CF Data: 120 degreesE>
>>> orog_field
<CF Field: surface_altitude(latitude(73), longitude(96)) m>
>>> c = cf.CoordinateReference('atmosphere_hybrid_height_coordinate',
...                            a='long_name:ak',
...                            b='long_name:bk',
...                            orog=orog_field)

CoordinateReference attributes

T Returns False.
X Returns False.
Y Returns False.
Z Returns False.

CoordinateReference methods

change_coord Change a link to a dimension or auxiliary coordinate object.
close Close all files referenced by coordinate conversion term values.
dump Return a string containing a full description of the coordinate reference.
equals True if two instances are equal, False otherwise.
equivalent True if two coordinate references are logically equal, False otherwise.
identity Return the identity of the coordinate reference.
match Test whether or not the coordinate reference satisfies the given conditions.
remove_all_coords Remove all links to coordinate objects.
set
setcoord

CoordinateReference class methods

canonical_units Return the canonical units for a standard CF coordinate conversion term.
default_value Return the default value for an unset standard CF coordinate conversion term.

CoordinateReference dict-like methods

These methods provide functionality similar to that of a built-in dict.

Undocumented methods behave exactly as their counterparts in a built-in dict.

clear
get
has_key
items
iteritems
iterkeys
itervalues
keys
pop
popitem
setdefault
update
values