Beispiel #1
0
    def test_bfuncs(self):
        """
        Test accuracy of built-in function specification
        """
        x = np.linspace(0, 10, 100)
        yb = spherical(x, .2, 4, 6)

        bfit = fvariogram(source="func", methd="sph", options=[.2, 4, 6])
        self.assertTrue(np.allclose(yb, bfit(x)))
Beispiel #2
0
    def test_bmodel(self):
        """
        Test accuracy of built-in model fitting
        """
        x = np.linspace(0, 10, 100)
        y = spherical(x, .2, 4, 6)

        fit = fvariogram(source="data", methd="bmodel", options=[x, y, "sph"])

        self.assertTrue(np.allclose(y, fit(x)))
Beispiel #3
0
    def test_poly(self):
        """
        Test accuracy of polyfit
        """
        x = np.linspace(0, 10, 100)

        for n in range(2, 8):
            y = x**n - 2 * x**(n - 1) + x**(n - 2)

            fit = fvariogram(source="data", methd="poly", options=[x, y, n])
            self.assertTrue(np.allclose(y, fit(x)))
Beispiel #4
0
    def test_lin_interp(self):
        """
        Test accuracy of linear interpolation
        """
        x = np.linspace(0, 10, 100)
        y = .04 * x

        fit = fvariogram(source="data",
                         methd="interp",
                         options=[x, y, "linear"])
        self.assertTrue(np.allclose(y, fit(x)))
Beispiel #5
0
    def test_ufuncs(self):
        """
        Test accuracy of user-specified function specification
        """
        def u(x):
            return np.sqrt(x)

        x = np.linspace(0, 10, 100)
        yu = u(x)

        ufunc = fvariogram(source="func", methd="ufunc", options=[u])
        self.assertTrue(np.allclose(yu, ufunc(x)))
Beispiel #6
0
    def test_umodel(self):
        """
        Test accuracy of user-specified model fitting
        """
        def u(x, v, h):
            return v * np.sqrt(h * x)

        x = np.linspace(0, 10, 100)
        y = u(x, 1.4, 3.2)

        fit = fvariogram(source="data", methd="umodel", options=[x, y, u])

        self.assertTrue(np.allclose(y, fit(x)))
Beispiel #7
0
    def test_near_interp(self):
        """
        Test accuracy of nearest interploation
        """
        x = np.linspace(0, 10, 100)

        def f(x):
            return x**2 + x * np.sin(x)

        y = f(x)

        fit = fvariogram(source="data",
                         methd="interp",
                         options=[x, y, "nearest"])

        xnew = x[:-1] + np.random.uniform(0, 1, 99) * np.diff(x)
        xnearest = np.array([x[np.abs(x - a).argmin()] for a in xnew])
        self.assertTrue(np.allclose(f(xnearest), fit(xnew)))
Beispiel #8
0
def bench_revarie(tlimit=15, path="."):
    """
    Run timing benchmark test for revarie class. Results are formatted and
    printed to a file named "revarie_timing###.dat".

    Parameters
    ----------
    tlimit : float
        Approximate wall time limit for tests to run.
    path : str, path-like
        Path for results file to be printed to
    """
    tot_time = time.time()

    nug = 0
    sill = 1
    rang = 0.3
    v = fvariogram("func", "sph", [nug, sill, rang])

    mu = 1

    n = 50
    ns = []
    ts = []
    while time.time() - tot_time < tlimit:
        start = time.time()
        ns.append(n)
        x = np.random.uniform(0, 1, n)

        Revarie(x, mu, sill, v).genf()

        ts.append(time.time() - start)
        n = int(n * 1.2)

    t = 0
    fname = Path("revarie_timing" + str(t).zfill(3) + ".dat")
    while (Path(path) / fname).is_file():
        t += 1
        fname = Path("revarie_timing" + str(t).zfill(3) + ".dat")
    write(np.asarray(ns), np.asarray(ts), Path(path) / fname, "Revarie", "1-D")