geocontour.contourutil module
Utility functions for operations involving contours and contour searches
- geocontour.contourutil.findstart(mask, searchdir='ru')
Find starting cell for contour, given a mask and a search criteria
- Parameters:
mask (ndarray) – 2D MxN bool array where M=len(latitudes) and N=len(longitudes)
searchdir ({'dr', 'ul', 'ru', 'ld', 'dl', 'ur', 'rd', 'lu'}) –
2 char string describing the search directions [e.g. ‘dr’ will search rows moving downward and columns moving rightward, in that order]
- for a desired clockwise search:
{‘dr’, ‘ul’, ‘ru’, ‘ld’}
- for a desired counterclockwise search:
{‘dl’, ‘ur’, ‘rd’, ‘lu’}
- Returns:
startcell (ndarray) – 1x2 array containing the indices of the start cell
startorientation (ndarray) – 1x2 array describing the orientation (entry direction) of the start cell
See also
- geocontour.contourutil.parsestart(start, buffermask)
Check start input for contour tracing
Mainly used internally for contour trace functions
- Parameters:
start (array_like) –
2x2 array describing the start cell and orientation
- row 1: indices of the start cell
e.g. for start cell [2,3] second row (lat) and third column (lon)
- row 2: the start orientation
e.g. orientation [0,1] points right, [1,0] points down
buffermask (ndarray) – 2D M+1xN+1 bool array where M=len(latitudes) and N=len(longitudes)
- Returns:
startcell (ndarray) – 1x2 array containing the indices of the start cell
startorientation (ndarray) – 1x2 array describing the orientation (entry direction) of the start cell
See also
- geocontour.contourutil.setstop(stop, startvisits, startcell, startorientation)
Create a stopping function for use in contour tracing while loop
Mainly used internally for contour trace functions
- Parameters:
stop ({'Elisoff', 'Nvisits', 'either'}, default='either') –
selector for the stopping criterion
Elisoffstops when the start cell has been re-visited with the same orientation as started with
Nvisitsstops when the start cell has been re-visited N number of times (N set by startvisits parameter)
eitherstops when either Elisoff or Nvisits has been satisfied
startvisits (int, default=3) – the number of times re-visiting the start cell will trigger an end to the search
startcell (ndarray) – 1x2 array containing the indices of the start cell
startorientation (ndarray) – 1x2 array describing the orientation (entry direction) of the start cell
- Returns:
checkbreak – stopping function that takes a cell, orientation, and start visit counter as input
- Return type:
function
See also
Notes
startvisits parameter will only be utilized when stop parameter is set to ‘Nvisits’ or ‘either’
- geocontour.contourutil.clean(contourcells, searchcells, latitudes=None, longitudes=None, closecontour=True, remcontourrepeat=True, remsearchrepeat=False)
Returns a cleaned contour that will pass checks
Mainly used internally for contour trace functions
- Parameters:
contourcells (array_like) – list of 1x2 numpy arrays containing contour indices
searchcells (array_like) – list of 1x2 numpy arrays containing contour search indices
latitudes (ndarray, optional) – 1D Nx1 array of latitude points (degrees)
longitudes (ndarray, optional) – 1D Nx1 array of longitude points (degrees)
remcontourrepeat (bool, default=True) – select whether to remove consecutive repeating cells in the output contour
remsearchrepeat (bool, default=False) – select whether to remove consecutive repeating cells in the output contoursearch
closecontour (bool, default=True) – select whether to close the output contour (first cell = last cell)
- Returns:
contour (ndarray) – 2D Nx2 array of ordered latitude/longitude points (degrees) describing the edge of a mask
contoursearch (ndarray) – 2D Nx2 array of ordered latitude/longitude points (degrees) describing the cells searched during contour tracing
Notes
If latitudes/longitudes not provided, returned contour/contoursearch will be indices of the input mask
- geocontour.contourutil.fancysearch(contoursearch, contraction=0.2, shift=0.25)
Create a contour search that is visually more easy to follow via:
contraction, which ranges from 0 (no change) to 0.5 (completely flattened to contour cell edges)
shift, which ranges from 0 (no change) to 0.5 (half a grid cell)
- Parameters:
contoursearch (ndarray) – 2D Nx2 array of ordered latitude/longitude points (degrees) describing the cells searched during contour tracing
contraction (float, default=0.2) – value determining how much contoursearch “shrinks” towards contour cell edges
shift (float, default=0.25) – value determining how much contoursearch “shifts” to avoid doubling back on itself
- Returns:
fancycontoursearch – 2D Nx2 array of ordered latitude/longitude points describing the cells searched during contour tracing, with contraction and shift applied
- Return type:
ndarray
See also