Skip to content

Commit 83f7073

Browse files
committed
SAR: python updates
Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>
1 parent 5931295 commit 83f7073

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

python/Tutorials/Dipole_SAR.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
### Import Libraries
1414
import os, tempfile
15-
from pylab import *
15+
from matplotlib import pylab as plt
16+
import numpy as np
1617

1718
from CSXCAD import ContinuousStructure
1819
from openEMS import openEMS
@@ -148,26 +149,29 @@ class phantom:
148149
port.CalcPort(Sim_Path, f)
149150
s11 = port.uf_ref/port.uf_inc
150151
s11_dB = 20.0*np.log10(np.abs(s11))
151-
figure()
152-
plot(f/1e9, s11_dB, 'k-', linewidth=2, label='$S_{11}$')
153-
grid()
154-
legend()
155-
ylabel('S-Parameter (dB)')
156-
xlabel('Frequency (GHz)')
152+
plt.figure()
153+
plt.plot(f/1e9, s11_dB, 'k-', linewidth=2, label='$S_{11}$')
154+
plt.grid()
155+
plt.legend()
156+
plt.ylabel('S-Parameter (dB)')
157+
plt.xlabel('Frequency (GHz)')
158+
plt.title('S-Parameter')
157159

158160
Zin = port.uf_tot/port.if_tot
159161

160162
Pin_f0 = np.interp(f0, f, port.P_acc)
161163

162164
# plot feed point impedance
163165
Zin = port.uf_tot/port.if_tot
164-
figure()
165-
plot(f/1e9, np.real(Zin), 'k-', linewidth=2, label=r'$\Re\{Z_{in}\}$')
166-
plot(f/1e9, np.imag(Zin), 'r--', linewidth=2, label=r'$\Im\{Z_{in}\}$')
167-
grid()
168-
legend()
169-
ylabel('Zin (Ohm)')
170-
xlabel('Frequency (GHz)')
166+
plt.figure()
167+
plt.plot(f/1e9, np.real(Zin), 'k-', linewidth=2, label=r'$\Re\{Z_{in}\}$')
168+
plt.plot(f/1e9, np.imag(Zin), 'r--', linewidth=2, label=r'$\Im\{Z_{in}\}$')
169+
plt.grid()
170+
plt.legend()
171+
plt.ylabel('Zin (Ohm)')
172+
plt.xlabel('Frequency (GHz)')
173+
plt.title('Input Impedance')
174+
171175

172176
SAR_src = os.path.join(Sim_Path, 'SAR.h5') # calculated SAR output
173177
SAR_fn = os.path.join(Sim_Path, 'SAR_10g.h5') # calculated SAR output
@@ -191,21 +195,22 @@ class phantom:
191195
# The nf2ff far-field is calculated to determine the radiated power (that was not absorbed)
192196
nf2ff_res = nf2ff.CalcNF2FF(Sim_Path, f0, theta, phi, center=[0,0,0], read_cached=post_proc_only, verbose=1)
193197

194-
print(f'max SAR: {max_sar/Pin_f0} W/kg normalized to 1 W accepted power')
195-
print(f'whole body SAR: {ptotal/Pin_f0/mass} W/kg normalized to 1 W accepted power')
196-
print(f'accepted power: {Pin_f0} W (100 %)')
197-
print(f'radiated power: {nf2ff_res.Prad[0]} W ({100*(nf2ff_res.Prad[0]) / Pin_f0:.1f}%)')
198-
print(f'absorbed power: {ptotal} W ({100*(ptotal) / Pin_f0:.1f}%)')
198+
print(f'max SAR: {max_sar/Pin_f0:.4g} W/kg normalized to 1 W accepted power')
199+
print(f'whole body SAR: {ptotal/Pin_f0/mass:.4g} W/kg normalized to 1 W accepted power')
200+
print(f'accepted power: {Pin_f0:.4g} W (100 %)')
201+
print(f'radiated power: {nf2ff_res.Prad[0]:.4g} W ({100*(nf2ff_res.Prad[0]) / Pin_f0:.1f}%)')
202+
print(f'absorbed power: {ptotal:.4g} W ({100*(ptotal) / Pin_f0:.1f}%)')
199203
print(f'power budget: {100*(nf2ff_res.Prad[0] + ptotal) / Pin_f0:.1f} %') # this ideally should be within 95 to 100%
200204

201205
# plot SAR on a x/y and x/z-plane
202-
fig, axs = subplots(1,2, figsize=(12, 5))
206+
fig, axs = plt.subplots(1,2, figsize=(12, 5))
203207

204208
X,Y = np.meshgrid(mesh[0], mesh[1], indexing='ij')
205209
Nz = len(mesh[2])
206210
sar_xy = sar[:,:,Nz//2]
207211
im = axs[0].pcolormesh(X,Y,sar_xy/Pin_f0, vmax=max_sar/Pin_f0)
208212
axs[0].axis('equal')
213+
axs[0].set_title('xy-plane')
209214
plt.colorbar(im)
210215
m_idx = np.unravel_index(np.argmax(sar_xy), sar_xy.shape)
211216

@@ -214,6 +219,8 @@ class phantom:
214219
sar_xz = sar[:,Ny//2,:]
215220
im = axs[1].pcolormesh(X,Z,sar_xz/Pin_f0, vmax=max_sar/Pin_f0)
216221
axs[1].axis('equal')
222+
axs[1].set_title('xz-plane')
217223
plt.colorbar(im)
224+
fig.suptitle('Specific Absorbtion Rate (SAR)')
218225

219-
show()
226+
plt.show()

python/openEMS/sar_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def readSAR(fn, f_idx=0):
88
with h5py.File(fn, 'r') as h5:
99
if 'openEMS_HDF5_version' in h5.attrs:
1010
sar = h5[f'/FieldData/FD/f{f_idx}']
11+
sar_data['mass'] = h5.attrs['mass']
1112
sar_data.update(sar.attrs)
1213
sar = np.array(sar)
1314
if h5.attrs['openEMS_HDF5_version'] <= 0.2:

0 commit comments

Comments
 (0)