Skip to content

Commit

Permalink
Updates to all examples to ensure changes to calculate farfield are w…
Browse files Browse the repository at this point in the history
…orking as expected. Bug fixes to the triangle export function in the base class, and to the emrotation function within the mesh transform..
  • Loading branch information
LyceanEM committed Dec 3, 2024
1 parent e12d363 commit cf70603
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 430 deletions.
4 changes: 2 additions & 2 deletions docs/examples/02_coherently_polarised_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@
UAV_Static_Pattern = antenna_pattern(
azimuth_resolution=az_res, elevation_resolution=elev_res
)
UAV_Static_Pattern.pattern[:, :, 0] = Etheta
UAV_Static_Pattern.pattern[:, :, 1] = Ephi
UAV_Static_Pattern.pattern[:, :, 0] = Etheta.reshape(elev_res,az_res)
UAV_Static_Pattern.pattern[:, :, 1] = Ephi.reshape(elev_res,az_res)

UAV_Static_Pattern.display_pattern(desired_pattern='Power')

Expand Down
104 changes: 67 additions & 37 deletions docs/examples/03_frequency_domain_channel_modelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Frequency and Mesh Resolution
# ------------------------------
#
freq = np.asarray(22.0e9)
freq = np.asarray(24.0e9)
wavelength = 3e8 / freq
mesh_resolution = 0.5 * wavelength

Expand Down Expand Up @@ -56,25 +56,25 @@
)
transmit_horn_structure = GF.mesh_rotate(transmit_horn_structure,rotation_vector2)

transmit_horn_structure = GF.translate_mesh(transmit_horn_structure,np.asarray([2.695, 0, 0]))
transmit_horn_structure = GF.translate_mesh(transmit_horn_structure,np.asarray([2.529, 0, 0]))

transmitting_antenna_surface_coords = GF.mesh_rotate(transmitting_antenna_surface_coords,rotation_vector1)

transmitting_antenna_surface_coords = GF.mesh_rotate(
transmitting_antenna_surface_coords,rotation_vector2)

transmitting_antenna_surface_coords = GF.translate_mesh(transmitting_antenna_surface_coords,np.asarray([2.695, 0, 0]))
transmitting_antenna_surface_coords = GF.translate_mesh(transmitting_antenna_surface_coords,np.asarray([2.529, 0, 0]))
# %%
# Position Receiver
# ------------------
# rotate the receiving horn to desired orientation and translate to final position.

receive_horn_structure = GF.mesh_rotate(receive_horn_structure,rotation_vector1)
#receive_horn_structure = GF.mesh_rotate(receive_horn_structure,rotation_vector3)
receive_horn_structure = GF.translate_mesh(receive_horn_structure,np.asarray([0, 1.427, 0]))
receive_horn_structure = GF.translate_mesh(receive_horn_structure,np.asarray([0, 1.609, 0]))
receiving_antenna_surface_coords = GF.mesh_rotate(receiving_antenna_surface_coords,rotation_vector1)
#receiving_antenna_surface_coords = GF.mesh_rotate(receiving_antenna_surface_coords,rotation_vector3)
receiving_antenna_surface_coords = GF.translate_mesh(receiving_antenna_surface_coords,np.asarray([0, 1.427, 0]))
receiving_antenna_surface_coords = GF.translate_mesh(receiving_antenna_surface_coords,np.asarray([0, 1.609, 0]))



Expand Down Expand Up @@ -123,20 +123,17 @@
# %%
# Visualise the Scene Geometry
# ------------------------------
#############################################NEED TO FIX THIS with pyvista

import pyvista as pv
def structure_cells(array):
## add collumn of 3s to beggining of each row
array = np.append(np.ones((array.shape[0], 1), dtype=np.int32) * 3, array, axis=1)
return array
pyvista_mesh = pv.PolyData(reflectorplate.points, structure_cells(reflectorplate.cells[0].data))
pyvista_mesh2 = pv.PolyData(receive_horn_structure.points, structure_cells(receive_horn_structure.cells[0].data))
pyvista_mesh3 = pv.PolyData(transmit_horn_structure.points, structure_cells(transmit_horn_structure.cells[0].data))
from lyceanem.utility.mesh_functions import pyvista_to_meshio
## plot the mesh
plotter = pv.Plotter()
plotter.add_mesh(pyvista_mesh, color="white", show_edges=True)
plotter.add_mesh(pyvista_mesh2, color="blue", show_edges=True)
plotter.add_mesh(pyvista_mesh3, color="red", show_edges=True)
plotter.add_mesh(pv.from_meshio(reflectorplate), color="grey")
plotter.add_mesh(pv.from_meshio(scatter_points), color="grey")
plotter.add_mesh(pv.from_meshio(receive_horn_structure), color="blue")
plotter.add_mesh(pv.from_meshio(receiving_antenna_surface_coords), color="blue")
plotter.add_mesh(pv.from_meshio(transmit_horn_structure), color="red")
plotter.add_mesh(pv.from_meshio(transmitting_antenna_surface_coords), color="red")
plotter.add_axes_at_origin()
plotter.show()
# Specify desired Transmit Polarisation
Expand Down Expand Up @@ -196,37 +193,70 @@ def structure_cells(array):
import copy

