Skip to content

Commit

Permalink
refactor: switch keyword argument name from input_grav_column to `g…
Browse files Browse the repository at this point in the history
…rav_data_column`

BREAKING CHANGE: make sure to switch all mentions of 'input_grav_column` to `grav_data_column` in your code!
  • Loading branch information
mdtanker committed May 29, 2024
1 parent 7555f18 commit f864c1f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/invert4geom/cross_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def grav_cv_score(
)

# compare forward of inverted layer with observed
observed = test[kwargs.get("input_grav_column")] - test.reg
observed = test[kwargs.get("grav_data_column")] - test.reg
predicted = test.test_point_grav

dif = predicted - observed
Expand All @@ -195,7 +195,7 @@ def grav_cv_score(

if plot:
test_grid = test.set_index(["northing", "easting"]).to_xarray()
obs = test_grid[kwargs.get("input_grav_column")] - test_grid.reg
obs = test_grid[kwargs.get("grav_data_column")] - test_grid.reg
pred = test_grid.test_point_grav.rename("")

polar_utils.grd_compare(
Expand Down Expand Up @@ -323,7 +323,7 @@ def constraints_cv_score(
----------
grav_df : pd.DataFrame
gravity dataframe with columns "res", "reg", and column set by kwarg
input_grav_column
grav_data_column
constraints : pd.DataFrame
constraints dataframe with columns "easting", "northing", and "upward"
rmse_as_median : bool, optional
Expand Down
19 changes: 10 additions & 9 deletions src/invert4geom/inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def end_inversion(
def update_gravity_and_misfit(
gravity_df: pd.DataFrame,
prisms_ds: xr.Dataset,
input_grav_column: str,
grav_data_column: str,
iteration_number: int,
) -> pd.DataFrame:
"""
Expand All @@ -710,12 +710,12 @@ def update_gravity_and_misfit(
----------
gravity_df : pd.DataFrame
gravity dataframe with gravity observation coordinate columns ('easting',
'northing', 'upwards'), a gravity data column, set by `input_grav_column`,
'northing', 'upwards'), a gravity data column, set by `grav_data_column`,
and a regional gravity column ('reg').
prisms_ds : xr.Dataset
harmonica prism layer
input_grav_column : str
grav_data_column : str
name of gravity data column
iteration_number : int
iteration number to use in updated column names
Expand All @@ -742,7 +742,7 @@ def update_gravity_and_misfit(
# Gres = Gobs_corr_shift - Gforward - Greg
# update the residual misfit with the new forward gravity and the same regional
gravity[f"iter_{iteration_number}_final_misfit"] = (
gravity[input_grav_column]
gravity[grav_data_column]
- gravity[f"iter_{iteration_number}_forward_grav"]
- gravity.reg
)
Expand All @@ -752,7 +752,7 @@ def update_gravity_and_misfit(

def run_inversion(
grav_df: pd.DataFrame,
input_grav_column: str,
grav_data_column: str,
prism_layer: xr.Dataset,
density_contrast: float,
zref: float,
Expand Down Expand Up @@ -787,8 +787,9 @@ def run_inversion(
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
grav_data_column : str
Column name containing the gravity anomaly data used to calculate the misfit.
This is typically a Topo-Free Disturbance (Complete Bouguer Anomaly).
prism_layer : xr.Dataset
starting prism layer
density_contrast : float
Expand Down Expand Up @@ -864,7 +865,7 @@ def run_inversion(

# create empty jacobian matrix
empty_jac: NDArray = np.empty(
(len(gravity[input_grav_column]), prisms_ds.top.size),
(len(gravity[grav_data_column]), prisms_ds.top.size),
dtype=np.float64,
)

Expand Down Expand Up @@ -975,7 +976,7 @@ def run_inversion(
gravity = update_gravity_and_misfit(
gravity,
prisms_ds,
input_grav_column,
grav_data_column,
iteration,
)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def test_update_gravity_and_misfit_forward_gravity():
updated_gravity_df = inversion.update_gravity_and_misfit(
gravity_df=gravity_df_copy,
prisms_ds=dummy_prism_layer(),
input_grav_column="observed_grav",
grav_data_column="observed_grav",
iteration_number=1,
)
# Check that 'iter_1_forward_grav' column is created
Expand Down Expand Up @@ -729,7 +729,7 @@ def test_update_gravity_and_misfit_forward_gravity_regional():
updated_gravity_df = inversion.update_gravity_and_misfit(
gravity_df=gravity_df_copy,
prisms_ds=dummy_prism_layer(),
input_grav_column="observed_grav",
grav_data_column="observed_grav",
iteration_number=1,
)
# expected_forward_grav = [7.18, 7.18, 7.70, 7.70]
Expand All @@ -751,8 +751,8 @@ def test_update_gravity_and_misfit_forward_gravity_regional():
# print(gravity_df)
# print(prisms_ds)
# results = inversion.run_inversion(
# input_grav=gravity_df,
# input_grav_column="observed_grav",
# grav_df=gravity_df,
# grav_data_column="observed_grav",
# prism_layer=prisms_ds,
# max_iterations=3,
# )
Expand Down Expand Up @@ -786,7 +786,7 @@ def test_update_gravity_and_misfit_forward_gravity_regional():
# updated_gravity_df = inversion.update_gravity_and_misfit(
# gravity_df=gravity_df_copy,
# prisms_ds=dummy_prism_layer(),
# input_grav_column="observed_grav",
# grav_data_column="observed_grav",
# iteration_number=5,
# )
# # Check that 'iter_5_forward_grav' column is created
Expand Down

0 comments on commit f864c1f

Please sign in to comment.