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

Raise error for zero depth value in equivalent sources #524

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 8 additions & 3 deletions harmonica/_equivalent_sources/cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ class EquivalentSources(vdb.BaseGridder):
depth : float or "default"
Parameter used to control the depth at which the point sources will be
located.
If a value is provided, each source is located beneath each data point
(or block-averaged location) at a depth equal to its elevation minus
the ``depth`` value.
If a non-zero value is provided, each source is located beneath each
data point (or block-averaged location) at a depth equal to its
elevation minus the ``depth`` value.
If set to ``"default"``, the depth of the sources will be estimated as
4.5 times the mean distance between first neighboring sources.
This parameter is ignored if *points* is specified.
Expand Down Expand Up @@ -178,6 +178,11 @@ def __init__(
f"Found invalid 'depth' value equal to '{depth}'. "
"It should be 'default' or a numeric value."
)
if depth == 0:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps check if depth <= 0.

Because depth cannot be smaller than zero

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @VascoSch92,

From the perspective of the equivalent source, you can have sources above the observation point. The only problem arises when you have them in the same position as the observation points.

Cheers

raise ValueError(
"Depth value cannot be zero. It should be a non-zero numeric value."
)

self.damping = damping
self.points = points
self.depth = depth
Expand Down
10 changes: 10 additions & 0 deletions harmonica/tests/test_eq_sources_cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,13 @@ def test_invalid_depth():
msg = f"Found invalid 'depth' value equal to '{invalid_depth}'"
with pytest.raises(ValueError, match=msg):
EquivalentSources(depth=invalid_depth)


def test_zero_depth():
"""
Test if error is raised after passing zero for depth.
"""
zero_depth = 0
msg = "Depth value cannot be zero. It should be a non-zero numeric value."
with pytest.raises(ValueError, match=msg):
EquivalentSources(depth=zero_depth)
10 changes: 10 additions & 0 deletions harmonica/tests/test_gradient_boosted_eqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,13 @@ def test_invalid_depth():
msg = f"Found invalid 'depth' value equal to '{invalid_depth}'"
with pytest.raises(ValueError, match=msg):
EquivalentSourcesGB(depth=invalid_depth)


def test_zero_depth():
"""
Test if error is raised after passing zero for depth.
"""
zero_depth = 0
msg = "Depth value cannot be zero. It should be a non-zero numeric value."
with pytest.raises(ValueError, match=msg):
EquivalentSourcesGB(depth=zero_depth)