def test_1d_peak():
    title = "Default Peak Test"
    dx = 0.25
    n = 50

    rawPts = []
    rawPts.append(PointValue(0, Y, 2))
    rawPts.append(PointValue(1, Y, 2))
    rawPts.append(PointValue(2 - dx, Y, 2))
    rawPts.append(PointValue(2, Y, 7))
    rawPts.append(PointValue(2 + dx, Y, 2))
    rawPts.append(PointValue(3, Y, 2))
    rawPts.append(PointValue(4, Y, 2))

    newXs = np.linspace(rawPts[0].X - 1, rawPts[-1].X + 1, n)
    totPts = []

    for x in newXs:
        interpolatedPt = PointValue(x, Y, 0)
        interpVal = inverse_weight(interpolatedPt, rawPts)
        interpolatedPt.Z = interpVal
        totPts.append(interpolatedPt)

    if ShowPlots:
        plotXs = [pt.X for pt in totPts]
        plotZs = [pt.Z for pt in totPts]
        plt.plot(plotXs, plotZs, "b--", label="Interpolated")
        plt.plot([pt.X for pt in rawPts], [pt.Z for pt in rawPts],
                 "ko",
                 label="Raw")

        plt.title(title)
        plt.legend(loc="upper left")
        plt.tight_layout()
        plt.show()
Exemple #2
0
def test_1d_sparse():
    title = "Sparse Step Interpolation"
    n = 50

    rawPts = []
    rawPts.append(PointValue(0, Y, 10))
    rawPts.append(PointValue(5, Y, 5))
    rawPts.append(PointValue(10, Y, 1))
    rawPts.append(PointValue(15, Y, 5))
    rawPts.append(PointValue(20, Y, 10))

    newXs = np.linspace(rawPts[0].X - 1, rawPts[-1].X + 1, n)
    totPts = []

    for x in newXs:
        interpolatedPt = PointValue(x, Y, 0)
        interpVal = step(interpolatedPt, rawPts)
        interpolatedPt.Z = interpVal
        totPts.append(interpolatedPt)

    if ShowPlots:
        plotXs = [pt.X for pt in totPts]
        plotZs = [pt.Z for pt in totPts]
        plt.plot(plotXs, plotZs, "b--", label="Interpolated")
        plt.plot([pt.X for pt in rawPts], [pt.Z for pt in rawPts],
                 "ko",
                 label="Raw")

        plt.title(title)
        plt.legend(loc="upper left")
        plt.tight_layout()
        plt.show()
Exemple #3
0
def getTestMap(w, h, val=0):
    pts = []
    for y in range(h):
        for x in range(w):
            pts.append(PointValue(x, y, val))

    return Map(pts)
Exemple #4
0
def test_1d_default():
    title = "Default Test of Current Approach to Step Interpolation"
    n = 50

    rawPts = []
    rawPts.append(PointValue(1, Y, 1))
    rawPts.append(PointValue(2, Y, 2))
    rawPts.append(PointValue(3, Y, 2))
    rawPts.append(PointValue(4, Y, 1))

    newXs = np.linspace(rawPts[0].X - 1, rawPts[-1].X + 1, n)
    totPts = []

    for x in newXs:
        interpolatedPt = PointValue(x, Y, 0)
        interpVal = step(interpolatedPt, rawPts)
        interpolatedPt.Z = interpVal
        totPts.append(interpolatedPt)

    if ShowPlots:
        plotXs = [pt.X for pt in totPts]
        plotZs = [pt.Z for pt in totPts]
        plt.plot(plotXs, plotZs, "b--", label="Interpolated")
        plt.plot([pt.X for pt in rawPts], [pt.Z for pt in rawPts],
                 "ko",
                 label="Raw")

        plt.title(title)
        plt.legend(loc="upper left")
        plt.tight_layout()
        plt.show()
Exemple #5
0
    def test_addPointValue(self):
        testName = "TestMap.test_addPointValue"
        running(testName)
        correct = True

        H = 3
        W = 4
        M = getTestMap(W, H)

        M.addRawPointValue(PointValue(W + 1, H + 1, 0))
        gotL = len(M.RawPointValues)
        expL = H * W + 1
        correct = gotL == expL
        if not correct: failed(testName, gotL, expL)

        if correct: passed(testName)
        assert correct
Exemple #6
0
def test_1_overlapping():
    testName = "test_1_overlapping"
    running(testName)
    correct = False

    x = 3
    y = 4
    z = 5

    p = Point(x, y)
    pv = PointValue(x, y, z)

    expWt = z
    gotWt = inverse_weight(p, [pv])

    correct = gotWt == expWt
    if correct: passed(testName)
    else: failed(testName, gotWt, expWt)
    assert correct
