invert4geom.plotting#

Functions#

plot_2_parameter_cv_scores(scores, parameter_pairs[, ...])

plot a scatter plot graph with x axis equal to parameter 1, y axis equal to

plot_2_parameter_cv_scores_uneven(study, param_names)

plot a scatter plot graph with x axis equal to parameter 1, y axis equal to

plot_cv_scores(scores, parameters[, logx, logy, ...])

plot a graph of cross-validation scores vs hyperparameter values

plot_convergence(results, params[, inversion_region, ...])

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

plot_dynamic_convergence(l2_norms, l2_norm_tolerance, ...)

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

align_yaxis(ax1, v1, ax2, v2)

adjust ax2 ylimit so that v2 in ax2 is aligned to v1 in ax1.

grid_inversion_results(misfits, topos, corrections, ...)

create grids from the various data variables of the supplied gravity dataframe and

plot_inversion_topo_results(prisms_ds[, region, ...])

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, grav_results, ...)

plot the starting misfit, updated topography, and correction grids for a specified

plot_inversion_results(grav_results, topo_results, ...)

plot various results from the inversion

add_light(plotter, prisms)

add a light to a pyvista plotter object

show_prism_layers(prisms[, cmap, color_by, region, ...])

show prism layers using PyVista

combined_slice(study, attribute_names[, parameter_name])

plot combined slice plots for optimizations.

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

plot the results of an optuna optimization

plot_stochastic_results(stats_ds[, points, region])

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

remove_df_from_hoverdata(plot)

Remove the dataframe from the hoverdata of a plotly plot

plot_latin_hypercube(params_dict[, ...])

With a dictionary of parameters and their sampled values, plot the individual

projection_2d(sample, var_names)

Plots the sample projected on each 2D plane

edge_effects(grav_ds, prism_layer, inner_region[, ...])

Show the gravity edge effects and the percentage decay within the inner region and

Module Contents#

plot_2_parameter_cv_scores(scores, parameter_pairs, param_names=('Hyperparameter 1', 'Hyperparameter 2'), figsize=(5, 3.5), cmap=None)[source]#

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.

Parameters:
  • scores (list[float]) – score values

  • parameter_pairs (list[float]) – parameter values

  • param_names (tuple[str, str], optional) – name to give for the parameters, by default “Hyperparameter”

  • figsize (tuple[float, float], optional) – size of the figure, by default (5, 3.5)

  • cmap (str, optional) – matplotlib colormap for scores, by default “viridis”

Return type:

None

plot_2_parameter_cv_scores_uneven(study, param_names, plot_param_names=('Hyperparameter 1', 'Hyperparameter 2'), figsize=(5, 3.5), cmap=None, best='min', logx=False, logy=False, robust=False)[source]#

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.

Parameters:
  • study (optuna.study.Study)

  • param_names (tuple[str, str], optional) – name to give for the parameters, by default “Hyperparameter”

  • figsize (tuple[float, float], optional) – size of the figure, by default (5, 3.5)

  • cmap (str, optional) – matplotlib colormap for scores, by default “viridis”

  • best (str, optional) – whether the ‘min’ or ‘max’ score is considered best, by default ‘min’

  • logx (bool, optional) – make the x or y axes log scale, by default False

  • logy (bool, optional) – make the x or y axes log scale, by default False

  • robust (bool, optional) – use robust color limits

  • plot_param_names (tuple[str, str])

Return type:

None

plot_cv_scores(scores, parameters, logx=False, logy=False, param_name='Hyperparameter', figsize=(5, 3.5), plot_title=None, fname=None, best='min')[source]#

plot a graph of cross-validation scores vs hyperparameter values

Parameters:
  • scores (list[float]) – score values

  • parameters (list[float]) – parameter values

  • logx (bool, optional) – make the x or y axes log scale, by default False

  • logy (bool, optional) – make the x or y axes log scale, by default False

  • param_name (str, optional) – name to give for the parameters, by default “Hyperparameter”

  • figsize (tuple[float, float], optional) – size of the figure, by default (5, 3.5)

  • plot_title (str | None, optional) – title of figure, by default None

  • fname (str | None, optional) – filename to save figure, by default None

  • best (str, optional) – which value to plot as the best, ‘min’ or ‘max’, by default “min”

Return type:

a matplotlib figure instance

plot_convergence(results, params, inversion_region=None, figsize=(5, 3.5), fname=None)[source]#

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

Parameters:
  • results (pandas.DataFrame) – gravity result dataframe

  • params (dict[str, Any]) – inversion parameters output from function run_inversion()

  • inversion_region (tuple[float, float, float, float] | None, optional) – inside region of inversion, by default None

  • figsize (tuple[float, float], optional) – width and height of figure, by default (5, 3.5)

  • fname (str | None, optional) – filename to save figure, by default None

Return type:

None

plot_dynamic_convergence(l2_norms, l2_norm_tolerance, delta_l2_norms, delta_l2_norm_tolerance, starting_misfit, figsize=(5, 3.5))[source]#

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

Parameters:
  • l2_norms (list[float]) – list of l2 norm values

  • l2_norm_tolerance (float) – l2 norm tolerance

  • delta_l2_norms (list[float]) – list of delta l2 norm values

  • delta_l2_norm_tolerance (float) – delta l2 norm tolerance

  • starting_misfit (float) – starting misfit rmse

  • figsize (tuple[float, float], optional) – width and height of figure, by default (5, 3.5)

Return type:

None

align_yaxis(ax1, v1, ax2, v2)[source]#

adjust ax2 ylimit so that v2 in ax2 is aligned to v1 in ax1. From https://stackoverflow.com/a/10482477/18686384

Parameters:
Return type:

None

grid_inversion_results(misfits, topos, corrections, prisms_ds, grav_results, region)[source]#

create grids from the various data variables of the supplied gravity dataframe and prism dataset

Parameters:
  • misfits (list[str]) – list of misfit column names in the gravity results dataframe

  • topos (list[str]) – list of topography variable names in the prism dataset

  • corrections (list[str]) – list of correction variable names in the prism dataset

  • prisms_ds (xarray.Dataset) – resulting dataset of prism layer from the inversion

  • grav_results (pandas.DataFrame) – resulting dataframe of gravity data from the inversion

  • region (tuple[float, float, float, float]) – region to use for gridding in format (xmin, xmax, ymin, ymax)

Returns:

  • misfit_grids (list[xarray.DataArray]) – list of misfit grids

  • topo_grids (list[xarray.DataArray]) – list of topography grids

  • corrections_grids (list[xarray.DataArray]) – list of correction grids

Return type:

tuple[list[xarray.DataArray], list[xarray.DataArray], list[xarray.DataArray]]

plot_inversion_topo_results(prisms_ds, region=None, constraints_df=None, constraint_style='x.3c', fig_height=12)[source]#

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

Parameters:
  • prisms_ds (xarray.Dataset) – dataset resulting from inversion

  • topo_cmap_perc (float, optional) – value to multiple min and max values by for colorscale, by default 1

  • region (tuple[float, float, float, float], optional) – clip grids to this region before plotting

  • constraints_df (pandas.DataFrame, optional) – constraint points to include in the plots

  • constraint_style (str, optional) – pygmt style string for for constraint points, by default ‘x.3c’

  • fig_height (float, optional) – height of the figure, by default 12

Return type:

None

plot_inversion_grav_results(grav_results, region, iterations, constraints_df=None, fig_height=12, constraint_style='x.3c')[source]#

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

Parameters:
  • grav_results (pandas.DataFrame) – resulting dataframe of gravity data from the inversion

  • region (tuple[float, float, float, float]) – region to use for gridding in format (xmin, xmax, ymin, ymax)

  • iterations (list[int]) – list of all the iteration numbers

  • constraints_df (pandas.DataFrame, optional) – constraint points to include in the plots

  • fig_height (float, optional) – height of the figure, by default 12

  • constraint_style (str, optional) – pygmt style string for for constraint points, by default ‘x.3c’

Return type:

None

plot_inversion_iteration_results(grids, grav_results, topo_results, parameters, iterations, topo_cmap_perc=1, misfit_cmap_perc=1, corrections_cmap_perc=1, constraints_df=None, constraint_size=1)[source]#

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

Parameters:
  • grids (tuple[list[xarray.DataArray], list[xarray.DataArray],) – list[xarray.DataArray]] lists of misfit, topography, and correction grids

  • grav_results (pandas.DataFrame) – gravity dataframe resulting from the inversion

  • topo_results (pandas.DataFrame) – topography dataframe resulting from the inversion

  • parameters (dict[str, Any]) – inversion parameters resulting from the inversion

  • iterations (list[int]) – list of all the iteration numbers which occurred in the inversion

  • topo_cmap_perc (float, optional) – value to multiply the max and min colorscale values by, by default 1

  • misfit_cmap_perc (float, optional) – value to multiply the max and min colorscale values by, by default 1

  • corrections_cmap_perc (float, optional) – value to multiply the max and min colorscale values by, by default 1

  • constraints_df (pandas.DataFrame, optional) – constraint points to include in the plots

  • constraint_size (float, optional) – size for constraint points, by default 1

Return type:

None

plot_inversion_results(grav_results, topo_results, parameters, grav_region, iters_to_plot=None, plot_iter_results=True, plot_topo_results=True, plot_grav_results=True, constraints_df=None, **kwargs)[source]#

plot various results from the inversion

Parameters:
  • grav_results (pandas.DataFrame | str) – gravity results dataframe or filename

  • topo_results (pandas.DataFrame | str) – topography results dataframe or filename

  • parameters (dict[str, Any] | str) – inversion parameters dictionary or filename

  • grav_region (tuple[float, float, float, float] | None) – region to use for gridding in format (xmin, xmax, ymin, ymax), by default None

  • iters_to_plot (int | None, optional) – number of iterations to plot, including the first and last, by default None

  • plot_iter_results (bool, optional) – plot the iteration results, by default True

  • plot_topo_results (bool, optional) – plot the topography results, by default True

  • plot_grav_results (bool, optional) – plot the gravity results, by default True

  • constraints_df (pandas.DataFrame, optional) – constraint points to include in the plots

  • kwargs (Any)

Return type:

None

add_light(plotter, prisms)[source]#

add a light to a pyvista plotter object

Parameters:
Return type:

None

show_prism_layers(prisms, cmap='viridis', color_by='density', region=None, clip_box=False, **kwargs)[source]#

show prism layers using PyVista

Parameters:
  • prisms (list | xarray.Dataset) – either a single harmonica prism layer of list of layers,

  • cmap (str, optional) – matplotlib colorscale to use, by default “viridis”

  • color_by (str, optional) – either use a variable of the prism_layer dataset, typically ‘density’ or ‘thickness’, or choose ‘constant’ to have each layer colored by a unique color use kwarg colors to alter these colors, by default is “density”

  • region (tuple[float, float, float, float], optional) – region to clip the model to, by default None

  • clip_box (bool, optional) – clip a corner out of the model to help visualize, by default False

  • kwargs (Any)

Return type:

None

combined_slice(study, attribute_names, parameter_name=None)[source]#

plot combined slice plots for optimizations.

Parameters:
  • study (optuna.study.Study) – the optuna study object

  • target_names (list[str]) – list of names for parameters in the study

  • attribute_names (list[str])

  • parameter_name (str | None)

Returns:

a plotly figure

Return type:

plotly.graph_objects.Figure

plot_optuna_figures(study, target_names, include_duration=False, plot_history=True, plot_slice=True, plot_importance=True)[source]#

plot the results of an optuna optimization

Parameters:
  • study (optuna.study.Study) – the optuna study object

  • target_names (list[str]) – list of names for parameters in the study

  • include_duration (bool, optional) – whether to add the duration to the plot, by default False

  • plot_history (bool, optional) – choose to plot the optimization history, by default True

  • plot_slice (bool, optional) – choose to plot the parameter values vs. score for each parameter, by default True

  • plot_importance (bool)

Return type:

None

plot_stochastic_results(stats_ds, points=None, region=None, **kwargs)[source]#

Plot the (weighted) standard deviation (uncertainty) and mean of the stochastic ensemble. Optionally, plot points as well.

Parameters:
  • stats_ds (xarray.Dataset) – dataset with the merged inversion results, generate from function uncertainty.model_ensemble_stats.

  • points (pandas.DataFrame | None, optional) – dataframe with points to plot, by default None

  • region (tuple[float, float, float, float] | None)

  • kwargs (Any)

Keyword Arguments:
  • cmap (str, optional) – colormap to use for the ensemble mean, by default “rain”

  • unit (str, optional) – unit of the data, by default “m”

  • reverse_cpt (bool, optional) – reverse the ensemble mean colormap, by default True

  • label (str, optional) – label for the colorbar, by default “ensemble mean”

  • points_label (str, optional) – label for the points, by default None

  • fig_height (float, optional) – height of the figure, by default 12

Return type:

None

remove_df_from_hoverdata(plot)[source]#

Remove the dataframe from the hoverdata of a plotly plot

Parameters:

plot (plotly.graph_objects.Figure) – plotly figure

Returns:

plotly figure with the dataframe removed from the hoverdata

Return type:

plotly.graph_objects.Figure

plot_latin_hypercube(params_dict, plot_individual_dists=True, plot_2d_projections=True)[source]#

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

Parameters:
  • params_dict (dict[str, dict[str, Any]]) – dictionary of sampled parameter values, can be created manually or from the output of func:.uncertainty.create_lhc

  • plot_individual_dists (bool, optional) – choose to plot distribution of each parameter, by default True

  • plot_2d_projections (bool, optional) – choose to plot the 2D projection of each parameter pair, by default True

Return type:

None

projection_2d(sample, var_names)[source]#

Plots the sample projected on each 2D plane

Parameters:
  • sample (NDArray) – The sampled values

  • var_names (list[str]) – The names of the variables

Return type:

None

edge_effects(grav_ds, prism_layer, inner_region, plot_profile=True)[source]#

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

Parameters:
  • grav_ds (xr.Dataset) – the gravity dataset

  • prism_layer (xr.DataArray) – the prism layer

  • inner_region (tuple[float, float, float, float]) – the inside region, where forward gravity is calculated

  • plot_profile (bool, optional) – plot a profile across the region, by default True

Return type:

None