verde.VectorSpline2D¶

class
verde.
VectorSpline2D
(poisson=0.5, mindist=10000.0, damping=None, force_coords=None, engine='auto')[source]¶ Elastically coupled interpolation of 2component vector data.
This gridder assumes Cartesian coordinates.
Uses the Green’s functions based on elastic deformation from [SandwellWessel2016]. The interpolation is done by estimating point forces that generate an elastic deformation that fits the observed vector data. The deformation equations are based on a 2D elastic sheet with a constant Poisson’s ratio. The data can then be predicted at any desired location.
The east and north data components are coupled through the elastic deformation equations. This coupling is controlled by the Poisson’s ratio, which is usually between 1 and 1. The special case of Poisson’s ratio 1 leads to an uncoupled interpolation, meaning that the east and north components don’t interfere with each other.
The point forces are traditionally placed under each data point. The force locations are set the first time
fit
is called. Subsequent calls will fit using the same force locations as the first call. This configuration results in an exact prediction at the data points but can be unstable.[SandwellWessel2016] stabilize the solution using Singular Value Decomposition but we use ridge regression instead. The regularization can be controlled using the damping argument. Alternatively, you can specify the position of the forces manually using the force_coords argument. Regularization or forces not coinciding with data points will result in a leastsquares estimate, not an exact solution. Note that the leastsquares solution is required for data weights to have any effect.
Before fitting, the Jacobian (design, sensitivity, feature, etc) matrix for the spline is normalized using
sklearn.preprocessing.StandardScaler
without centering the mean so that the transformation can be undone in the estimated forces.Parameters:  poisson : float
The Poisson’s ratio for the elastic deformation Green’s functions. Default is 0.5. A value of 1 will lead to uncoupled interpolation of the east and north data components.
 mindist : float
A minimum distance between the point forces and data points. Needed because the Green’s functions are singular when forces and data points coincide. Acts as a fudge factor. A good rule of thumb is to use the average spacing between data points.
 damping : None or float
The positive damping regularization parameter. Controls how much smoothness is imposed on the estimated forces. If None, no regularization is used.
 force_coords : None or tuple of arrays
The easting and northing coordinates of the point forces. If None (default), then will be set to the data coordinates the first time
fit
is called. engine : str
Computation engine for the Jacobian matrix. Can be
'auto'
,'numba'
, or'numpy'
. If'auto'
, will use numba if it is installed or numpy otherwise. The numba version is multithreaded and considerably faster, which makes fitting and predicting faster.
Attributes: Methods
filter
(coordinates, data[, weights])Filter the data through the gridder and produce residuals. fit
(coordinates, data[, weights])Fit the gridder to the given 2component vector data. get_params
([deep])Get parameters for this estimator. grid
([region, shape, spacing, adjust, dims, …])Interpolate the data onto a regular grid. jacobian
(coordinates, force_coords[, dtype])Make the Jacobian matrix for the 2D coupled elastic deformation. predict
(coordinates)Evaluate the fitted gridder on the given set of points. profile
(point1, point2, size[, dims, …])Interpolate data along a profile between two points. scatter
([region, size, random_state, dims, …])Interpolate values onto a random scatter of points. score
(coordinates, data[, weights])Score the gridder predictions against the given data. set_params
(**params)Set the parameters of this estimator.
Examples using verde.VectorSpline2D
¶

VectorSpline2D.
filter
(coordinates, data, weights=None)¶ Filter the data through the gridder and produce residuals.
Calls
fit
on the data, evaluates the residuals (data  predicted data), and returns the coordinates, residuals, and weights.No very useful by itself but this interface makes gridders compatible with other processing operations and is used by
verde.Chain
to join them together (for example, so you can fit a spline on the residuals of a trend).Parameters:  coordinates : tuple of arrays
Arrays with the coordinates of each data point. Should be in the following order: (easting, northing, vertical, …).
 data : array or tuple of arrays
The data values of each data point. If the data has more than one component, data must be a tuple of arrays (one for each component).
 weights : None or array or tuple of arrays
If not None, then the weights assigned to each data point. If more than one data component is provided, you must provide a weights array for each data component (if not None).
Returns:  coordinates, residuals, weights
The coordinates and weights are same as the input. Residuals are the input data minus the predicted data.

