API Reference#

Inv Dataset Accessor#

xarray.Dataset accessor for properties and methods for both gravity and model datasets.

DatasetAccessorInvert4Geom(ds)

A class which allows adding properties and methods as xarray dataset accessors.

Model creation#

Create a topography grid (or provide your own) and convert it into an initial prism or tesseroid model for the inversion.

create_topography(method, region, spacing[, ...])

Create a grid of topography data from either the interpolation (with splines) of point data or creating a grid of constant value.

create_model(zref, density_contrast, topography)

Convert a topography grid into a model, which can be used as the starting model for an inversion.

normalized_mindist(points, grid[, low, ...])

Find the minimum distance between each grid cell and the nearest point.

Gravity data processing#

Process gravity data and prepare it for the inversion.

create_data(gravity[, buffer_width, model_type])

Convert a dataset of gravity data into the format needed for the inversion.

DatasetAccessorInvert4Geom.forward_gravity(layer)

Calculate the forward gravity of the model at each point of the gravity grid.

Regional gravity misfit estimation.

DatasetAccessorInvert4Geom.regional_separation(...)

Calculate the gravity misfit as the difference between dataset variables gravity_anomaly and forward_gravity.

DatasetAccessorInvert4Geom.regional_constant([...])

Calculate the gravity misfit as the difference between dataset variables gravity_anomaly and forward_gravity.

DatasetAccessorInvert4Geom.regional_filter(...)

Calculate the gravity misfit as the difference between dataset variables gravity_anomaly and forward_gravity.

DatasetAccessorInvert4Geom.regional_trend(trend)

Calculate the gravity misfit as the difference between dataset variables gravity_anomaly and forward_gravity.

DatasetAccessorInvert4Geom.regional_eq_sources([...])

Calculate the gravity misfit as the difference between dataset variables gravity_anomaly and forward_gravity.

DatasetAccessorInvert4Geom.regional_constraints(...)

Calculate the gravity misfit as the difference between dataset variables gravity_anomaly and forward_gravity.

DatasetAccessorInvert4Geom.regional_constraints_cv(...)

This is a convenience function to wrap optimize_regional_constraint_point_minimization.

xarray.Dataset properties#

Properties of both the gravity and model xarray.Dataset can be accessed via the inv Accessor. For example, to return just the inner region of a dataset ds, use ds.inv.inner. These are intended to be used for both the the gravity and the model datasets.

DatasetAccessorInvert4Geom.df

return the dataframe representation of the xarray dataset without nans

DatasetAccessorInvert4Geom.inner_df

return the dataframe representation of the inner region of the xarray dataset without nans

DatasetAccessorInvert4Geom.masked_df

return the dataframe representation of the masked xarray dataset without nans

DatasetAccessorInvert4Geom.masked

return only the model elements with a non-nan mask value

Inversion class#

Class for attributes and methods for performing a gravity inversion.

Inversion(data, model[, style, ...])

A class which holds the gravity dataset, the model dataset, inversion stopping criteria, parameters which control the inversion, and methods used to run the inversion and cross-validations.

Function to run a full inversion workflow.

run_inversion_workflow(grav_ds[, ...])

This function runs the full inversion workflow.

Cross-Validation#

Split data (gravity and constraints) into training and test sets.

add_test_points(ds)

take a dataframe of coordinates and make all rows that fall on the data_spacing grid training points.

remove_test_points(ds)

Remove the test rows and the column denoting test points

split_test_train(data_df, method[, spacing, ...])

Split data into training or testing sets either using KFold (optional blocked) or LeaveOneOut methods.

random_split_test_train(data_df[, ...])

split data into training and testing sets randomly with a specified percentage of points to be in the test set set by test_size.

kfold_df_to_lists(df)

convert a single dataframe with fold columns in the form fold_0, fold_1 etc.

Calculate optimization and cross-validation scores.

eq_sources_score(coordinates, data[, ...])

Calculate the cross-validation score for fitting gravity data to equivalent sources.

regional_separation_score(grav_ds, testing_df)

Evaluate the effectiveness of the gravity regional-residual separation.

Inversion.gravity_score([results_fname, ...])

Find the score, represented by the root mean (or median) squared error (RMSE), between the testing gravity data, and the predict gravity data after an inversion.

Inversion.constraints_score(constraints_df)

Find the score, represented by the root mean squared error (RMSE), between the constraint point elevation, and the inverted topography at the constraint points.

Optimization#

Run optimization routines with optuna to find optimal parameters.

Routines for optimal regional field estimation parameters.

optimize_regional_filter(testing_df, ...[, ...])

Run an Optuna optimization to find the optimal filter width for estimating the regional component of gravity misfit.

optimize_regional_trend(testing_df, grav_ds, ...)

Run an Optuna optimization to find the optimal trend order for estimating the regional component of gravity misfit.

