def contour_edges(a):
import matplotlib.pyplot as plt
a = checkma(a)
#Contour nodata value
levels = [a.fill_value]
#kw = {'antialiased':True, 'colors':'r', 'linestyles':'-'}
kw = {'antialiased':True}
#Generate contours around nodata
cs = plt.contour(a.filled(), levels, **kw)
#This returns a list of numpy arrays
#allpts = np.vstack(cs.allsegs[0])
#Extract paths
p = cs.collections[0].get_paths()
#Sort by number of vertices in each path
p_len = [i.vertices.shape[0] for i in p]
p_sort = [x for (y,x) in sorted(zip(p_len,p), reverse=True)]
#cp = p[0].make_compound_path(*p)
return p_sort
#Brute force search for edges of valid data
评论列表
文章目录