VectorSpline2D.
fit
(coordinates, data, weights=None)[source]¶ Fit the gridder to the given 2component vector data.
The data region is captured and used as default for the
grid
andscatter
methods.All input arrays must have the same shape.
Parameters:  coordinates : tuple of arrays
Arrays with the coordinates of each data point. Should be in the following order: (easting, northing, vertical, …). Only easting and northing will be used, all subsequent coordinates will be ignored.
 data : tuple of array
A tuple
(east_component, north_component)
of arrays with the vector data values at each point. weights : None or tuple array
If not None, then the weights assigned to each data point. Must be one array per data component. Typically, this should be 1 over the data uncertainty squared.
Returns:  self
Returns this estimator instance for chaining operations.

VectorSpline2D.
get_params
(deep=True)¶ Get parameters for this estimator.
Parameters:  deep : boolean, optional
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns:  params : mapping of string to any
Parameter names mapped to their values.

VectorSpline2D.
grid
(region=None, shape=None, spacing=None, adjust='spacing', dims=None, data_names=None, projection=None)¶ Interpolate the data onto a regular grid.
The grid can be specified by either the number of points in each dimension (the shape) or by the grid node spacing.
If the given region is not divisible by the desired spacing, either the region or the spacing will have to be adjusted. By default, the spacing will be rounded to the nearest multiple. Optionally, the East and North boundaries of the region can be adjusted to fit the exact spacing given. See
verde.grid_coordinates
for more details.If the interpolator collected the input data region, then it will be used if
region=None
. Otherwise, you must specify the grid region.Use the dims and data_names arguments to set custom names for the dimensions and the data field(s) in the output
xarray.Dataset
. Default names are provided.Parameters:  region : list = [W, E, S, N]
The boundaries of a given region in Cartesian or geographic coordinates.
 shape : tuple = (n_north, n_east) or None
The number of points in the SouthNorth and WestEast directions, respectively. If None and spacing is not given, defaults to
(101, 101)
. spacing : tuple = (s_north, s_east) or None
The grid spacing in the SouthNorth and WestEast directions, respectively.
 adjust : {‘spacing’, ‘region’}
Whether to adjust the spacing or the region if required. Ignored if shape is given instead of spacing. Defaults to adjusting the spacing.
 dims : list or None
The names of the northing and easting data dimensions, respectively, in the output grid. Defaults to
['northing', 'easting']
for Cartesian grids and['latitude', 'longitude']
for geographic grids. NOTE: This is an exception to the “easting” then “northing” pattern but is required for compatibility with xarray. data_names : list of None
The name(s) of the data variables in the output grid. Defaults to
['scalars']
for scalar data,['east_component', 'north_component']
for 2D vector data, and['east_component', 'north_component', 'vertical_component']
for 3D vector data. projection : callable or None
If not None, then should be a callable object
projection(easting, northing) > (proj_easting, proj_northing)
that takes in easting and northing coordinate arrays and returns projected northing and easting coordinate arrays. This function will be used to project the generated grid coordinates before passing them intopredict
. For example, you can use this to generate a geographic grid from a Cartesian gridder.
Returns:  grid : xarray.Dataset
The interpolated grid. Metadata about the interpolator is written to the
attrs
attribute.
See also
verde.grid_coordinates
 Generate the coordinate values for the grid.

VectorSpline2D.
jacobian
(coordinates, force_coords, dtype='float64')[source]¶ Make the Jacobian matrix for the 2D coupled elastic deformation.
The Jacobian is segmented into 4 parts, each relating a force component to a data component [SandwellWessel2016]:
 J_ee J_ne *f_e = d_e  J_ne J_nn  f_n d_n
The forces and data are assumed to be stacked into 1D arrays with the east component on top of the north component.
Parameters:  coordinates : tuple of arrays
Arrays with the coordinates of each data point. Should be in the following order: (easting, northing, vertical, …). Only easting and northing will be used, all subsequent coordinates will be ignored.
 force_coords : tuple of arrays
Arrays with the coordinates for the forces. Should be in the same order as the coordinate arrays.
 dtype : str or numpy dtype
The type of the Jacobian array.
Returns:  jacobian : 2D array
The (n_data*2, n_forces*2) Jacobian matrix.

VectorSpline2D.
predict
(coordinates)[source]¶ Evaluate the fitted gridder on the given set of points.
Requires a fitted estimator (see
fit
).Parameters:  coordinates : tuple of arrays
Arrays with the coordinates of each data point. Should be in the following order: (easting, northing, vertical, …). Only easting and northing will be used, all subsequent coordinates will be ignored.
Returns:  data : tuple of arrays
A tuple
(east_component, north_component)
of arrays with the predicted vector data values at each point.

