ZH: mutliple k script saves results into hdf5 file

+ slightly improve power per antenna plot if tx is plotted
This commit is contained in:
Eric Teunis de Boone 2023-01-09 11:51:03 +01:00
parent ed1eb3f5cb
commit ab07fe2126

View file

@ -311,20 +311,27 @@ if __name__ == "__main__":
axs.set_title(f"Grid Run {r}") axs.set_title(f"Grid Run {r}")
axs.set_ylabel("vxvxB [km]") axs.set_ylabel("vxvxB [km]")
axs.set_xlabel(" vxB [km]") axs.set_xlabel(" vxB [km]")
axs.set_aspect('equal', 'datalim')
sc = axs.scatter(xx/1e3, yy/1e3, c=maxima_per_loc, cmap='Spectral_r', alpha=0.6) sc = axs.scatter(xx/1e3, yy/1e3, c=maxima_per_loc, cmap='Spectral_r', alpha=0.6)
fig.colorbar(sc, ax=axs) fig.colorbar(sc, ax=axs)
if fig_dir: if fig_dir:
old_xlims = axs.get_xlim()
old_ylims = axs.get_ylim()
fig.tight_layout() fig.tight_layout()
fig.savefig(path.join(fig_dir, __file__+f'.maxima.run{r}.pdf')) fig.savefig(path.join(fig_dir, __file__+f'.maxima.run{r}.pdf'))
if True: if True:
axs.plot(tx.x/1e3, tx.y/1e3, marker='X', color='k') axs.plot(tx.x/1e3, tx.y/1e3, marker='X', color='k')
fig.tight_layout() fig.tight_layout()
fig.savefig(path.join(fig_dir, __file__+f'.maxima.run{r}.with_tx.pdf')) fig.savefig(path.join(fig_dir, __file__+f'.maxima.run{r}.with_tx.pdf'))
axs.set_xlim(*old_xlims)
axs.set_ylim(*old_ylims)
fig.tight_layout()
## Save ks to file ## Save ks to file
best_idx = np.argmax(maxima_per_loc) best_idx = np.argmax(maxima_per_loc)
np.savetxt(fig_dir + __file__+f'.bestk.run{r}.txt', ks_per_loc[best_idx] ) np.savetxt(fig_dir + __file__+f'.bestk.run{r}.txt', ks_per_loc[best_idx] )
print("Max at location: ", locs[best_idx])
print('Best k:', ks_per_loc[best_idx]) print('Best k:', ks_per_loc[best_idx])
# Abort if no improvement # Abort if no improvement
@ -332,12 +339,24 @@ if __name__ == "__main__":
print("No changes from previous grid, breaking") print("No changes from previous grid, breaking")
break break
old_ks_per_loc = ks_per_loc[best_idx]
# Save best ks to hdf5 antenna file # Save best ks to hdf5 antenna file
with h5py.File(antennas_fname, 'a') as fp: with h5py.File(antennas_fname, 'a') as fp:
group = fp.require_group('antennas') group = fp.require_group('antennas')
for i, ant in enumerate(antennas): for i, ant in enumerate(antennas):
h5ant = group[ant.name] h5ant = group[ant.name]
h5ant.attrs['best_k'] = old_ks_per_loc[i]
h5beacon_info = h5ant['beacon_info']
# find out freq_name
if freq_name is None:
freq_name = [ k for k in h5beacon_info.keys() if np.isclose(h5beacon_info[k].attrs['freq'], f_beacon)][0]
h5attrs = h5beacon_info[freq_name].attrs
h5attrs['best_k'] = old_ks_per_loc[i]
h5attrs['best_k_time'] = old_ks_per_loc[i]*dt/f_beacon
plt.show() plt.show()