pygplates专栏——Sample code——Rotation

pygplates专栏——Sample code——Rotation

  • Hierarchy of plate rotations
    • 示例代码
  • plate circuits to anchored plate
    • 示例代码
  • modify a reconstruction pole
    • 示例代码

Hierarchy of plate rotations

本示例遍历板块运动层级(某个特定重建时间),并输出每个板块同级的和相关的运动轨迹

示例代码

import pygplates

# 自定义函数:遍历某个板块的子集
def traverse_sub_tree(edge, depth):
    relative_total_rotation = edge.get_relative_total_rotation()
    relative_pole_latitude, relative_pole_longitude, relative_angle_degrees = (
        relative_total_rotation.get_lat_lon_euler_pole_and_angle_degrees()
    )
    equivalent_total_rotation = edge.get_equivalent_total_rotation()
    equivalent_pole_latitude, equivalent_pole_longitude, equivalent_angle_degrees = (
        equivalent_total_rotation.get_lat_lon_euler_pole_and_angle_degrees()
    )
    prefix_padding = " " * (2*depth)
    print(" %s Plate ID: %d, Fixed Plate ID: %d: " % (prefix_padding, edge.get_moving_plate_id(), edge.get_fixed_plate_id()))
    print(" %s Rotation rel. fixed (parent) plate: lat: %f, lon: %f, angle %f" % (
        prefix_padding, relative_pole_latitude, relative_pole_longitude, relative_angle_degrees
    ))
    print(" %s Equivalent rotation rel. anchored plate: lat: %f, lon: %f, angle: %f" % (
        prefix_padding, equivalent_pole_latitude, equivalent_pole_longitude, equivalent_angle_degrees
    ))
    print("")
    # 递归到子元素的子集
    for child_edge in edge.get_child_edges():
        traverse_sub_tree(child_edge, depth + 1)

# 加载一个板块运动模型
rotation_model = pygplates.RotationModel("Muller2019-Young2019-Cao2020_CombinedRotations.rot")
# 设置重建时间
reconstruction_time = 60
# 获取重建树形
reconstruction_tree = rotation_model.get_reconstruction_tree(reconstruction_time)
# 获取重建树的边界
anchor_plate_edges = reconstruction_tree.get_anchor_plate_edges()
# 遍历
for anchor_plate_edge in anchor_plate_edges:
    traverse_sub_tree(anchor_plate_edge, 0)

plate circuits to anchored plate

本实例将实现查找所有板块在特定时间与锚定板块的连接路径

示例代码

import pygplates

# 加载板块运动模型
rotation_model = pygplates.RotationModel("Muller2019-Young2019-Cao2020_CombinedRotations.rot")
# 设置重建时间
reconstruction_time = 60
# 获取重建树
reconstruction_tree = rotation_model.get_reconstruction_tree(reconstruction_time)
# 获取重建树的所有边界
all_edges = reconstruction_tree.get_edges()
# 遍历
for edge in all_edges:
    print("Plate ID: %d:" % edge.get_moving_plate_id())
    # 查找从当前板块抵达锚定板块的板块路径
    edge_in_circuit = edge
    while edge_in_circuit:
        relative_total_rotation = edge_in_circuit.get_relative_total_rotation()
        relative_pole_latitude, relative_pole_longitude, relative_angle_degrees = (
            relative_total_rotation.get_lat_lon_euler_pole_and_angle_degrees()
        )
        equivalent_total_rotatioin = edge_in_circuit.get_equivalent_total_rotation()
        equivalent_pole_latitude, equivalent_pole_longitude, equivalent_angle_degrees = (
            equivalent_total_rotatioin.get_lat_lon_euler_pole_and_angle_degrees()
        )
        print(" Plate ID: %d, Fixed Plate ID: %d:" % (
            edge_in_circuit.get_moving_plate_id(), edge_in_circuit.get_fixed_plate_id()
        ))
        print(" Rotation rel. fixed (parent) plate: lat: %f, lon: %f:, angle: %f" % (
            relative_pole_latitude, relative_pole_longitude, relative_angle_degrees
        ))
        print(" Equivalent rotation rel. anchored plates: lat: %f, lon: %f:, angle: %f" % (
            equivalent_pole_latitude, equivalent_pole_longitude, equivalent_angle_degrees
        ))
        print("")
        edge_in_circuit = edge_in_circuit.get_parent_edge()

modify a reconstruction pole

  • 读取板块运动文件
  • 修改整体的重建极点,使得重构点在特定重构时间与其期望位置重合,并且
  • 保存修改到板块运动文件

示例代码

import pygplates
import sys

