Ejemplo n.º 1
0
 def test_nnearest_warning(self):
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter("always")
         ipol.Idw(self.src, self.trg, nnearest=len(self.src) + 1)
         ipol.OrdinaryKriging(self.src, self.trg, nnearest=len(self.src) + 1)
         ipol.ExternalDriftKriging(self.src, self.trg, nnearest=len(self.src) + 1)
         for item in w:
             assert issubclass(item.category, UserWarning)
             assert "nnearest" in str(item.message)
Ejemplo n.º 2
0
    def test_OrdinaryKriging_1(self):
        """testing the basic behaviour of the OrdinaryKriging class"""

        ip = ipol.OrdinaryKriging(self.src, self.trg, '1.0 Lin(2.0)')

        res = ip(self.vals)
        self.assertTrue(np.all(res == np.array([[1., 2., 3.],
                                                [2., 2., 2.],
                                                [1.5, 2., 2.5],
                                                [3., 2., 1.]])))
Ejemplo n.º 3
0
    def test_OrdinaryKriging_1(self):
        """testing the basic behaviour of the OrdinaryKriging class"""

        ip = ipol.OrdinaryKriging(self.src, self.trg, "1.0 Lin(2.0)")
        # input more than one dataset
        res = ip(self.vals)
        assert np.all(res == np.array([[1.0, 2.0, 3.0], [2.0, 2.0, 2.0],
                                       [1.5, 2.0, 2.5], [3.0, 2.0, 1.0]]))
        # input only one flat array
        res = ip(self.vals[:, 2])
        assert np.allclose(res, np.array([3.0, 2.0, 2.5, 1.0]))
Ejemplo n.º 4
0
 def test_MissingErrors(self):
     with pytest.raises(ipol.MissingSourcesError):
         ipol.Nearest(np.array([]), self.trg)
     with pytest.raises(ipol.MissingTargetsError):
         ipol.Nearest(self.src, np.array([]))
     with pytest.raises(ipol.MissingSourcesError):
         ipol.Idw(np.array([]), self.trg)
     with pytest.raises(ipol.MissingTargetsError):
         ipol.Idw(self.src, np.array([]))
     with pytest.raises(ipol.MissingSourcesError):
         ipol.Linear(np.array([]), self.trg)
     with pytest.raises(ipol.MissingTargetsError):
         ipol.Linear(self.src, np.array([]))
     with pytest.raises(ipol.MissingSourcesError):
         ipol.OrdinaryKriging(np.array([]), self.trg)
     with pytest.raises(ipol.MissingTargetsError):
         ipol.OrdinaryKriging(self.src, np.array([]))
     with pytest.raises(ipol.MissingSourcesError):
         ipol.ExternalDriftKriging(np.array([]), self.trg)
     with pytest.raises(ipol.MissingTargetsError):
         ipol.ExternalDriftKriging(self.src, np.array([]))
Ejemplo n.º 5
0
# Interpolation IDW
idw = ipol.Idw(src, trg)
gridplot(idw(vals.ravel()), "IDW")

# Other approach for IDW
ip_near = ipol.Nearest(src, trg)
maxdist = trg[1, 0] - trg[0, 0]
result_near = ip_near(vals.ravel(), maxdist=maxdist)

# 5.2.3 Kriging ===============================
df_meg_nodes_np = np.array(df_meg_nodes)
gridx = np.arange(0.0, 5.5, 0.5)
gridy = np.arange(0.0, 5.5, 0.5)

# Ordninary Kriging
ok = ipol.OrdinaryKriging(src, trg)
gridplot(ok(vals.ravel()), "Ordinary Kriging")

# Universal Kriging
UK = UniversalKriging(df_meg_nodes_np[:, 0],
                      df_meg_nodes_np[:, 4],
                      df_meg_nodes_np[:, 1],
                      variogram_model='linear',
                      drift_terms=['regional_linear'])
z, ss = UK.execute('grid', xtrg, ytrg)

# Variogram KDE Sample Points
from skgstat import Variogram

data = np.array(df_meg_nodes_np[:, [5, 6, 7]])
coordinates = np.array(data[:, [0, 1]])