Skip to content

Commit

Permalink
saving progress preUAV
Browse files Browse the repository at this point in the history
  • Loading branch information
tf17270 committed Apr 26, 2024
1 parent 8c8c73f commit 696fcf7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 117 deletions.
108 changes: 29 additions & 79 deletions docs/examples/04_time_domain_channel_modelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"""

import numpy as np
import open3d as o3d

import meshio
# %%
# Frequency and Mesh Resolution
# ------------------------------
Expand Down Expand Up @@ -57,38 +56,25 @@
#
rotation_vector1 = np.radians(np.asarray([90.0, 0.0, 0.0]))
rotation_vector2 = np.radians(np.asarray([0.0, 0.0, -90.0]))
transmit_horn_structure = GF.open3drotate(
transmit_horn_structure,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1),
)
transmit_horn_structure = GF.open3drotate(
transmit_horn_structure,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector2),
)
transmit_horn_structure.translate(np.asarray([2.695, 0, 0]), relative=True)
transmitting_antenna_surface_coords = GF.open3drotate(
transmitting_antenna_surface_coords,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1),
)
transmitting_antenna_surface_coords = GF.open3drotate(
transmitting_antenna_surface_coords,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector2),
)
transmitting_antenna_surface_coords.translate(np.asarray([2.695, 0, 0]), relative=True)



transmit_horn_structure = GF.mesh_rotate(transmit_horn_structure, rotation_vector1)
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]))
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]))
# %%
# Position Receiver
# ------------------
# rotate the receiving horn to desired orientation and translate to final position.
receive_horn_structure = GF.open3drotate(
receive_horn_structure,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1),
)
receive_horn_structure.translate(np.asarray([0, 1.427, 0]), relative=True)
receiving_antenna_surface_coords = GF.open3drotate(
receiving_antenna_surface_coords,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1),
)
receiving_antenna_surface_coords.translate(np.asarray([0, 1.427, 0]), relative=True)


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

# %%
# Create Scattering Plate
Expand All @@ -100,16 +86,11 @@
)
position_vector = np.asarray([29e-3, 0.0, 0])
rotation_vector1 = np.radians(np.asarray([0.0, 90.0, 0.0]))
scatter_points = GF.open3drotate(
scatter_points,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1),
)
reflectorplate = GF.open3drotate(
reflectorplate,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1),
)
reflectorplate.translate(position_vector, relative=True)
scatter_points.translate(position_vector, relative=True)
scatter_points = GF.mesh_rotate(scatter_points, rotation_vector1)
reflectorplate = GF.mesh_rotate(reflectorplate, rotation_vector1)
reflectorplate = GF.translate_mesh(reflectorplate, position_vector)
scatter_points = GF.translate_mesh(scatter_points, position_vector)


# %%
# Specify Reflection Angle
Expand All @@ -119,15 +100,8 @@
plate_orientation_angle = 45.0

rotation_vector = np.radians(np.asarray([0.0, 0.0, plate_orientation_angle]))
scatter_points = GF.open3drotate(
scatter_points,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector),
)
reflectorplate = GF.open3drotate(
reflectorplate,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector),
)

scatter_points = GF.mesh_rotate(scatter_points, rotation_vector)
reflectorplate = GF.mesh_rotate(reflectorplate, rotation_vector)
from lyceanem.base_classes import structures

blockers = structures([reflectorplate, receive_horn_structure, transmit_horn_structure])
Expand All @@ -138,20 +112,8 @@
# Use open3d function :func:`open3d.visualization.draw_geometries` to visualise the scene and ensure that all the
# relavent sources and scatter points are correct. Point normal vectors can be displayed by pressing 'n' while the
# window is open.
mesh_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(
size=0.5, origin=[0, 0, 0]
)
o3d.visualization.draw_geometries(
[
transmitting_antenna_surface_coords,
receiving_antenna_surface_coords,
scatter_points,
reflectorplate,
mesh_frame,
receive_horn_structure,
transmit_horn_structure,
]
)


# %%
# .. image:: ../_static/03_frequency_domain_channel_model_picture_01.png

Expand Down Expand Up @@ -183,14 +145,8 @@
rotation_vector = np.radians(
np.asarray([0.0, 0.0, plate_orientation_angle + angle_increment])
)
scatter_points = GF.open3drotate(
scatter_points,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector),
)
reflectorplate = GF.open3drotate(
reflectorplate,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector),
)
scatter_points = GF.mesh_rotate(scatter_points, rotation_vector)
reflectorplate = GF.mesh_rotate(reflectorplate, rotation_vector)

from tqdm import tqdm

Expand All @@ -201,14 +157,8 @@

for angle_inc in tqdm(range(len(angle_values))):
rotation_vector = np.radians(np.asarray([0.0, 0.0, angle_increment]))
scatter_points = GF.open3drotate(
scatter_points,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector),
)
reflectorplate = GF.open3drotate(
reflectorplate,
o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector),
)
scatter_points = GF.mesh_rotate(scatter_points, rotation_vector)
reflectorplate = GF.mesh_rotate(reflectorplate, rotation_vector)
blockers = structures(
[reflectorplate, transmit_horn_structure, receive_horn_structure]
)
Expand Down
10 changes: 0 additions & 10 deletions docs/examples/05_array_beamforming.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"""
import numpy as np
import open3d as o3d

