Python 将三维钻孔轨迹转换为笛卡尔坐标,并使用matplotlib进行打印

Python 将三维钻孔轨迹转换为笛卡尔坐标,并使用matplotlib进行打印,python,matplotlib,plot,Python,Matplotlib,Plot,我想能够绘制两条线使用方向和距离。这是一个钻孔轨迹,所以我现在有这种格式的数据 深度实际上是井下的距离,而不是垂直深度。方位角是从磁北方向。倾角基于0为水平。我想从同一点画两条线(0,0,0很好),看看它们有什么不同,基于这种信息 我没有使用Matplotlib的经验,但是我对Python很熟悉,并且希望了解这个绘图工具。我发现了,这有助于理解框架,但我仍然不知道如何用3d向量绘制线条。有人能给我指点一下怎么做,或者在哪里找到我需要的方向吗?感谢您将坐标转换为笛卡尔坐标并使用matplotli

我想能够绘制两条线使用方向和距离。这是一个钻孔轨迹,所以我现在有这种格式的数据

深度实际上是井下的距离,而不是垂直深度。方位角是从磁北方向。倾角基于0为水平。我想从同一点画两条线(0,0,0很好),看看它们有什么不同,基于这种信息


我没有使用Matplotlib的经验,但是我对Python很熟悉,并且希望了解这个绘图工具。我发现了,这有助于理解框架,但我仍然不知道如何用3d向量绘制线条。有人能给我指点一下怎么做,或者在哪里找到我需要的方向吗?感谢您将坐标转换为笛卡尔坐标并使用matplotlib打印的脚本,其中包括以下注释:

import numpy as np
import matplotlib.pyplot as plt
# import for 3d plot
from mpl_toolkits.mplot3d import Axes3D
# initializing 3d plot
fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')
# several data points 
r = np.array([0, 14, 64, 114])
# get lengths of the separate segments 
r[1:] = r[1:] - r[:-1]
phi = np.array([255.6, 255.6, 261.7, 267.4])
theta = np.array([-79.5, -79.5, -79.4, -78.8])
# convert to radians
phi = phi * 2 * np.pi / 360.
# in spherical coordinates theta is measured from zenith down; you are measuring it from horizontal plane up 
theta = (90. - theta) * 2 * np.pi / 360.
# get x, y, z from known formulae
x = r*np.cos(phi)*np.sin(theta)
y = r*np.sin(phi)*np.sin(theta)
z = r*np.cos(theta)
# np.cumsum is employed to gradually sum resultant vectors 
ax.plot(np.cumsum(x),np.cumsum(y),np.cumsum(z))

对于500m的钻孔,可以使用最小曲率法,否则位置误差将非常大。我在一个python地质统计学模块(PyGSLIB)中实现了这一点。显示真实钻孔数据库的完整去勘测过程的示例,包括分析/岩性间隔的位置,如下所示:

这还显示了如何将VTK格式的钻孔导出到paraview中的lad

在Cython中,一个间隔的测量代码如下:

cpdef dsmincurb( float len12,
                 float azm1,
                 float dip1,
                 float azm2,
                 float dip2):

    """    
    dsmincurb(len12, azm1, dip1, azm2, dip2)

    Desurvey one interval with minimum curvature 

    Given a line with length ``len12`` and endpoints p1,p2 with 
    direction angles ``azm1, dip1, azm2, dip2``, this function returns 
    the differences in coordinate ``dz,dn,de`` of p2, assuming
    p1 with coordinates (0,0,0)

    Parameters
    ----------
    len12, azm1, dip1, azm2, dip2: float
        len12 is the length between a point 1 and a point 2.
        azm1, dip1, azm2, dip2 are direction angles azimuth, with 0 or 
        360 pointing north and dip angles measured from horizontal 
        surface positive downward. All these angles are in degrees.


    Returns
    -------
    out : tuple of floats, ``(dz,dn,de)``
        Differences in elevation, north coordinate (or y) and 
        east coordinate (or x) in an Euclidean coordinate system. 

    See Also
    --------
    ang2cart, 

    Notes
    -----
    The equations were derived from the paper: 
        http://www.cgg.com/data//1/rec_docs/2269_MinimumCurvatureWellPaths.pdf

    The minimum curvature is a weighted mean based on the
    dog-leg (dl) value and a Ratio Factor (rf = 2*tan(dl/2)/dl )
    if dl is zero we assign rf = 1, which is equivalent to  balanced 
    tangential desurvey method. The dog-leg is zero if the direction 
    angles at the endpoints of the desurvey intervals are equal.  

    Example
    --------

    >>> dsmincurb(len12=10, azm1=45, dip1=75, azm2=90, dip2=20)
    (7.207193374633789, 1.0084573030471802, 6.186459064483643)

    """

    # output
    cdef:
        float dz
        float dn
        float de 


    # internal 
    cdef:
        float i1
        float a1
        float i2
        float a2
        float DEG2RAD
        float rf
        float dl

    DEG2RAD=3.141592654/180.0

    i1 = (90 - dip1) * DEG2RAD
    a1 = azm1 * DEG2RAD

    i2 = (90 - dip2) * DEG2RAD
    a2 = azm2 * DEG2RAD

    # calculate the dog-leg (dl) and the Ratio Factor (rf)
    dl = acos(cos(i2-i1)-sin(i1)*sin(i2)*(1-cos(a2-a1))) 

    if dl!=0.: 
        rf = 2*tan(dl/2)/dl  # minimum curvature
    else:
        rf=1                 # balanced tangential



    dz = 0.5*len12*(cos(i1)+cos(i2))*rf
    dn = 0.5*len12*(sin(i1)*cos(a1)+sin(i2)*cos(a2))*rf
    de = 0.5*len12*(sin(i1)*sin(a1)+sin(i2)*sin(a2))*rf

    return dz,dn,de

第一步,也可能是最大的挑战,是找到一种将这些数据转换为笛卡尔坐标的方法。然后,你只需要知道,我希望这是一个相当常见的任务,matplotlib中有一个模块。我已经用shapely在2d中完成了这项工作,我将查看是否有人制作了3d等效物。matplotlib支持极坐标,但如果我正确阅读了您的解释,您需要移动每个点的“中心”,并根据您希望最终结果的方向,在角度上执行更正。这是正确的。从0,0,0开始。找到下一个坐标,该坐标在水平面上为255.6°,距离水平面向下为79.5°,距离0,0,0为14 M。然后从找到的坐标,找到下一个,等等…检查球坐标,转换成笛卡尔坐标。可能有用…那太棒了!非常感谢。里面有很多。对所有点进行变换,然后将它们相加,得到每个坐标,这很容易。我仍然在思考极坐标的φ和θ转换。但是我不明白r[1:]=r[1:]-r[:-1]是如何工作的。你能详细解释一下吗?@cndnflyr
r[1:]=r[1:]-r[:-1]
与在范围(1,len(r))]内对n说[r[n+1]-r[n]是一样的,如果这有帮助的话。换句话说:从
r
的第二个元素开始,重新定义每个后续元素,使其与原来的前一个元素不同。@Paul谢谢,这确实有帮助。它使用从原始列表中取出的两个列表,并使用从r[0]开始的列表从从r[1]开始的列表中减去。因为它们的长度相同,所以这是可行的。这太好了。奇怪的是,
r[1:]-r[:-1]
np.diff(r)
@tcaswell快:这可能是因为函数调用开销-
np.diff
是递归的。整个python模块都可以用conda安装,用一行代码
conda安装-chttps://conda.binstar.org/opengeostat pygslib
。它使用GPL/MIT许可证,由Opengeostat Consulting开发。这很有趣。您是否可以在某个地方重新托管ipynb?当然,IPython和测试数据在这里:。如果使用pygslib的开发版本来运行此代码,则可能需要进行一些更新。