Skip to content

Commit

Permalink
Randmeth: rename summators; remove superfluous tests for structured s…
Browse files Browse the repository at this point in the history
…ummation
  • Loading branch information
MuellerSeb committed Nov 23, 2020
1 parent 04c4c6c commit 713843e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 60 deletions.
8 changes: 3 additions & 5 deletions gstools/field/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import numpy as np
from gstools.covmodel.base import CovModel
from gstools.random.rng import RNG
from gstools.field.summator import summate_unstruct, summate_incompr_unstruct
from gstools.field.summator import summate, summate_incompr


__all__ = ["RandMeth", "IncomprRandMeth"]
Expand Down Expand Up @@ -98,9 +98,7 @@ def __call__(self, pos):
the random modes
"""
pos = np.array(pos, dtype=np.double)
summed_modes = summate_unstruct(
self._cov_sample, self._z_1, self._z_2, pos
)
summed_modes = summate(self._cov_sample, self._z_1, self._z_2, pos)
nugget = self._set_nugget(summed_modes.shape)

return np.sqrt(self.model.var / self._mode_no) * summed_modes + nugget
Expand Down Expand Up @@ -367,7 +365,7 @@ def __call__(self, pos):
the random modes
"""
pos = np.array(pos, dtype=np.double)
summed_modes = summate_incompr_unstruct(
summed_modes = summate_incompr(
self._cov_sample, self._z_1, self._z_2, pos
)
nugget = self._set_nugget(summed_modes.shape)
Expand Down
4 changes: 2 additions & 2 deletions gstools/field/summator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DTYPE = np.double
ctypedef np.double_t DTYPE_t


def summate_unstruct(
def summate(
const double[:,:] cov_samples,
const double[:] z_1,
const double[:] z_2,
Expand Down Expand Up @@ -52,7 +52,7 @@ cdef (double) abs_square(const double[:] vec) nogil:
return r


def summate_incompr_unstruct(
def summate_incompr(
const double[:,:] cov_samples,
const double[:] z_1,
const double[:] z_2,
Expand Down
31 changes: 0 additions & 31 deletions tests/test_incomprrandmeth.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,6 @@ def test_unstruct_3d(self):
self.assertAlmostEqual(modes[0, 1], 1.38687858)
self.assertAlmostEqual(modes[1, 0], -0.27245271)

# def test_struct_2d(self):
# modes = self.rm_2d(self.x_grid, self.y_grid, mesh_type="structured")
# self.assertAlmostEqual(modes[0, 0, 0], 0.50751115)
# self.assertAlmostEqual(modes[0, 1, 0], 0.69751927)
# self.assertAlmostEqual(modes[1, 1, 1], -0.19747468)

# def test_struct_3d(self):
# modes = self.rm_3d(
# self.x_grid, self.y_grid, self.z_grid, mesh_type="structured"
# )
# self.assertAlmostEqual(modes[0, 0, 0, 0], 1.49469700)
# self.assertAlmostEqual(modes[1, 0, 1, 1], 0.12813365)
# self.assertAlmostEqual(modes[1, 1, 0, 1], 0.01443056)
# self.assertAlmostEqual(modes[1, 1, 1, 1], -0.12304040)

# def test_struct_unstruct(self):
# x_grid = np.arange(0.0, 2.0, 1.0)
# y_grid = np.arange(0.0, 2.0, 1.0)
# x_tuple = np.array((0.0, 0.0, 1.0, 1.0))
# y_tuple = np.array((0.0, 1.0, 0.0, 1.0))
# unstr_modes = self.rm_2d(x_tuple, y_tuple, mesh_type="unstructured")
# str_modes = self.rm_2d(x_grid, y_grid, mesh_type="structured")
# for d in range(2):
# k = 0
# for i in range(len(x_grid)):
# for j in range(len(y_grid)):
# self.assertAlmostEqual(
# str_modes[d, i, j], unstr_modes[d, k]
# )
# k += 1

def test_assertions(self):
cov_model_1d = Gaussian(dim=1, var=1.5, len_scale=2.5)
self.assertRaises(ValueError, IncomprRandMeth, cov_model_1d)
Expand Down
22 changes: 0 additions & 22 deletions tests/test_randmeth.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,6 @@ def test_unstruct_3d(self):
self.assertAlmostEqual(modes[0], 0.55488481)
self.assertAlmostEqual(modes[1], 1.18506639)

# def test_struct_1d(self):
# modes = self.rm_1d(self.x_grid, mesh_type="structured")
# self.assertAlmostEqual(modes[0], 3.19799030)
# self.assertAlmostEqual(modes[1], 2.34788923)

# def test_struct_2d(self):
# modes = self.rm_2d(self.x_grid, self.y_grid, mesh_type="structured")
# self.assertAlmostEqual(modes[0, 0], 1.67318010)
# self.assertAlmostEqual(modes[1, 0], 1.54740003)
# self.assertAlmostEqual(modes[0, 1], 2.02106551)
# self.assertAlmostEqual(modes[1, 1], 1.86883255)

# def test_struct_3d(self):
# modes = self.rm_3d(
# self.x_grid, self.y_grid, self.z_grid, mesh_type="structured"
# )
# self.assertAlmostEqual(modes[0, 0, 0], 0.55488481)
# self.assertAlmostEqual(modes[0, 1, 0], 0.41858766)
# self.assertAlmostEqual(modes[1, 1, 0], 0.95133855)
# self.assertAlmostEqual(modes[0, 1, 1], 0.65475042)
# self.assertAlmostEqual(modes[1, 1, 1], 1.40915120)

def test_reset(self):
modes = self.rm_2d((self.x_tuple, self.y_tuple))
self.assertAlmostEqual(modes[0], 1.67318010)
Expand Down

0 comments on commit 713843e

Please sign in to comment.