Beispiel #1
0
def TopHTSection(lines, rstep, tstep):
    fig, ax = plt.subplots(1, 2)

    ax[0], img = HThist(lines['AvgRho'],
                        lines['AvgTheta'],
                        rstep=rstep,
                        tstep=tstep,
                        ax=ax[0])
    h = img[0]

    xedges = img[1]
    yedges = img[2]

    [i, j] = np.unravel_index(h.argmax(), h.shape)

    xe = [xedges[i], xedges[i + 1]]
    ye = [yedges[j], yedges[j + 1]]
    print(h.max(), "clustered lines at", xe, "degrees", ye, "rho (m)")
    #     masklat= (dikeset['latitude'] > lat1) & (dikeset['latitude'] < lat2)
    # masklong=(dikeset['longitude'] > lon1) & (dikeset['longitude'] < lon2)
    # masklatlong= (masklat==1) & (masklong==1)

    maskTheta = (lines['AvgTheta'] > xe[0]) & (lines['AvgTheta'] < xe[1])
    maskRho = (lines['AvgRho'] > ye[0]) & (lines['AvgRho'] < ye[1])
    mask = (maskTheta == True) & (maskRho == True)

    print(np.sum(mask), "should equal", h.max())
    print(np.sum(mask) == h.max())
    toplines = lines[mask]
    plotlines(lines, 'k', ax[1], alpha=0.1)
    plotlines(toplines, 'r', ax[1])
    print(toplines['Size'].sum(), "dike segements")

    return toplines
Beispiel #2
0
def checkoutCluster(dikeset, label):
    fig, ax = plt.subplots()
    mask = (dikeset['Labels'] == label)
    lines = dikeset[mask]
    plotlines(lines, 'r', ax)
    xc, yc = HT_center(dikeset)
    x, y = endpoints2(lines)
    plotlines(lines, 'r', ax, linewidth=3)
    #pltRec(lines, xc, yc, ax)
    #pltLine(lines, xc, yc, ax)

    return fig, ax
Beispiel #3
0
def rotateHT(dikeset, deg):
    xci, yci = HT_center(dikeset)
    p = 2
    fig, ax = plt.subplots(1, 4)
    fig2, ax2 = plt.subplots(2, 3)

    plotlines(dikeset, 'k', ax[0])
    theta, rho, xc, yc = AKH_HT(dikeset)
    theta0 = theta
    rho0 = rho
    ax[0].plot(xc,
               yc,
               "*",
               color='grey',
               markeredgecolor="black",
               markersize=20)
    ax[1].set_title('not Rotated (black)')
    ax[1].scatter(theta, rho, c='grey')
    mrho = max(rho)
    minrho = min(rho)
    colors = [
        'red', 'green', 'blue', 'yellow', 'orange', 'purple', 'magenta',
        'lime', 'tab:cyan', 'turquoise'
    ]

    for i in [deg, 2 * deg]:
        dfr = rotateData2(dikeset, i)
        theta, rho, xc, yc = AKH_HT(dfr)
        dist = np.sqrt((theta0 - theta)**2 + (rho0 - rho)**2)
        print("jittering mean:", np.mean(dist), "max:", max(dist))
        ax[p].scatter(theta0, rho0, c='grey', alpha=0.5)
        ax[p].scatter(theta, rho, c=dist, cmap="plasma")
        ax[p].set_title("Rotated " + str(i) + colors[p])
        print(colors[p])
        plotlines(dfr, colors[p], ax[0])

        ax2[0, p - 1].scatter(theta0, dist)
        ax2[0, p - 1].set_xlabel("theta")
        ax2[0, p - 1].set_ylabel("jitter")
        ax2[1, p - 1].scatter((rho0), dist)
        ax2[1, p - 1].set_xlabel("rho")
        ax2[1, p - 1].set_xlim([-90, 90])
        ax2[1, p - 1].set_ylabel("jitter")

        p = p + 1
        print("                         ")

    for i in range(p - 1):
        ax[i + 1].set_ylim(minrho, mrho)
        ax[i + 1].set_xlim([-90, 90])
