Skip to content

Commit

Permalink
better conversion for pos2xyz; 1D special case
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed Sep 3, 2019
1 parent 02d7640 commit a6f5be8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions gstools/field/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def ordinary(srf):
krige_field, krige_var = krige_ok(srf.pos, srf.mesh_type)

# evaluate the field at the conditional points
x, y, z = pos2xyz(srf.cond_pos)
x, y, z = pos2xyz(srf.cond_pos, max_dim=srf.model.dim)
if srf.model.do_rotation:
x, y, z = unrotate_mesh(srf.model.dim, srf.model.angles, x, y, z)
y, z = make_isotropic(srf.model.dim, srf.model.anis, y, z)
Expand Down Expand Up @@ -84,7 +84,7 @@ def simple(srf):
krige_field, krige_var = krige_sk(srf.pos, srf.mesh_type)

# evaluate the field at the conditional points
x, y, z = pos2xyz(srf.cond_pos)
x, y, z = pos2xyz(srf.cond_pos, max_dim=srf.model.dim)
if srf.model.do_rotation:
x, y, z = unrotate_mesh(srf.model.dim, srf.model.angles, x, y, z)
y, z = make_isotropic(srf.model.dim, srf.model.anis, y, z)
Expand Down
6 changes: 3 additions & 3 deletions gstools/field/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _plot_1d(pos, field, fig=None, ax=None): # pragma: no cover
"""Plot a 1d field."""
fig, ax = _get_fig_ax(fig, ax)
title = "Field 1D: " + str(field.shape)
x, __, __ = pos2xyz(pos)
x, __, __ = pos2xyz(pos, max_dim=1)
x = x.flatten()
arg = np.argsort(x)
ax.plot(x[arg], field.ravel()[arg])
Expand All @@ -73,7 +73,7 @@ def _plot_2d(pos, field, mesh_type, fig=None, ax=None): # pragma: no cover
"""Plot a 2d field."""
fig, ax = _get_fig_ax(fig, ax)
title = "Field 2D " + mesh_type + ": " + str(field.shape)
x, y, __ = pos2xyz(pos)
x, y, __ = pos2xyz(pos, max_dim=2)
if mesh_type == "unstructured":
cont = ax.tricontourf(x, y, field.ravel(), levels=256)
else:
Expand Down Expand Up @@ -242,7 +242,7 @@ def plot_vec_field(fld, field="field", fig=None, ax=None): # pragma: no cover

fig, ax = _get_fig_ax(fig, ax)
title = "Field 2D " + fld.mesh_type + ": " + str(plot_field.shape)
x, y, __ = pos2xyz(fld.pos)
x, y, __ = pos2xyz(fld.pos, max_dim=2)

sp = plt.streamplot(
x,
Expand Down
17 changes: 12 additions & 5 deletions gstools/krige/ordinary.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, model, cond_pos, cond_val):
self.krige_var = None
# initialize private attributes
self._value_type = "scalar"
self._c_x = self._c_y = self._c_z = None
self._cond_pos = None
self._cond_val = None
self.set_condition(cond_pos, cond_val)
Expand Down Expand Up @@ -78,9 +79,7 @@ def __call__(self, pos, mesh_type="unstructured"):
"""
# internal conversation
x, y, z = pos2xyz(pos, dtype=np.double, max_dim=self.model.dim)
c_x, c_y, c_z = pos2xyz(
self.cond_pos, dtype=np.double, max_dim=self.model.dim
)
c_x, c_y, c_z = self.cond_xyz
self.pos = xyz2pos(x, y, z)
self.mesh_type = mesh_type
# format the positional arguments of the mesh
Expand Down Expand Up @@ -157,8 +156,16 @@ def set_condition(self, cond_pos, cond_val):
cond_val : :class:`numpy.ndarray`
the values of the conditions
"""
self._cond_pos = cond_pos
self._cond_val = np.array(cond_val, dtype=np.double)
self._c_x, self._c_y, self._c_z = pos2xyz(
cond_pos, dtype=np.double, max_dim=self.model.dim
)
self._cond_pos = xyz2pos(self._c_x, self._c_y, self._c_z)
self._cond_val = np.array(cond_val, dtype=np.double).reshape(-1)

@property
def cond_xyz(self):
""":class:`list`: The position coordinates of the conditions."""
return self._c_x, self._c_y, self._c_z

@property
def cond_pos(self):
Expand Down
17 changes: 12 additions & 5 deletions gstools/krige/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, model, mean, cond_pos, cond_val):
self.krige_var = None
# initialize private attributes
self._value_type = "scalar"
self._c_x = self._c_y = self._c_z = None
self._cond_pos = None
self._cond_val = None
self.set_condition(cond_pos, cond_val)
Expand Down Expand Up @@ -81,9 +82,7 @@ def __call__(self, pos, mesh_type="unstructured"):
"""
# internal conversation
x, y, z = pos2xyz(pos, dtype=np.double, max_dim=self.model.dim)
c_x, c_y, c_z = pos2xyz(
self.cond_pos, dtype=np.double, max_dim=self.model.dim
)
c_x, c_y, c_z = self.cond_xyz
self.pos = xyz2pos(x, y, z)
self.mesh_type = mesh_type
# format the positional arguments of the mesh
Expand Down Expand Up @@ -144,8 +143,16 @@ def set_condition(self, cond_pos, cond_val):
cond_val : :class:`numpy.ndarray`
the values of the conditions
"""
self._cond_pos = cond_pos
self._cond_val = np.array(cond_val, dtype=np.double)
self._c_x, self._c_y, self._c_z = pos2xyz(
cond_pos, dtype=np.double, max_dim=self.model.dim
)
self._cond_pos = xyz2pos(self._c_x, self._c_y, self._c_z)
self._cond_val = np.array(cond_val, dtype=np.double).reshape(-1)

@property
def cond_xyz(self):
""":class:`list`: The position coordinates of the conditions."""
return self._c_x, self._c_y, self._c_z

@property
def cond_pos(self):
Expand Down
2 changes: 2 additions & 0 deletions gstools/tools/geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def pos2xyz(pos, dtype=None, calc_dim=False, max_dim=3):
-----
If len(pos) > 3, everything after pos[2] will be ignored.
"""
if max_dim == 1: # sanity check
pos = np.array(pos, ndmin=2)
x = np.array(pos[0], dtype=dtype).reshape(-1)
dim = 1
y = z = None
Expand Down

0 comments on commit a6f5be8

Please sign in to comment.