def common_mask(ma_list, apply=False):
if type(ma_list) is not list:
print("Input must be list of masked arrays")
return None
#Note: a.mask will return single False if all elements are False
#np.ma.getmaskarray(a) will return full array of False
#ma_list = [np.ma.array(a, mask=np.ma.getmaskarray(a), shrink=False) for a in ma_list]
a = np.ma.array(ma_list, shrink=False)
#Check array dimensions
#Check dtype = bool
#Masked values are listed as true, so want to return any()
#a+b+c - OR (any)
mask = np.ma.getmaskarray(a).any(axis=0)
#a*b*c - AND (all)
#return a.all(axis=0)
if apply:
return [np.ma.array(b, mask=mask) for b in ma_list]
else:
return mask
#This will attempt to remove islands
#Not sure about what happens if the dilation hits the edge of the array
#Should look into binary_closing
#Also, ndimage now has greyscale support for closing holes
#http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.morphology.grey_closing.html
评论列表
文章目录