cfdm.DomainTopology.sort¶
- DomainTopology.sort()[source]¶
Sort the domain topology node ids.
Only edge and point domain topologies can be sorted.
Sorting is across both array dimensions. In general, dimension 1 is sorted first, and then dimension 0 is sorted by the values in the first column.
For an edge domain topology, the second column is also sorted within each unique first column value.
For a point dimension topology, the first column is omitted from the dimension 1 sort (because it contains the node id definition for each row).
See the examples for more details.
Note
The purpose of this method is to facilitate the comparison of normalised domain topologies, to see if they belong to the same UGRID mesh. The sorted domain topology will, in general, be inconsistent with other metadata, such as the node geo-locations stored as domain cell coordinates or cell bounds. For this reason,
sortis not allowed to occur in-place.Added in version (cfdm): 1.13.1.0
- Returns:
DomainTopologyThe sorted domain topology construct.
Examples
>>> f = cfdm.example_field(9) >>> print(f) Field: northward_wind (ncvar%v) ------------------------------- Data : northward_wind(time(2), ncdim%nMesh2_edge(9)) ms-1 Cell methods : time(2): point (interval: 3600 s) Dimension coords: time(2) = [2016-01-02 01:00:00, 2016-01-02 11:00:00] gregorian Auxiliary coords: longitude(ncdim%nMesh2_edge(9)) = [-41.5, ..., -43.0] degrees_east : latitude(ncdim%nMesh2_edge(9)) = [34.5, ..., 32.0] degrees_north Topologies : cell:edge(ncdim%nMesh2_edge(9), 2) = [[1, ..., 5]] Connectivities : connectivity:node(ncdim%nMesh2_edge(9), 6) = [[0, ..., --]] >>> dt = f.domain_topology() >>> print(dt.array) [[1 6] [3 6] [3 1] [0 1] [2 0] [2 3] [2 4] [5 4] [3 5]] >>> print(dt.sort().array) [[0 1] [0 2] [1 3] [1 6] [2 3] [2 4] [3 5] [3 6] [4 5]]
>>> f = cfdm.example_field(10) >>> print(f) Field: air_pressure (ncvar%pa) ------------------------------ Data : air_pressure(time(2), ncdim%nMesh2_node(7)) hPa Cell methods : time(2): point (interval: 3600 s) Dimension coords: time(2) = [2016-01-02 01:00:00, 2016-01-02 11:00:00] gregorian Auxiliary coords: longitude(ncdim%nMesh2_node(7)) = [-45.0, ..., -40.0] degrees_east : latitude(ncdim%nMesh2_node(7)) = [35.0, ..., 34.0] degrees_north Topologies : cell:point(ncdim%nMesh2_node(7), 5) = [[0, ..., --]] >>> dt = f.domain_topology() >>> dt = dt[::-1] >>> print(dt.array) [[6 3 1 -- --] [5 4 3 -- --] [4 2 5 -- --] [3 2 1 5 6] [2 0 3 4 --] [1 6 0 3 --] [0 1 2 -- --]] >>> print(dt.sort().array) [[0 1 2 -- --] [1 0 3 6 --] [2 0 3 4 --] [3 1 2 5 6] [4 2 5 -- --] [5 3 4 -- --] [6 1 3 -- --]]