Skip to content

Commit

Permalink
Merge branch 'main' into fix-reduction_to_pole-coord-name-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
santisoler authored Aug 12, 2024
2 parents dd91935 + 99c5c01 commit 2aa50c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
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:
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)

0 comments on commit 2aa50c2

Please sign in to comment.