figure beacon_field: single/three baseline at 1.5km

This commit is contained in:
Eric Teunis de Boone 2022-10-06 12:36:56 +02:00
parent 169842900d
commit d324b28f81

View file

@ -49,18 +49,21 @@ def phase(a,b,f=f_beacon,wrap=False):
return phase
def grid_plot(grid, text_dx=(0,0), ax=None, plot_kwargs={}, annot_kwargs={}):
def grid_plot(grid, text_dx=(0,0), ax=None, plot_kwargs={}, annot_kwargs={}, scaler=None):
if ax is None:
ax = plt.gca()
if scaler is None:
scaler = 1
if not grid:
return
default_plot_kwargs=dict(color='k', marker='x', markersize=10, linestyle='None')
plot_kwargs = {**default_plot_kwargs, **plot_kwargs}
x = [a.x for a in grid]
y = [a.y for a in grid]
x = [a.x/scaler for a in grid]
y = [a.y/scaler for a in grid]
l = [a.name for a in grid]
ax.plot(x, y, **plot_kwargs)
@ -116,13 +119,29 @@ def plot_field(
ref_ant=None, plot_phase=None, mask=None,
color_label='$\\left( t - \\tau \\right)^2$',
ax=None, bin_type='square', colorbar=True,
grid_kwargs={},
grid_kwargs={}, scaler=None,
**scatter_kwargs
):
if ax is None:
ax = plt.gca()
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_xlabel('x [m]')
ax.set_ylabel('y [m]')
max_xx, max_yy = max(xx), max(yy)
if max_xx > 1e3 or max_yy > 1e3:
ax.set_xlabel('x [km]')
ax.set_ylabel('y [km]')
scaler = 1e3
dxx = xx[-1] - xx[0]
dyy = yy[-1] - yy[0]
if scaler is None:
scaler = 1
else:
xx = np.array(xx)/scaler
yy = np.array(yy)/scaler
default_scatter_kwargs = {}
default_scatter_kwargs['cmap'] = 'Spectral_r'
@ -133,7 +152,8 @@ def plot_field(
if plot_phase is None:
pass
elif plot_phase:
default_scatter_kwargs['vmax'] = len(ants)*np.pi
val_min = min(val)
default_scatter_kwargs['vmax'] = len(ants)*np.pi + val_min
pass
scatter_kwargs = {**default_scatter_kwargs, **scatter_kwargs}
@ -152,18 +172,18 @@ def plot_field(
grid_text_kwargs = {**grid_text_kwargs, **grid_kwargs['text_kwargs']}
if tx:
grid_plot([tx], text_dx=(20, 0), ax=ax, plot_kwargs=grid_plot_kwargs, annot_kwargs=grid_text_kwargs)
grid_plot([tx], text_dx=(dxx *0/scaler, 0), ax=ax, plot_kwargs=grid_plot_kwargs, annot_kwargs=grid_text_kwargs, scaler=scaler)
if len(ants) > 3:
grid_text_kwargs = None
grid_plot(ants, text_dx=(20, 0), ax=ax, plot_kwargs=grid_plot_kwargs, annot_kwargs=grid_text_kwargs)
grid_plot(ants, text_dx=(dxx*0/scaler, 0), ax=ax, plot_kwargs=grid_plot_kwargs, annot_kwargs=grid_text_kwargs, scaler=scaler)
title = ''
if len(ants) == 1:
title += "Single Antenna\n"
title += "Single Antenna"
elif len(ants) == 2:
title += "Single Baseline\n"
title += "Single Baseline"
else:
if len(ants) == 3:
title += "Three Baseline"
@ -176,9 +196,10 @@ def plot_field(
if ref_ant is not None:
title += " with Reference antenna={}".format(ref_ant.name)
if plot_phase:
title += "\n"
title += "f=${}$MHz".format(f_beacon/1e6)
title += "f=${}$MHz".format(f_beacon/1e6)
ax.set_title(title)
@ -214,6 +235,9 @@ def triangular_grid(dx=1, N_x=10, dy=None, N_y=None, x_start=0, y_start=0):
if __name__ == "__main__":
km = 1e3#m
from argparse import ArgumentParser
import os.path as path
@ -231,33 +255,33 @@ if __name__ == "__main__":
args = parser.parse_args()
if args.fname is not None and path.isdir(args.fname):
args.fname = path.join(args.fname, path.splitext(path.basename(__file__))[0]) # leave off extension
if not path.splitext(args.fname)[1]:
args.fname = [ args.fname+ext for ext in ['.pdf', '.png'] ]
if args.fname is not None:
if path.isdir(args.fname):
args.fname = path.join(args.fname, path.splitext(path.basename(__file__))[0]) # leave off extension
if not path.splitext(args.fname)[1]:
args.fname = [ args.fname+ext for ext in ['.pdf', '.png'] ]
args.plot_phase = args.phase or args.time
del args.time, args.phase
if 'single' in args.type or 'three' in args.type: # single baseline
### Field
x_low, x_high, N_x = -300, 300, 151
y_low, y_high, N_y = -300, 300, 151
x_low, x_high, N_x = -5*km, 5*km, 151
y_low, y_high, N_y = -5*km, 5*km, 151
### Geometry
ants = [
Antenna(x=-50,y=0,z=0,name="a"),
Antenna(x=50,y=0,z=0,name="b"),
Antenna(x=-.75*km,y=0,z=0,name="a"),
Antenna(x=.75*km, y=0,z=0,name="b"),
]
if 'three' in args.type:
ants.append(Antenna(x=0, y=-50,z=0, name='c'))
ants.append(Antenna(x=0, y=-.75*km*np.sqrt(2),z=0, name='c'))
if 'center' in args.type:
tx = Antenna(x=-000,y=200,z=0,name="tx")
tx = Antenna(x=-000,y=4*km,z=0,name="tx")
else:
tx = Antenna(x=-200,y=200,z=0,name="tx")
tx = Antenna(x=-4*km,y=4*km,z=0,name="tx")
elif args.type == 'square' or args.type == 'tri': # from grid definition
### Field
@ -294,8 +318,8 @@ if __name__ == "__main__":
if args.zoom != 'none': # tx zoom
if args.zoom == 'tx':
x_low, x_high, N_x = tx.x - 40, tx.x + 40, 81
y_low, y_high, N_y = -x_low, x_high, N_x
x_low, x_high, N_x = tx.x - 250, tx.x + 250, 151
y_low, y_high, N_y = x_low, x_high, N_x
else:
raise NotImplementedError# args.zoom
@ -321,7 +345,8 @@ if __name__ == "__main__":
mask = None
if plot_phase:
color_label='$\\sqrt{ \\sum_{(i,j)} \\left(\\Delta\\varphi_{ij}(x) - \\Delta \\varphi_{ij}\\right)^2}$'
mask = abs(val) > np.pi
min_val = min(val)
mask = abs(val) > np.pi + min_val
else:
color_label='$\\sqrt{ \\sum_{(i,j)} \\left(\Delta t_{ij}(x) - \\Delta t_{ij}\\right)^2}$ [ns]'
val *= 1e9