Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eqs default depth bug #91

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,262 changes: 441 additions & 821 deletions docs/gallery/bishop_basement_model.ipynb

Large diffs are not rendered by default.

601 changes: 303 additions & 298 deletions docs/gallery/uieda_et_al_2017_CRUST1.ipynb

Large diffs are not rendered by default.

211 changes: 108 additions & 103 deletions docs/gallery/uieda_et_al_2017_synthetic.ipynb

Large diffs are not rendered by default.

800 changes: 256 additions & 544 deletions docs/user_guide/adhering_to_constraints.ipynb

Large diffs are not rendered by default.

5,950 changes: 5,078 additions & 872 deletions docs/user_guide/combining_it_all.ipynb

Large diffs are not rendered by default.

829 changes: 444 additions & 385 deletions docs/user_guide/damping_cross_validation.ipynb

Large diffs are not rendered by default.

388 changes: 233 additions & 155 deletions docs/user_guide/density_cross_validation.ipynb

Large diffs are not rendered by default.

85 changes: 47 additions & 38 deletions docs/user_guide/discretization.ipynb

Large diffs are not rendered by default.

4,087 changes: 2,491 additions & 1,596 deletions docs/user_guide/estimating_regional_field.ipynb

Large diffs are not rendered by default.

761 changes: 398 additions & 363 deletions docs/user_guide/including_starting_model.ipynb

Large diffs are not rendered by default.

480 changes: 299 additions & 181 deletions docs/user_guide/reference_level_cross_validation.ipynb

Large diffs are not rendered by default.

5,891 changes: 4,597 additions & 1,294 deletions docs/user_guide/regional_field_hyperparameters.ipynb

Large diffs are not rendered by default.

1,359 changes: 1,049 additions & 310 deletions docs/user_guide/simple_inversion.ipynb

Large diffs are not rendered by default.

894 changes: 391 additions & 503 deletions docs/user_guide/uncertainty_analysis.ipynb

Large diffs are not rendered by default.

947 changes: 23 additions & 924 deletions docs/user_guide/variable_density_contrast.ipynb

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/invert4geom/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,7 @@ def __call__(self, trial: optuna.trial) -> float:
depth = kwargs.pop("depth", "default")
# calculate 4.5 times the mean distance between points
if depth == "default":
depth = np.mean(
depth = 4.5 * np.mean(
vd.median_distance(
(kwargs.get("coordinates")[0], kwargs.get("coordinates")[1]), # type: ignore[unused-ignore, index]
k_nearest=1,
Expand Down Expand Up @@ -1977,7 +1977,7 @@ def optimize_eq_source_params(
log.warning(msg)
best_depth = "default"
if best_depth == "default":
best_depth = np.mean(
best_depth = 4.5 * np.mean(
vd.median_distance((coordinates[0], coordinates[1]), k_nearest=1)
)
if best_block_size is None:
Expand Down Expand Up @@ -2376,7 +2376,7 @@ def __call__(self, trial: optuna.trial) -> float:
eq_depth = self.kwargs.get("depth", "default")
if eq_depth == "default":
# calculate 4.5 times the mean distance between points
eq_depth = np.mean(
eq_depth = 4.5 * np.mean(
vd.median_distance(
(self.training_df.easting, self.training_df.northing),
k_nearest=1,
Expand Down Expand Up @@ -2429,7 +2429,7 @@ def __call__(self, trial: optuna.trial) -> float:
eq_depth = self.kwargs.get("depth", "default")
if eq_depth == "default":
# calculate 4.5 times the mean distance between points
eq_depth = np.mean(
eq_depth = 4.5 * np.mean(
vd.median_distance(
(
self.training_df[i].easting,
Expand Down Expand Up @@ -2941,7 +2941,7 @@ def optimize_regional_eq_sources(
depth = best_trial.params.get("depth", kwargs.pop("depth", "default"))
if depth == "default":
# calculate 4.5 times the mean distance between points
depth = np.mean(
depth = 4.5 * np.mean(
vd.median_distance((grav_df.easting, grav_df.northing), k_nearest=1)
)
damping = best_trial.params.get("damping", kwargs.pop("damping", None))
Expand Down Expand Up @@ -3247,7 +3247,7 @@ def optimize_regional_constraint_point_minimization(
depth = best_trial.params.get("depth", kwargs.pop("depth", "default"))
if depth == "default":
# calculate 4.5 times the mean distance between points
depth = np.mean(
depth = 4.5 * np.mean(
vd.median_distance(
(constraints_df.easting, constraints_df.northing), k_nearest=1
)
Expand Down
17 changes: 13 additions & 4 deletions src/invert4geom/regional.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def regional_constraints(
tension_factor: float = 1,
registration: str = "g",
spline_dampings: float | list[float] | None = None,
depth: float | None = None,
depth: float | str | None = None,
damping: float | None = None,
cv: bool = False,
block_size: float | None = None,
Expand Down Expand Up @@ -378,7 +378,7 @@ def regional_constraints(
grid registration used if `grid_method` is "pygmt",, by default "g"
spline_dampings : float | list[float] | None, optional
damping values used if `grid_method` is "verde", by default None
depth : float | None, optional
depth : float | str | None, optional
depth of each source relative to the data elevation, positive downwards in
meters, by default None
damping : float | None, optional
Expand Down Expand Up @@ -433,7 +433,6 @@ def regional_constraints(
no_skip=True,
verbose="q",
)
log.debug("sampled constraints: %s", constraints_df.describe())

# drop rows with NaN values
constraints_df = constraints_df[constraints_df.sampled_grav.notna()]
Expand Down Expand Up @@ -539,6 +538,15 @@ def regional_constraints(
constraints_df.northing,
constraints_df.sampled_grav_height,
)

if depth == "default":
depth = 4.5 * np.mean(
vd.median_distance(
(coords[0], coords[1]),
k_nearest=1,
)
)

if cv is True:
# eqs = utils.best_equivalent_source_damping(
_, eqs = optimization.optimize_eq_source_params(
Expand Down Expand Up @@ -566,6 +574,8 @@ def regional_constraints(
weights=weights,
)

log.debug(f"depth: {eqs.depth}, damping: {eqs.damping}")

# predict sources at gravity points and chosen height for upward continuation
grav_df["reg"] = eqs.predict(
(
Expand Down Expand Up @@ -630,7 +640,6 @@ def regional_constraints_cv(
df,
**split_kwargs,
)
log.debug("cv constraints split: %s", testing_training_df.describe())

_, grav_df, _ = optimization.optimize_regional_constraint_point_minimization(
testing_training_df=testing_training_df,
Expand Down
Loading