Skip to content

Commit

Permalink
Merge 8145043 into 79e7b60
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed Apr 8, 2021
2 parents 79e7b60 + 8145043 commit 1327ae1
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 112 deletions.
14 changes: 6 additions & 8 deletions gstools/covmodel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
.. autosummary::
CovModel
"""
# pylint: disable=C0103, R0201, E1101
# pylint: disable=C0103, R0201, E1101, C0302, W0613

import copy
import numpy as np
Expand Down Expand Up @@ -212,14 +212,12 @@ def __init_subclass__(cls):
cls.__doc__ = "User defined GSTools Covariance-Model."
cls.__doc__ += CovModel.__doc__[45:]
# overridden functions get standard doc if no new doc was created
ignore = ["__", "variogram", "covariance", "cor"]
for attr in cls.__dict__:
if any(
[attr.startswith(ign) for ign in ignore]
) or attr not in dir(CovModel):
ign = ["__", "variogram", "covariance", "cor"]
for att in cls.__dict__:
if any(att.startswith(i) for i in ign) or att not in dir(CovModel):
continue
attr_doc = getattr(CovModel, attr).__doc__
attr_cls = cls.__dict__[attr]
attr_doc = getattr(CovModel, att).__doc__
attr_cls = cls.__dict__[att]
if attr_cls.__doc__ is None:
attr_cls.__doc__ = attr_doc

Expand Down
4 changes: 2 additions & 2 deletions gstools/covmodel/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
.. autosummary::
fit_variogram
"""
# pylint: disable=C0103, W0632

# pylint: disable=C0103
import numpy as np
from scipy.optimize import curve_fit
from gstools.covmodel.tools import check_arg_in_bounds, default_arg_from_bounds
Expand Down Expand Up @@ -341,7 +341,7 @@ def _check_vario(model, x_data, y_data):
raise ValueError(
"CovModel.fit_variogram: lat-lon models don't support anisotropy."
)
elif model.latlon:
if model.latlon:
# convert to yadrenko model
x_data = 2 * np.sin(x_data / 2)
return x_data, y_data, is_dir_vario
Expand Down
2 changes: 1 addition & 1 deletion gstools/covmodel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import numpy as np
from scipy import special as sps
from gstools.covmodel.tools import AttributeWarning
from gstools.covmodel import CovModel
from gstools.covmodel.base import CovModel

