ugrid classes
set of classes for working with unstructured model grids
The “ugrid” class is the base class: it stores everything in memory
It can read from and write to netcdf files in the UGRID format.
It may be able to reference a netcdf file at some point, rather than storing directly in memory.
NOTE: only tested for triangular and quad mesh grids at the moment.
NOTE: This code has been extracted from the pull request by @Chilipp to the gridded package, at https://github.com/NOAA-ORR-ERD/gridded/pull/62/. Gridded is licensed under the Unlicense.
Classes:
|
A basic class to hold an unstructured grid as defined in the UGrid convention. |
- class psy_ugrid.ugrid.UGrid(nodes=None, node_lon=None, node_lat=None, faces=None, edges=None, boundaries=None, face_face_connectivity=None, face_edge_connectivity=None, edge_coordinates=None, face_coordinates=None, boundary_coordinates=None, data=None, mesh_name='mesh', edge_face_connectivity=None, edge_orientation=None)
Bases:
object
A basic class to hold an unstructured grid as defined in the UGrid convention.
The internal structure mirrors the netcdf data standard.
Attributes:
summary of information about the grid
Maximum number of vertices in a face.
Methods:
Builds the boundary segments from the cell array.
Builds the boundary_coordinates array, using the average of the nodes defining each boundary segment.
Builds the edge_coordinates array, using the average of the nodes defining each edge.
Build the edge_face_connectivity
Builds the edges array: all the edges defined by the faces
Builds the face_coordinates array, using the average of the nodes defining each face.
Builds the face-edge connectivity array
Builds the face_face_connectivity array: giving the neighbors of each cell.
create_dual_mesh
([location])Create the dual mesh for edge or nodes.
Get the orientation for each edge in the corresponding face
infer_location
(data[, axis])- param data:
- property boundaries
- build_boundaries()
Builds the boundary segments from the cell array.
It is assumed that -1 means no neighbor, which indicates a boundary
This will over-write the existing boundaries array if there is one.
This is a not-very-smart just loop through all the faces method.
- build_boundary_coordinates()
Builds the boundary_coordinates array, using the average of the nodes defining each boundary segment.
Note that you may want a different definition of the boundary coordinates than this computes, but this is here to have an easy default.
This will write-over an existing face_coordinates array
Useful if you want this in the output file
- build_edge_coordinates()
Builds the edge_coordinates array, using the average of the nodes defining each edge.
Note that you may want a different definition of the edge coordinates than this computes, but this is here to have an easy default.
This will write-over an existing edge_coordinates array
Useful if you want this in the output file
- build_edge_face_connectivity()
Build the edge_face_connectivity
The edge_face_connectivity is the mapping from each edge in the
edges
to the attached face in faces.
- build_edges()
Builds the edges array: all the edges defined by the faces
This will replace the existing edge array, if there is one.
NOTE: arbitrary order – should the order be preserved?
- build_face_coordinates()
Builds the face_coordinates array, using the average of the nodes defining each face.
Note that you may want a different definition of the face coordinates than this computes, but this is here to have an easy default.
This will write-over an existing face_coordinates array.
Useful if you want this in the output file.
- build_face_edge_connectivity()
Builds the face-edge connectivity array
- build_face_face_connectivity()
Builds the face_face_connectivity array: giving the neighbors of each cell.
Note: arbitrary order and CW vs CCW may not be consistent.
- create_dual_mesh(location='edge')
Create the dual mesh for edge or nodes.
This method creates the dual mesh, either specified through the nodes, or specified through the edges. For a Delaunay triangulation case with
location == "node"
, this is commonly known as Voronoi Polygons.- :param location=”edge”the source for the dual mash. can be one of
"node"
or"edge"
- Returns:
A
UGrid
with nodes and faces of the dual mesh.
- property edges
- property face_edge_connectivity
- property face_face_connectivity
- property faces
- get_face_edge_orientation()
Get the orientation for each edge in the corresponding face
This method returns an array with the same shape as
faces
that is one if the corresponding edge has the same orientation as inedges
, and -1 otherwise
- get_lines()
- infer_location(data, axis=-1)
- Parameters:
data –
axis –
- Returns:
‘nodes’ if data will fit to the nodes, ‘faces’ if the data will fit to the faces, ‘boundaries’ if the data will fit the boundaries. None otherwise.
If data is a netcdf variable, the “location” attribute is checked.
- property info
summary of information about the grid
- property node_lat
- property node_lon
- property nodes
- property num_vertices
Maximum number of vertices in a face.