我试图识别地球仪上的连接特征(即在球体上的时空中)。cc3d包已经让我完成了90%的工作,但是我很难处理日期边界(即三维中的一个周期性边界条件)。
在2DMap上,我的方法的问题变得明显(注意,在南极附近的0经度周围连接的购买不同标记的区域):
这是因为数据是在经度0到360之间定义的(而我在这里显示的是从-180到180,以使问题更加明显)。
对于这类问题,我的两个典型解决方案都不起作用:
- 将逆子午线翻转到太平洋只是将问题转移,因此没有帮助。
- 在右侧边界连接数据的副本也没有帮助,因为它会导致原始左侧和右侧粘贴数据之间的标签不明确
MWE
问题的二维分解应如下:
import cc3d
import numpy as np
import matplotlib.pyplot as plt
arr = np.sin(np.random.RandomState(0).randn(100).reshape(10, 10)) > .3
labels = cc3d.connected_components(arr)
map = plt.pcolormesh(labels, vmin=.5)
map.cmap.set_under('none')
在这里,右上角的黄色结构应该连接到顶部结构的其余部分,底部的两个结构也是如此。请记住,任何有用的解决方案也应该适用于三维中的连接特征。
任何关于如何处理这一点的帮助都很感激。
1条答案
按热度按时间44u64gxh1#
好的,我有一个输出的修复。它相当慢,需要运行
connected_components
两次,但对我来说很有效。我把它放在这里,以防以后对任何人有帮助。我将在这里修复MWE,但它等效于完整的3D时空数据(每天独立)。**我处理的数据的约定是经度是最后一个维度,所以(time,latitude,longitude)但它被绘制在x轴上,因此我对MWE示例中的所有函数调用都执行
swapaxes
。功能
在重新排列的字段上再次运行元件标签,然后再次重新排列:
固定标签:
注意,在固定数组中,标签将不再严格连续!