<jupyter_start><jupyter_text>Test dhole module with *"known"* large deviations<jupyter_code># load some modules
import pandas as pd
import numpy as np
from pygslib.drillhole import *   # here we are importing all the classes and functions in pygslib.drillhole
import matplotlib.pylab as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Smooth regular change<jupyter_code># create artificial "know data" to desurvey
DEG2RAD=3.141592654/180.0
azm= np.linspace(0.0,359.0,360)
dip= np.linspace(90,0,360)

#make sure BHID is string, XCOLLAR is float...
collar=pd.DataFrame({'BHID': ['1'],'XCOLLAR':[0.], 'YCOLLAR': [0.], 'ZCOLLAR':[0.]})
assay = pd.DataFrame({'BHID': np.ones([360], dtype = str),
                      'FROM':np.linspace(0,359,360), 
                      'TO': np.linspace(1,360,360), 
                      'R_AZM':azm,
                      'R_DIP':dip})

#assuming each 1m interval straight we calculate x,y,z
assay['xb_real']=np.zeros([360], dtype = float)
assay['yb_real']=np.zeros([360], dtype = float)
assay['zb_real']=np.zeros([360], dtype = float)

DEG2RAD=3.141592654/180.0
for i in range(1,360):
    x,y,z = ang2cart( assay['R_AZM'][i-1], assay['R_DIP'][i-1]) # this is for one unit length interval
    assay.loc[i, 'xb_real']= assay['xb_real'][i-1] + x
    assay.loc[i,'yb_real']= assay['yb_real'][i-1] + y
    assay.loc[i,'zb_real']= assay['zb_real'][i-1] + z

# create survey every 50m 
survey = pd.DataFrame({'BHID': assay['BHID'][::50],
                       'AT': assay['FROM'][::50],
                       'AZ': assay['R_AZM'][::50],
                       'DIP': assay['R_DIP'][::50]}) 
#print values 
print (collar)
print (assay.head())
print (survey)

#plot drillhole
plt.plot (assay['xb_real'],assay['yb_real'], label= 'reference data')
plt.xlabel('xb_real')
plt.ylabel('yb_real')
plt.legend(loc=2)
plt.show()

plt.plot (assay['xb_real'],assay['zb_real'], label= 'reference data')
plt.xlabel('xb_real')
plt.ylabel('zb_real')
plt.legend(loc=2)
plt.show()

# creating a working Drillhole database. 
mydholedb=Drillhole(collar=collar,survey=survey)
# add assay table
mydholedb.addtable(assay, 'assay' ,overwrite = False)<jupyter_output><empty_output><jupyter_text>Validating the datasetAn error will be raised is there is anything wrong in the database. Z<jupyter_code>mydholedb.validate()
mydholedb.validate_table('assay')<jupyter_output><empty_output><jupyter_text>Desurveying drillhole tables<jupyter_code>mydholedb.desurvey('assay', endpoints=True)
mydholedb.table['assay'].head()<jupyter_output><empty_output><jupyter_text>Calculate desurvey error<jupyter_code># this is the euclidean distance between real and estimate at xbig, ybig, zbig
mydholedb.table['assay']['err']=np.sqrt(((mydholedb.table['assay']['xb_real']-mydholedb.table['assay']['xb'])**2 + \
                                 (mydholedb.table['assay']['yb_real']-mydholedb.table['assay']['yb'])**2 + \
                                 (mydholedb.table['assay']['zb_real']-mydholedb.table['assay']['zb'])**2))

plt.plot(mydholedb.table['assay']['FROM'],mydholedb.table['assay']['err'])
mydholedb.survey
#plot drillhole
plt.plot (mydholedb.table['assay']['xb_real'],mydholedb.table['assay']['yb_real'], label= 'reference data')
plt.plot (mydholedb.table['assay']['xm'],mydholedb.table['assay']['ym'], label= 'desurveyed data')
plt.xlabel('xb')
plt.ylabel('yb')
plt.legend(loc=2)
plt.show()

plt.plot (mydholedb.table['assay']['xb_real'],mydholedb.table['assay']['zb_real'], label= 'reference data')
plt.plot (mydholedb.table['assay']['xm'],mydholedb.table['assay']['zm'], label= 'desurveyed data')
plt.xlabel('xb')
plt.ylabel('zb')
plt.legend(loc=2)
plt.show()

mydholedb.table['assay']['len']=np.sqrt(((mydholedb.table['assay']['xb']-mydholedb.table['assay']['xe'])**2 + \
                                 (mydholedb.table['assay']['yb']-mydholedb.table['assay']['ye'])**2 + \
                                 (mydholedb.table['assay']['zb']-mydholedb.table['assay']['ze'])**2))

mydholedb.table['assay']['len2']= mydholedb.table['assay']['TO'] - mydholedb.table['assay']['FROM']

print ('desurveyed legth: ', mydholedb.table['assay']['len'].sum())
print ('interval legth  : ', mydholedb.table['assay']['len2'].sum())
print ('desurveyed legth: ')
mydholedb.table['assay']['len']<jupyter_output>desurveyed legth:
{'fraction_non_alphanumeric': 0.19838337182448038, 'fraction_numerical': 0.024942263279445726, 'mean_word_length': 4.932876712328767, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '422869', 'license': 'MIT', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1652, 'n_words': 260, 'path': 'doc/source/Ipython_templates/dhole2.ipynb', 'repo_name': 'cmrajan/pygslib', 'size': '4330'}