mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 11:33:32 +01:00
ZH: view_beacon: plot noise and beacon traces
This commit is contained in:
parent
5ccba0158c
commit
91016be038
1 changed files with 34 additions and 10 deletions
|
@ -21,7 +21,7 @@ if __name__ == "__main__":
|
||||||
from scriptlib import MyArgumentParser
|
from scriptlib import MyArgumentParser
|
||||||
parser = MyArgumentParser()
|
parser = MyArgumentParser()
|
||||||
parser.add_argument('ant_idx', default=[72], nargs='*', type=int, help='Antenna Indices')
|
parser.add_argument('ant_idx', default=[72], nargs='*', type=int, help='Antenna Indices')
|
||||||
parser.add_argument('-p', '--polarisations', choices=['x', 'y', 'z', 'b', 'AxB'], action='append', help='Default: x,y,z')
|
parser.add_argument('-p', '--polarisations', choices=['x', 'y', 'z', 'b', 'AxB', 'n', 'b+n'], action='append', help='Default: x,y,z')
|
||||||
parser.add_argument('--geom', action='store_true', help='Make a figure containg the geometry from tx to antenna(s)')
|
parser.add_argument('--geom', action='store_true', help='Make a figure containg the geometry from tx to antenna(s)')
|
||||||
parser.add_argument('--ft', action='store_true', help='Add FT strenghts of antenna traces')
|
parser.add_argument('--ft', action='store_true', help='Add FT strenghts of antenna traces')
|
||||||
|
|
||||||
|
@ -42,8 +42,11 @@ if __name__ == "__main__":
|
||||||
####
|
####
|
||||||
fname_dir = path.dirname(fname)
|
fname_dir = path.dirname(fname)
|
||||||
antennas_fname = path.join(fname_dir, beacon.antennas_fname)
|
antennas_fname = path.join(fname_dir, beacon.antennas_fname)
|
||||||
|
tx_fname = path.join(fname_dir, beacon.tx_fname)
|
||||||
|
|
||||||
f_beacon, tx, antennas = beacon.read_beacon_hdf5(antennas_fname)
|
f_beacon, tx, antennas = beacon.read_beacon_hdf5(antennas_fname)
|
||||||
|
_, __, txdata = beacon.read_tx_file(tx_fname)
|
||||||
|
beacon_amp = np.max(txdata['amplitudes'])# mu V/m
|
||||||
|
|
||||||
idx = args.ant_idx
|
idx = args.ant_idx
|
||||||
|
|
||||||
|
@ -66,7 +69,7 @@ if __name__ == "__main__":
|
||||||
name_dist='.raw'
|
name_dist='.raw'
|
||||||
|
|
||||||
|
|
||||||
fig1, axs = plt.subplots(1+plot_ft_amplitude*2, figsize=figsize)
|
fig1, axs = plt.subplots(1+plot_ft_amplitude*1 +0*1, figsize=figsize)
|
||||||
if not plot_ft_amplitude:
|
if not plot_ft_amplitude:
|
||||||
axs = [axs]
|
axs = [axs]
|
||||||
axs[0].set_xlabel('t [ns]')
|
axs[0].set_xlabel('t [ns]')
|
||||||
|
@ -84,6 +87,7 @@ if __name__ == "__main__":
|
||||||
axs[1].set_xlabel('f [GHz]')
|
axs[1].set_xlabel('f [GHz]')
|
||||||
axs[1].set_ylabel('Power')
|
axs[1].set_ylabel('Power')
|
||||||
|
|
||||||
|
if len(axs) > 2:
|
||||||
axs[2].set_ylabel("Phase")
|
axs[2].set_ylabel("Phase")
|
||||||
axs[2].set_xlabel('f [GHz]')
|
axs[2].set_xlabel('f [GHz]')
|
||||||
axs[2].set_ylim(-np.pi,+np.pi)
|
axs[2].set_ylim(-np.pi,+np.pi)
|
||||||
|
@ -102,11 +106,19 @@ if __name__ == "__main__":
|
||||||
pattr = 'E'+str(p)
|
pattr = 'E'+str(p)
|
||||||
if p == 'b':
|
if p == 'b':
|
||||||
pattr = 'beacon'
|
pattr = 'beacon'
|
||||||
|
elif p == 'n':
|
||||||
|
pattr = 'noise'
|
||||||
elif p == 'AxB':
|
elif p == 'AxB':
|
||||||
pattr = 'E_AxB'
|
pattr = 'E_AxB'
|
||||||
|
elif p =='b+n':
|
||||||
|
mydict[p] = getattr(ant,'noise') + beacon_amp*getattr(ant, 'beacon')
|
||||||
|
continue
|
||||||
|
|
||||||
mydict[p] = getattr(ant, pattr)
|
mydict[p] = getattr(ant, pattr)
|
||||||
|
|
||||||
|
if 'b' in mydict:
|
||||||
|
mydict['b'] *= beacon_amp
|
||||||
|
|
||||||
for j, (direction, trace) in enumerate(mydict.items()):
|
for j, (direction, trace) in enumerate(mydict.items()):
|
||||||
l = axs[0].plot(ant.t, trace, label=f"$E_{{{direction}}}$ {ant.name}", alpha=0.7)
|
l = axs[0].plot(ant.t, trace, label=f"$E_{{{direction}}}$ {ant.name}", alpha=0.7)
|
||||||
|
|
||||||
|
@ -118,26 +130,38 @@ if __name__ == "__main__":
|
||||||
if not plot_ft_amplitude:
|
if not plot_ft_amplitude:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
freqs = ft.fftfreq(n_samples, 1/samplerate)[:n_samples//2]
|
fft, freqs = lib.get_freq_spec(trace, 1/samplerate)
|
||||||
fft = 2*ft.fft(trace)[:n_samples//2]/n_samples
|
|
||||||
|
|
||||||
#axs[1].plot(freqs, np.abs(fft)**2, color=l[0].get_color())
|
axs[1].plot(freqs, np.abs(fft)**2, color=l[0].get_color())
|
||||||
|
|
||||||
if True:
|
if True:
|
||||||
cft = lib.direct_fourier_transform(f_beacon, ant.t, trace)
|
cft = lib.direct_fourier_transform(f_beacon, ant.t, trace)
|
||||||
amp = 2*len(ant.t) * (cft[0]**2 + cft[1]**2)
|
amp = (cft[0]**2 + cft[1]**2)
|
||||||
|
|
||||||
#axs[0].axhline(amp, color=l[0].get_color())
|
#axs[0].axhline(amp, color=l[0].get_color())
|
||||||
|
|
||||||
print(amp)
|
print(amp)
|
||||||
phase = np.arctan2(cft[0],cft[1])
|
phase = np.arctan2(cft[0],cft[1])
|
||||||
axs[1].plot(f_beacon, amp, color=l[0].get_color(), marker='3', alpha=0.8, ms=30)
|
axs[1].plot(f_beacon, amp, color=l[0].get_color(), marker='3', alpha=0.8, ms=30)
|
||||||
|
if len(axs) > 2:
|
||||||
axs[2].plot(f_beacon, phase, color=l[0].get_color(), marker='3', alpha=0.8, ms=30)
|
axs[2].plot(f_beacon, phase, color=l[0].get_color(), marker='3', alpha=0.8, ms=30)
|
||||||
|
|
||||||
if plot_ft_amplitude:
|
if plot_ft_amplitude:
|
||||||
fig1.legend(loc='center right', ncol=min(2, len(idx)))
|
fig1.legend(loc='center right', ncol=min(2, len(idx)))
|
||||||
else:
|
else:
|
||||||
axs[0].legend(loc='upper right', ncol=min(3, len(idx)))
|
axs[0].legend(loc='upper right', ncol=min(3, len(idx)))
|
||||||
|
|
||||||
|
# Keep trace plot symmetric around 0
|
||||||
|
max_lim = max(np.abs(axs[0].get_ylim()))
|
||||||
|
axs[0].set_ylim(-max_lim, max_lim)
|
||||||
|
|
||||||
|
# Keep spectrum between 0 and 100 MHz
|
||||||
|
if len(axs) > 1:
|
||||||
|
xlims = axs[1].get_xlim()
|
||||||
|
axs[1].set_xlim(max(0, xlims[0]), min(0.1, xlims[1]))
|
||||||
|
if False: # extra zoom
|
||||||
|
axs[1].set_xlim(f_beacon - 0.01, f_beacon + 0.01)
|
||||||
|
|
||||||
if fig_dir:
|
if fig_dir:
|
||||||
fig1.savefig(path.join(fig_dir, path.basename(__file__) + f".trace{name_dist}.pdf"))
|
fig1.savefig(path.join(fig_dir, path.basename(__file__) + f".trace{name_dist}.pdf"))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue