Skip to content

Commit

Permalink
Fix TxMagneticDipole-repr; closes #311 (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
prisae authored Mar 5, 2024
1 parent 8750f85 commit be4d60e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
20 changes: 15 additions & 5 deletions emg3d/electrodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def __init__(self, coordinates, length=1.0):

if is_flat:
# Re-arrange for points.
points = np.array([coordinates[::2], coordinates[1::2]])
points = coordinates.reshape((2, 3), order='F')

# Store original input.
self._coordinates = coordinates
Expand Down Expand Up @@ -375,10 +375,20 @@ def __repr__(self):

# Finite dipole.
else:
s1 = (f" e1={{{self.points[0, 0]:,.1f}; "
f"{self.points[0, 1]:,.1f}; {self.points[0, 2]:,.1f}}} m; ")
s2 = (f"e2={{{self.points[1, 0]:,.1f}; "
f"{self.points[1, 1]:,.1f}; {self.points[1, 2]:,.1f}}} m")

# Finite magnetic dipole.
if self._xtype == 'magnetic':
if self.coordinates.ndim == 1:
points = self.coordinates
else:
points = self.coordinates.ravel('F')
else:
points = self.points.ravel('F')

s1 = (f" e1={{{points[0]:,.1f}; "
f"{points[2]:,.1f}; {points[4]:,.1f}}} m; ")
s2 = (f"e2={{{points[1]:,.1f}; "
f"{points[3]:,.1f}; {points[5]:,.1f}}} m")

return s0 + s1 + s2 if len(s1+s2) < 80 else s0 + s1 + "\n " + s2

Expand Down
4 changes: 3 additions & 1 deletion tests/test_electrodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ def test_tx_magnetic_dipole():
s5a = electrodes.TxMagneticDipole(
(-1, 1, -1, 1, -np.sqrt(2), np.sqrt(2)), strength=np.pi)
s5b = electrodes.TxMagneticDipole.from_dict(s5a.to_dict())
rep = s5b.__repr__()
assert "m; e2={1.0; 1.0; " in rep
assert s5a == s5b
s6a = electrodes.TxMagneticDipole(
[[-1, -1, -np.sqrt(2)], [1, 1, np.sqrt(2)]], strength=np.pi)
Expand All @@ -287,7 +289,7 @@ def test_tx_magnetic_dipole():

rep = s6b.__repr__()
assert "3.1 A" in rep
assert "m; e2={-0.7" in rep
assert "m; e2={1.0; 1.0; " in rep


def test_tx_electric_wire():
Expand Down

0 comments on commit be4d60e

Please sign in to comment.