<jupyter_start><jupyter_text>Visualize original beam<jupyter_code>path = "../AntennaSimResults/004_Freq1-50MHz_Delta1MHz_AntennaLength1-6m_Delta1m_AntennaAngle75deg_LanderHeight2m/"
fname = "RadiatedElectricField_AntennaLength1m_AntennaAngle75deg_LanderHeight2m_LBoxZ70cm_perpendicular_Phase+180deg.fits"
beam = luseebeam(path + fname)
for f in [0, 10, 20, 30, 40, 45, 50]:
    beam.plot_power(f)
for phi in [0, 90]:
    beam.plot_beamcuts(phi)
f = beam.frequencies
find_to_plot = [9, 19, 29, 39, 49]
fig, axs = plt.subplots(figsize=(17,8), ncols=2, subplot_kw={'projection': 'polar'})
el = np.deg2rad(np.arange(-91, 91))
gain = beam.power
for j, find in enumerate(find_to_plot):  # loop over the frequencies to plot gain for in each panel
    phi0 = gain[find, :, 0]  # phi = 0
    reverse0 = np.flip(phi0)
    gain0 = np.concatenate((reverse0, phi0))
    axs[0].plot(el, gain0, label='{:d} MHz'.format(int(f[find])), linewidth=0.75)  # phi = 0 
    phi90 = gain[find, :, 45]  # phi = 90
    reverse90 = np.flip(phi90)
    gain90 = np.concatenate((reverse90, phi90))
    axs[1].plot(el, gain90, label='{:d} MHz'.format(int(f[find])), linewidth=0.75)  # phi = 90
plt.setp(axs, theta_zero_location='N')
plt.setp(axs, thetamin=-90, thetamax=90)
handles, labels = axs[-1].get_legend_handles_labels()
fig.legend(handles, labels, loc='upper center', ncol=3, fontsize=12)
for ax in axs:
    ax.set_rgrids([0, 1, 2, 3, 4, 5, 6], ['0', ' ', '2', ' ', '4', ' ', '6'], angle=22.5)
thetas = [-90, -45, 0, 45, 90]
tticks = [np.deg2rad(t) for t in thetas]
tlabels = [r'${:d} \degree$'.format(int(np.abs(t))) for t in thetas]
plt.setp(axs, xticks=tticks, xticklabels=tlabels)
axs[0].set_title(r'$\phi=0 \degree$', fontsize=14)
axs[1].set_title(r'$\phi=90 \degree$', fontsize=14)
plt.show()
freq = 45
find = np.argmin(np.abs(beam.frequencies - freq))

left, right = beam.phi.min(), beam.phi.max()
top, bottom = beam.theta.min(), beam.theta.max()
extent = [left, right, bottom, top]
components = ["$|E_x|^2$", "$|E_y|^2$", "$|E_z|^2$"]
fig, axs = plt.subplots(figsize=(15,7), ncols=3, sharex=True, sharey=True)
for i, ax in enumerate(axs):
    im = ax.imshow(np.abs(beam.E_field[find, :, :, i])**2, interpolation="none", aspect="auto", extent=extent)
    ax.set_xlabel("$\\phi$ [deg]")
    if i == 0:
        ax.set_ylabel("$\\theta$ [deg]")
    ax.set_title(components[i], fontsize=14)
cax=fig.add_axes([0.92, 0.125, .02, .76])
plt.colorbar(im, cax, label="$\\rm{V}^2$")
plt.suptitle('$\\nu={:.0f}$ MHz'.format(beam.frequencies[find]), fontsize=16)
plt.show()<jupyter_output><empty_output><jupyter_text>Initialize UVBeam object<jupyter_code>uvb = beam.to_uvbeam(beam_type="E_field", verbose=True)
uvb.data_array.shape
FREQ = 10  # MHz
FREQ *= 1e6  # Hz
FREQ_IND = np.argmin(np.abs(uvb.freq_array[0]-FREQ))

left, right = np.degrees(uvb.axis1_array).min(), np.degrees(uvb.axis1_array).max()
top, bottom = np.degrees(uvb.axis2_array).min(), np.degrees(uvb.axis2_array).max()
plt.figure()
plt.imshow(np.abs(uvb.data_array[0,0,0,FREQ_IND])**2, interpolation="none", aspect="auto", extent=[left, right, bottom, top])
plt.title('X-polarized $E_\\theta\, (\\nu={:.0f}$ MHz)'.format(uvb.freq_array[0, FREQ_IND]/1e6))
plt.colorbar(label="Power $\\rm{V}^2$")
plt.xlabel("$\\phi$ [deg]")
plt.ylabel("$\\theta$ [deg]")
plt.show()
uvb.to_healpix()
uvb.interpolation_function = "healpix_simple"
freq = 45e6
find = np.argmin(np.abs(uvb.freq_array[0] - freq))
hp.mollview(np.abs(uvb.data_array[0, 0, 0, find])**2, title="{:.0f} MHz".format(uvb.freq_array[0, find]/1e6))
# uvb_path = "../luseesky/uvbeams/003/"
# uvb_fname = fname[:-len(".fits")] + ".uvbeam"

# OVERWRITE = True

# if OVERWRITE:
#     try:
#         print("Deleting saved UVBeam.")
#         Path(uvb_path + uvb_fname).unlink()
#     except (FileNotFoundError):
#         pass
#     uvb = beam.to_uvbeam(verbose=True)
#     print("Saving new UVBeam.")
#     uvb.write_beamfits(uvb_path + uvb_fname, clobber=True)
# else:
#     print("Reading saved UVBeam.")
#     uvb = uvbeam.UVBeam()
#     uvb.read_beamfits(uvb_path + uvb_fname)
# print(np.allclose(beam.E_field[:, :, :, 0], uvb.data_array[0, 0, 0]))  # E_x and E polarized along x 
# print(np.allclose(beam.E_field[:, :, :, 1], uvb.data_array[1, 0, 1]))  # E_y and E polarized along y<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20171973042063676, 'fraction_numerical': 0.04740878456890542, 'mean_word_length': 4.9529737206085755, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '55643', 'license': 'MIT', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1862, 'n_words': 325, 'path': 'notebooks/visualize_beams.ipynb', 'repo_name': 'christianhbye/lusee_sky_simulations', 'size': '4303'}