VectorSpline2D.
profile
(point1, point2, size, dims=None, data_names=None, projection=None)¶ Interpolate data along a profile between two points.
Generates the profile using a straight line if the interpolator assumes Cartesian data or a great circle if geographic data.
Use the dims and data_names arguments to set custom names for the dimensions and the data field(s) in the output
pandas.DataFrame
. Default names are provided.Includes the calculated distance to point1 for each data point in the profile.
Parameters:  point1 : tuple
The easting and northing coordinates, respectively, of the first point.
 point2 : tuple
The easting and northing coordinates, respectively, of the second point.
 size : int
The number of points to generate.
 dims : list or None
The names of the northing and easting data dimensions, respectively, in the output dataframe. Defaults to
['northing', 'easting']
for Cartesian grids and['latitude', 'longitude']
for geographic grids. NOTE: This is an exception to the “easting” then “northing” pattern but is required for compatibility with xarray. data_names : list of None
The name(s) of the data variables in the output dataframe. Defaults to
['scalars']
for scalar data,['east_component', 'north_component']
for 2D vector data, and['east_component', 'north_component', 'vertical_component']
for 3D vector data. projection : callable or None
If not None, then should be a callable object
projection(easting, northing) > (proj_easting, proj_northing)
that takes in easting and northing coordinate arrays and returns projected northing and easting coordinate arrays. This function will be used to project the generated profile coordinates before passing them intopredict
. For example, you can use this to generate a geographic profile from a Cartesian gridder.
Returns:  table : pandas.DataFrame
The interpolated values along the profile.

VectorSpline2D.
scatter
(region=None, size=300, random_state=0, dims=None, data_names=None, projection=None)¶ Interpolate values onto a random scatter of points.
If the interpolator collected the input data region, then it will be used if
region=None
. Otherwise, you must specify the grid region.Use the dims and data_names arguments to set custom names for the dimensions and the data field(s) in the output
pandas.DataFrame
. Default names are provided.Parameters:  region : list = [W, E, S, N]
The boundaries of a given region in Cartesian or geographic coordinates.
 size : int
The number of points to generate.
 random_state : numpy.random.RandomState or an int seed
A random number generator used to define the state of the random permutations. Use a fixed seed to make sure computations are reproducible. Use
None
to choose a seed automatically (resulting in different numbers with each run). dims : list or None
The names of the northing and easting data dimensions, respectively, in the output dataframe. Defaults to
['northing', 'easting']
for Cartesian grids and['latitude', 'longitude']
for geographic grids. NOTE: This is an exception to the “easting” then “northing” pattern but is required for compatibility with xarray. data_names : list of None
The name(s) of the data variables in the output dataframe. Defaults to
['scalars']
for scalar data,['east_component', 'north_component']
for 2D vector data, and['east_component', 'north_component', 'vertical_component']
for 3D vector data. projection : callable or None
If not None, then should be a callable object
projection(easting, northing) > (proj_easting, proj_northing)
that takes in easting and northing coordinate arrays and returns projected northing and easting coordinate arrays. This function will be used to project the generated scatter coordinates before passing them intopredict
. For example, you can use this to generate a geographic scatter from a Cartesian gridder.
Returns:  table : pandas.DataFrame
The interpolated values on a random set of points.

VectorSpline2D.
score
(coordinates, data, weights=None)¶ Score the gridder predictions against the given data.
Calculates the R^2 coefficient of determination of between the predicted values and the given data values. A maximum score of 1 means a perfect fit. The score can be negative.
If the data has more than 1 component, the scores of each component will be averaged.
Parameters:  coordinates : tuple of arrays
Arrays with the coordinates of each data point. Should be in the following order: (easting, northing, vertical, …).
 data : array or tuple of arrays
The data values of each data point. If the data has more than one component, data must be a tuple of arrays (one for each component).
 weights : None or array or tuple of arrays
If not None, then the weights assigned to each data point. If more than one data component is provided, you must provide a weights array for each data component (if not None).
Returns:  score : float
The R^2 score

VectorSpline2D.
set_params
(**params)¶ Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form
<component>__<parameter>
so that it’s possible to update each component of a nested object.Returns:  self