# %%
# Setting Farfield Resolution and Wavelength
Expand All @@ -38,16 +37,7 @@

body, array, source_coords = data.exampleUAV(10e9)

# %%
# Visualise the Resultant UAV and Array
# ---------------------------------------
# :func:`open3d.visualization.draw_geometries` can be used to visualise the open3d data
# structures :class:`open3d.geometry.PointCloud` and :class:`open3d.geometry.PointCloud`

mesh_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(
size=0.5, origin=[0, 0, 0]
)
o3d.visualization.draw_geometries([body, array, source_coords, mesh_frame])

# %%
# .. image:: ../_static/UAVArraywithPoints.png
Expand Down
2 changes: 1 addition & 1 deletion lyceanem/electromagnetics/beamforming.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ def MaximumfieldMapDiscrete(


@njit(cache=True, nogil=True)
def directivity_transformv2(
def directivity_transform(
Etheta,
Ephi,
az_range=np.linspace(-180.0, 180.0, 19),
Expand Down
54 changes: 27 additions & 27 deletions lyceanem/models/time_domain.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import copy

import numpy as np
import open3d as o3d
import scipy.constants
import meshio

from ..base_types import scattering_t
from ..electromagnetics import empropagation as EM
Expand Down Expand Up @@ -79,10 +79,10 @@ def calculate_scattering(
if not multiE:
if project_vectors:
conformal_E_vectors = EM.calculate_conformalVectors(
desired_E_axis, np.asarray(aperture_coords.normals), antenna_axes
desired_E_axis, np.asarray(aperture_coords.point_data["normals"]), antenna_axes
)
else:
if desired_E_axis.shape[0] == np.asarray(aperture_coords.normals).shape[0]:
if desired_E_axis.shape[0] == np.asarray(aperture_coords.point_data["normals"]).shape[0]:
conformal_E_vectors = copy.deepcopy(desired_E_axis)
else:
conformal_E_vectors = np.repeat(
Expand All @@ -91,7 +91,7 @@ def calculate_scattering(
else:
if project_vectors:
conformal_E_vectors = EM.calculate_conformalVectors(
desired_E_axis, np.asarray(aperture_coords.normals), antenna_axes
desired_E_axis, np.asarray(aperture_coords.point_data["normals"]), antenna_axes
)
else:
if desired_E_axis.size == 3:
Expand All @@ -103,16 +103,16 @@ def calculate_scattering(

if scattering == 0:
# only use the aperture point cloud, no scattering required.
scatter_points = o3d.geometry.PointCloud()
scatter_points = meshio.Mesh(points = np.empty((0,3), dtype=np.float32), cells=[])

unified_model = np.append(
np.asarray(aperture_coords.points).astype(np.float32),
np.asarray(sink_coords.points).astype(np.float32),
axis=0,
)
unified_normals = np.append(
np.asarray(aperture_coords.normals).astype(np.float32),
np.asarray(sink_coords.normals).astype(np.float32),
np.asarray(aperture_coords.point_data["normals"]).astype(np.float32),
np.asarray(sink_coords.point_data["normals"]).astype(np.float32),
axis=0,
)
unified_weights = np.ones((unified_model.shape[0], 3), dtype=np.complex64)
Expand All @@ -138,13 +138,13 @@ def calculate_scattering(
aperture_coords.points
).astype(np.float32)[:, 2]
point_informationv2[0:num_sources]["nx"] = np.asarray(
aperture_coords.normals
aperture_coords.point_data["normals"]
).astype(np.float32)[:, 0]
point_informationv2[0:num_sources]["ny"] = np.asarray(
aperture_coords.normals
aperture_coords.point_data["normals"]
).astype(np.float32)[:, 1]
point_informationv2[0:num_sources]["nz"] = np.asarray(
aperture_coords.normals
aperture_coords.point_data["normals"]
).astype(np.float32)[:, 2]
# set position and velocity of sinks
point_informationv2[num_sources : (num_sources + num_sinks)]["px"] = np.asarray(
Expand All @@ -157,13 +157,13 @@ def calculate_scattering(
sink_coords.points
).astype(np.float32)[:, 2]
point_informationv2[num_sources : (num_sources + num_sinks)]["nx"] = np.asarray(
sink_coords.normals
sink_coords.point_data["normals"]
).astype(np.float32)[:, 0]
point_informationv2[num_sources : (num_sources + num_sinks)]["ny"] = np.asarray(
sink_coords.normals
sink_coords.point_data["normals"]
).astype(np.float32)[:, 1]
point_informationv2[num_sources : (num_sources + num_sinks)]["nz"] = np.asarray(
sink_coords.normals
sink_coords.point_data["normals"]
).astype(np.float32)[:, 2]

point_informationv2[:]["ex"] = unified_weights[:, 0]
Expand Down Expand Up @@ -191,11 +191,11 @@ def calculate_scattering(
)
unified_normals = np.append(
np.append(
np.asarray(aperture_coords.normals).astype(np.float32),
np.asarray(sink_coords.normals).astype(np.float32),
np.asarray(aperture_coords.point_data["normals"]).astype(np.float32),
np.asarray(sink_coords.point_data["normals"]).astype(np.float32),
axis=0,
),
np.asarray(scatter_points.normals).astype(np.float32),
np.asarray(scatter_points.point_data["normals"]).astype(np.float32),
axis=0,
)
unified_weights = np.ones((unified_model.shape[0], 3), dtype=np.complex64)
Expand Down Expand Up @@ -224,13 +224,13 @@ def calculate_scattering(
aperture_coords.points
).astype(np.float32)[:, 2]
point_informationv2[0:num_sources]["nx"] = np.asarray(
aperture_coords.normals
aperture_coords.point_data["normals"]
).astype(np.float32)[:, 0]
point_informationv2[0:num_sources]["ny"] = np.asarray(
aperture_coords.normals
aperture_coords.point_data["normals"]
).astype(np.float32)[:, 1]
point_informationv2[0:num_sources]["nz"] = np.asarray(
aperture_coords.normals
aperture_coords.point_data["normals"]
).astype(np.float32)[:, 2]
# point_informationv2[0:num_sources]['ex']=unified_weights[0:num_sources,0]
# point_informationv2[0:num_sources]['ey']=unified_weights[0:num_sources,1]
Expand All @@ -249,13 +249,13 @@ def calculate_scattering(
# point_informationv2[num_sources:(num_sources+num_sinks)]['vy']=0.0
# point_informationv2[num_sources:(num_sources+num_sinks)]['vz']=0.0
point_informationv2[num_sources : (num_sources + num_sinks)]["nx"] = np.asarray(
sink_coords.normals
sink_coords.point_data["normals"]
).astype(np.float32)[:, 0]
point_informationv2[num_sources : (num_sources + num_sinks)]["ny"] = np.asarray(
sink_coords.normals
sink_coords.point_data["normals"]
).astype(np.float32)[:, 1]
point_informationv2[num_sources : (num_sources + num_sinks)]["nz"] = np.asarray(
sink_coords.normals
sink_coords.point_data["normals"]
).astype(np.float32)[:, 2]
point_informationv2[(num_sources + num_sinks) :]["px"] = np.asarray(
scatter_points.points
Expand All @@ -267,13 +267,13 @@ def calculate_scattering(
scatter_points.points
).astype(np.float32)[:, 2]
point_informationv2[(num_sources + num_sinks) :]["nx"] = np.asarray(
scatter_points.normals
scatter_points.point_data["normals"]
).astype(np.float32)[:, 0]
point_informationv2[(num_sources + num_sinks) :]["ny"] = np.asarray(
scatter_points.normals
scatter_points.point_data["normals"]
).astype(np.float32)[:, 1]
point_informationv2[(num_sources + num_sinks) :]["nz"] = np.asarray(
scatter_points.normals
scatter_points.point_data["normals"]
).astype(np.float32)[:, 2]
point_informationv2[:]["ex"] = unified_weights[:, 0]
point_informationv2[:]["ey"] = unified_weights[:, 1]
Expand Down Expand Up @@ -305,7 +305,7 @@ def calculate_scattering(
for e_inc in range(desired_E_axis.shape[0]):
conformal_E_vectors = EM.calculate_conformalVectors(
desired_E_axis[e_inc, :],
np.asarray(aperture_coords.normals).astype(np.float32),
np.asarray(aperture_coords.point_data["normals"]).astype(np.float32),
)
unified_weights[0:num_sources, :] = conformal_E_vectors #/ num_sources
point_informationv2[:]["ex"] = unified_weights[:, 0]
Expand Down Expand Up @@ -399,7 +399,7 @@ def calculate_scattering(
for e_inc in range(desired_E_axis.shape[1]):
conformal_E_vectors = EM.calculate_conformalVectors(
desired_E_axis[e_inc, :],
np.asarray(aperture_coords.normals).astype(np.float32),antenna_axes
np.asarray(aperture_coords.point_data["normals"]).astype(np.float32),antenna_axes
)
for element in range(num_sources):
point_informationv2[0:num_sources]["ex"] = 0.0
Expand Down

0 comments on commit 696fcf7

Please sign in to comment.