From 755426e15614eef2d1c55cd87f449b4026393348 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 22 Dec 2022 16:33:19 +0100 Subject: [PATCH] ZH: show sigma_phase matrix as a plot --- .../bd_antenna_phase_deltas.py | 72 +++++++++++++++++-- 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py b/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py index 17cf4f1..fc0fe6d 100755 --- a/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py +++ b/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py @@ -4,6 +4,8 @@ import h5py from itertools import combinations, zip_longest import matplotlib.pyplot as plt +from matplotlib.colors import Normalize +import matplotlib as mpl import numpy as np import aa_generate_beacon as beacon @@ -50,17 +52,53 @@ if __name__ == "__main__": idx = (name2idx(b[0]), name2idx(b[1])) if idx[0] == idx[1]: + # hopefully 0 pass - sigma_phase_matrix[(idx[0], idx[1])] = true_phase_diffs[i] - sigma_phase_matrix[(idx[1], idx[0])] = true_phase_diffs[i] + sigma_phase_matrix[(idx[0], idx[1])] = lib.phase_mod(true_phase_diffs[i]) + sigma_phase_matrix[(idx[1], idx[0])] = lib.phase_mod(true_phase_diffs[i]) - # for each row j subtract the 0,j element from the whole row - # and apply phase_mod - first_row = sigma_phase_matrix[0] + mat_kwargs = dict( + norm = Normalize(vmin=-np.pi, vmax=+np.pi), + cmap = mpl.cm.get_cmap('Spectral_r') + ) - sigma_phase_matrix = sigma_phase_matrix - first_row[:,np.newaxis] - sigma_phase_matrix = lib.phase_mod(sigma_phase_matrix) + # Show Matrix as figure + if True: + fig, ax = plt.subplots() + ax.set_title("Measured phase differences Baseline i,j") + ax.set_ylabel("Antenna no. i") + ax.set_xlabel("Antenna no. j") + + im = ax.imshow(sigma_phase_matrix, interpolation='none', **mat_kwargs) + fig.colorbar(im, ax=ax) + + if fig_dir: + fig.savefig(path.join(fig_dir, __file__ + f".matrix.original.pdf")) + + + # Modify the matrix to let each column represent multiple + # measurements of the same baseline (j,0) phase difference + if True: + # for each row j subtract the 0,j element from the whole row + # and apply phase_mod + first_row = (sigma_phase_matrix[0,:] * np.ones_like(sigma_phase_matrix)).T + + # Show subtraction Matrix as figure + if True: + fig, ax = plt.subplots() + ax.set_title("Subtraction matrix i,j") + ax.set_ylabel("Antenna no. i") + ax.set_xlabel("Antenna no. j") + + im = ax.imshow(first_row, interpolation='none', **mat_kwargs) + fig.colorbar(im, ax=ax) + + if fig_dir: + fig.savefig(path.join(fig_dir, __file__ + f".matrix.first_row.pdf")) + + sigma_phase_matrix = sigma_phase_matrix - first_row + sigma_phase_matrix = lib.phase_mod(sigma_phase_matrix) # Except for the first row, these are all separate measurements # Condense into phase offset per antenna @@ -72,6 +110,26 @@ if __name__ == "__main__": mean_sigma_phase = np.nanmean(sigma_phase_matrix[my_mask], axis=0) std_sigma_phase = np.nanstd( sigma_phase_matrix[my_mask], axis=0) + + # Show resulting matrix as figure + if True: + fig, axs = plt.subplots(2,1, sharex=True) + axs[0].set_title("Modified measured phase differences Baseline 0,j") + axs[0].set_ylabel("Antenna no. 0") + axs[-1].set_xlabel("Antenna no. j") + + im = axs[0].imshow(sigma_phase_matrix, interpolation='none', **mat_kwargs) + fig.colorbar(im, ax=axs) + axs[0].set_aspect('auto') + + colours = [mat_kwargs['cmap'](mat_kwargs['norm'](x)) for x in mean_sigma_phase] + axs[1].set_ylabel("Mean Baseline Phase (0, j)[rad]") + axs[1].errorbar(np.arange(N_ant), mean_sigma_phase, yerr=std_sigma_phase, ls='none') + axs[1].scatter(np.arange(N_ant), mean_sigma_phase, c=colours,s=4) + + if fig_dir: + fig.savefig(path.join(fig_dir, __file__ + f".matrix.modified.pdf")) + # write into antenna hdf5 with h5py.File(antennas_fname, 'a') as fp: group = fp['antennas']