Miscellaneous cartopy utilities¶
This module contains utilities that are useful in conjunction with cartopy.
-
cartopy.util.
add_cyclic_point
(data, coord=None, axis=-1)[source]¶ Add a cyclic point to an array and optionally a corresponding coordinate.
Args:
- data:
An n-dimensional array of data to add a cyclic point to.
Kwargs:
- coord:
A 1-dimensional array which specifies the coordinate values for the dimension the cyclic point is to be added to. The coordinate values must be regularly spaced.
- axis:
Specifies the axis of the data array to add the cyclic point to. Defaults to the right-most axis.
Returns:
- cyclic_data:
The data array with a cyclic point added.
- cyclic_coord:
The coordinate with a cyclic point, only returned if the coord keyword was supplied.
Examples:
Adding a cyclic point to a data array, where the cyclic dimension is the right-most dimension
>>> import numpy as np >>> data = np.ones([5, 6]) * np.arange(6) >>> cyclic_data = add_cyclic_point(data) >>> print(cyclic_data) [[ 0. 1. 2. 3. 4. 5. 0.] [ 0. 1. 2. 3. 4. 5. 0.] [ 0. 1. 2. 3. 4. 5. 0.] [ 0. 1. 2. 3. 4. 5. 0.] [ 0. 1. 2. 3. 4. 5. 0.]]
Adding a cyclic point to a data array and an associated coordinate
>>> lons = np.arange(0, 360, 60) >>> cyclic_data, cyclic_lons = add_cyclic_point(data, coord=lons) >>> print(cyclic_data) [[ 0. 1. 2. 3. 4. 5. 0.] [ 0. 1. 2. 3. 4. 5. 0.] [ 0. 1. 2. 3. 4. 5. 0.] [ 0. 1. 2. 3. 4. 5. 0.] [ 0. 1. 2. 3. 4. 5. 0.]] >>> print(cyclic_lons) [ 0 60 120 180 240 300 360]