optimize_regional_eq_sources(testing_df, grav_ds)

Run an Optuna optimization to find the optimal equivalent source parameters for estimating the regional component of gravity misfit.

optimize_regional_constraint_point_minimization(...)

Run an Optuna optimization to find the optimal hyperparameters for the Constraint Point Minimization technique for estimating the regional component of gravity misfit.

Routines for optimal interpolation parameters.

optimize_eq_source_params(coordinates, data)

Use Optuna to find the optimal parameters for fitting equivalent sources to gravity data.

optimal_spline_damping(coordinates, data[, ...])

Find the best damping parameter for a verde.SplineCV() fit.

Routines for optimal inversion parameters.

Inversion.optimize_inversion_damping(...[, ...])

Use Optuna to find the optimal damping regularization parameter for a gravity inversion.

Inversion.optimize_inversion_zref_density_contrast(...)

Run an Optuna optimization to find the optimal zref and or density contrast values for a gravity inversion.

Inversion.optimize_inversion_zref_density_contrast_kfolds(...)

Perform an optimization for zref and density contrast values same as function optimize_inversion_zref_density_contrast, but pass a dataframe of constraint points and split_kwargs which are both passed split_test_train create K-folds of testing and training constraints.

optimal_buffer(target[, buffer_perc_limits, ...])

Run an optimization to find best buffer zone width.

Uncertainty#

Monte Carlo simulations to estimate the spatially variable uncertainties for the inversion and data processing.

full_workflow_uncertainty_loop(...[, fname, ...])

Run a series of inversions (N=runs), and save results of each inversion to pickle files starting with fname.

merged_stats(results[, plot, ...])

Use the outputs of the function uncertainty.full_workflow_uncertainty_loop to calculate the cell-wise statistics of the inversion ensemble and plot the resulting mean and standard deviation of the ensemble.

randomly_sample_data(seed, data_df, ...)

Given a dataframe with a data column and an uncertainty column, sample the data with a normal distribution within the uncertainty range.

regional_misfit_uncertainty(runs[, ...])

Create a stochastic ensemble of regional gravity anomalies by sampling the constraints, gravity, or parameters within their respective distributions and calculate the cell-wise (weighted) statistics of the ensemble.

Plotting#

Plot gravity data.

DatasetAccessorInvert4Geom.plot_observed([coast])

plot observed gravity

DatasetAccessorInvert4Geom.plot_anomalies([...])

plot gravity anomalies

DatasetAccessorInvert4Geom.plot_regional_separation([...])

plot gravity misfit and estimate regional and residual components

Plot model.

DatasetAccessorInvert4Geom.plot_model(**kwargs)

Use pyvista to plot the prism model.

plot_prism_layers(prisms[, cmap, color_by, ...])

show prism layers using PyVista

Plot inversion results.

Inversion.plot_convergence()

plot a graph of L2-norm and delta L2-norm vs iteration number.

Inversion.plot_dynamic_convergence()

plot a dynamic graph of L2-norm and delta L2-norm vs iteration number.

plot_inversion_topo_results(prisms_ds[, ...])

plot the initial and final topography grids from the inversion and their difference

plot_inversion_grav_results(grav_results, region)

plot the initial and final misfit grids from the inversion and their difference

plot_inversion_iteration_results(grids, ...)

plot the starting misfit, updated topography, and correction grids for a specified number of the iterations of an inversion

plot_inversion_results(grav_results, ...[, ...])

DEPRECATED: use the Inversion class method plot_inversion_results instead

Plot optimization and cross-validation results.

plot_2_parameter_scores(scores, parameter_pairs)

plot a scatter plot graph with x axis equal to parameter 1, y axis equal to parameter 2, and points colored by cross-validation scores.

plot_2_parameter_scores_uneven(study, ...[, ...])

plot a scatter plot graph with x axis equal to parameter 1, y axis equal to parameter 2, and points colored by cross-validation scores.

plot_scores(scores, parameters[, logx, ...])

plot a graph of cross-validation scores vs hyperparameter values

plot_optimization_combined_slice(study, ...)

plot combined slice plots for optimizations.

plot_optuna_figures(study, target_names[, ...])

plot the results of an optuna optimization

Plot parameter sampling and uncertainty results.

plot_stochastic_results(stats_ds[, points, ...])

Plot the (weighted) standard deviation (uncertainty) and mean of the stochastic ensemble.

plot_latin_hypercube(params_dict[, ...])

With a dictionary of parameters and their sampled values, plot the individual distributions and or the 2D projections of the parameter pairs.

plot_sampled_projection_2d(sample, var_names)

Plots the samples projected on each 2D plane

Other plotting functions.

plot_edge_effects(grav_ds, layer, inner_region)

Show the gravity edge effects and the percentage decay within the inner region and optionally a profile across the region.