def endmembers_by_query(rast, query, gt, wkt, dd=False):
'''
Returns a list of endmember locations based on a provided query, e.g.:
> query = rast[1,...] < -25 # Band 2 should be less than -25
> endmembers_by_query(rast, query, gt, wkt)
Arguments:
rast The raster array to find endmembers within
query A NumPy boolean array representing a query in the feature space
gt The GDAL GeoTransform
wkt The GDAL WKT projection
dd True for coordinates in decimal degrees
'''
assert isinstance(rast, np.ndarray), 'Requires a NumPy array'
shp = rast.shape
idx = np.indices((shp[-2], shp[-1]))
# Execute query on the indices (pixel locations), then return the coordinates
return list(pixel_to_xy([
(x, y) for y, x in idx[:,query].T
], gt, wkt, dd=dd))
评论列表
文章目录