Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_core_initialize_variogram_model(validation_ref):
data, _, _ = validation_ref
# Note the variogram_function argument is not a string in real life...
# core._initialize_variogram_model also checks the length of input
# lists, which is redundant now because the same tests are done in
# core._make_variogram_parameter_list
with pytest.raises(ValueError):
core._initialize_variogram_model(
np.vstack((data[:, 0], data[:, 1])).T,
data[:, 2],
"linear",
[0.0],
"linear",
6,
False,
"euclidean",
)
with pytest.raises(ValueError):
core._initialize_variogram_model(
np.vstack((data[:, 0], data[:, 1])).T,
data[:, 2],
"spherical",
[0.0],
"spherical",
# now because the same tests are done in
# core._make_variogram_parameter_list
with pytest.raises(ValueError):
core._initialize_variogram_model(
np.vstack((data[:, 0], data[:, 1], data[:, 2])).T,
data[:, 3],
"linear",
[0.0],
"linear",
6,
False,
"euclidean",
)
with pytest.raises(ValueError):
core._initialize_variogram_model(
np.vstack((data[:, 0], data[:, 1], data[:, 2])).T,
data[:, 3],
"spherical",
[0.0],
"spherical",
6,
False,
"euclidean",
)
with pytest.raises(ValueError):
core._initialize_variogram_model(
np.vstack((data[:, 0], data[:, 1], data[:, 2])).T,
data[:, 3],
"linear",
[0.0, 0.0],
with pytest.raises(ValueError):
core._initialize_variogram_model(
np.vstack((data[:, 0], data[:, 1])).T,
data[:, 2],
"spherical",
[0.0],
"spherical",
6,
False,
"euclidean",
)
# core._initialize_variogram_model does also check coordinate type,
# this is NOT redundant
with pytest.raises(ValueError):
core._initialize_variogram_model(
np.vstack((data[:, 0], data[:, 1])).T,
data[:, 2],
"spherical",
[0.0, 0.0, 0.0],
"spherical",
6,
False,
"tacos",
)
x = np.array([1.0 + n / np.sqrt(2) for n in range(4)])
y = np.array([1.0 + n / np.sqrt(2) for n in range(4)])
z = np.arange(1.0, 5.0, 1.0)
lags, semivariance, variogram_model_parameters = core._initialize_variogram_model(
np.vstack((x, y)).T, z, "linear", [0.0, 0.0], "linear", 6, False, "euclidean"
)
with pytest.raises(ValueError):
core._initialize_variogram_model(
np.vstack((data[:, 0], data[:, 1])).T,
data[:, 2],
"spherical",
[0.0, 0.0, 0.0],
"spherical",
6,
False,
"tacos",
)
x = np.array([1.0 + n / np.sqrt(2) for n in range(4)])
y = np.array([1.0 + n / np.sqrt(2) for n in range(4)])
z = np.arange(1.0, 5.0, 1.0)
lags, semivariance, variogram_model_parameters = core._initialize_variogram_model(
np.vstack((x, y)).T, z, "linear", [0.0, 0.0], "linear", 6, False, "euclidean"
)
assert_allclose(lags, np.array([1.0, 2.0, 3.0]))
assert_allclose(semivariance, np.array([0.5, 2.0, 4.5]))
def test_core_initialize_variogram_model_3d(sample_data_3d):
data, _, _ = sample_data_3d
# Note the variogram_function argument is not a string in real life...
# again, these checks in core._initialize_variogram_model are redundant
# now because the same tests are done in
# core._make_variogram_parameter_list
with pytest.raises(ValueError):
core._initialize_variogram_model(
np.vstack((data[:, 0], data[:, 1], data[:, 2])).T,
data[:, 3],
"linear",
[0.0],
"linear",
6,
False,
"euclidean",
)
with pytest.raises(ValueError):
core._initialize_variogram_model(
np.vstack((data[:, 0], data[:, 1], data[:, 2])).T,
data[:, 3],
"spherical",
[0.0],
[self.XCENTER, self.YCENTER, self.ZCENTER],
[self.anisotropy_scaling_y, self.anisotropy_scaling_z],
[self.anisotropy_angle_x, self.anisotropy_angle_y, self.anisotropy_angle_z],
).T
if self.verbose:
print("Initializing variogram model...")
vp_temp = _make_variogram_parameter_list(
self.variogram_model, variogram_parameters
)
(
self.lags,
self.semivariance,
self.variogram_model_parameters,
) = _initialize_variogram_model(
np.vstack((self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED)).T,
self.VALUES,
self.variogram_model,
vp_temp,
self.variogram_function,
nlags,
weight,
"euclidean",
)
if self.verbose:
if self.variogram_model == "linear":
print("Using '%s' Variogram Model" % "linear")
print("Slope:", self.variogram_model_parameters[0])
print("Nugget:", self.variogram_model_parameters[1], "\n")
elif self.variogram_model == "power":
[self.XCENTER, self.YCENTER, self.ZCENTER],
[self.anisotropy_scaling_y, self.anisotropy_scaling_z],
[self.anisotropy_angle_x, self.anisotropy_angle_y, self.anisotropy_angle_z],
).T
if self.verbose:
print("Initializing variogram model...")
vp_temp = _make_variogram_parameter_list(
self.variogram_model, variogram_parameters
)
(
self.lags,
self.semivariance,
self.variogram_model_parameters,
) = _initialize_variogram_model(
np.vstack((self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED)).T,
self.VALUES,
self.variogram_model,
vp_temp,
self.variogram_function,
nlags,
weight,
"euclidean",
)
if self.verbose:
if self.variogram_model == "linear":
print("Using '%s' Variogram Model" % "linear")
print("Slope:", self.variogram_model_parameters[0])
print("Nugget:", self.variogram_model_parameters[1], "\n")
elif self.variogram_model == "power":
self.anisotropy_scaling = 1.0
self.anisotropy_angle = 0.0
self.X_ADJUSTED = self.X_ORIG
self.Y_ADJUSTED = self.Y_ORIG
if self.verbose:
print("Updating variogram mode...")
# See note above about the 'use_psill' kwarg...
vp_temp = _make_variogram_parameter_list(
self.variogram_model, variogram_parameters
)
(
self.lags,
self.semivariance,
self.variogram_model_parameters,
) = _initialize_variogram_model(
np.vstack((self.X_ADJUSTED, self.Y_ADJUSTED)).T,
self.Z,
self.variogram_model,
vp_temp,
self.variogram_function,
nlags,
weight,
self.coordinates_type,
)
if self.verbose:
print("Coordinates type: '%s'" % self.coordinates_type, "\n")
if self.variogram_model == "linear":
print("Using '%s' Variogram Model" % "linear")
print("Slope:", self.variogram_model_parameters[0])
print("Nugget:", self.variogram_model_parameters[1], "\n")
self.anisotropy_angle_y,
self.anisotropy_angle_z,
],
).T
if self.verbose:
print("Updating variogram mode...")
vp_temp = _make_variogram_parameter_list(
self.variogram_model, variogram_parameters
)
(
self.lags,
self.semivariance,
self.variogram_model_parameters,
) = _initialize_variogram_model(
np.vstack((self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED)).T,
self.VALUES,
self.variogram_model,
vp_temp,
self.variogram_function,
nlags,
weight,
"euclidean",
)
if self.verbose:
if self.variogram_model == "linear":
print("Using '%s' Variogram Model" % "linear")
print("Slope:", self.variogram_model_parameters[0])
print("Nugget:", self.variogram_model_parameters[1], "\n")
elif self.variogram_model == "power":
[self.anisotropy_scaling],
[self.anisotropy_angle],
).T
if self.verbose:
print("Initializing variogram model...")
# see comment in ok.py about 'use_psill' kwarg...
vp_temp = _make_variogram_parameter_list(
self.variogram_model, variogram_parameters
)
(
self.lags,
self.semivariance,
self.variogram_model_parameters,
) = _initialize_variogram_model(
np.vstack((self.X_ADJUSTED, self.Y_ADJUSTED)).T,
self.Z,
self.variogram_model,
vp_temp,
self.variogram_function,
nlags,
weight,
"euclidean",
)
# TODO extend geographic capabilities to UK...
if self.verbose:
if self.variogram_model == "linear":
print("Using '%s' Variogram Model" % "linear")
print("Slope:", self.variogram_model_parameters[0])
print("Nugget:", self.variogram_model_parameters[1], "\n")