def test_direct_dist_setting(): V = Variogram([(0, 0), (4, 1), (1, 1)], [1, 2, 3], n_lags=2) V.distance = np.array([0, 0, 100]) assert_array_almost_equal(V.distance, [0, 0, 100], decimal=0)
def test_sparse_maxlag_30(self): V = Variogram(self.c, self.v, maxlag=30) for x, y in zip(V.parameters, [17.128, 6.068, 0]): self.assertAlmostEqual(x, y, places=3)
def test_sparse_standard_settings(self): V = Variogram(self.c, self.v, maxlag=10000) for x, y in zip(V.parameters, [7.122, 13.966, 0]): self.assertAlmostEqual(x, y, places=3)
def test_n_lags_not_implemented(self): with self.assertRaises(NotImplementedError): Variogram(self.c, self.v, n_lags='auto')
class TestVariogramFittingProcedure(unittest.TestCase): def setUp(self): np.random.seed(1337) self.c = np.random.gamma(10, 8, (50, 3)) np.random.seed(1337) self.v = np.random.normal(10, 4, 50) # build a standard variogram to be used self.V = Variogram(self.c, self.v, n_lags=5, normalize=False, use_nugget=True) def test_fit_sigma_is_None(self): self.V.fit_sigma = None self.assertIsNone(self.V.fit_sigma) def test_fit_sigma_explicit(self): sigs = [.8, .5, 2., 2., 5.] self.V.fit_sigma = sigs for x, y in zip(sigs, self.V.fit_sigma): self.assertEqual(x, y) def test_fit_sigma_raises_AttributeError(self): self.V.fit_sigma = (0, 1, 2) with self.assertRaises(AttributeError) as e: self.V.fit_sigma self.assertEqual(str(e.exception), 'fit_sigma and bins need the same length.') def test_fit_sigma_raises_ValueError(self): self.V.fit_sigma = 'notAnFunction' with self.assertRaises(ValueError) as e: self.V.fit_sigma self.assertTrue("fit_sigma is not understood." in str(e.exception)) def test_fit_sigma_linear(self): self.V.fit_sigma = 'linear' # test the sigmas sigma = self.V.fit_sigma for s, _s in zip(sigma, [.2, .4, .6, .8, 1.]): self.assertAlmostEqual(s, _s, places=8) # test parameters: self.V.fit() assert_array_almost_equal(self.V.parameters, [13., 0.3, 18.], decimal=1) def test_fit_sigma_exp(self): self.V.fit_sigma = 'exp' # test the sigmas sigma = self.V.fit_sigma for s, _s in zip(sigma, [0.0067, 0.0821, 0.1889, 0.2865, 0.3679]): self.assertAlmostEqual(s, _s, places=4) # test parameters assert_array_almost_equal(self.V.parameters, [25., 0.2, 18.5], decimal=1) def test_fit_sigma_sqrt(self): self.V.fit_sigma = 'sqrt' # test the sigmas assert_array_almost_equal(self.V.fit_sigma, [0.447, 0.632, 0.775, 0.894, 1.], decimal=3) # test the parameters assert_array_almost_equal(self.V.parameters, [19.7, 1.5, 16.4], decimal=1) def test_fit_sigma_sq(self): self.V.fit_sigma = 'sq' # test the sigmas assert_array_almost_equal(self.V.fit_sigma, [0.04, 0.16, 0.36, 0.64, 1.], decimal=2) # test the parameters assert_array_almost_equal(self.V.parameters, [5.4, 0.1, 18.5], decimal=1) def test_fit_sigma_entropy(self): # load data sample data = pd.read_csv(os.path.dirname(__file__) + '/sample.csv') V = Variogram(data[['x', 'y']].values, data.z.values, n_lags=12, fit_method='ml', fit_sigma='entropy') assert_array_almost_equal(V.parameters, [65.9, 1.3, 0], decimal=1) def test_fit_sigma_on_the_fly(self): self.V.fit(sigma='sq') # test the sigmas assert_array_almost_equal(self.V.fit_sigma, [0.04, 0.16, 0.36, 0.64, 1.], decimal=2) # test the parameters assert_array_almost_equal(self.V.parameters, [5.4, 0.1, 18.5], decimal=1) def test_fit_lm(self): df = pd.read_csv(os.path.dirname(__file__) + '/sample.csv') V = Variogram(df[['x', 'y']], df.z.values, use_nugget=True, n_lags=8, fit_method='lm') # test the parameters assert_array_almost_equal(V.parameters, [162.3, 0.5, 0.8], decimal=1) def test_fitted_model(self): self.V.fit_method = 'trf' self.V.fit_sigma = None fun = self.V.fitted_model result = np.array([12.48, 17.2, 17.2, 17.2]) assert_array_almost_equal(result, list(map(fun, np.arange(0, 20, 5))), decimal=2) def test_unavailable_method(self): with self.assertRaises(ValueError) as e: self.V.fit(method='unsupported') self.assertTrue("fit method has to be one of" in str(e.exception)) def test_implicit_run_fit_fitted_model(self): self.V.fit_sigma = None self.V.fit_method = 'trf' result = np.array([12.48, 17.2, 17.2, 17.2]) # remove cof self.V.cof = None # test on fitted model fun = self.V.fitted_model assert_array_almost_equal(result, list(map(fun, np.arange(0, 20, 5))), decimal=2) def test_implicit_run_fit_transform(self): self.V.fit_sigma = None self.V.fit_method = 'trf' result = np.array([12.48, 17.2, 17.2, 17.2]) # test on transform self.V.cof = None res = self.V.transform(np.arange(0, 20, 5)) assert_array_almost_equal(result, res, decimal=2) def test_harmonize_model(self): # load data sample data = pd.read_csv(os.path.dirname(__file__) + '/sample.csv') V = Variogram(data[['x', 'y']].values, data.z.values) V.model = 'harmonize' x = np.linspace(0, np.max(V.bins), 10) assert_array_almost_equal( V.transform(x), [np.NaN, 0.57, 1.01, 1.12, 1.15, 1.15, 1.15, 1.15, 1.21, 1.65], decimal=2) def test_ml_default(self): # load data sample df = pd.read_csv(os.path.dirname(__file__) + '/sample.csv') V = Variogram(df[['x', 'y']], df.z.values, use_nugget=True, n_lags=15, fit_method='ml') assert_array_almost_equal(V.parameters, np.array([41.18, 1.2, 0.]), decimal=2) def test_ml_sq_sigma(self): # load data sample df = pd.read_csv(os.path.dirname(__file__) + '/sample.csv') V = Variogram(df[['x', 'y']], df.z.values, use_nugget=True, n_lags=15, fit_method='ml', fit_sigma='sq') assert_array_almost_equal(V.parameters, np.array([42.72, 1.21, 0.]), decimal=2) def test_manual_fit(self): V = Variogram(self.c, self.v, fit_method='manual', model='spherical', fit_range=10., fit_sill=5.) self.assertEqual(V.parameters, [10., 5., 0.0]) def test_manual_fit_change(self): V = Variogram( self.c, self.v, fit_method='trf', model='matern', ) # switch to manual fit V.fit_method = 'manual' V.fit(range=10, sill=5, shape=3) self.assertEqual(V.parameters, [10., 5., 3., 0.0]) def test_manual_raises_missing_params(self): with self.assertRaises(AttributeError) as e: Variogram(self.c, self.v, fit_method='manual') self.assertTrue('For manual fitting' in str(e.exception)) def test_manual_preserve_params(self): V = Variogram(self.c, self.v, fit_method='trf', n_lags=8) params = V.parameters # switch fit method V.fit_method = 'manual' V.fit(sill=14) # expected output params[1] = 14. assert_array_almost_equal(V.parameters, params, decimal=1)
def test_binning_ward_method(self): V = Variogram(self.c, self.v, n_lags=6, bin_func='ward') assert_array_almost_equal(V.bins, np.array([2.5, 7.1, 11.1, 16.2, 23., 30.]), decimal=1)
def test_use_nugget_exception(self): with self.assertRaises(ValueError) as e: Variogram(self.c, self.v, use_nugget=42) self.assertEqual(str(e.exception), 'use_nugget has to be of type bool.')
from skgstat import Variogram import numpy as np train_data = np.load('train_data.npy') train_x = np.array(np.nonzero(train_data)).transpose() train_y = np.array([train_data[tuple(i)] for i in train_x]) V = Variogram(train_x, train_y) V.distance_difference_plot()
def read_file(path): im = Image.open(path) # im_crop = im.crop((4096, 4096, 4096 + 2048, 4096 + 2048)) # im = im_crop print(im.size, im.mode, im.format) sample_shape = (im.size[0], im.size[1]) # Sampling. coords = generate_points_with_min_distance(n=30000, shape=sample_shape, min_dist=20) GRVI_array = np.zeros(shape=(len(coords), 1)) VARI_array = np.zeros(shape=(len(coords), 1)) ExG_array = np.zeros(shape=(len(coords), 1)) # Calculating GRVI values. for ptr in range(len(coords)): # converting numpy.int64 to int. Band_R, Band_G, Band_B = im.getpixel( (int(coords[ptr][0]), int(coords[ptr][1]))) GRVI_array[ptr] = GRVI(Band_R, Band_G) VARI_array[ptr] = VARI(Band_R, Band_G, Band_B) ExG_array[ptr] = ExG(Band_R, Band_G, Band_B) print(coords.shape) _, ax = plt.subplots(1, 1, figsize=(9, 9)) art = ax.scatter(coords[:, 0], coords[:, 1], s=10, c=GRVI_array, cmap='plasma') plt.colorbar(art) plt.title("GRVI") _, ax = plt.subplots(1, 1, figsize=(9, 9)) art = ax.scatter(coords[:, 0], coords[:, 1], s=10, c=VARI_array, cmap='plasma') plt.colorbar(art) plt.title("VARI") _, ax = plt.subplots(1, 1, figsize=(9, 9)) art = ax.scatter(coords[:, 0], coords[:, 1], s=10, c=ExG_array, cmap='plasma') plt.colorbar(art) plt.title("ExG") # Computing the variogram here. V = Variogram(coords, ExG_array.flatten(), model='spherical', n_lags=15, use_nugget=True) # Performing ordinary kriging here. # ok = OrdinaryKriging(V, min_points = 5, max_points = 15, mode='exact') # plt.figure() V.plot() print(V) im = im.rotate(90) # plot plt.figure() plt.imshow(im) plt.scatter(coords[:, 0], coords[:, 1], s=3) plt.show()
# 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]]) values = np.array(data[:, 2]) V_exp = Variogram(coordinates, values, model="exponential") V_exp.plot() V_gaussian = Variogram(coordinates, values, model="gaussian") V_gaussian.plot() V_matern = Variogram(coordinates, values, model="matern") V_matern.plot() V_stable = Variogram(coordinates, values, model="stable") V_stable.plot()
val_raw_repeat = np.zeros(N_points * N_days) val_clean_repeat = np.zeros(N_points_clean * N_days) count = 0 for i in range(N_days): val_raw = raw[s][i, ~land_mask[s]] val_clean = clean[s][i, ~land_mask[s]] #~land_mask_clean if i % 30 == 0: val_raw_repeat[N_points * count:N_points * (count + 1)] = val_raw val_clean_repeat[N_points_clean * count:N_points_clean * (count + 1)] = val_clean count += 1 V_raw = Variogram(points, val_raw, n_lags=N_bins, normalize=False) V_clean = Variogram(points_clean, val_clean, n_lags=N_bins, normalize=False) if i == 0: raw_dist = V_raw._dist clean_dist = V_clean._dist raw_diff = np.zeros([N_days, len(raw_dist)]) clean_diff = np.zeros([N_days, len(clean_dist)]) raw_diff[i, :] = V_raw._diff clean_diff[i, :] = V_clean._diff
class TestPyKrigeInterface(unittest.TestCase): def setUp(self): # use real sample data in the interface df = pd.read_csv(os.path.join(os.path.dirname(__file__), 'sample.csv')) self.c = df[['x', 'y']].values self.v = df.z.values self.V = Variogram(self.c, self.v, model='matern', normalize=False, use_nugget=True) if not PYKRIGE_AVAILABLE: print('PyKrige not found, will skip all pykrige interface tests') def test_model_interface(self): if not PYKRIGE_AVAILABLE: # pragma: no cover return True # get the function model = pykrige_interface.pykrige_model(self.V) # use the transform function. xi = np.arange(1, 85) yi = self.V.transform(xi) assert_array_almost_equal(yi, model([], xi), decimal=6) def test_model_interface_from_list(self): if not PYKRIGE_AVAILABLE: # pragma: no cover return True # get the function model = pykrige_interface.pykrige_model(self.V) # use the transform function xi = list(range(1, 85)) yi = self.V.transform(np.array(xi)) assert_array_almost_equal(yi, model([], xi), decimal=6) def test_parameters(self): if not PYKRIGE_AVAILABLE: # pragma: no cover return True p = pykrige_interface.pykrige_params(self.V) params = self.V.parameters self.assertAlmostEqual(p[0], params[1], places=4) self.assertAlmostEqual(p[1], params[0], places=4) self.assertAlmostEqual(p[2], params[2], places=4) def test_as_kwargs(self): if not PYKRIGE_AVAILABLE: # pragma: no cover return True args = pykrige_interface.pykrige_as_kwargs(self.V) pars = pykrige_interface.pykrige_params(self.V) # test self.assertEqual(args['variogram_model'], 'custom') assert_array_almost_equal(pars, args['variogram_parameters']) xi = np.arange(1, 80) yi = self.V.transform(xi) assert_array_almost_equal(yi, args['variogram_function']([], xi), decimal=6) def test_as_kwargs_adjust_maxlag(self): if not PYKRIGE_AVAILABLE: # pragma: no cover return True V = self.V.clone() # now maxlag should be changed args = pykrige_interface.pykrige_as_kwargs(V, adjust_maxlag=True) # should be None self.assertIsNone(V.maxlag) # transform should change xi = np.arange(1, 20) yi = V.transform(xi) # test changed values assert_array_almost_equal(yi, args['variogram_function']([], xi)) def test_as_kwargs_adjust_nlags(self): if not PYKRIGE_AVAILABLE: # pragma: no cover return True args = pykrige_interface.pykrige_as_kwargs(self.V, adjust_nlags=True) self.assertEqual(args['nlags'], self.V.n_lags)
class TestVariogramMethods(unittest.TestCase): def setUp(self): # set up default values, whenever c and v are not important np.random.seed(42) self.c = np.random.gamma(10, 4, (30, 2)) np.random.seed(42) self.v = np.random.normal(10, 4, 30) self.V = Variogram(self.c, self.v, normalize=False, n_lags=10) def test_clone_method(self): # copy variogram copy = self.V.clone() # test against bins and experimental assert_array_almost_equal(copy.experimental, self.V.experimental) assert_array_almost_equal(copy.bins, self.V.bins) def test_data_no_force(self): lags, var = self.V.data(n=10, force=False) assert_array_almost_equal( lags, [0., 4.7, 9.4, 14.1, 18.8, 23.5, 28.2, 32.9, 37.6, 42.3], decimal=2 ) assert_array_almost_equal( var, [0., 11.82, 13.97, 13.97, 13.97, 13.97, 13.97, 13.97, 13.97, 13.97], decimal=2 ) def test_data_with_force(self): # should work if _dist is corccupted self.V._dist = self.V._dist * 5. self.V.cof = None lags, var = self.V.data(n=10, force=True) assert_array_almost_equal( lags, [0., 4.7, 9.4, 14.1, 18.8, 23.5, 28.2, 32.9, 37.6, 42.3], decimal=2 ) assert_array_almost_equal( var, [0., 11.82, 13.97, 13.97, 13.97, 13.97, 13.97, 13.97, 13.97, 13.97], decimal=2 ) def test_data_normalized(self): V = self.V.clone() V.normalize = True lags, var = V.data(n=5, force=True) assert_array_almost_equal( lags, [0., 10.58, 21.15, 31.73, 42.3], decimal=2 ) assert_array_almost_equal( var, [0., 13.97, 13.97, 13.97, 13.97], decimal=2 ) def test_parameter_property_matern(self): V = self.V.clone() # test matern param = [42.3, 16.2, 0.1, 0.] V.set_model('matern') assert_array_almost_equal(V.parameters, param, decimal=2) def test_parameter_property_stable(self): V = self.V.clone() # test stable param = [42.3 , 15.79, 0.45, 0.] V.set_model('stable') assert_array_almost_equal(V.parameters, param, decimal=2)
class TestVariogramFittingProcedure(unittest.TestCase): def setUp(self): np.random.seed(1337) self.c = np.random.gamma(10, 8, (50, 3)) np.random.seed(1337) self.v = np.random.normal(10, 4, 50) # build a standard variogram to be used self.V = Variogram( self.c, self.v, n_lags=5, normalize=False, use_nugget=True ) def test_fit_sigma_is_None(self): self.V.fit_sigma = None self.assertIsNone(self.V.fit_sigma) def test_fit_sigma_explicit(self): sigs = [.8, .5, 2., 2., 5.] self.V.fit_sigma = sigs for x, y in zip(sigs, self.V.fit_sigma): self.assertEqual(x, y) # test parameter estimated self.V.fit() assert_array_almost_equal( self.V.parameters, [24.008, 17.083, 0.99], decimal=3 ) def test_fit_sigma_raises_AttributeError(self): self.V.fit_sigma = (0, 1, 2) with self.assertRaises(AttributeError) as e: self.V.fit_sigma self.assertEqual( str(e.exception), 'fit_sigma and bins need the same length.' ) def test_fit_sigma_raises_ValueError(self): self.V.fit_sigma = 'notAnFunction' with self.assertRaises(ValueError) as e: self.V.fit_sigma self.assertEqual( str(e.exception), "fit_sigma is not understood. It has to be an array or one of ['linear', 'exp', 'sqrt', 'sq']." ) def test_fit_sigma_linear(self): self.V.fit_sigma = 'linear' # test the sigmas sigma = self.V.fit_sigma for s, _s in zip(sigma, [.2, .4, .6, .8, 1.]): self.assertAlmostEqual(s, _s, places=8) # test parameters: self.V.fit() assert_array_almost_equal( self.V.parameters, [25.077, 17.393, 0.925], decimal=3 ) def test_fit_sigma_exp(self): self.V.fit_sigma = 'exp' # test the sigmas sigma = self.V.fit_sigma for s, _s in zip(sigma, [0.0067, 0.0821, 0.1889, 0.2865, 0.3679]): self.assertAlmostEqual(s, _s, places=4) # test parameters assert_array_almost_equal( self.V.parameters, [25.3, 17.7, 1.], decimal=1 ) def test_fit_sigma_sqrt(self): self.V.fit_sigma = 'sqrt' # test the sigmas assert_array_almost_equal( self.V.fit_sigma, [0.447, 0.632, 0.775, 0.894, 1.], decimal=3 ) # test the parameters assert_array_almost_equal( self.V.parameters, [23., 17., 1.], decimal=1 ) def test_fit_sigma_sq(self): self.V.fit_sigma = 'sq' # test the sigmas assert_array_almost_equal( self.V.fit_sigma, [0.04, 0.16, 0.36, 0.64, 1.], decimal=2 ) # test the parameters assert_array_almost_equal( self.V.parameters, [25.3, 17.6, 1.], decimal=1 ) def test_fit_sigma_on_the_fly(self): self.V.fit(sigma='sq') # test the sigmas assert_array_almost_equal( self.V.fit_sigma, [0.04, 0.16, 0.36, 0.64, 1.], decimal=2 ) # test the parameters assert_array_almost_equal( self.V.parameters, [25.3, 17.6, 1.], decimal=1 ) def test_fit_lm(self): self.V.fit(method='lm', sigma='sqrt') # test the parameters assert_array_almost_equal( self.V.parameters, [1., 17., 1.], decimal=0 ) def test_fitted_model(self): fun = self.V.fitted_model result = [0.99, 7.19, 12.53, 16.14] assert_array_almost_equal( result, list(map(fun, np.arange(0, 20, 5))), decimal=2 ) def test_unavailable_method(self): with self.assertRaises(ValueError) as e: self.V.fit(method='unsupported') self.assertEqual( "fit method has to be one of ['trf', 'lm']", str(e.exception) ) def test_implicit_run_fit_fitted_model(self): self.V.fit_sigma = None self.V.fit_method = 'trf' result = [0.99, 7.19, 12.53, 16.14] # remove cof self.V.cof = None # test on fitted model fun = self.V.fitted_model assert_array_almost_equal( result, list(map(fun, np.arange(0, 20, 5))), decimal=2 ) def test_implicit_run_fit_transform(self): self.V.fit_sigma = None self.V.fit_method = 'trf' result = [0.99, 7.19, 12.53, 16.14] # test on transform self.V.cof = None res = self.V.transform(np.arange(0, 20, 5)) assert_array_almost_equal(result, res, decimal=2) def test_harmonize_model(self): # load data sample data = pd.read_csv(os.path.dirname(__file__) + '/sample.csv') V = Variogram(data[['x', 'y']].values, data.z.values) V.model = 'harmonize' x = np.linspace(0, np.max(V.bins), 10) assert_array_almost_equal( V.transform(x), [np.NaN, 0.57, 1.01, 1.12, 1.15, 1.15, 1.15, 1.15, 1.21, 1.65], decimal=2 )
def test_value_warning(self): with self.assertRaises(Warning) as w: Variogram(self.c, [42] * 30) self.assertEqual('All input values are the same.', str(w.exception))
def test_location_trend_raises(self): V = Variogram(self.c, self.v) with self.assertRaises(ValueError): V.location_trend(axes=[0, 1, 2])
def test_binning_non_string_arg(self): V = Variogram(self.c, self.v, n_lags=8) return True
def test_variogram_default_describe(self): V = Variogram(self.c, self.v) desc = V.describe() self.assertTrue('params' in desc.keys()) self.assertTrue('kwargs' in desc.keys())
def test_maxlag_custom_value(self): V = Variogram(self.c, self.v) V.maxlag = 33.3 self.assertAlmostEqual(V.maxlag, 33.3, places=1)
def test_variogram_describe_short(self): V = Variogram(self.c, self.v) desc = V.describe(short=True) self.assertFalse('params' in desc.keys()) self.assertFalse('kwargs' in desc.keys())
def test_n_lags_change(self): V = Variogram(self.c, self.v, n_lags=10) self.assertEqual(len(V.bins), 10) V.n_lags = 5 self.assertEqual(len(V.bins), 5)
class TestVariogramPlotlyPlots(unittest.TestCase): def setUp(self): # set up default values, whenever c and v are not important np.random.seed(42) self.c = np.random.gamma(10, 4, (150, 2)) np.random.seed(42) self.v = np.random.normal(10, 4, 150) self.V = Variogram(self.c, self.v) def test_plotly_main_plot(self): if PLOTLY_FOUND: # switch to plotly plotting.backend('plotly') self.assertTrue(isinstance(self.V.plot(show=False), go.Figure)) plotting.backend('matplotlib') def test_plotly_scattergram(self): if PLOTLY_FOUND: # switch to plotly plotting.backend('plotly') self.assertTrue( isinstance(self.V.scattergram(show=False), go.Figure)) plotting.backend('matplotlib') def test_plotly_location_trend(self): if PLOTLY_FOUND: # switch to plotly plotting.backend('plotly') self.assertTrue( isinstance(self.V.location_trend(show=False), go.Figure)) plotting.backend('matplotlib') def test_plotly_dd_plot(self): if PLOTLY_FOUND: # switch to plotly plotting.backend('plotly') self.assertTrue( isinstance(self.V.distance_difference_plot(show=False), go.Figure)) plotting.backend('matplotlib') def test_undefined_backend(self): # force the backend into an undefined state import skgstat skgstat.__backend__ = 'not-a-backend' for fname in ('plot', 'scattergram', 'location_trend', 'distance_difference_plot'): with self.assertRaises(ValueError) as e: self.V.plot() self.assertEqual( str(e.exception), 'The plotting backend has an undefined state.') # make the backend valid again skgstat.__backend__ = 'matplotlib'
def test_dense_maxlag_inf(self): Vdense = Variogram(self.c, self.v) Vsparse = Variogram(self.c, self.v, maxlag=10000000) for x, y in zip(Vdense.parameters, Vsparse.parameters): self.assertAlmostEqual(x, y, places=3)
def test_unknown_binning_func(self): with self.assertRaises(ValueError) as e: Variogram(self.c, self.v, bin_func='notafunc') self.assertEqual("'notafunc' is not a valid estimator for `bins`", str(e.exception))
def test_sparse_maxlag_50(self): V = Variogram(self.c, self.v, maxlag=50) for x, y in zip(V.parameters, [20.264, 6.478, 0]): self.assertAlmostEqual(x, y, places=3)
def test_invalid_binning_func(self): with self.assertRaises(AttributeError) as e: V = Variogram(self.c, self.v) V.set_bin_func(42) self.assertTrue('of type string' in str(e.exception))
def test_manual_raises_missing_params(self): with self.assertRaises(AttributeError) as e: Variogram(self.c, self.v, fit_method='manual') self.assertTrue('For manual fitting' in str(e.exception))
def test_unsupported_n_lags(self): with self.assertRaises(ValueError) as e: Variogram(self.c, self.v, n_lags=15.7) self.assertEqual('n_lags has to be a positive integer', str(e.exception))
def test_nrmse_r(self): V = Variogram(self.c, self.v, estimator='cressie') self.assertAlmostEqual(V.nrmse_r, 0.63543, places=5)
def test_NS(self): V = Variogram(self.c, self.v, n_lags=15, normalize=False) for estimator, NS in zip(('matheron', 'genton', 'dowd'), [0.0206, 0.0206, 0.0206]): self.assertAlmostEqual(V.NS, NS, places=4)