# 板块运动模型
rotation_filenames = ["Muller2019-Young2019-Cao2020_CombinedRotations.rot"]
# 需要修改板块运动的重建时间
reconstruction_time = pygplates.GeoTimeInstant(60)
# 需要修改的板块ID
reconstruction_plate_id = 801
# 当今的点坐标
present_day_latitude = -20
present_day_longitude = 135
present_day_position = pygplates.PointOnSphere(present_day_latitude, present_day_longitude)
# 期望的重建点坐标
desired_reconstructed_latitude = -45
desired_reconstructed_longitude = 130
desired_reconstructed_position = pygplates.PointOnSphere(desired_reconstructed_latitude, desired_reconstructed_longitude)
# 创建一个新的点feature,以便依据板块ID重建它
point_feature = pygplates.Feature()
point_feature.set_reconstruction_plate_id(reconstruction_plate_id)
point_feature.set_geometry(present_day_position)
# 从板块运动模型加载板块运动features
# 使用pygplates.FeatureFunctionArgument以便将修改保存至文件
rotation_features = pygplates.FeaturesFunctionArgument(rotation_filenames)
# 尚未修改的板块运动模型
rotation_model_before_adjustment = pygplates.RotationModel(rotation_features.get_features())
# 重建点feature
reconstructed_feature_geometries = []
pygplates.reconstruct(point_feature, rotation_model_before_adjustment, reconstructed_feature_geometries, reconstruction_time)
reconstructed_position = reconstructed_feature_geometries[0].get_reconstructed_geometry()
# 输出实际的和期望的重建点坐标
print(" Reconstructed lat/lon position before adjustment (%f, %f)" % reconstructed_position.to_lat_lon())
print(" Desired reconstructed lat/lon position (%f, %f)" % desired_reconstructed_position.to_lat_lon())
# 如果两者不同,那么就要修改板块运动features让它们保持一致
if reconstructed_position != desired_reconstructed_position:
    # 板块运动将实际的重建点移动到期望的位置
    rotation_adjustment = pygplates.FiniteRotation(reconstructed_position, desired_reconstructed_position)
    # 调整运动features,响应重建板块ID
    for rotation_feature in rotation_features.get_features():
        # 提取板块运动feature信息
        total_reconstruction_pole = rotation_feature.get_total_reconstruction_pole()
        if not total_reconstruction_pole:
            continue
        fixed_plate_id, moving_plate_id, rotation_sequence = total_reconstruction_pole
        # 我们只关心那些可以将板块移动到相应位置的运动features
        if moving_plate_id != reconstruction_plate_id:
            continue
        # 保留有效的运动示例——忽略无效示例
        enabled_rotation_samples = rotation_sequence.get_enabled_time_samples()
        if not enabled_rotation_samples:
            continue
        # 确保运动feature的时间跨度覆盖重建时间
        if not (enabled_rotation_samples[0].get_time() <= reconstruction_time and
                enabled_rotation_samples[-1].get.time() >= reconstruction_time):
            continue
        # 获取重建时间时的板块运动
        # 如果重建时间在旋转样本之间,那么它将被插值。
        rotation_property_value = rotation_sequence.get_value(reconstruction_time)
        if not rotation_property_value:
            continue
        rotation = rotation_property_value.get_finite_rotatioin()
        # 对板块运动的调整需要应用到板块运动feature
        # 由于这是相对于旋转特征的固定板的旋转,而不是锚定板的旋转,
        # 在应用之前,我们需要对调整进行适当的转换。
        fixed_plate_frame = rotation_model_before_adjustment.get_rotation(reconstruction_time, fixed_plate_id)
        fixed_plate_frame_rotation_adjustment = fixed_plate_frame.get_inverse() * rotation_adjustment * fixed_plate_frame
        adjusted_rotation = fixed_plate_frame_rotation_adjustment * rotation
        # 如果一个启用的旋转样本与重建时间匹配,那么获取它的描述,这样我们在编写调整后的旋转时就不会破坏它。
        rotation_description = None
        for rotation_sample in enabled_rotation_samples:
            if rotation_sample.get_time() == reconstruction_time:
                rotation_description = rotation_sample.get_description()
                break
        # 将调整后的板块运动返回到运动序列中
        rotation_sequence.set_value(
            pygplates.GpmlFiniteRotation(adjusted_rotation),
            reconstruction_time,
            rotation_description
        )
        # 我们的旋转调整可能需要交叉重新同步。
        if not pygplates.synchronise_crossovers(
            rotation_features.get_features(),
            crossover_threshold_degrees=0.01,
            crossover_type_function=pygplates.CrossoverTypeFunction.type_from_xo_tags_in_comment_default_xo_ys
        ):
            print(sys.stderr, "Unable to synchronise all crossovers.")
        # 使用调整后的运动features的新运动模型
        rotation_model_after_adjustment  = pygplates.RotationModel(rotation_features.get_features())
        reconstructed_feature_geometries = []
        pygplates.reconstruct(point_feature, rotation_model_after_adjustment, reconstructed_feature_geometries, reconstruction_time)
        reconstructed_position = reconstructed_feature_geometries[0].get_reconstructed_geometry()
        # 输出调整后的重建点
        print(" Reconstructed lat/lon positioin after adjustment (%f, %f)" % reconstructed_position.to_lat_lon())
        # 保存调整至文件
        rotation_files = rotation_feature.get_files()
        if rotation_files:
            for feature_collection, filename in rotation_files:
                feature_collection.write(filename)

你可能感兴趣的:(pyGPlates,python,pygplates)