__all__ = [
"Gaussian",
Expand Down
83 changes: 36 additions & 47 deletions gstools/covmodel/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
plot_spectral_density
plot_spectral_rad_pdf
"""
# pylint: disable=C0103, C0415
import numpy as np

import gstools
# pylint: disable=C0103, C0415, E1130

import numpy as np
from gstools.tools.geometric import generate_grid
from gstools.tools.misc import get_fig_ax

__all__ = [
"plot_variogram",
Expand All @@ -51,69 +51,58 @@
# plotting routines #######################################################


def _get_fig_ax(fig, ax, ax_name="rectilinear"): # pragma: no cover
from matplotlib import pyplot as plt
def _plot_spatial(dim, pos, field, fig, ax, latlon, **kwargs):
from gstools.field.plot import plot_1d, plot_nd

if fig is None and ax is None:
fig = plt.figure()
ax = fig.add_subplot(111, projection=ax_name)
elif ax is None:
ax = fig.add_subplot(111, projection=ax_name)
elif fig is None:
fig = ax.get_figure()
assert ax.name == ax_name
else:
assert ax.name == ax_name
assert ax.get_figure() == fig
return fig, ax
if dim == 1:
return plot_1d(pos, field, fig, ax, **kwargs)
return plot_nd(pos, field, "structured", fig, ax, latlon, **kwargs)


def plot_vario_spatial(
model, x_min=0.0, x_max=None, fig=None, ax=None
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot spatial variogram of a given CovModel."""
field = gstools.field.base.Field(model, "scalar")
if x_max is None:
x_max = 3 * model.len_scale
x_s = np.linspace(-x_max, x_max) + x_min
iso_pos, shape = field.pre_pos([x_s] * model.dim, "structured")
field.field = model.vario_spatial(model.anisometrize(iso_pos)).reshape(
shape
)
return field.plot(fig=fig, ax=ax)
pos = [x_s] * model.dim
shp = tuple(len(p) for p in pos)
fld = model.vario_spatial(generate_grid(pos)).reshape(shp)
return _plot_spatial(model.dim, pos, fld, fig, ax, model.latlon, **kwargs)


def plot_cov_spatial(
model, x_min=0.0, x_max=None, fig=None, ax=None
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot spatial covariance of a given CovModel."""
field = gstools.field.base.Field(model, "scalar")
if x_max is None:
x_max = 3 * model.len_scale
x_s = np.linspace(-x_max, x_max) + x_min
iso_pos, shape = field.pre_pos([x_s] * model.dim, "structured")
field.field = model.cov_spatial(model.anisometrize(iso_pos)).reshape(shape)
return field.plot(fig=fig, ax=ax)
pos = [x_s] * model.dim
shp = tuple(len(p) for p in pos)
fld = model.cov_spatial(generate_grid(pos)).reshape(shp)
return _plot_spatial(model.dim, pos, fld, fig, ax, model.latlon, **kwargs)


def plot_cor_spatial(
model, x_min=0.0, x_max=None, fig=None, ax=None
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot spatial correlation of a given CovModel."""
field = gstools.field.base.Field(model, "scalar")
if x_max is None:
x_max = 3 * model.len_scale
x_s = np.linspace(-x_max, x_max) + x_min
iso_pos, shape = field.pre_pos([x_s] * model.dim, "structured")
field.field = model.cor_spatial(model.anisometrize(iso_pos)).reshape(shape)
return field.plot(fig=fig, ax=ax)
pos = [x_s] * model.dim
shp = tuple(len(p) for p in pos)
fld = model.cor_spatial(generate_grid(pos)).reshape(shp)
return _plot_spatial(model.dim, pos, fld, fig, ax, model.latlon, **kwargs)


def plot_variogram(
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot variogram of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = 3 * model.len_scale
x_s = np.linspace(x_min, x_max)
Expand All @@ -128,7 +117,7 @@ def plot_covariance(
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot covariance of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = 3 * model.len_scale
x_s = np.linspace(x_min, x_max)
Expand All @@ -143,7 +132,7 @@ def plot_correlation(
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot correlation function of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = 3 * model.len_scale
x_s = np.linspace(x_min, x_max)
Expand All @@ -158,7 +147,7 @@ def plot_vario_yadrenko(
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot Yadrenko variogram of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = min(3 * model.len_rescaled, np.pi)
x_s = np.linspace(x_min, x_max)
Expand All @@ -173,7 +162,7 @@ def plot_cov_yadrenko(
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot Yadrenko covariance of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = min(3 * model.len_rescaled, np.pi)
x_s = np.linspace(x_min, x_max)
Expand All @@ -188,7 +177,7 @@ def plot_cor_yadrenko(
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot Yadrenko correlation function of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = min(3 * model.len_rescaled, np.pi)
x_s = np.linspace(x_min, x_max)
Expand All @@ -203,7 +192,7 @@ def plot_vario_axis(
model, axis=0, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot variogram of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = 3 * model.len_scale
x_s = np.linspace(x_min, x_max)
Expand All @@ -218,7 +207,7 @@ def plot_cov_axis(
model, axis=0, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot variogram of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = 3 * model.len_scale
x_s = np.linspace(x_min, x_max)
Expand All @@ -233,7 +222,7 @@ def plot_cor_axis(
model, axis=0, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot variogram of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = 3 * model.len_scale
x_s = np.linspace(x_min, x_max)
Expand All @@ -248,7 +237,7 @@ def plot_spectrum(
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot specturm of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = 3 / model.len_scale
x_s = np.linspace(x_min, x_max)
Expand All @@ -263,7 +252,7 @@ def plot_spectral_density(
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot spectral density of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = 3 / model.len_scale
x_s = np.linspace(x_min, x_max)
Expand All @@ -278,7 +267,7 @@ def plot_spectral_rad_pdf(
model, x_min=0.0, x_max=None, fig=None, ax=None, **kwargs
): # pragma: no cover
"""Plot radial spectral pdf of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
fig, ax = get_fig_ax(fig, ax)
if x_max is None:
x_max = 3 / model.len_scale
x_s = np.linspace(x_min, x_max)
Expand Down
2 changes: 1 addition & 1 deletion gstools/covmodel/tpl_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import warnings
import numpy as np
from gstools.covmodel import CovModel
from gstools.covmodel.base import CovModel
from gstools.covmodel.tools import AttributeWarning
from gstools.tools.special import (
tplstable_cor,
Expand Down
8 changes: 3 additions & 5 deletions gstools/field/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
.. autosummary::
Field
"""
# pylint: disable=C0103
# pylint: disable=C0103, W0107, C0415
from functools import partial
import numpy as np
from gstools.covmodel.base import CovModel
Expand Down Expand Up @@ -83,9 +83,8 @@ def __init__(
self.normalizer = normalizer
self.trend = trend

def __call__(*args, **kwargs):
def __call__(self, *args, **kwargs):
"""Generate the field."""
pass

def structured(self, *args, **kwargs):
"""Generate a field on a structured mesh.
Expand Down Expand Up @@ -297,9 +296,8 @@ def plot(
"Specify 'scalar' or 'vector' before plotting."
)

elif self.value_type == "scalar":
if self.value_type == "scalar":
r = plot_field(self, field, fig, ax, **kwargs)

elif self.value_type == "vector":
if self.model.dim == 2:
r = plot_vec_field(self, field, fig, ax, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion gstools/field/cond_srf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
.. autosummary::
CondSRF
"""
# pylint: disable=C0103
# pylint: disable=C0103, W0231, W0221, E1102

import numpy as np
from gstools.field.generator import RandMeth
Expand Down
2 changes: 1 addition & 1 deletion gstools/field/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
RandMeth
IncomprRandMeth
"""
# pylint: disable=C0103
# pylint: disable=C0103, W0222

import warnings
from copy import deepcopy as dcp
Expand Down
Loading

0 comments on commit 1327ae1

Please sign in to comment.