Skip to content

Commit

Permalink
added vtk_export to srf and kriging classes; pos and meshtype now stored
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed May 24, 2019
1 parent 3518c4c commit 29f7f1b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
26 changes: 25 additions & 1 deletion gstools/field/srf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
reshape_axis_from_struct_to_unstruct,
reshape_field_from_unstruct_to_struct,
)
from gstools.tools.geometric import pos2xyz
from gstools.tools.geometric import pos2xyz, xyz2pos
from gstools.tools.export import vtk_export as vtk_ex
from gstools.field.upscaling import var_coarse_graining, var_no_scaling
from gstools.field.condition import ordinary, simple

Expand Down Expand Up @@ -101,6 +102,8 @@ def __init__(
self._cond_val = None
self._krige_type = None
# initialize attributes
self.pos = None
self.mesh_type = None
self.field = None
self.raw_field = None
self.krige_field = None
Expand Down Expand Up @@ -149,6 +152,8 @@ def __call__(
"""
# internal conversation
x, y, z = pos2xyz(pos)
self.pos = xyz2pos(x, y, z)
self.mesh_type = mesh_type
# update the model/seed in the generator if any changes were made
self.generator.update(self.model, seed)
# format the positional arguments of the mesh
Expand Down Expand Up @@ -203,6 +208,24 @@ def __call__(

return self.field

def vtk_export(self, filename, fieldname="field"):
"""Export the stored field to vtk.
Parameters
----------
filename : :class:`str`
Filename of the file to be saved, including the path. Note that an
ending (.vtr or .vtu) will be added to the name.
fieldname : :class:`str`, optional
Name of the field in the VTK file. Default: "field"
"""
if not (
self.pos is None or self.field is None or self.mesh_type is None
):
vtk_ex(filename, self.pos, self.field, fieldname, self.mesh_type)
else:
print("gstools.SRF.vtk_export: No field stored in the srf class.")

def set_condition(
self, cond_pos=None, cond_val=None, krige_type="ordinary"
):
Expand Down Expand Up @@ -252,6 +275,7 @@ def cond_func(self, *args, **kwargs):
"""Conditioning method applied to the field."""
if self.condition:
return CONDITION[self._krige_type](*args, **kwargs)
return None

def structured(self, *args, **kwargs):
"""Generate an SRF on a structured mesh.
Expand Down
23 changes: 22 additions & 1 deletion gstools/krige/ordinary.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
reshape_axis_from_struct_to_unstruct,
reshape_field_from_unstruct_to_struct,
)
from gstools.tools.geometric import pos2xyz
from gstools.tools.geometric import pos2xyz, xyz2pos
from gstools.tools.export import vtk_export as vtk_ex
from gstools.krige.krigesum import krigesum

__all__ = ["Ordinary"]
Expand Down Expand Up @@ -84,6 +85,8 @@ def __call__(self, pos, mesh_type="unstructured"):
# internal conversation
x, y, z = pos2xyz(pos, dtype=np.double)
c_x, c_y, c_z = pos2xyz(self.cond_pos, dtype=np.double)
self.pos = xyz2pos(x, y, z)
self.mesh_type = mesh_type
# format the positional arguments of the mesh
check_mesh(self.model.dim, x, y, z, mesh_type)
mesh_type_changed = False
Expand Down Expand Up @@ -143,6 +146,24 @@ def _get_vario_mat(self, pos1, pos2, add=False):
return np.vstack((res, np.ones((1, res.shape[1]))))
return res

def vtk_export(self, filename, fieldname="field"):
"""Export the stored field to vtk.
Parameters
----------
filename : :class:`str`
Filename of the file to be saved, including the path. Note that an
ending (.vtr or .vtu) will be added to the name.
fieldname : :class:`str`, optional
Name of the field in the VTK file. Default: "field"
"""
if not (
self.pos is None or self.field is None or self.mesh_type is None
):
vtk_ex(filename, self.pos, self.field, fieldname, self.mesh_type)
else:
print("gstools.SRF.vtk_export: No field stored in the srf class.")

def set_condition(self, cond_pos, cond_val):
"""Set the conditions for kriging.
Expand Down
23 changes: 22 additions & 1 deletion gstools/krige/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
reshape_axis_from_struct_to_unstruct,
reshape_field_from_unstruct_to_struct,
)
from gstools.tools.geometric import pos2xyz
from gstools.tools.geometric import pos2xyz, xyz2pos
from gstools.tools.export import vtk_export as vtk_ex
from gstools.krige.krigesum import krigesum

__all__ = ["Simple"]
Expand Down Expand Up @@ -87,6 +88,8 @@ def __call__(self, pos, mesh_type="unstructured"):
# internal conversation
x, y, z = pos2xyz(pos, dtype=np.double)
c_x, c_y, c_z = pos2xyz(self.cond_pos, dtype=np.double)
self.pos = xyz2pos(x, y, z)
self.mesh_type = mesh_type
# format the positional arguments of the mesh
check_mesh(self.model.dim, x, y, z, mesh_type)
mesh_type_changed = False
Expand Down Expand Up @@ -135,6 +138,24 @@ def _get_cov_mat(self, pos1, pos2):
)
)

def vtk_export(self, filename, fieldname="field"):
"""Export the stored field to vtk.
Parameters
----------
filename : :class:`str`
Filename of the file to be saved, including the path. Note that an
ending (.vtr or .vtu) will be added to the name.
fieldname : :class:`str`, optional
Name of the field in the VTK file. Default: "field"
"""
if not (
self.pos is None or self.field is None or self.mesh_type is None
):
vtk_ex(filename, self.pos, self.field, fieldname, self.mesh_type)
else:
print("gstools.SRF.vtk_export: No field stored in the srf class.")

def set_condition(self, cond_pos, cond_val):
"""Set the conditions for kriging.
Expand Down

0 comments on commit 29f7f1b

Please sign in to comment.