def test_1_overlapping():
    testName = "test_1_overlapping"
    running(testName)
    correct = False

    x = 3
    y = 4
    z = 5

    p = Point(x, y)
    pv = PointValue(x, y, z)

    expV = z
    gotV = step(p, [pv])

    correct = gotV == expV
    if correct: passed(testName)
    else: failed(testName, gotV, expV)
    assert correct
Exemple #8
0
def test_2_singleRawPt():
    testName = "test_2_singleRawPt"
    running(testName)
    correct = False

    x = 3
    y = 4
    z = 5
    d = 10E3

    p = Point(x, y)
    pv = PointValue(x + d, y + d, z)

    expWt = z
    gotWt = inverse_weight(p, [pv])

    correct = gotWt == expWt
    if correct: passed(testName)
    else: failed(testName, gotWt, expWt)
    assert correct
def test_2_singleRawPt():
    testName = "test_2_singleRawPt"
    running(testName)
    correct = False

    x = 3
    y = 4
    z = 5
    d = 10E3

    p = Point(x, y)
    pv = PointValue(x + d, y + d, z)

    expV = z
    gotV = step(p, [pv])

    correct = gotV == expV
    if correct: passed(testName)
    else: failed(testName, gotV, expV)
    assert correct
Exemple #10
0
def test_3_symmetric():
    testName = "test_3_symmetric"
    running(testName)
    correct = False

    x = 3
    y = 4
    z = 5
    d = 10

    p1 = Point(x + d, y + d)
    pv = PointValue(x, y, z)
    p2 = Point(x - d, y - d)

    gotWt1 = inverse_weight(p1, [pv])
    gotWt2 = inverse_weight(p2, [pv])

    correct = gotWt1 == gotWt2
    if correct: passed(testName)
    else: failed(testName, f"{gotWt1} != {gotWt2}", f"{gotWt1} == {gotWt2}")
    assert correct
Exemple #11
0
def getPointValuesFromCsv(filename):
    """
    Reads pointValues in from csv in the form:  
        x, y, z(value)
    """
    try:
        with open(filename, 'r+') as f:
            pointValues = []
            # skip first line of headers "x, y, z\n"
            for line in f.readlines()[1:]:
                l = line.split(',')

                x = int(l[0])
                y = int(l[1])
                z = float(l[2])

                p = PointValue(x, y, z)
                pointValues.append(p)
            return pointValues
    except Exception:
        print(
            f"[IO] - [getPointValuesFromCsv] - [ERROR] - could not read pointValues from file '{filename}'"
        )
def test_1d_comparison():
    title = "Comparisons of Power P Across a Set of Points From Shepard's Method"
    n = 50
    p1 = -2
    p2 = 1 / 2
    p3 = 1
    p4 = 2

    rawPts = []
    rawPts.append(PointValue(1, Y, 2))
    rawPts.append(PointValue(2, Y, 4))
    rawPts.append(PointValue(3, Y, 4))
    rawPts.append(PointValue(4, Y, 2))

    newXs = np.linspace(rawPts[0].X - 1, rawPts[-1].X + 1, n)
    pts_p1 = []
    pts_p2 = []
    pts_p3 = []
    pts_p4 = []

    for x in newXs:
        interpolatedPt_p1 = PointValue(x, Y, 0)
        interpolatedPt_p2 = PointValue(x, Y, 0)
        interpolatedPt_p3 = PointValue(x, Y, 0)
        interpolatedPt_p4 = PointValue(x, Y, 0)

        interpVal1 = inverse_weight(interpolatedPt_p1, rawPts, p=p1)
        interpVal2 = inverse_weight(interpolatedPt_p2, rawPts, p=p2)
        interpVal3 = inverse_weight(interpolatedPt_p3, rawPts, p=p3)
        interpVal4 = inverse_weight(interpolatedPt_p4, rawPts, p=p4)

        interpolatedPt_p1.Z = interpVal1
        interpolatedPt_p2.Z = interpVal2
        interpolatedPt_p3.Z = interpVal3
        interpolatedPt_p4.Z = interpVal4

        pts_p1.append(interpolatedPt_p1)
        pts_p2.append(interpolatedPt_p2)
        pts_p3.append(interpolatedPt_p3)
        pts_p4.append(interpolatedPt_p4)

    if ShowPlots:
        plt.plot([pt.X for pt in rawPts], [pt.Z for pt in rawPts],
                 "ko",
                 label="Raw")
        plt.plot(newXs, [pt.Z for pt in pts_p1], "b", label=f"P = {p1}")
        plt.plot(newXs, [pt.Z for pt in pts_p2], "g", label=f"P = {p2}")
        plt.plot(newXs, [pt.Z for pt in pts_p3], "y", label=f"P = {p3}")
        plt.plot(newXs, [pt.Z for pt in pts_p4], "r", label=f"P = {p4}")

        plt.title(title)
        plt.legend(loc="upper left")
        plt.tight_layout()
        plt.show()