<jupyter_start><jupyter_text>Read Correnso Data<jupyter_code>#Correnso data
data = pd.read_csv("corr_ori_v8tek.csv") 
#data.INCL[0]
#len(data)
Str2=[]
Dip2=[]
for i in range(0,len(data)):
    if np.isreal(data.AZI[i]): #Check if the cell has a number 
        strike,dip=dip2strike(data.AZI[i],data.INCL[i])
        Str2=np.append(Str2,strike)
        Dip2=np.append(Dip2,dip)

fig, ax = plt.subplots(figsize=(10,8),subplot_kw=dict(projection='stereonet'))
ax.pole(Str2, Dip2,color='m',markersize=4)
# Contour poles
cax = ax.density_contourf(Str2, Dip2, measurement='poles') 
ax.set_azimuth_ticklabels(['N', '','W', '', 'S', '', 'E', ''])
ax.grid(True)
fig.colorbar(cax)<jupyter_output><empty_output><jupyter_text>Find the main direction of pole axes<jupyter_code>#Find the eigenvectors and eigenvalues of all the poles    
w,E=axis_poles(Str2,Dip2)
    
fig, ax = plt.subplots(figsize=(10,8),subplot_kw=dict(projection='stereonet'))
ax.pole(Str2, Dip2,color='m',markersize=4)
# Contour poles
cax = ax.density_contourf(Str2, Dip2, measurement='poles') 
ax.set_azimuth_ticklabels(['N', '','W', '', 'S', '', 'E', ''])
ax.grid(True)
fig.colorbar(cax)    
    
#Plot the eigenvectors and auxiliary planes of the matrix
for i in range(0,len(E)):
    x,y,z=E[:,i] #Cartesian coordinates of eigenvector
    lon,lat=cart2sph(x,y,z)
    strike,dip=geographic2pole(lon,lat)
    #ax.pole(strike,dip,markersize=10,color='r')
    #ax.plane(strike,dip,'-.',lw=2,color='m')
    ax.pole(strike,dip,markersize=10,label='$e_'+np.str(i+1)+'$')
    ax.plane(strike,dip,'-.',lw=2,color='m')
    ax.legend()
    #print(x,y,z)
ax.grid(True) #Remove the grid lines
plt.show()<jupyter_output>The Eigenvectors: 
 [[ 9.86357533e-01 -1.64617074e-01 -1.92340709e-04]
 [-9.27162891e-03 -5.43873917e-02 -9.98476864e-01]
 [-1.64355879e-01 -9.84856959e-01  5.51716819e-02]]
The Eigenvalues: [123.79837943 168.49407987 533.7075407 ]
The trace of the Eigenvalues should be N (number of points):  826.0<jupyter_text>Find the optimal concentrations using the Nelder-Mead Algorithm<jupyter_code>from scipy.optimize import minimize
num=len(data)
#print('The Eigenvectors: \n',E)
#print('The Eigenvalues: \n',w)
#Sort the eigenvectors to follow the convention needed for the Bingham distribution
ws,Es=sort_eig(w,E)
print('The Sorted Eigenvectors: \n',Es)
print('The Sorted Eigenvalues: \n',ws)

#Define the log-likelihood function (set it as negative to be minimize)
def log_likelihood(params):
    k1,k2=params
    #The log-likelihood
    Sum=-num*np.log(4*np.pi)-num*np.log(norm_bingham_onstott(k1,k2))+k1*ws[0]+k2*ws[1] #
    return -Sum 

params0=np.array([-ws[1],-ws[0]])
res=minimize(log_likelihood,params0,method='Nelder-Mead',options={'disp': True},tol=1e-6)
k1,k2=res.x
print('k1 and k2 values',k1,k2)
print(res.x)<jupyter_output>The Sorted Eigenvectors: 
 [[ 9.86357533e-01 -1.64617074e-01 -1.92340709e-04]
 [-9.27162891e-03 -5.43873917e-02 -9.98476864e-01]
 [-1.64355879e-01 -9.84856959e-01  5.51716819e-02]]
The Sorted Eigenvalues: 
 [123.79837943 168.49407987 533.7075407 ]
Optimization terminated successfully.
         Current function value: 1665.645458
         Iterations: 65
         Function evaluations: 123
k1 and k2 values -3.824541453473228 -2.7689341671026066
[-3.82454145 -2.76893417]<jupyter_text>Generate points distributed according to a Bingham distribution from the concentrations calculated<jupyter_code>n=len(data)
x,y,z=pbingham_EK(n,Es,k1,k2) #Generate n points from symmetric matrix M

#Plot the distribution
fig, ax = plt.subplots(figsize=(10,8),subplot_kw=dict(projection='stereonet'))
lon,lat=cart2sph(x,y,z) #transform the (x,y,z) coords to (lon,lat)
strike,dip=geographic2pole(lon,lat) #transform (lon, lat) to (strike, dip)
#Contour the data
cax = ax.density_contourf(strike, dip, measurement='poles') 

# Plot the poles as points on top of the contours
ax.pole(strike,dip,color='m',markersize=4)
ax.set_azimuth_ticklabels(['N', '','W', '', 'S', '', 'E', ''])
# Turn on a grid and add a colorbar
ax.grid(True)
fig.colorbar(cax)

#Recalculate the Eigenvectors and Eigenvalues for the generated points
w,E=axis_poles(strike,dip)
#Sort the eigenvectors to follow the convention needed for the Bingham distribution
ws,Es=sort_eig(w,E)

#Plot the eigenvectors
#Plot the eigenvectors and auxiliary planes of the matrix
for i in range(0,len(Es)):
    x,y,z=Es[:,i] #Cartesian coordinates of eigenvector
    lon,lat=cart2sph(x,y,z)
    strike,dip=geographic2pole(lon,lat)
    #ax.pole(strike,dip,markersize=10,color='r')
    #ax.plane(strike,dip,'-.',lw=2,color='m')
    ax.pole(strike,dip,markersize=10,label='$e_'+np.str(i+1)+'$')
    ax.plane(strike,dip,'-.',lw=2,color='m')
    ax.legend()
    #print(x,y,z)
    ax.grid(True) #Remove the grid lines

plt.show()<jupyter_output>The Eigenvectors: 
 [[-0.04338491 -0.95684939  0.28732732]
 [-0.99342557  0.07181466  0.08915315]
 [ 0.10594045  0.2815704   0.95367433]]
The Eigenvalues: [530.72271124 127.49172578 167.78556298]
The trace of the Eigenvalues should be N (number of points):  826.0000000000002
{'fraction_non_alphanumeric': 0.1607920792079208, 'fraction_numerical': 0.10693069306930693, 'mean_word_length': 5.500643500643501, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '450194', 'license': 'MIT', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2054, 'n_words': 393, 'path': 'Fit_Bingham_Correnso.ipynb', 'repo_name': 'edur409/Bingham_distributions', 'size': '5050'}