invert4geom.utils
#
Module Contents#
Functions#
|
function to give the root mean/median squared error (RMSE) of data |
|
fill missing values in a grid with the nearest value. |
|
_summary_ |
|
for all gridcells calculate to the distance to the nearest target. |
|
Normalize a grid between provided values |
|
Find the minimum distance between each grid cell and the nearest point. If low and |
|
Sample data at every point along a line |
|
extract necessary info from starting prism layer, adds variables 'topo' and |
|
Extract spacing of harmonica prism layer using a dataframe representation. |
|
sample upper and/or lower confining layers into prisms dataframe |
|
alter the surface correction values to ensure when added to the current iteration's |
|
update the prisms dataframe and dataset with the surface correction. Ensure that |
|
apply the corrections grid and update the prism tops, bottoms, topo, and |
|
update the prisms dataframe the the new prism tops, bottoms, topo, and densities |
|
create a Harmonica layer of prisms with assigned densities. |
|
find the best damping parameter for a verde.SplineCV() fit |
|
_summary_ |
- rmse(data, as_median=False)[source]#
function to give the root mean/median squared error (RMSE) of data
- nearest_grid_fill(grid, method='verde')[source]#
fill missing values in a grid with the nearest value.
- Parameters:
grid (xr.DataArray) â grid with missing values
method (str, optional) â choose method of filling, by default âverdeâ
- Returns:
filled grid
- Return type:
xr.DataArray
- filter_grid(grid, filter_width=None, filt_type='lowpass')[source]#
_summary_
- Parameters:
grid (xr.DataArray) â grid to filter the values of
filter_width (float, optional) â width of the filter in meters, by default None
filt_type (str, optional) â type of filter to use, by default âlowpassâ
change_spacing (bool, optional) â if True, will filter the grid and resample the grid to be at the same spacing of the filter width, by default False
- Returns:
a filtered grid
- Return type:
xr.DataArray
- dist_nearest_points(targets, data, coord_names=None)[source]#
for all gridcells calculate to the distance to the nearest target.
- Parameters:
- Returns:
the distance to the nearest target for each gridcell, in the same format as the input for data.
- Return type:
- normalized_mindist(points, grid, low=None, high=None, mindist=None, region=None)[source]#
Find the minimum distance between each grid cell and the nearest point. If low and high are provided, normalize the min dists grid between these values. If region is provided, all grid cells outside region are set to a distance of 0.
- Parameters:
points (pd.DataFrame) â coordinates of the points
grid (xr.DataArray) â gridded data to find min dists for each grid cell
low (float | None, optional) â lower value for normalization, by default None
high (float | None, optional) â higher value for normalization, by default None
mindist (float | None, optional) â the minimum allowed distance, all values below are set equal to, by default None
region (list[float] | None, optional) â bounding region for which all grid cells outside will be set to low, by default None
- Returns:
grid of normalized minimum distances
- Return type:
xr.DataArray
- sample_grids(df, grid, sampled_name, **kwargs)[source]#
Sample data at every point along a line
- Parameters:
- Returns:
Dataframe with new column (sampled_name) of sample values from (grid)
- Return type:
pd.DataFrame
- extract_prism_data(prism_layer)[source]#
extract necessary info from starting prism layer, adds variables âtopoâ and âstarting_topoâ to prism layer dataset (prisms_ds), converts it into dataframe (prisms_df), gets the prism spacing (spacing) from prisms_ds, and creates a grid of the starting topography (topo_grid) from the tops and bottoms of the prism layer.
- get_spacing(prisms_df)[source]#
Extract spacing of harmonica prism layer using a dataframe representation.
- Parameters:
prisms_df (pd.DataFrame) â dataframe of harmonica prism layer
- Returns:
spacing of prisms
- Return type:
- sample_bounding_surfaces(prisms_df, upper_confining_layer=None, lower_confining_layer=None)[source]#
sample upper and/or lower confining layers into prisms dataframe
- Parameters:
prisms_df (pd.DataFrame) â dataframe of prism properties
upper_confining_layer (xr.DataArray | None, optional) â layer which the inverted topography should always be below, by default None
lower_confining_layer (xr.DataArray | None, optional) â layer which the inverted topography should always be above, by default None
- Returns:
a dataframe with added columns âupper_boundsâ and âlower_boundsâ, which are the sampled values of the supplied confining grids.
- Return type:
pd.DataFrame
- enforce_confining_surface(prisms_df, iteration_number)[source]#
alter the surface correction values to ensure when added to the current iterationâs topography it doesnât intersect optional confining layers.
- Parameters:
prisms_df (pd.DataFrame) â prism layer dataframe with optional âupper_boundsâ or âlower_boundsâ columns, and current iterationâs topography.
iteration_number (int) â number of the current iteration, starting at 1 not 0
- Returns:
a dataframe with added column âiter_{iteration_number}_correction
- Return type:
pd.DataFrame
- apply_surface_correction(prisms_df, iteration_number)[source]#
update the prisms dataframe and dataset with the surface correction. Ensure that the updated surface doesnât intersect the optional confining surfaces.
- update_prisms_ds(prisms_ds, correction_grid, zref)[source]#
apply the corrections grid and update the prism tops, bottoms, topo, and densities.
- Parameters:
prisms_ds (xr.Dataset) â harmonica prism layer
correction_grid (xr.DataArray) â grid of corrections to apply to the prism layer
zref (float) â reference level for the prism layer
- Returns:
updated prism layer with new tops, bottoms, topo, and densities
- Return type:
xr.Dataset
- add_updated_prism_properties(prisms_df, prisms_ds, iteration_number)[source]#
update the prisms dataframe the the new prism tops, bottoms, topo, and densities the iteration number, starting at 1 not 0
- Parameters:
prisms_df (pd.DataFrame) â dataframe of prism properties
prisms_ds (xr.Dataset) â dataset of prism properties
iteration_number (int) â the iteration number, starting at 1 not 0
- Returns:
updated prism dataframe with new tops, bottoms, topo, and densities
- Return type:
pd.DataFrame
- grids_to_prisms(surface, reference, density, input_coord_names=('easting', 'northing'))[source]#
create a Harmonica layer of prisms with assigned densities.
- Parameters:
surface (xr.DataArray) â data to use for prism surface
reference (float | xr.DataArray) â data or constant to use for prism reference, if value is below surface, prism will be inverted
density (float | int | xr.DataArray) â data or constant to use for prism densities.
input_coord_names (tuple[str, str], optional) â names of the coordinates in the input dataarray, by default [âeastingâ, ânorthingâ]
- Returns:
a prisms layer with assigned densities
- Return type:
xr.Dataset
- best_spline_cv(coordinates, data, weights=None, dampings=None, delayed=False, force_coords=None)[source]#
find the best damping parameter for a verde.SplineCV() fit
- Parameters:
coordinates (tuple[pd.Series | NDArray, pd.Series | NDArray]) â easting and northing coordinates of the data
data (pd.Series | NDArray) â data for fitting the spline to
weights (pd.Series | NDArray | None, optional) â if not None, then the weights assigned to each data point. Typically, this should be 1 over the data uncertainty squared, by default None
dampings (Any | None, optional) â the positive damping regularization parameter. Controls how much smoothness is imposed on the estimated forces. If None, no regularization is used, by default None
delayed (bool, optional) â if True, will use dask.delayed to dispatch computations and allow mod:dask to execute the grid search in parallel, by default False
force_coords (tuple[pd.Series | NDArray, pd.Series | NDArray] | None, optional) â the easting and northing coordinates of the point forces. Same as force_coords if it is not None. Otherwise, same as the data locations used to fit the spline, by default None
- Returns:
the spline which best fits the data
- Return type:
vd.Spline
- eq_sources_score(params, coordinates, data, delayed=False, **kwargs)[source]#
_summary_
- Parameters:
params (dict[str, float]) â dictionary with damping and depth parameters for the equivalent sources fit
coordinates (tuple[pd.Series | NDArray, pd.Series |) â NDArray, pd.Series | NDArray] easting, northing, and upwards coordinates of the gravity data
data (pd.Series | NDArray) â gravity data values
delayed (bool, optional) â If True, will use dask.delayed to dispatch computations without actually executing them. The returned scores will be a list of delayed objects, by default False
kwargs (Any)
- Returns:
the mean score of the equivalent sources fit
- Return type: