cf.Field.create_latlon_coordinates

Field.create_latlon_coordinates(*args, **kwargs)[source]

Create latitude and longitude coordinates.

Creates 1-d or 2-d latitude and longitude coordinate constructs that are implied by the Field coordinate reference constructs. By default (or if overwrite is False), new coordinates are only created if the Field doesn’t already include any latitude or longitude coordinates.

Note

Latitude and longitude coordinates can only be created if each relevant coordinate reference construct has a grid_mapping_name parameter set to a valid CF grid mapping name, and this is also the case when there is a crs_wkt parameter. See CF 5.6.1: Use of the CRS Well-known Text Format (https://doi.org/10.5281/zenodo.14274886).

When it is not possible to create latitude and longitude coordinates, the reason why will be reported if the log level is at 2/'INFO' or higher (as set by cf.log_level or the verbose parameter).

If the log level is at 3/'DEBUG'/-1 then information on how the latitude and longitude coordinates were created is also reported.

Added in version 3.20.0.

See also

healpix_to_ugrid

Parameters:
one_d: bool, optional`

If True (the default) then consider creating 1-d latitude and longitude coordinates. If False then 1-d coordinates will not be created.

two_d: bool, optional`

If True (the default) then consider creating 2-d latitude and longitude coordinates. If False then 2-d coordinates will not be created.

longitude_at_pole: None or number

Define the treatment of longitudes of coordinates or coordinate bounds that lie exactly on the north or south pole. If None (the default) then the longitudes of such points are determined by whichever algorithm was used to create the coordinates, which could result in different grid points on a pole having different longitudes. If set to a number, then the longitudes of all grid points on the north or south pole will be given that value.

overwrite: bool, optional

If True then remove any existing latitude and longitude coordinates, prior to attempting to create new ones. If False (the default) then if any latitude or longitude coordinates already exist, new ones will not be created. Note that when overwrite is True and no new coordinates could be created, the returned field will not have any latitude and longitude coordinates.

cache: bool, optional

If True (the default) then cache in memory the first and last values of any newly-created coordinates and bounds. This may greatly speed up, and reduce the memory requirement of, a future inspection of the coordinates and bounds. Even when cache is True, new cached values will only be created if the existing source coordinates (from which the newly-created latitude and longitude coordinates are calculated) have cached first and last values.

inplace: bool, optional

If True then do the operation in-place and return None.

verbose: int or str or None, optional

If an integer from -1 to 3, or an equivalent string equal ignoring case to one of:

  • 'DISABLE' (0)

  • 'WARNING' (1)

  • 'INFO' (2)

  • 'DETAIL' (3)

  • 'DEBUG' (-1)

set for the duration of the method call only as the minimum cut-off for the verboseness level of displayed output (log) messages, regardless of the globally-configured cf.log_level. Note that increasing numerical value corresponds to increasing verbosity, with the exception of -1 as a special case of maximal and extreme verbosity.

Otherwise, if None (the default value), output messages will be shown according to the value of the cf.log_level setting.

Overall, the higher a non-negative integer or equivalent string that is set (up to a maximum of 3/'DETAIL') for increasing verbosity, the more description that is printed to convey information about the operation.

pole_longitude: Deprecated at version 3.21.0

Use longitude_at_pole instead.

Returns:
Field or None

The Field with new latitude and longitude constructs, if any could be created. If the operation was in-place then None is returned.

Examples

>>> f = cf.example_field(12)
>>> print(f)
Field: air_temperature (ncvar%tas)
----------------------------------
Data            : air_temperature(time(2), healpix_index(48)) K
Cell methods    : time(2): mean area: mean
Dimension coords: time(2) = [2025-06-16 00:00:00, 2025-07-16 12:00:00] proleptic_gregorian
                : healpix_index(healpix_index(48)) = [0, ..., 47]
                : height(1) = [1.5] m
Coord references: grid_mapping_name:healpix
>>> g = f.create_latlon_coordinates()
>>> print(g)
Field: air_temperature (ncvar%tas)
----------------------------------
Data            : air_temperature(time(2), healpix_index(48)) K
Cell methods    : time(2): mean area: mean
Dimension coords: time(2) = [2025-06-16 00:00:00, 2025-07-16 12:00:00] proleptic_gregorian
                : healpix_index(48) = [0, ..., 47]
                : height(1) = [1.5] m
Auxiliary coords: latitude(healpix_index(48)) = [19.47122063449069, ..., -19.47122063449069] degrees_north
                : longitude(healpix_index(48)) = [45.0, ..., 315.0] degrees_east
Coord references: grid_mapping_name:healpix