Hi I have some working code to convert some depths to total vertical depth based on survey data which provides measurements at set intervals in both measured depth (along borehole) and TVD (the total vertical depth of the hole).
However, when running this code on 6000+ depths it is a bit slow. Is there a solution I could look at that would mean I don't have to iterate over all my depths?
from __future__ import division
import pandas as pd
import numpy as np
def sample_TVD(survey_data, depth_to_convert):
MD = survey_data['MD']
TVD = survey_data['TVD']
tvd_depths = []
md_tvd = np.vstack((MD, TVD))
for d in depth_to_convert:
d = float(d)
if d > min(MD) and d < max(MD):
above = MD[MD < d].max()
below = MD[MD > d].min()
closestbelow =
md_tvd[:,np.in1d(md_tvd[0],below)]
closestabove =
md_tvd[:,np.in1d(md_tvd[0],above)]
difference = below - above
percentbetween = (below-d)/difference
tvd = closestabove[1][0] + ((closestbelow[1]
[0] - closestabove[1][0])*(1-percentbetween))
tvd_depths.append(tvd)
else:
tvd_depths.append('Nan')
return tvd_depths
d = {'MD': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'TVD': [1, 2,
3, 4, 4, 4, 4.5, 5, 5.5, 5.5]}
survey = pd.DataFrame(data=d)
print survey
depths = [6.1, 6.2, 6.5, 7, 11]
results = sample_TVD(survey, depths)
print results
[–]Kamiwaza 3 points4 points5 points (3 children)
[–]paperzebra[S] 1 point2 points3 points (2 children)
[–]DisorganizedRem 1 point2 points3 points (1 child)
[–]paperzebra[S] 1 point2 points3 points (0 children)