cf.Domain.transpose

Domain.transpose(axes, inplace=False)[source]

Permute the data axes of the metadata constructs.

Each metadata construct has its data axis order changed to the relative ordering defined by the axes parameter. For instance, if the given axes are ['X', 'Z', 'Y'] then a metadata construct whose data axis order is ('Y', 'X') will be transposed to have data order ('X', 'Y').

New in version 3.11.0.

See also

domain_axis, flip

Parameters
axes: sequence of str

Define the new domain axis order.

A domain axis is identified by that which would be selected by passing a given axis description to a call of the domain_axis method. For example, a value of 'X' would select the domain axis construct returned by f.domain_axis('X').

Each domain axis of the domain construct data must be specified.

constructs: bool, optional

If True then metadata constructs are also transposed so that their axes are in the same relative order as in the transposed data array of the field. By default metadata constructs are not altered.

inplace: bool, optional

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

Returns
Domain or None

The domain construct with transposed constructs, or None if the operation was in-place.

Examples

>>> d = cf.example_field(7).domain
>>> print(d)
Dimension coords: time(3) = [1979-05-01 12:00:00, 1979-05-02 12:00:00, 1979-05-03 12:00:00] gregorian
                : air_pressure(1) = [850.0] hPa
                : grid_latitude(4) = [0.44, ..., -0.88] degrees
                : grid_longitude(5) = [-1.18, ..., 0.58] degrees
Auxiliary coords: latitude(grid_latitude(4), grid_longitude(5)) = [[52.4243, ..., 51.1163]] degrees_north
                : longitude(grid_latitude(4), grid_longitude(5)) = [[8.0648, ..., 10.9238]] degrees_east
Coord references: grid_mapping_name:rotated_latitude_longitude
>>> print(d.transpose(['X', 'T', 'Y', 'Z']))
Dimension coords: time(3) = [1979-05-01 12:00:00, 1979-05-02 12:00:00, 1979-05-03 12:00:00] gregorian
                : air_pressure(1) = [850.0] hPa
                : grid_latitude(4) = [0.44, ..., -0.88] degrees
                : grid_longitude(5) = [-1.18, ..., 0.58] degrees
Auxiliary coords: latitude(grid_longitude(5), grid_latitude(4)) = [[52.4243, ..., 51.1163]] degrees_north
                : longitude(grid_longitude(5), grid_latitude(4)) = [[8.0648, ..., 10.9238]] degrees_east
Coord references: grid_mapping_name:rotated_latitude_longitude