from tqdm import tqdm

from lyceanem.electromagnetics.emfunctions import update_electric_fields, PoyntingVector
for angle_inc in tqdm(range(len(angle_values))):
rotation_vector = np.radians(np.asarray([0.0, 0.0, angle_values[angle_inc]]))
scatter_points_temp = GF.mesh_rotate(copy.deepcopy(scatter_points),rotation_vector)
reflectorplate_temp = GF.mesh_rotate(copy.deepcopy(reflectorplate),rotation_vector)
scatter_points_temp = GF.mesh_rotate(scatter_points,rotation_vector)
reflectorplate_temp = GF.mesh_rotate(reflectorplate,rotation_vector)
blockers = structures([reflectorplate_temp, receive_horn_structure, transmit_horn_structure])
# pyvista_mesh = pv.PolyData(reflectorplate_temp.points, structure_cells(reflectorplate_temp.cells[0].data))
# pyvista_mesh2 = pv.PolyData(receive_horn_structure.points, structure_cells(receive_horn_structure.cells[0].data))
# pyvista_mesh3 = pv.PolyData(transmit_horn_structure.points, structure_cells(transmit_horn_structure.cells[0].data))
# pyvista_mesh4 = pv.PolyData(scatter_points_temp.points)
# ## plot the mesh

