invert4geom.inversion
#
Module Contents#
Functions#
|
Function to calculate the vertical derivate of the gravitational acceleration at |
|
Function to calculate the Jacobian matrix using the annular cylinder |
|
extract prism properties from prism layer |
|
Function to calculate the Jacobian matrix with the vertical gravity derivative |
|
dispatcher for creating the jacobian matrix with 2 method options |
|
Calculate shift to add to prism's for each iteration of the inversion. Finds |
|
update the l2 norm and delta l2 norm of the misfit |
|
check if the inversion should be terminated |
|
calculate the forward gravity of the supplied prism layer, add the results to a |
|
perform a geometric inversion, where the topography is updated to minimize the |
- grav_column_der(grav_easting, grav_northing, grav_upward, prism_easting, prism_northing, prism_top, prism_spacing, prism_density)[source]#
Function to calculate the vertical derivate of the gravitational acceleration at an observation point caused by a right, rectangular prism. Approximated with Hammerâs annulus approximation [1].
- Parameters:
grav_easting (NDArray) â coordinates of gravity observation points.
grav_northing (NDArray) â coordinates of gravity observation points.
grav_upward (NDArray) â coordinates of gravity observation points.
prism_easting (NDArray) â coordinates of prismâs center in northing, easting, and upward directions, respectively
prism_northing (NDArray) â coordinates of prismâs center in northing, easting, and upward directions, respectively
prism_top (NDArray) â coordinates of prismâs center in northing, easting, and upward directions, respectively
prism_spacing (float) â resolution of prism layer in meters
prism_density (NDArray) â density of prisms, in kg/m^3
- Returns:
array of vertical derivative of gravity at observation point for series of prisms
- Return type:
NDArray
References
- jacobian_annular(grav_easting, grav_northing, grav_upward, prism_easting, prism_northing, prism_top, prism_density, prism_spacing, jac)[source]#
Function to calculate the Jacobian matrix using the annular cylinder approximation. The resulting Jacobian is a matrix (numpy array) with a row per gravity observation and a column per prism. This approximates the prisms as an annulus [1], and calculates itâs vertical gravity derivative. Takes arrays from jacobian, feeds them into grav_column_der, and returns the jacobian.
- Parameters:
grav_easting (NDArray) â coordinates of gravity observation points
grav_northing (NDArray) â coordinates of gravity observation points
grav_upward (NDArray) â coordinates of gravity observation points
prism_easting (NDArray) â coordinates of prismâs center in northing, easting, and upward directions, respectively
prism_northing (NDArray) â coordinates of prismâs center in northing, easting, and upward directions, respectively
prism_top (NDArray) â coordinates of prismâs center in northing, easting, and upward directions, respectively
prism_density (NDArray) â density of prisms, in kg/m^3
prism_spacing (float) â resolution of prism layer in meters
jac (NDArray) â empty jacobian matrix with a row per gravity observation and a column per prism
- Returns:
returns a jacobian matrix of shape (number of gravity points, number of prisms)
- Return type:
NDArray
References
- prism_properties(prisms_layer, method='itertools')[source]#
extract prism properties from prism layer
- Parameters:
prisms_layer (xr.Dataset) â harmonica prism layer
method (str, optional) â choice of method to extract properties, by default âitertoolsâ
- Returns:
array of prism properties
- Return type:
NDArray
- jacobian_prism(prisms_properties, grav_easting, grav_northing, grav_upward, delta, jac)[source]#
Function to calculate the Jacobian matrix with the vertical gravity derivative as a numerical approximation with small prisms
Takes arrays from jacobian and calculates the jacobian.
- Parameters:
prisms_properties (NDArray) â array of prism properties of shape (number of prisms, 7) with the 7 entries for each prism being: west, east, south, north, bottom, top, density
grav_easting (NDArray) â coordinates of gravity observation points.
grav_northing (NDArray) â coordinates of gravity observation points.
grav_upward (NDArray) â coordinates of gravity observation points.
delta (float) â thickness in meters of small prisms used to calculate vertical derivative
jac (NDArray) â empty jacobian matrix with a row per gravity observation and a column per prism
- Returns:
returns a NDArray of shape (number of gravity points, number of prisms)
- Return type:
NDArray
- jacobian(deriv_type, coordinates, empty_jac=None, prisms_layer=None, prism_spacing=None, prism_size=None, prisms_properties_method='itertools')[source]#
dispatcher for creating the jacobian matrix with 2 method options
- Parameters:
deriv_type (str) â choose between âannulusâ and âprismsâ methods of calculating the vertical derivative of gravity of a prism
coordinates (pd.DataFrame) â coordinate dataframe of gravity observation points with columns âeastingâ, ânorthingâ, âupwardâ
empty_jac (NDArray, optional) â optionally provide an empty jacobian matrix of shape (number of gravity observations x number of prisms), by default None
prisms_layer (xr.Dataset, optional) â harmonica prism layer, by default None
prism_spacing (float, optional) â resolution of prism layer, by default None
prism_size (float, optional) â height of prisms for small prism vertical derivative method, by default None
prisms_properties_method (str, optional) â method for extracting prism properties, by default âitertoolsâ
- Returns:
a filled out jacobian matrix
- Return type:
NDArray
- solver(jac, residuals, damping=None, solver_type='scipy least squares')[source]#
Calculate shift to add to prismâs for each iteration of the inversion. Finds the least-squares solution to the Jacobian and the gravity residual
- Parameters:
jac (NDArray) â input jacobian matrix with a row per gravity observation, and a column per prisms.
residuals (NDArray) â array of gravity residuals
damping (float | None, optional) â positive damping (Tikhonov 0th order) regularization
solver_type â âverde least squaresâ, âscipy least squaresâ, âscipy conjugateâ, ânumpy least squaresâ, âsteepest descentâ, âgauss newtonâ, } optional choose which solving method to use, by default âscipy least squaresâ
- Returns:
array of correction values to apply to each prism.
- Return type:
NDArray
- end_inversion(iteration_number, max_iterations, l2_norm, starting_l2_norm, l2_norm_tolerance, delta_l2_norm, previous_delta_l2_norm, delta_l2_norm_tolerance, perc_increase_limit=0.2)[source]#
check if the inversion should be terminated
- Parameters:
iteration_number (int) â the iteration number, starting at 1 not 0
max_iterations (int) â the maximum allowed iterations, inclusive and starting at 1
l2_norm (float) â the current iterationâs l2 norm
starting_l2_norm (float) â the l2 norm of iteration 1
l2_norm_tolerance (float) â the l2 norm value to end the inversion at
delta_l2_norm (float) â the current iterationâs delta l2 norm
previous_delta_l2_norm (float) â the delta l2 norm of the previous iteration
delta_l2_norm_tolerance (float) â the delta l2 norm value to end the inversion at
perc_increase_limit (float, optional) â the set tolerance for decimal percentage increase relative to the starting l2 norm, by default 0.20
- Returns:
first term is a boolean of whether or not to end the inversion, second term is a list of termination reasons.
- Return type:
- update_gravity_and_misfit(gravity_df, prisms_ds, input_grav_column, iteration_number)[source]#
calculate the forward gravity of the supplied prism layer, add the results to a new dataframe column, and update the residual misfit. The supplied gravity dataframe needs a âregâ column, which describes the regional component and can be 0.
- Parameters:
gravity_df (pd.DataFrame) â gravity dataframe with gravity observation coordinate columns (âeastingâ, ânorthingâ, âupwardsâ), a gravity data column, set by input_grav_column, and a regional gravity column (âregâ).
prisms_ds (xr.Dataset) â harmonica prism layer
input_grav_column (str) â name of gravity data column
iteration_number (int) â iteration number to use in updated column names
- Returns:
a gravity dataframe with 2 new columns, one for the iterations forward gravity and one for the iterations residual misfit.
- Return type:
pd.DataFrame
- run_inversion(input_grav, input_grav_column, prism_layer, density_contrast, zref, max_iterations, l2_norm_tolerance=0.2, delta_l2_norm_tolerance=1.001, perc_increase_limit=0.1, deriv_type='annulus', jacobian_prism_size=1, solver_type='scipy least squares', solver_damping=None, upper_confining_layer=None, lower_confining_layer=None, weights_after_solving=False, inversion_region=None, plot_convergence=False, plot_dynamic_convergence=False)[source]#
perform a geometric inversion, where the topography is updated to minimize the residual misfit between the forward gravity of the layer, and the observed gravity. To aid in regularizing an ill-posed problem choose any of the following options: * add damping to the solver, with solver_damping * weight the surface correction values with a weighting grid with weights_after_solving and the weights variable of the prisms dataset * bound the topography of the layer, with upper_confining_layer and lower_confining_layer
- Parameters:
input_grav (pd.DataFrame) â dataframe with gravity data and coordinates, must have columns âresâ and âregâ for residual and regional gravity, and coordinate columns âeastingâ, ânorthingâ, and âupwardâ.
input_grav_column (str) â column name containing the gravity data before regional separation
prism_layer (xr.Dataset) â starting prism layer
density_contrast (float) â density contrast of the prisms layer, should be same value used to create the starting model
zref (float) â reference height of the prisms layer, should be same value used to create the starting model
max_iterations (int) â the maximum allowed iterations, inclusive and starting at 1
l2_norm_tolerance (float, optional) â _the l2 norm value to end the inversion at, by default 0.2
delta_l2_norm_tolerance (float, optional) â the delta l2 norm value to end the inversion at, by default 1.001
perc_increase_limit (float, optional) â the set tolerance for decimal percentage increase relative to the starting l2 norm, by default 0.10
deriv_type (str, optional) â either âannulusâ or âprismâ to determine method of calculating the vertical derivate of gravity of a prism, by default âannulusâ
jacobian_prism_size (float, optional) â height of prisms in meters for vertical derivative, by default 1
solver_type (str, optional) â solver type to use, by default âscipy least squaresâ
solver_damping (float | None, optional) â damping parameter for regularization of the solver, by default None
upper_confining_layer (xr.DataArray | None, optional) â topographic layer to use as upper limit for inverted topography, by default None
lower_confining_layer (xr.DataArray | None, optional) â topographic layer to use as lower limit for inverted topography, by default None
weights_after_solving (bool, optional) â use âweightsâ variable of prisms dataset to scale surface corrections grid, by default False, by default False
inversion_region (tuple[float, float, float, float]) â inside region to calculated residual RMSE within, in the form (min_easting, max_easting, min_northing, max_northing)
plot_convergence (bool, optional) â plot the misfit convergence, by default False
plot_dynamic_convergence (bool, optional) â plot the misfit convergence dynamically, by default False
- Returns:
prisms_df: pd.DataFrame, prism properties for each iteration, gravity: pd.DataFrame, gravity anomalies for each iteration, params: dict, Properties of the inversion such as kwarg values, elapsed_time: float, time in seconds for the inversion to run
- Return type: