invert4geom.plotting#
Functions#
|
plot a scatter plot graph with x axis equal to parameter 1, y axis equal to |
|
plot a scatter plot graph with x axis equal to parameter 1, y axis equal to |
|
plot a graph of cross-validation scores vs hyperparameter values |
|
plot a graph of L2-norm and delta L2-norm vs iteration number. |
|
plot a dynamic graph of L2-norm and delta L2-norm vs iteration number. |
|
adjust ax2 ylimit so that v2 in ax2 is aligned to v1 in ax1. |
|
create grids from the various data variables of the supplied gravity dataframe and |
|
plot the initial and final topography grids from the inversion and their difference |
|
plot the initial and final misfit grids from the inversion and their difference |
|
plot the starting misfit, updated topography, and correction grids for a specified |
|
plot various results from the inversion |
|
add a light to a pyvista plotter object |
|
show prism layers using PyVista |
|
plot combined slice plots for optimizations. |
|
plot the results of an optuna optimization |
|
Plot the (weighted) standard deviation (uncertainty) and mean of the stochastic |
|
Remove the dataframe from the hoverdata of a plotly plot |
|
With a dictionary of parameters and their sampled values, plot the individual |
|
Plots the sample projected on each 2D plane |
|
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.
- 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
- 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:
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.
- 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:
ax1 (matplotlib.axes.Axes)
v1 (float)
ax2 (matplotlib.axes.Axes)
v2 (float)
- 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)
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:
plotter (pyvista.Plotter) – pyvista plotter object
prisms (xarray.Dataset) – harmonica prisms layer
- 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.
- 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
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