m-thesis-introduction/simulations/airshower_beacon_simulation/view_orig_ant0.py

99 lines
2.5 KiB
Python
Raw Permalink Normal View History

2022-09-22 09:36:37 +02:00
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
2022-09-26 17:17:35 +02:00
def plot_antenna_Efields(antenna, ax=None, plot_Ex=True, plot_Ey=True, plot_Ez=True, label_append="",**kwargs):
2022-09-22 09:36:37 +02:00
"""Show waveforms from an antenna"""
if ax is None:
ax = plt.gca()
default_kwargs = dict(alpha=0.6)
kwargs = {**default_kwargs, **kwargs}
i = antenna.name
if plot_Ex:
2022-09-26 17:17:35 +02:00
ax.plot(antenna.t, antenna.Ex, label=f"E{{x}}{label_append}".format(x='x', i=i), **kwargs)
2022-09-22 09:36:37 +02:00
if plot_Ey:
2022-09-26 17:17:35 +02:00
ax.plot(antenna.t, antenna.Ey, label=f"E{{x}}{label_append}".format(x='y', i=i), **kwargs)
2022-09-22 09:36:37 +02:00
if plot_Ez:
2022-09-26 17:17:35 +02:00
ax.plot(antenna.t, antenna.Ez, label=f"E{{x}}{label_append}".format(x='z', i=i), **kwargs)
2022-09-22 09:36:37 +02:00
ax.set_xlabel("[ns]")
ax.set_ylabel("[$\mu$V/m]")
ax.set_title("Antenna {i}".format(i=i))
ax.legend()
return ax
2022-11-18 11:02:41 +01:00
def plot_antenna_geometry(antennas, ax=None, plot_names=True, plot_max_values=True, log_max=False, colors=None,**kwargs):
2022-09-22 09:36:37 +02:00
"""Show the max values at each antenna."""
default_kwargs = dict(
cmap='Spectral_r'
)
2022-09-26 17:17:35 +02:00
2022-09-22 09:36:37 +02:00
kwargs = {**default_kwargs, **kwargs}
x = [ a.x for a in antennas ]
y = [ a.y for a in antennas ]
if ax is None:
ax = plt.gca()
2022-09-26 17:17:35 +02:00
if plot_max_values:
max_vals = np.asarray([ np.max([np.max(a.Ex), np.max(a.Ey), np.max(a.Ez)]) for a in antennas ])
if log_max:
max_vals = np.log10(max_vals)
2022-11-18 11:02:41 +01:00
colors = max_vals
sc = ax.scatter(x, y, c=colors, **kwargs)
2022-09-26 17:17:35 +02:00
if plot_max_values:
fig = ax.get_figure()
fig.colorbar(sc, ax=ax, label="[$\mu$V/m]")
2022-09-22 09:36:37 +02:00
if plot_names:
[ ax.annotate(a.name, (a.x, a.y), ha='center',va='center') for a in antennas ]
2022-09-26 17:17:35 +02:00
2022-09-22 09:36:37 +02:00
ax.set_title("Maximum E field at each antenna")
ax.set_ylabel("[m]")
ax.set_xlabel("[m]")
2022-11-18 11:02:41 +01:00
return ax, sc
2022-09-22 09:36:37 +02:00
if __name__ == "__main__":
2022-11-18 19:36:48 +01:00
import os.path as path
from earsim import REvent
import aa_generate_beacon as beacon
2022-09-22 09:36:37 +02:00
fname = "ZH_airshower/mysim.sry"
i = 0
2022-11-18 19:36:48 +01:00
if True:
ev = REvent(fname)
antennas = ev.antennas
else:
fname_dir = path.dirname(fname)
antennas_fname = path.join(fname_dir, beacon.antennas_fname)
f_beacon, tx, antennas = beacon.read_beacon_hdf5(antennas_fname)
2022-09-22 09:36:37 +02:00
2022-09-26 17:17:35 +02:00
if True:
fig, ax1 = plt.subplots()
2022-11-18 19:36:48 +01:00
plot_antenna_Efields(antennas[i], ax=ax1)
2022-09-22 09:36:37 +02:00
2022-09-26 17:17:35 +02:00
if True:
fig2, ax2 = plt.subplots()
2022-11-18 19:36:48 +01:00
plot_antenna_geometry(antennas, ax=ax2, plot_max_values=True, plot_names=False)
2022-09-26 17:17:35 +02:00
ax2.set_aspect('equal', 'datalim')
2022-09-22 09:36:37 +02:00
plt.show()