Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecation warning for VectorSpline2D #214

Merged
merged 2 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions examples/vector_uncoupled.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
Gridding 2D vectors (uncoupled)
===============================
Gridding 2D vectors
===================
We can use :class:`verde.Vector` to simultaneously process and grid all
components of vector data. Each component is processed and gridded separately (see
:class:`verde.VectorSpline2D` for a coupled alternative) but we have the convenience of
dealing with a single estimator. :class:`verde.Vector` can be combined with
:class:`verde.Trend`, :class:`verde.Spline`, and :class:`verde.Chain` to create a full
processing pipeline.
components of vector data. Each component is processed and gridded separately
(see `Erizo <https://github.com/fatiando/erizo>`__ for an elastically coupled
alternative) but we have the convenience of dealing with a single estimator.
:class:`verde.Vector` can be combined with :class:`verde.Trend`,
:class:`verde.Spline`, and :class:`verde.Chain` to create a full processing
pipeline.
"""
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
Expand Down
129 changes: 0 additions & 129 deletions examples/vectorspline2d.py

This file was deleted.

10 changes: 5 additions & 5 deletions tutorials/trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Trend Estimation
================
Trend estimation and removal is a common operation, particularly when dealing with
geophysical data. Moreover, some of the interpolation methods, like
:class:`verde.VectorSpline2D`, struggle with long-wavelength trends in the data. The
:class:`verde.Trend` class fits a 2D polynomial trend of arbitrary degree to the data
and can be used to remove it.
Trend estimation and removal is a common operation, particularly when dealing
with geophysical data. Moreover, some of the interpolation methods, like
:class:`verde.Spline`, can struggle with long-wavelength trends in the data.
The :class:`verde.Trend` class fits a 2D polynomial trend of arbitrary degree
to the data and can be used to remove it.
"""
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
Expand Down
71 changes: 15 additions & 56 deletions tutorials/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,59 +281,18 @@
plt.show()

########################################################################################
# Another way of gridding 2-component vector data is using
# :class:`verde.VectorSpline2D`. This gridder uses linear elasticity theory to couple
# the two vector components. The degree of coupling can be controlled through the
# ``poisson`` parameter which sets the `Poisson's ratio
# <https://en.wikipedia.org/wiki/Poisson%27s_ratio>`__ of the elastic medium.

chain_coupled = vd.Chain(
[
("mean", vd.BlockMean(spacing=spacing * 111e3, uncertainty=True)),
("trend", vd.Vector([vd.Trend(1), vd.Trend(1)])),
("spline", vd.VectorSpline2D(poisson=0.5, damping=1e-10)),
]
)
chain_coupled.fit(*train)
print(chain_coupled.score(*test))

########################################################################################
# :class:`~verde.VectorSpline2D` generally gives better results when gridding GPS
# velocities, particularly for higher density grids and areas with sharp changes in
# velocity [SandwellWessel2016]_. Here, we won't see a big difference because of the
# low-density grid that we're making.

grid_coupled = chain_coupled.grid(
region=region,
spacing=spacing,
projection=projection,
dims=["latitude", "longitude"],
)
grid_coupled = vd.distance_mask(
(data.longitude, data.latitude),
maxdist=spacing * 2 * 111e3,
grid=grid_coupled,
projection=projection,
)

fig, axes = plt.subplots(
1, 2, figsize=(9, 6.5), subplot_kw=dict(projection=ccrs.Mercator())
)
crs = ccrs.PlateCarree()
titles = ["Gridded velocity (uncoupled)", "Gridded velocity (coupled)"]
grids = [grid, grid_coupled]
for ax, grd, title in zip(axes, grids, titles):
ax.set_title(title)
tmp = ax.quiver(
grd.longitude.values,
grd.latitude.values,
grd.east_component.values,
grd.north_component.values,
scale=0.3,
transform=crs,
width=0.002,
)
vd.datasets.setup_california_gps_map(ax)
ax.quiverkey(tmp, 0.15, 0.15, 0.05, label="0.05 m/yr", coordinates="figure")
plt.tight_layout()
plt.show()
# GPS/GNSS data
# +++++++++++++
#
# For some types of vector data, like GPS/GNSS displacements, the vector
# components are coupled through elasticity. In these cases, elastic Green's
# functions can be used to achieve better interpolation results. The `Erizo
# package <https://github.com/fatiando/erizo>`__ implements some of these
# Green's functions.
#
# .. warning::
#
# The :class:`verde.VectorSpline2D` class implemented an elastically
# coupled Green's function but it is deprecated and will be removed in
# Verde v2.0.0. Please use the implementation in the `Erizo
# <https://github.com/fatiando/erizo>`__ package instead.
18 changes: 18 additions & 0 deletions verde/vector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Classes for dealing with vector data.
"""
import warnings

import numpy as np
from sklearn.utils.validation import check_is_fitted

Expand All @@ -17,6 +19,9 @@
from .utils import dummy_jit as jit


# Otherwise, DeprecationWarning won't be shown, kind of defeating the purpose.
warnings.simplefilter("default")

# Default arguments for numba.jit
JIT_ARGS = dict(nopython=True, target="cpu", fastmath=True, parallel=True)

Expand Down Expand Up @@ -141,6 +146,13 @@ class VectorSpline2D(BaseGridder):
r"""
Elastically coupled interpolation of 2-component vector data.
.. warning::
The :class:`~verde.VectorSpline2D` class is deprecated and will be
removed in Verde v2.0.0. Its usage is restricted to GPS/GNSS data and
not in the general scope of Verde. Please use the implementation in the
`Erizo <https://github.com/fatiando/erizo>`__ package instead.
This gridder assumes Cartesian coordinates.
Uses the Green's functions based on elastic deformation from
Expand Down Expand Up @@ -221,6 +233,12 @@ def __init__(
self.damping = damping
self.force_coords = force_coords
self.engine = engine
warnings.warn(
"VectorSpline2D is deprecated and will be removed in Verde v2.0.0."
" Please use the implementation in the Erizo package instead "
"(https://github.com/fatiando/erizo).",
DeprecationWarning,
)

def fit(self, coordinates, data, weights=None):
"""
Expand Down