将3d钻孔轨迹转换为笛卡尔坐标并使用matplotlib绘制它

时间:2013-12-19 16:45:08

标签: python matplotlib plot

我希望能够使用方向和距离绘制两条线。这是一个Drillhole跟踪,所以我现在有这种格式的数据,

enter image description here

深度实际上是距离孔的距离,而不是垂直深度。方位角来自磁北。 Dip基于0是水平的。我想从同一点绘制两条线(0,0,0很好),并根据这种信息看看它们有何不同。

我没有使用Matplotlib的经验,但我对Python感到满意,并希望了解这个绘图工具。我找到this page并且它有助于理解框架,但我仍然无法弄清楚如何使用3d向量绘制线条。有人可以给我一些关于如何做到这一点或在哪里找到我需要的指示的指示?谢谢

2 个答案:

答案 0 :(得分:5)

将坐标转换为笛卡尔坐标并使用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))

答案 1 :(得分:2)

对于500米的钻孔,您可以使用最小曲率法,否则位置误差将非常大。我在gethonatistics(PyGSLIB)的python模块中实现了它。显示真实钻孔数据库的完整去污过程的示例,包括在化验/岩性区间的位置,如下所示:

http://nbviewer.ipython.org/github/opengeostat/pygslib/blob/master/pygslib/Ipython_templates/demo_1.ipynb

这也显示了如何以VTK格式导出钻孔以便在paraview中输入。

Results shown in Paraview

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