geocontour.masksearch module
Functions for finding a mask on a lat/lon grid from an input boundary
- geocontour.masksearch.center(latitudes, longitudes, boundary, precision=1e-05)
Find a mask on a lat/lon grid from an input boundary
Criteria for inclusion of a cell is whether the center of the cell falls within the boundary
- 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
precision (float, default=1e-5) – value by which boundary is expanded, capturing indeterminate points that may fall on/near boundary
- Returns:
mask – 2D MxN bool array where M=len(latitudes) and N=len(longitudes)
- Return type:
ndarray
Notes
Regarding precision: Shapely can’t beat machine precision, and can thus give “incorrect” results for very close points or shapes. The precision input errs on being more inclusive, in particular to capture points falling directly on a boundary. A decent rule is to set the precision value as high as you can without impeding the accuracy. For instance, the default of 1e-5 (degrees) translates to roughly 1m precision at the equator. The buffer can be negated by setting this input very low (to machine precision).
- geocontour.masksearch.center2(latitudes, longitudes, boundary, precision=1e-05)
Find a mask on a lat/lon grid from an input boundary
Criteria for inclusion of a cell is whether the center of the cell falls within the boundary
Functionally identical to center(), but utilizes matplotlib.path functions, which are faster (possibly due to avoidance of overhead in converting to shapely geometries)
- 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
precision (float, default=1e-5) – value by which boundary is expanded, capturing indeterminate points that may fall on/near boundary
- Returns:
mask – 2D MxN bool array where M=len(latitudes) and N=len(longitudes)
- Return type:
ndarray
Notes
Regarding precision: Matplotlib.Path can’t beat machine precision, and can thus give “incorrect” results for very close points or shapes. The precision input errs on being more inclusive, in particular to capture points falling directly on a boundary. A decent rule is to set the precision value as high as you can without impeding the accuracy. For instance, the default of 1e-5 (degrees) translates to roughly 1m precision at the equator. The buffer can be negated by setting this input very low (to machine precision).
- geocontour.masksearch.nodes(latitudes, longitudes, boundary, nodes=2, precision=1e-05)
Find a mask on a lat/lon grid from an input boundary
Criteria for inclusion of a cell is whether a given number of cell nodes (corners) fall within the boundary
- 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
nodes (int, default=2) – number of cell nodes (corners) to use as a criteria for inclusion (1-4)
precision (float, default=1e-5) – value by which boundary is expanded, capturing indeterminate points that may fall on/near boundary
- Returns:
mask – 2D MxN bool array where M=len(latitudes) and N=len(longitudes)
- Return type:
ndarray
Notes
Regarding precision: Shapely can’t beat machine precision, and can thus give “incorrect” results for very close points or shapes. The precision input errs on being more inclusive, in particular to capture points falling directly on a boundary. A decent rule is to set the precision value as high as you can without impeding the accuracy. For instance, the default of 1e-5 (degrees) translates to roughly 1m precision at the equator. The buffer can be negated by setting this input very low (to machine precision).
- geocontour.masksearch.nodes2(latitudes, longitudes, boundary, nodes=2, precision=1e-05)
Find a mask on a lat/lon grid from an input boundary
Criteria for inclusion of a cell is whether a given number of cell nodes (corners) fall within the boundary
Functionally identical to nodes(), but utilizes matplotlib.path functions, which are faster (possibly due to avoidance of overhead in converting to shapely geometries)
- 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
nodes (int, default=2) – number of cell nodes (corners) to use as a criteria for inclusion (1-4)
precision (float, default=1e-5) – value by which boundary is expanded, capturing indeterminate points that may fall on/near boundary
- Returns:
mask – 2D MxN bool array where M=len(latitudes) and N=len(longitudes)
- Return type:
ndarray
Notes
Regarding precision: Matplotlib.Path can’t beat machine precision, and can thus give “incorrect” results for very close points or shapes. The precision input errs on being more inclusive, in particular to capture points falling directly on a boundary. A decent rule is to set the precision value as high as you can without impeding the accuracy. For instance, the default of 1e-5 (degrees) translates to roughly 1m precision at the equator. The buffer can be negated by setting this input very low (to machine precision).
- geocontour.masksearch.area(latitudes, longitudes, boundary, area=0.5)
Find a mask on a lat/lon grid from an input boundary
Criteria for inclusion of a cell is whether the area of the cell enclosed by the boundary is greater than some fraction between 0 and 1
- 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
area (float, default=0.5) – the fraction of the cell enclosed by the boundary to use as a criteria for inclusion (0-1)
- Returns:
mask – 2D MxN bool array where M=len(latitudes) and N=len(longitudes)
- Return type:
ndarray