Beispiel #4
0
def plotlabel(df, label):
    fig, ax = plt.subplots()
    mask = df['Labels'] == label
    xc, yc = HT_center(df)
    lines = df[mask]
    plotlines(lines, "r", ax)
    x, y = endpoints2(lines)
    w, l = fit_Rec(lines, xc, yc)
    r = squaresError(lines, xc, yc)
    avgtheta = np.average(lines['theta'])

    x1, x2, y1, y2 = clustered_lines(x, y, avgtheta)
    ax.plot([x1, x2], [y1, y2], 'g')

    ax.set_title("Label" + str(label))
    ax.text(.89, .89, "W:" + str(w), transform=ax.transAxes)
    ax.text(.84, .84, "L:" + str(l), transform=ax.transAxes)
    ax.text(.80, .80, "errors:" + str(r), transform=ax.transAxes)
Beispiel #5
0
"""
import numpy as np 
from plotmod import plotlines
import pandas as pd
from htMOD import AKH_HT as HT 
import matplotlib.pyplot as plt
from sklearn.cluster import DBSCAN
import matplotlib.lines as mlines
from sklearn.preprocessing import scale

true=pd.read_csv('/home/akh/myprojects/Linking-and-Clustering-Dikes/test_rand1.csv')
theta, r, xc, yc= HT(true, xc=0, yc=0)


fig,ax=plt.subplots(2)
plotlines(true,'r', ax[0], linewidth=3)

ax[1].scatter(theta,r,c='red', edgecolor="black", s=100)
ax[1].set_ylabel('Rho (m)')
ax[1].set_xlabel('Theta (deg)')

true=pd.read_csv('/home/akh/myprojects/Linking-and-Clustering-Dikes/test_rand2.csv')
theta, r, xc, yc= HT(true, xc=0, yc=0)

plotlines(true,'b', ax[0], linewidth=3)

ax[1].scatter(theta,r, c="blue", edgecolor="black", s=100)
ax[1].set_ylabel('Rho (m)')
ax[1].set_xlabel('Theta (deg)')

Beispiel #6
0
def moveHTcenter(dikeset, r):
    xci, yci = HT_center(dikeset)
    p = 2
    fig, ax = plt.subplots(1, 10)
    fig2, ax2 = plt.subplots(2, 9)

    plotlines(dikeset, 'k', ax[0])
    theta, rho, xc, yc = AKH_HT(dikeset)
    theta0 = theta
    rho0 = rho
    ax[0].plot(xc,
               yc,
               "*",
               color='grey',
               markeredgecolor="black",
               markersize=20)
    ax[1].set_title('grey')
    ax[1].scatter(theta, rho, c='grey')
    mrho = max(rho)
    minrho = min(rho)
    colors = [
        'red', 'green', 'blue', 'yellow', 'orange', 'purple', 'magenta',
        'lime', 'tab:cyan', 'turquoise'
    ]
    for i in [-r, 0, r]:
        for j in [-r, 0, r]:
            if i == 0 and j == 0:
                continue

            print(colors[p], i, j, np.sqrt(i**2 + j**2))
            theta, rho, xc, yc = AKH_HT(dikeset, xc=xci + i, yc=yci + j)
            if max(rho) > mrho:
                mrho = max(rho)

            if min(rho) < minrho:
                minrho = min(rho)

            dist = np.sqrt((theta0 - theta)**2 + (rho0 - rho)**2)
            print("jittering mean:", np.mean(dist), "max:", max(dist))
            ax[p].scatter(theta0, rho0, c='grey', alpha=0.5)
            ax[p].scatter(theta,
                          rho,
                          c=dist / np.sqrt(i**2 + j**2),
                          cmap="plasma")
            ax[p].set_title(colors[p])
            ax2[0, p - 1].scatter(theta, dist)
            ax2[0, p - 1].set_xlabel("theta")
            ax2[0, p - 1].set_ylabel("jitter (m)")
            ax2[1, p - 1].scatter((rho), dist - np.sqrt(i**2 + j**2))
            ax2[1, p - 1].set_xlabel("rho")
            ax2[1, p - 1].set_ylabel("jitter (m)")

            ax[0].plot(xc,
                       yc,
                       "*",
                       color=colors[p],
                       markeredgecolor="black",
                       markersize=20)
            p = p + 1
            print("                         ")

    for i in range(p - 1):
        ax[i + 1].set_ylim(minrho, mrho)
Beispiel #7
0
points.sort_values(by='FormationID')
npoints = len(points)

myProj = Proj("+proj=utm +zone=11, +ellps=WGS84 +datum=WGS84 +units=m")
#myProj = Proj("+proj=utm +zone=11, +ellps=WGS84 +datum=NAD83 +units=m")
#lon1, lat1 = myProj(df['Xstart'].values, df['Ystart'].values, inverse = True)
#lon2, lat2 = myProj(df['Xend'].values, df['Yend'].values, inverse = True)

linelocSegments = np.empty([npoints, 4])
fig1, ax1 = plt.subplots(2)
#ax[0].scatter(points['longitude'], points['latitude'], c='r')
#plotlines(df, 'k', ax[0], myProj=myProj)

UTMx, UTMy = myProj(points['Long.'], points['Lat.'])
ax1[0].scatter(UTMx, UTMy, c='r')
plotlines(dfSegments, 'k', ax1[0])

x1 = dfSegments['Xstart'].values
x2 = dfSegments['Xend'].values
y1 = dfSegments['Ystart'].values
y2 = dfSegments['Yend'].values
b = np.linspace(0, 50, 10)

for i in range(npoints):
    #print(i)
    dist = abs((x2 - x1) * (y1 - UTMy[i]) - (x1 - UTMx[i]) *
               (y2 - y1)) / np.sqrt((x2 - x1)**2 + (y2 - y1)**2)
    loc = np.argmin(dist)

    linelocSegments[i, 0] = loc
    linelocSegments[i, 1] = np.min(dist)
Beispiel #8
0
m2 = np.append(m2, linearm * np.ones(20))

df = pd.DataFrame({
    'Xstart': Xstart,
    'Xend': Xend,
    'Ystart': Ystart,
    'Yend': Yend,
    'Slope': m2
})

df.to_csv('/home/akh/myprojects/Linking-and-Clustering-Dikes/synthetic.csv')

#df=rotateData2(df, 50)
fig, ax = plt.subplots(2, 2)

plotlines(df, 'k', ax[0][0])
theta1, rho1, xc, yc = AKH_HT(df.astype(float), xc=0, yc=0)
ax[1][0].scatter(theta1, rho1, edgecolor='black')
ax[0][0].plot(0, 0, "*", mec='black', markersize=20)
ax[1][1].set_xlabel('Theta (deg)')
ax[1][0].set_xlabel('Theta (deg)')

ax[0][1].set_label('Perfect Radial Swarm')
ax[0][0].set_label('With Noise')

ax[1][0].set_ylabel('Rho (m)')

#dfFrag1=fragmentDikes(df, distortion=1)
d = 20000
# plotlines(dfFrag1, 'r', ax[0][1], linewidth=2)
# plotlines(df, 'k', ax[0][1], alpha=0.1)
Beispiel #9
0
Xend = np.append(Xend1, dikelength[1] / np.sqrt(1 + m**2))
m2 = np.append(m, m)
Yend = m2 * Xend
labels = np.arange(0, ndikes * 2)

df = pd.DataFrame({
    "label": labels,
    'Xstart': Xstart,
    'Xend': Xend,
    'Ystart': Ystart,
    'Yend': Yend,
    'Slope': m2
})

npoints = 70
points = np.random.rand(npoints, 2) * dikelength[0] / 2
lineloc = np.empty([npoints])
fig, ax = plt.subplots()
ax.scatter(points[:, 0], points[:, 1], c='r')

plotlines(df, 'k', ax)
x1 = df['Xstart'].values
x2 = df['Xend'].values
y1 = df['Ystart'].values
y2 = df['Yend'].values

for i in range(npoints):
    dist = abs((x2 - x1) * (y1 - points[i, 1]) - (x1 - points[i, 0]) *
               (y2 - y1)) / np.sqrt((x2 - x1)**2 + (y2 - y1)**2)
    loc = np.argmin(dist)
    print(labels[loc])