Skip to content

Commit c471fd7

Browse files
authored
Revers par in func_eta;zeta when positive up (#249)
1 parent 22ab4dc commit c471fd7

File tree

4 files changed

+46
-25
lines changed

4 files changed

+46
-25
lines changed

CHANGELOG.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,23 @@ v2.5.x
1010
""""""
1111

1212

13-
*latest*
14-
--------
13+
v2.5.4: Bugfix ext. fcts with z+ up
14+
-----------------------------------
15+
16+
**2026-01-21**
1517

18+
- Bugfix: Since v1.10.5, one can provide depth also in decreasing order.
19+
Internally, all parameters are reversed then. However, parameters in
20+
user-provided ``func_eta`` and ``func_zeta`` were not reversed, so far the
21+
user had to take care of this (and hence define them differently to the rest,
22+
which is a bug really). Now any provided parameter in the ``res``-dict is
23+
also reversed. If verb>2, these parameters are finally also printed.
1624

1725
- Gallery
1826

1927
- New example *IP and VRM*, based on a notebook from @orerocks.
2028

2129

22-
2330
v2.5.3: Flexible bipole coordinates
2431
-----------------------------------
2532

empymod/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ def check_model(depth, res, aniso, epermH, epermV, mpermH, mpermV, xdirect,
750750

751751
# Check if the user provided a model for etaH/etaV/zetaH/zetaV
752752
if isinstance(res, dict):
753+
res = copy.deepcopy(res)
753754
res_dict, res = res, res['res']
754755
else:
755756
res_dict = False
@@ -824,7 +825,10 @@ def check_inp(var, name, min_val):
824825
# Loop over key, value pair and check
825826
for key, value in res_dict.items():
826827
if key not in ['res', 'func_eta', 'func_zeta']:
827-
res_dict[key] = check_inp(value, key, None)
828+
res_dict[key] = check_inp(value, key, None)[::swap]
829+
# Print model parameters
830+
if verb > 2:
831+
print(f" {key:16}: {_strvar(res_dict[key])}")
828832

829833
# Put res back
830834
res_dict['res'] = res

examples/time_domain/ip_vrm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def simulate_empymod(inp, res, times, compute_B_field=True, loop_current=1.0,
419419
'inp': {
420420
'src': src_bipole,
421421
'rec': rec,
422-
'depth': [0.0, -50.0],
422+
'depth': [0.0, 50.0],
423423
'verb': 1,
424424
}
425425
}

tests/test_model.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def test_multisrc_multirec(self):
501501
assert_allclose(out0f, out1f)
502502
assert_allclose(out0t, out1t)
503503

504-
def test_cole_cole(self):
504+
def test_cole_cole(self, capsys):
505505
# Check user-hook for eta/zeta
506506

507507
def func_eta(inp, pdict):
@@ -518,25 +518,35 @@ def func_zeta(inp, pdict):
518518

519519
return etaH, etaV
520520

521-
model = {'src': [0, 0, 500, 0, 0], 'rec': [500, 0, 600, 0, 0],
522-
'depth': [0, 550], 'freqtime': [0.1, 1, 10]}
523-
res = np.array([2, 10, 5])
524-
fact = np.array([2, 2, 2])
525-
eta = {'res': fact*res, 'fact': fact, 'func_eta': func_eta}
526-
zeta = {'res': res, 'fact': fact, 'func_zeta': func_zeta}
527-
528-
# Frequency domain
529-
standard = bipole(res=res, **model)
530-
outeta = bipole(res=eta, **model)
531-
assert_allclose(standard, outeta)
532-
outzeta = bipole(res=zeta, mpermH=fact, mpermV=fact, **model)
533-
assert_allclose(standard, outzeta)
534-
# Time domain
535-
standard = bipole(res=res, signal=0, **model)
536-
outeta = bipole(res=eta, signal=0, **model)
537-
assert_allclose(standard, outeta)
538-
outzeta = bipole(res=zeta, signal=0, mpermH=fact, mpermV=fact, **model)
539-
assert_allclose(standard, outzeta)
521+
for rev in [1, -1]:
522+
model = {
523+
'src': [0, 0, 500, 0, 0], 'rec': [500, 0, 600, 0, 0],
524+
'depth': [0, rev*550], 'freqtime': [0.1, 1, 10], 'verb': 3,
525+
}
526+
res = np.array([2, 10, 5])
527+
fact = np.array([1.5, 2, 2.5])
528+
eta = {'res': fact*res, 'fact': fact, 'func_eta': func_eta}
529+
zeta = {'res': res, 'fact': fact, 'func_zeta': func_zeta}
530+
531+
# Frequency domain
532+
standard = bipole(res=res, **model)
533+
_, _ = capsys.readouterr()
534+
outeta = bipole(res=eta, **model)
535+
out, _ = capsys.readouterr()
536+
if rev == 1:
537+
assert "fact : 1.5 2 2.5" in out
538+
else:
539+
assert "fact : 2.5 2 1.5" in out
540+
assert_allclose(standard, outeta)
541+
outzeta = bipole(res=zeta, mpermH=fact, mpermV=fact, **model)
542+
assert_allclose(standard, outzeta)
543+
# Time domain
544+
standard = bipole(res=res, signal=0, **model)
545+
outeta = bipole(res=eta, signal=0, **model)
546+
assert_allclose(standard, outeta)
547+
outzeta = bipole(
548+
res=zeta, signal=0, mpermH=fact, mpermV=fact, **model)
549+
assert_allclose(standard, outzeta)
540550

541551
def test_src_rec_definitions(self):
542552
inp = {'depth': [0, -250], 'res': [1e20, 0.3, 5], 'freqtime': 1.23456}

0 commit comments

Comments
 (0)