Ex, Ey, Ez = FD.calculate_scattering(
aperture_coords=transmitting_antenna_surface_coords,
sink_coords=scatter_points_temp,
antenna_solid=blockers,
desired_E_axis=np.tile(desired_E_axis,[transmitting_antenna_surface_coords.points.shape[0],1]),
scatter_points=scatter_points_temp,
wavelength=wavelength,
scattering=0,
project_vectors=False,
beta=(2*np.pi)/wavelength
)
scattered_field=np.array([Ex*scatter_points_temp.point_data['Area'],
Ey*scatter_points_temp.point_data['Area'],
Ez*scatter_points_temp.point_data['Area']]).transpose()
#scatter_points_temp=update_electric_fields(scatter_points_temp,
# Ex*scatter_points_temp.point_data['Area'],
# Ey*scatter_points_temp.point_data['Area'],
# Ez*scatter_points_temp.point_data['Area'])
#scatter_points_temp=PoyntingVector(scatter_points_temp)
#scatter_points_temp.point_data["Ex"]=np.abs(scatter_points_temp.point_data['Ex-Real']+1j*scatter_points_temp.point_data['Ex-Imag'])
#scatter_points_temp.point_data["Ey"]=np.abs(scatter_points_temp.point_data['Ey-Real']+1j*scatter_points_temp.point_data['Ey-Imag'])
#scatter_points_temp.point_data["Ez"]=np.abs(scatter_points_temp.point_data['Ez-Real']+1j*scatter_points_temp.point_data['Ez-Imag'])
# plotter = pv.Plotter()
# plotter.add_mesh(pyvista_mesh, color="white", show_edges=True)
# plotter.add_mesh(pyvista_mesh2, color="blue", show_edges=True)
# plotter.add_mesh(pyvista_mesh3, color="red", show_edges=True)
# plotter.add_mesh(pyvista_mesh4, color="green")
# plotter.add_mesh(pv.from_meshio(reflectorplate_temp), color="grey")
# plotter.add_mesh(pv.from_meshio(scatter_points_temp), scalars="Ey",clim=[0,0.0015])
# plotter.add_mesh(pv.from_meshio(receive_horn_structure), color="blue")
# plotter.add_mesh(pv.from_meshio(receiving_antenna_surface_coords), color="blue")
# plotter.add_mesh(pv.from_meshio(transmit_horn_structure), color="red")
# plotter.add_mesh(pv.from_meshio(transmitting_antenna_surface_coords), color="red")
# plotter.add_axes_at_origin()
# plotter.show()
Ex, Ey, Ez = FD.calculate_scattering(

Ex2, Ey2, Ez2 = FD.calculate_scattering(
aperture_coords=scatter_points_temp,
sink_coords=receiving_antenna_surface_coords,
antenna_solid=blockers,
desired_E_axis=scattered_field,
scatter_points=scatter_points_temp,
wavelength=wavelength,
scattering=0,
project_vectors=False,
beta=(2*np.pi)/wavelength
)
Ex3, Ey3, Ez3 = FD.calculate_scattering(
aperture_coords=transmitting_antenna_surface_coords,
sink_coords=receiving_antenna_surface_coords,
antenna_solid=blockers,
desired_E_axis=desired_E_axis,
desired_E_axis=np.tile(desired_E_axis,[transmitting_antenna_surface_coords.points.shape[0],1]),
scatter_points=scatter_points_temp,
wavelength=wavelength,
scattering=1,
project_vectors=False
scattering=0,
project_vectors=False,
beta=(2*np.pi)/wavelength
)
responsex[angle_inc] = np.sum(Ex)
responsey[angle_inc] = np.sum(Ey)
responsez[angle_inc] = np.sum(Ez)
responsex[angle_inc] = np.sum((Ex2+Ex3)*receiving_antenna_surface_coords.point_data["Area"])
responsey[angle_inc] = np.sum((Ey2+Ey3)*receiving_antenna_surface_coords.point_data["Area"])
responsez[angle_inc] = np.sum((Ez2+Ez3)*receiving_antenna_surface_coords.point_data["Area"])



Expand Down Expand Up @@ -258,10 +288,10 @@ def structure_cells(array):
ax.plot(angle_values - 45, EzdB, label="Ez")
plt.xlabel("$\\theta_{N}$ (degrees)")
plt.ylabel("Normalised Level (dB)")
ax.set_ylim(-60.0, 0)
ax.set_ylim(-40.0, 0)
ax.set_xlim(np.min(angle_values) - 45, np.max(angle_values) - 45)
ax.set_xticks(np.linspace(np.min(angle_values) - 45, np.max(angle_values) - 45, 19))
ax.set_yticks(np.linspace(-60, 0.0, 21))
ax.set_yticks(np.linspace(-40, 0.0, 21))
legend = ax.legend(loc="upper right", shadow=True)
plt.grid()
plt.show()
3 changes: 2 additions & 1 deletion docs/examples/05_array_beamforming.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@

az_range = np.linspace(-180, 180, az_res)
el_range = np.linspace(-90, 90, elev_res)
num_elements=Etheta.shape[0]
directivity_map = MaximumDirectivityMap(
Etheta, Ephi, source_coords, wavelength, az_range, el_range
Etheta.reshape(num_elements,elev_res,az_res), Ephi.reshape(num_elements,elev_res,az_res), source_coords, wavelength, az_range, el_range
)

from lyceanem.electromagnetics.beamforming import PatternPlot
Expand Down
122 changes: 62 additions & 60 deletions docs/examples/06_farfield_polarisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
u_pattern = antenna_pattern(
azimuth_resolution=az_res, elevation_resolution=elev_res
)
u_pattern.pattern[:, :, 0] = Etheta
u_pattern.pattern[:, :, 1] = Ephi
u_pattern.pattern[:, :, 0] = Etheta.reshape(elev_res,az_res)
u_pattern.pattern[:, :, 1] = Ephi.reshape(elev_res,az_res)
u_pattern.display_pattern(desired_pattern='Power')

# %%
Expand All @@ -99,8 +99,8 @@
v_pattern = antenna_pattern(
azimuth_resolution=az_res, elevation_resolution=elev_res
)
v_pattern.pattern[:, :, 0] = Etheta
v_pattern.pattern[:, :, 1] = Ephi
v_pattern.pattern[:, :, 0] = Etheta.reshape(elev_res,az_res)
v_pattern.pattern[:, :, 1] = Ephi.reshape(elev_res,az_res)
v_pattern.display_pattern(desired_pattern='Power')

# %%
Expand All @@ -124,64 +124,66 @@
n_pattern = antenna_pattern(
azimuth_resolution=az_res, elevation_resolution=elev_res
)
n_pattern.pattern[:, :, 0] = Etheta
n_pattern.pattern[:, :, 1] = Ephi
n_pattern.pattern[:, :, 0] = Etheta.reshape(elev_res,az_res)
n_pattern.pattern[:, :, 1] = Ephi.reshape(elev_res,az_res)
n_pattern.display_pattern(desired_pattern='Power')

# %%
# The point source can then be rotated, by providing a rotation matrix, and the u,v,n directions are moved with it in a consistent way.
from scipy.spatial.transform import Rotation as R

# point_antenna.rotate_antenna(o3d.geometry.get_rotation_matrix_from_axis_angle(np.radians(np.asarray([90.0,0.0,0.0]))))

# desired_E_axis = np.zeros((1, 3), dtype=np.complex64)
# desired_E_axis[0, 0] = 1.0
# Etheta, Ephi = calculate_farfield(
# point_antenna.export_all_points(),
# point_antenna.export_all_structures(),
# point_antenna.excitation_function(desired_e_vector=desired_E_axis),
# az_range=np.linspace(-180, 180, az_res),
# el_range=np.linspace(-90, 90, elev_res),
# wavelength=wavelength,
# farfield_distance=20,
# elements=False,
# project_vectors=False,
# )
# u_pattern.pattern[:, :, 0] = Etheta
# u_pattern.pattern[:, :, 1] = Ephi
# u_pattern.display_pattern(desired_pattern='Power')


# desired_E_axis = np.zeros((1, 3), dtype=np.complex64)
# desired_E_axis[0, 1] = 1.0
# Etheta, Ephi = calculate_farfield(
# point_antenna.export_all_points(),
# point_antenna.export_all_structures(),
# point_antenna.excitation_function(desired_e_vector=desired_E_axis),
# az_range=np.linspace(-180, 180, az_res),
# el_range=np.linspace(-90, 90, elev_res),
# wavelength=wavelength,
# farfield_distance=20,
# elements=False,
# project_vectors=False,
# )
# v_pattern.pattern[:, :, 0] = Etheta
# v_pattern.pattern[:, :, 1] = Ephi
# v_pattern.display_pattern(desired_pattern='Power')


# desired_E_axis = np.zeros((1, 3), dtype=np.complex64)
# desired_E_axis[0, 2] = 1.0
# Etheta, Ephi = calculate_farfield(
# point_antenna.export_all_points(),
# point_antenna.export_all_structures(),
# point_antenna.excitation_function(desired_e_vector=desired_E_axis),
# az_range=np.linspace(-180, 180, az_res),
# el_range=np.linspace(-90, 90, elev_res),
# wavelength=wavelength,
# farfield_distance=20,
# elements=False,
# project_vectors=False,
# )
# n_pattern.pattern[:, :, 0] = Etheta
# n_pattern.pattern[:, :, 1] = Ephi
# n_pattern.display_pattern(desired_pattern='Power')
r=R.from_euler('xyz', np.radians(np.asarray([90.0,0.0,0.0])))
point_antenna.rotate_antenna(r.as_matrix())

desired_E_axis = np.zeros((1, 3), dtype=np.complex64)
desired_E_axis[0, 0] = 1.0
Etheta, Ephi = calculate_farfield(
point_antenna.export_all_points(),
point_antenna.export_all_structures(),
point_antenna.excitation_function(desired_e_vector=desired_E_axis),
az_range=np.linspace(-180, 180, az_res),
el_range=np.linspace(-90, 90, elev_res),
wavelength=wavelength,
farfield_distance=20,
elements=False,
project_vectors=False,
)
u_pattern.pattern[:, :, 0] = Etheta.reshape(elev_res,az_res)
u_pattern.pattern[:, :, 1] = Ephi.reshape(elev_res,az_res)
u_pattern.display_pattern(desired_pattern='Power')


desired_E_axis = np.zeros((1, 3), dtype=np.complex64)
desired_E_axis[0, 1] = 1.0
Etheta, Ephi = calculate_farfield(
point_antenna.export_all_points(),
point_antenna.export_all_structures(),
point_antenna.excitation_function(desired_e_vector=desired_E_axis),
az_range=np.linspace(-180, 180, az_res),
el_range=np.linspace(-90, 90, elev_res),
wavelength=wavelength,
farfield_distance=20,
elements=False,
project_vectors=False,
)
v_pattern.pattern[:, :, 0] = Etheta.reshape(elev_res,az_res)
v_pattern.pattern[:, :, 1] = Ephi.reshape(elev_res,az_res)
v_pattern.display_pattern(desired_pattern='Power')


desired_E_axis = np.zeros((1, 3), dtype=np.complex64)
desired_E_axis[0, 2] = 1.0
Etheta, Ephi = calculate_farfield(
point_antenna.export_all_points(),
point_antenna.export_all_structures(),
point_antenna.excitation_function(desired_e_vector=desired_E_axis),
az_range=np.linspace(-180, 180, az_res),
el_range=np.linspace(-90, 90, elev_res),
wavelength=wavelength,
farfield_distance=20,
elements=False,
project_vectors=False,
)
n_pattern.pattern[:, :, 0] = Etheta.reshape(elev_res,az_res)
n_pattern.pattern[:, :, 1] = Ephi.reshape(elev_res,az_res)
n_pattern.display_pattern(desired_pattern='Power')
Loading

0 comments on commit cf70603

Please sign in to comment.