geocontour.maskutil module
Utility functions for operations involving masks and mask searches
- geocontour.maskutil.bbox(latitudes, longitudes, boundary)
Check input dimensions (lat/lon) against input boundary and return min/max indicies of bounding box
Mainly used internally for mask search functions
- Parameters:
latitudes (ndarray) – 1D Nx1 array of latitude points (degrees)
longitudes (ndarray) – 1D Nx1 array of longitude points (degrees)
boundary (ndarray) – 2D Nx2 array of latitude/longitude points (degrees) with the last point equal to the first
- Returns:
boxlatmin (int) – the minimum bounding box latitude index
boxlatmax (int) – the maximum bounding box latitude index
boxlonmin (int) – the minimum bounding box longitude index
boxlonmax (int) – the maximum bounding box longitude index
- geocontour.maskutil.edge(mask, latitudes=None, longitudes=None, connectivity=8)
Find a mask’s edge cells only, and optionally an array of the edge cells
- Parameters:
mask (ndarray) – 2D MxN bool array where M=len(latitudes) and N=len(longitudes)
latitudes (ndarray, optional) – 1D Nx1 array of latitude points (degrees)
longitudes (ndarray, optional) – 1D Nx1 array of longitude points (degrees)
connectivity ({4, 8}, default=8) –
connectivity parameter for finding edge cells
4test only lateral neighbors
8test lateral and diagonal neighbors
- Returns:
edgemask (ndarray) – 2D bool array of the same dimensions as mask input
edgecells (ndarray, optional) – 2D Nx2 bool array of latitude/longitude points (degrees) of edge cells (unordered), where N is number of edge cells
Notes
edgecells only returned if optional parameters latitudes and longitudes are provided
- geocontour.maskutil.vertex(mask, latitudes, longitudes)
Find the vertex points of all cells in a mask, and the vertex points of only the mask edge
- Parameters:
mask (ndarray) – 2D MxN bool array where M=len(latitudes) and N=len(longitudes)
latitudes (ndarray, optional) – 1D Nx1 array of latitude points (degrees)
longitudes (ndarray, optional) – 1D Nx1 array of longitude points (degrees)
- Returns:
vertexpoints (ndarray) – 2D Nx2 array of latitude/longitude points (degrees) of all vertices of mask cells
edgevertexpoints (ndarray) – 2D Nx2 array of latitude/longitude points (degrees) of all vertices of cells at the mask edge (8-connected)
- geocontour.maskutil.neighbors(cell, connectivity=8, direction='cw')
Find the neighbors of a cell, with selected connectivity and direction
- Parameters:
cell (ndarray) – 1x2 numpy array describing the indices of the cell
connectivity ({4, 8}, default=8) –
connectivity parameter for finding neighbor cells
4test only lateral neighbors
8test lateral and diagonal neighbors
direction ({'cw', 'ccw'}, default='cw') – select the direction of the returned neighbors
- Returns:
neighbors – 8x2 or 4x2 array of the neighboring cell indices for the input cell
- Return type:
ndarray
See also
- geocontour.maskutil.conn(mask, checkcells='full', connectivity=8)
Determine whether a mask or its inverse are connected
- Parameters:
mask (ndarray) – 2D MxN bool array where M=len(latitudes) and N=len(longitudes)
checkcells ({'full', 'empty'}, default='full') – select the mask cells to test (‘empty’ would select the mask inverse)
connectivity ({4, 8}, default=8) –
connectivity parameter for testing connectivity
4test only lateral neighbors
8test lateral and diagonal neighbors
- Returns:
connected – descriptor for whether the input mask is connected under the input conditions
- Return type:
bool