From 182b20dd8c27dcf6c8f8c3de5ff3c711be095a6e Mon Sep 17 00:00:00 2001 From: Souza-Junior Date: Mon, 12 Aug 2024 12:11:46 -0300 Subject: [PATCH 1/3] Raise error for zero depth value in Equivalent Sources --- harmonica/_equivalent_sources/cartesian.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/harmonica/_equivalent_sources/cartesian.py b/harmonica/_equivalent_sources/cartesian.py index c04e2767c..b5ea48820 100644 --- a/harmonica/_equivalent_sources/cartesian.py +++ b/harmonica/_equivalent_sources/cartesian.py @@ -110,7 +110,7 @@ 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 + 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 @@ -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 From 2bc97c2d392d5fa8e8b4210ae1f14a78ffcced1e Mon Sep 17 00:00:00 2001 From: Souza-Junior Date: Mon, 12 Aug 2024 12:13:03 -0300 Subject: [PATCH 2/3] Add tests for the zero value equivalent sources depth --- harmonica/tests/test_eq_sources_cartesian.py | 10 ++++++++++ harmonica/tests/test_gradient_boosted_eqs.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/harmonica/tests/test_eq_sources_cartesian.py b/harmonica/tests/test_eq_sources_cartesian.py index 33f008d46..a01e7d818 100644 --- a/harmonica/tests/test_eq_sources_cartesian.py +++ b/harmonica/tests/test_eq_sources_cartesian.py @@ -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) diff --git a/harmonica/tests/test_gradient_boosted_eqs.py b/harmonica/tests/test_gradient_boosted_eqs.py index da02cc7ad..d164ec83d 100644 --- a/harmonica/tests/test_gradient_boosted_eqs.py +++ b/harmonica/tests/test_gradient_boosted_eqs.py @@ -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) From 5f8f9e84f9bffd02b06e23857851589a9860b2fa Mon Sep 17 00:00:00 2001 From: Souza-Junior Date: Mon, 12 Aug 2024 12:30:36 -0300 Subject: [PATCH 3/3] Fix docstring formatting --- harmonica/_equivalent_sources/cartesian.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/harmonica/_equivalent_sources/cartesian.py b/harmonica/_equivalent_sources/cartesian.py index b5ea48820..fcc5142e0 100644 --- a/harmonica/_equivalent_sources/cartesian.py +++ b/harmonica/_equivalent_sources/cartesian.py @@ -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 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 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.