figure: beacon_field bin_type: hex,square

This commit is contained in:
Eric Teunis de Boone 2022-09-26 14:39:22 +02:00
parent 3e6ba822d7
commit 48b2d6de0f

View file

@ -103,7 +103,13 @@ def calculate_field(field, tx, ant_combi, ref_ant=None, calculate_phase=True):
return np.array(xx), np.array(yy), np.array(val)
def plot_field(tx, ants, xx, yy, val, ax=None, ref_ant=None, color_label='$\\left( t - \\tau \\right)^2$', plot_phase=None, mask=None,**scatter_kwargs):
def plot_field(
tx, ants, xx, yy, val,
ref_ant=None, plot_phase=None, mask=None,
color_label='$\\left( t - \\tau \\right)^2$',
ax=None, bin_type='square', colorbar=True,
**scatter_kwargs
):
if ax is None:
ax = plt.gca()
@ -117,20 +123,26 @@ def plot_field(tx, ants, xx, yy, val, ax=None, ref_ant=None, color_label='$\\lef
pass
elif plot_phase:
default_scatter_kwargs['vmax'] = len(ants)*np.pi
#default_scatter_kwargs['cmap'] = 'gray'
pass
scatter_kwargs = {**default_scatter_kwargs, **scatter_kwargs}
grid_plot([tx] + ants, ax=ax)
if ref_ant is not None:
ax.set_title("Single reference antenna: {}, f: {}MHz".format(ref_ant.name, f_beacon/1e6))
ax.set_title("Single baseline\n reference antenna={}, f={}MHz".format(ref_ant.name, f_beacon/1e6))
else:
ax.set_title("All baselines f: {} MHz".format(f_beacon/1e6))
ax.set_title("All baselines\n f={} MHz".format(f_beacon/1e6))
sc = ax.scatter(xx,yy,c=val, **scatter_kwargs)
fig = ax.get_figure()
fig.colorbar(sc, ax=ax, label=color_label)
if bin_type == 'hex': # hexbin
sc = ax.hexbin(xx, yy, C=val, **scatter_kwargs)
elif bin_type == 'square': # squarebinning
_, _, _, sc = ax.hist2d(xx, yy, weights=val, bins=int(len(xx)**0.5), **scatter_kwargs)
else: # overlayed markers
sc = ax.scatter(xx,yy,c=val, **scatter_kwargs)
if colorbar:
fig = ax.get_figure()
fig.colorbar(sc, ax=ax, label=color_label)
return ax
@ -138,9 +150,6 @@ def square_grid(dx=1, N_x=10, dy=None, N_y=None, x_start=0, y_start=0):
N_y = N_x if N_y is None else N_y
dy = dx if dy is None else dy
print([(N_x,N_y), (dx,dy), (x_start,y_start)])
return product(
(x_start + n*dx for n in range(N_x)),
(y_start + n*dy for n in range(N_y)),
@ -183,8 +192,8 @@ if __name__ == "__main__":
if 'single' in args.type: # single baseline
### Field
x_low, x_high, N_x = -300, 300, 81
y_low, y_high, N_y = -300, 300, 81
x_low, x_high, N_x = -300, 300, 151
y_low, y_high, N_y = -300, 300, 151
### Geometry
ants = [
@ -199,7 +208,7 @@ if __name__ == "__main__":
elif args.type == 'square' or args.type == 'tri': # from grid definition
### Field
x_low, x_high, N_x = -1800, 1800, 161
x_low, x_high, N_x = -1800, 1800, 261
y_low, y_high, N_y = -x_low, -x_high, N_x
### Geometry
@ -244,20 +253,24 @@ if __name__ == "__main__":
xx, yy, val = calculate_field((xs, ys), tx, ant_combi, calculate_phase=plot_phase)
mask = None
if False and plot_phase:
mask = abs(val) > np.pi
kwargs = {}
mask = None
if plot_phase:
color_label='$\\sqrt{ \\sum \\left(\\varphi(x) - \\Delta \\varphi\\right)^2}$'
mask = abs(val) > np.pi
else:
color_label='$\\sqrt{ \\sum \\left(t(x) - \\Delta t\\right)^2}$ [ns]'
val *= 1e9
kwargs['vmax'] = 100
if not True:
mask = abs(val) > 1.1*kwargs['vmax']
ax = plot_field(tx, ants, xx, yy, val, ax=None, ref_ant=ref_ant, mask=mask, color_label=color_label, **kwargs)
if mask is not None:
ax = plot_field([], [], xx, yy, val, cmap='Greys', colorbar=False)
ax = plot_field(tx, ants, xx, yy, val, ref_ant=ref_ant, mask=mask, color_label=color_label, **kwargs)
# if plot_phase:
# N_lowest = np.min(len(ant_combi)-1, 10)