wells = [
[
[0, 0.4, 'descroption_1'],
[0.4, 0.8, 'descroption_2'],
[0.8, 1.2, 'descroption_3'],
[1.2, 2, 'descroption_4'],
[2, 2.4, 'descroption_5']
],
[
[0, 0.4, 'descroption_1'],
[0.4, 1.6, 'descroption_4'],
[1.6, 2, 'descroption_6'],
[2, 3.2, 'descroption_7'],
[3.2, 3.6, 'базальты']
]
]
def merge_wells(well1, well2):
merged_well = []
for interval1 in well1:
for interval2 in well2:
start1, end1, description1 = interval1
start2, end2, description2 = interval2
if description1 == description2:
if [start1, start2] not in merged_well:
merged_well.append([start1, start2])
if [end1, end2] not in merged_well:
merged_well.append([end1, end2])
现在我的代码使用相同的描述连接第一个和第二个列表的范围。
输出如下所示:
[0, 0]
[0.4, 0.4]
[1.2, 0.4]
[2, 1.6]
[2, 3.2]
[2.4, 3.6]
我需要编写一个条件来显示如何将间隔与不同的描述连接起来
结果应该是这样的:
[0, 0]
[0.4, 0.4]
[0.8, 0.4]
[1.2, 0.4]
[2, 1.6]
[2, 2]
[2, 3.2]
[2.4, 3.6].
elif description1 != description2 and start1 <= start2 and end1 == end2:
merged_well.append([end1, end2])
我使用了这个条件并且它适用于这个数据。但对于其他数据,输出已经不正确
您永远不会真正指定哪些间隔连接到哪个其他间隔。我做了一些简化的假设,并假设我们将根据
description
字段连接按字母顺序相邻的间隔。看起来像这样:
wells = [
[
[0, 0.4, 'descroption_1'],
[0.4, 0.8, 'descroption_2'],
[0.8, 1.2, 'descroption_3'],
[1.2, 2, 'descroption_4'],
[2, 2.4, 'descroption_5']
],
[
[0, 0.4, 'descroption_1'],
[0.4, 1.6, 'descroption_4'],
[1.6, 2, 'descroption_6'],
[2, 3.2, 'descroption_7'],
[3.2, 3.6, 'базальты']
]
]
def merge_wells(well1, well2):
merged_well = []
descriptions = dict()
for interval in well1:
start, end, description = interval
if description not in descriptions:
descriptions[description] = [start, end]
lowest, highest = descriptions[description]
lowest = min(lowest, start)
highest = max(end, highest)
descriptions[description] = [lowest, highest]
for interval in well2:
start, end, description = interval
if description not in descriptions:
descriptions[description] = [start, end]
lowest, highest = descriptions[description]
lowest = min(lowest, start)
highest = max(end, highest)
descriptions[description] = [lowest, highest]
cur = 0
for k, v in descriptions.items():
merged_well.append([cur, v[0]])
cur = v[1]
return merged_well
print(merge_wells(wells[0], wells[1]))
请注意,这将产生与您提供的预期输出不同的输出,但同样这是因为我无法确定您打算连接哪些间隔以及如何连接。