Skip to content

Instantly share code, notes, and snippets.

@onslauth
Last active March 9, 2018 07:52
Show Gist options
  • Save onslauth/d94c5dc0ba20c15b9ab85e77e05d94be to your computer and use it in GitHub Desktop.
Save onslauth/d94c5dc0ba20c15b9ab85e77e05d94be to your computer and use it in GitHub Desktop.
import math
import numpy as np
import scipy, scipy.interpolate
radians = math.pi / 180.0
# Depth, Inclination, Direction
survey_data = [ [1.92, -89.098, 312.804],
[3.0, -89.148, 317.651],
[6.0, -89.259, 325.05],
[9.0, -89.206, 330.3],
[12.0, -89.232, 329.721],
[15.0, -89.268, 331.173],
[18.0, -89.224, 331.01099999999997],
[21.0, -89.231, 334.148],
[24.0, -89.288, 335.70799999999997] ]
original_data = np.array(survey_data)
DHS = original_data.copy()
radians = DHS.take([1,2],1) * radians
cos = np.cos(radians)
sin = np.sin(radians)
directions = np.zeros(shape = (DHS.shape[0],3),dtype = 'd')
np.multiply(cos[:,0],cos[:,1],directions[:,0])
np.multiply(cos[:,0],sin[:,1],directions[:,1])
directions[:,2] = sin[:,0]
inter, u = scipy.interpolate.splprep(directions.transpose(), u = DHS[:,0], s = 0, k = 3)
print( "Position at each point in dataset:" )
for i in range(0, len(DHS)):
coord = scipy.interpolate.splint(0, DHS[i, 0], inter)
print("{} - {}, {}, {}".format(DHS[i,0], coord[0], coord[1], coord[2]))
print("\nPosition at even points along spline:")
for i in range(0, int(DHS[-1, 0])):
pos = scipy.interpolate.splint(0, i, inter)
print("{} - {}, {}, {}".format(i, pos[0], pos[1], pos[2]))
$ python3 ./interpolate.py
Position at each point in dataset:
1.92 - 0.0, 0.0, 0.0
3.0 - 0.011768740474603122, -0.011617451038488333, -1.0798732343929476
6.0 - 0.04400874773674483, -0.03715285610355032, -4.079590739136859
9.0 - 0.07790714445298916, -0.05821395360214117, -7.079324381029499
12.0 - 0.11375407646308983, -0.0787789316752744, -10.079039917541477
15.0 - 0.14761324040330698, -0.0980331862566914, -13.078786910853909
18.0 - 0.18207435265381422, -0.11709852260096285, -16.078528190937057
21.0 - 0.21818121456370504, -0.13601030482085064, -19.078251221143635
24.0 - 0.2535592157262484, -0.1521833753145591, -22.07799899238067
Position at even points along spline:
0 - 0.0, 0.0, 0.0
1 - -0.009484899451329317, 0.01132419169216216, 0.9198816382268374
2 - 0.0008575964173419639, -0.0009189940162013943, -0.07999012324148493
3 - 0.011768740474603122, -0.011617451038488333, -1.0798732343929476
4 - 0.022706415932142048, -0.021043008977450466, -2.0797690067522665
5 - 0.033431676770034655, -0.02946551945326816, -3.0796761434328626
6 - 0.04400874773674483, -0.03715285610355032, -4.079590739136859
7 - 0.054778685016195504, -0.044367964754487975, -5.07950656755988
8 - 0.06606964356554926, -0.05133641530354373, -6.079418242843801
9 - 0.07790714445298916, -0.05821395360214117, -7.079324381029499
10 - 0.09000914988239538, -0.06508369960569668, -8.079227638629284
11 - 0.10202162112700804, -0.07195777514127995, -9.079131975470892
12 - 0.11375407646308983, -0.0787789316752744, -10.079039917541477
13 - 0.12519448874001454, -0.08542957631759196, -11.078952326870667
14 - 0.13643760071757774, -0.09182943010037382, -12.078868607400263
15 - 0.14761324040330698, -0.0980331862566914, -13.078786910853909
16 - 0.15887501685711544, -0.1042261285904431, -14.078704293939968
17 - 0.17034765870517918, -0.11057827526651859, -15.078618241713297
18 - 0.18207435265381422, -0.11709852260096285, -16.078528190937057
19 - 0.1940152343571133, -0.12363211621627945, -17.07843556305489
20 - 0.20608344944707033, -0.12997868995959944, -18.078342603523236
21 - 0.21818121456370504, -0.13601030482085064, -19.078251221143635
22 - 0.23020309563052896, -0.14168217974350014, -20.07816288254752
23 - 0.24203600785454507, -0.14703269162455432, -21.078078612196144
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment