pygplates专栏——Reconstruc features——reconstruct regular features

pygplates专栏------Reconstruc features------reconstruct regular features

Reconstruct regular features

这个例子展示了几个不同的场景,涉及到重建地质时代的常见特征。

导出重构特征到文件

在这个例子中,我们重建常规特征并将结果导出到Shapefile。

示例代码

bash 复制代码
import pygplates

# 加载板块运动模型
rotation_model = pygplates.RotationModel("Muller2019-Young2019-Cao2020_CombinedRotations.rot")
# 加载一些features
features = pygplates.FeatureCollection("Global_EarthByte_GPlates_PresentDay_Coastlines.gpmlz")
# 重建的地质时间
reconstruction_time = 50
# 输出的文件
export_filename = "6-Exported_reconstructed_features_to_a_file_reconstructed_{0}Ma.shp".format(reconstruction_time)
# 重建
pygplates.reconstruct(features, rotation_model, export_filename, reconstruction_time)

详解

首先加载板块运动模型(pygplates.RotationModel)

bash 复制代码
rotation_model = pygplates.RotationModel('rotations.rot')

加载需要重建的特征(pygplates.FeatureCollection)

bash 复制代码
features = pygplates.FeatureCollection('features.gpml')

设置重建时间

bash 复制代码
reconstruction_time = 50

最后完成重建结果并保存

bash 复制代码
pygplates.reconstruct(features, rotation_model, export_filename, reconstruction_time)

计算重建距离

示例代码

bash 复制代码
import pygplates

# 返回几何要素(点/多点/折线/多边形)质心的函数。
def get_geometry_centroid(geometry):
    # 检查几何要素是否为多边形
    try:
        return geometry.get_interior_centroid()
    except AttributeError:
        # 不是多边形,继续
        pass
    # 检查几何要素是否为多线条或多点
    try:
        return geometry.get_centroid()
    except AttributeError:
        pass
    # 仅剩点
    return geometry
# 加载板块运动模型
rotation_model = pygplates.RotationModel("Muller2019-Young2019-Cao2020_CombinedRotations.rot")
# 加载一些特征
features = pygplates.FeatureCollection("2-output_points.gpml")
# 重建地质时间
reconstruction_time = 50
# 重建
reconstructed_feature_geometries = []
pygplates.reconstruct(features, rotation_model, reconstructed_feature_geometries, reconstruction_time)
# 遍历所有重建结果
for reconstructed_feature_geometry in reconstructed_feature_geometries:
    # 计算距离:今时今日几何要素的质点和重建后的质点
    distance_reconstructed = pygplates.GeometryOnSphere.distance(
        get_geometry_centroid(reconstructed_feature_geometry.get_present_day_geometry()),
        get_geometry_centroid(reconstructed_feature_geometry.get_reconstructed_geometry())
    )
    # 将弧度转换为公里
    distance_reconstructed_in_kms = distance_reconstructed * pygplates.Earth.mean_radius_in_kms
    # 输出相关特征名称和板块ID,以及重建的距离
    print("Feature: %s" % reconstructed_feature_geometry.get_feature().get_name())
    print("  plate ID: %d" % reconstructed_feature_geometry.get_feature().get_reconstruction_plate_id())
    print("  distance reconstructed: %f Kms" % distance_reconstructed_in_kms)

详解

为了某个功能,pygplates定义了许多相关的函数

如果,我们可以忽略掉几何要素是否为pygplates.PointOnSphere,pygplates.MultiPointOnSphere,pygplates.PolyineOnSphere或pygplates.PolygonOnSphere。每种几何要素类型需要不同的方法获取质点。

因此我们首先尝试pygplates.PolygonOnSphere.get_interior_centroid(),然后尝试get_centroid(),最后几何要素点就是它本身的质点。

bash 复制代码
def get_geometry_centroid(geometry):
    try:
        return geometry.get_interior_centroid()
    except AttributeError:
        pass
    try:
        return geometry.get_centroid()
    except AttributeError:
        pass
    return geometry

使用pygplates.GeometryOnSphere.distance()方法来计算两个质点之间的最短距离,然后使用pygplates.Earth将其转换为公里数。

bash 复制代码
distance_reconstructed = pygplates.GeometryOnSphere.distance(
    get_geometry_centroid(reconstructed_feature_geometry.get_present_day_geometry()),
    get_geometry_centroid(reconstructed_feature_geometry.get_reconstructed_geometry()))
distance_reconstructed_in_kms = distance_reconstructed * pygplates.Earth.mean_radius_in_kms
相关推荐
belldeep1 小时前
python:reportlab 将多个图片合并成一个PDF文件
python·pdf·reportlab
FreakStudio4 小时前
全网最适合入门的面向对象编程教程:56 Python字符串与序列化-正则表达式和re模块应用
python·单片机·嵌入式·面向对象·电子diy
丶21364 小时前
【CUDA】【PyTorch】安装 PyTorch 与 CUDA 11.7 的详细步骤
人工智能·pytorch·python
_.Switch5 小时前
Python Web 应用中的 API 网关集成与优化
开发语言·前端·后端·python·架构·log4j
一个闪现必杀技5 小时前
Python入门--函数
开发语言·python·青少年编程·pycharm
小鹿( ﹡ˆoˆ﹡ )5 小时前
探索IP协议的神秘面纱:Python中的网络通信
python·tcp/ip·php
卷心菜小温6 小时前
【BUG】P-tuningv2微调ChatGLM2-6B时所踩的坑
python·深度学习·语言模型·nlp·bug
陈苏同学6 小时前
4. 将pycharm本地项目同步到(Linux)服务器上——深度学习·科研实践·从0到1
linux·服务器·ide·人工智能·python·深度学习·pycharm
唐家小妹6 小时前
介绍一款开源的 Modern GUI PySide6 / PyQt6的使用
python·pyqt
羊小猪~~7 小时前
深度学习项目----用LSTM模型预测股价(包含LSTM网络简介,代码数据均可下载)
pytorch·python·rnn·深度学习·机器学习·数据分析·lstm