Skip to content

Commit

Permalink
DOCS: Update EMIT Examples (#177)
Browse files Browse the repository at this point in the history
Make consistent with template.

Co-authored-by: Sébastien Morais <[email protected]>
  • Loading branch information
Devin-Crawford and SMoraisAnsys authored Aug 4, 2024
1 parent ca408ab commit f20faa0
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 38 deletions.
39 changes: 23 additions & 16 deletions examples/07-EMIT/ComputeInterferenceType.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#
# Keywords: **EMIT**, **Interference**.

# +
# Perform required imports

# +
import os
import subprocess
import sys
Expand All @@ -17,11 +17,13 @@
import pyaedt
from pyaedt import Emit
from pyaedt.emit_core.emit_constants import InterfererType

# -

# Set constant values

AEDT_VERSION = "2024.1"
NG_MODE = False # Open Electronics UI when the application is launched.

# ## Python Dependencies
#
Expand Down Expand Up @@ -56,8 +58,7 @@ def install(package):

# Check that EMIT version 2023.2 or greater is installed.

desktop_version = AEDT_VERSION
if desktop_version <= "2023.1":
if AEDT_VERSION <= "2023.1":
print("Warning: this example requires AEDT 2023.2 or later.")
sys.exit()

Expand All @@ -66,22 +67,18 @@ def install(package):
# Launch AEDT with EMIT. The ``Desktop`` class initializes AEDT and starts it
# on the specified version and in the specified graphical mode.

non_graphical = False
new_thread = True
desktop = pyaedt.launch_desktop(
desktop_version, non_graphical=non_graphical, new_desktop=new_thread)
desktop = pyaedt.launch_desktop(AEDT_VERSION, non_graphical=NG_MODE, new_desktop=True)


# ## Download project
#
# Download project

path_to_desktop_project = pyaedt.downloads.download_file(
"emit", "interference.aedtz", destination=temp_dir.name)
path_to_desktop_project
project_name = pyaedt.downloads.download_file(
"emit", "interference.aedtz", destination=temp_dir.name
)

# ## Launch EMIT and open project

emitapp = Emit(non_graphical=False, new_desktop=False, project=path_to_desktop_project)
emitapp = Emit(non_graphical=NG_MODE, new_desktop=False, project=project_name)

# ## Get a List of Transmitters
#
Expand All @@ -108,7 +105,8 @@ def install(package):
power_matrix = []
all_colors = []
all_colors, power_matrix = rev.interference_type_classification(
domain, use_filter=False, filter_list=[])
domain, use_filter=False, filter_list=[]
)

# ## Release AEDT
#
Expand All @@ -122,9 +120,10 @@ def install(package):
# and receivers down the left-most column. The power at the input to each
# receiver is shown in each cell of the matrix and color-coded based on the
# interference type.

#
# Set up colors to visualize results in a table.

# +
table_colors = {
"green": "#7d73ca",
"yellow": "#d359a2",
Expand Down Expand Up @@ -183,6 +182,9 @@ def create_scenario_view(emis, colors, tx_radios, rx_radios):
fig.show()


# -


# ## Generate a legend
#
# Define the interference types and colors used to display the results of
Expand Down Expand Up @@ -243,6 +245,11 @@ def create_legend_table():
# Create a legend for the interference types
create_legend_table()

# ## Clean temporary directory
# ## Cleanup
#
# All project files are saved in the folder ``temp_dir.name``.
# If you've run this example as a Jupyter notebook you
# can retrieve those project files. The following cell
# removes all temporary files, including the project folder.

temp_dir.cleanup()
52 changes: 34 additions & 18 deletions examples/07-EMIT/ComputeProtectionLevels.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import pyaedt
from pyaedt import Emit
from pyaedt.emit_core.emit_constants import InterfererType

# -

# Set constant values

AEDT_VERSION = "2024.1"
NG_MODE = False # Open Electronics UI when the application is launched.

# ## Python Dependencies
#
Expand All @@ -50,19 +52,11 @@ def install(package):

# Import to support plotting.

# Import required modules
import plotly.graph_objects as go

# ## Set non-graphical mode
#
# Set non-graphical mode.
# You can set ``non_graphical`` either to ``True`` or ``False``.

non_graphical = False

# ## Create temporary directory

temp_dir = tempfile.TemporaryDirectory(suffix="_ansys")
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")

# ## Launch AEDT with EMIT
#
Expand All @@ -75,8 +69,8 @@ def install(package):
print("Warning: this example requires AEDT 2023.2 or later.")
sys.exit()

project_name = pyaedt.generate_unique_project_name(rootname=temp_dir.name, project_name="emit")
d = pyaedt.launch_desktop(AEDT_VERSION, non_graphical, True)
project_name = os.path.join(temp_dir.name, "emit.aedt")
d = pyaedt.launch_desktop(AEDT_VERSION, NG_MODE, True)
emitapp = Emit(project_name)

# ## Specify the protection levels
Expand All @@ -97,17 +91,25 @@ def install(package):
intermod_threshold = -30
desense_threshold = -104

protection_levels = [damage_threshold, overload_threshold, intermod_threshold, desense_threshold]
protection_levels = [
damage_threshold,
overload_threshold,
intermod_threshold,
desense_threshold,
]
# -

# ## Create and connect EMIT components
#
# Set up the scenario with radios connected to antennas.

bluetooth, blue_ant = emitapp.modeler.components.create_radio_antenna(
"Bluetooth Low Energy (LE)", "Bluetooth")
"Bluetooth Low Energy (LE)", "Bluetooth"
)
gps, gps_ant = emitapp.modeler.components.create_radio_antenna("GPS Receiver", "GPS")
wifi, wifi_ant = emitapp.modeler.components.create_radio_antenna("WiFi - 802.11-2012", "WiFi")
wifi, wifi_ant = emitapp.modeler.components.create_radio_antenna(
"WiFi - 802.11-2012", "WiFi"
)

# ## Configure the radios
#
Expand All @@ -127,6 +129,7 @@ def install(package):
for band in bands:
band.set_band_power_level(-20)


def get_radio_node(radio_name):
"""Get the radio node that matches the
given radio name.
Expand All @@ -144,6 +147,7 @@ def get_radio_node(radio_name):
radio = wifi
return radio


bands = gps.bands()
for band in bands:
for child in band.children:
Expand Down Expand Up @@ -184,7 +188,10 @@ def create_legend_table():
font=dict(color="white", size=16),
),
cells=dict(
values=[["Damage", "Overload", "Intermodulation", "Clear"], protectionLevels],
values=[
["Damage", "Overload", "Intermodulation", "Clear"],
protectionLevels,
],
line_color="darkslategray",
fill_color=["white", ["red", "orange", "yellow", "green"]],
align=["left", "center"],
Expand All @@ -195,7 +202,9 @@ def create_legend_table():
)
fig.update_layout(
title=dict(
text="Protection Levels (dBm)", font=dict(color="darkslategray", size=20), x=0.5
text="Protection Levels (dBm)",
font=dict(color="darkslategray", size=20),
x=0.5,
),
width=600,
)
Expand Down Expand Up @@ -241,7 +250,9 @@ def create_scenario_view(emis, colors, tx_radios, rx_radios):
)
fig.update_layout(
title=dict(
text="Protection Levels (dBm)", font=dict(color="darkslategray", size=20), x=0.5
text="Protection Levels (dBm)",
font=dict(color="darkslategray", size=20),
x=0.5,
),
width=600,
)
Expand Down Expand Up @@ -284,6 +295,11 @@ def create_scenario_view(emis, colors, tx_radios, rx_radios):

emitapp.release_desktop()

# ## Clean temporary directory
# ## Cleanup
#
# All project files are saved in the folder ``temp_dir.name``.
# If you've run this example as a Jupyter notebook you
# can retrieve those project files. The following cell
# removes all temporary files, including the project folder.

temp_dir.cleanup()
1 change: 1 addition & 0 deletions examples/07-EMIT/EMIT_Example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import pyaedt
from pyaedt.emit_core.emit_constants import ResultType, TxRxMode

# -

# Set constant values
Expand Down
17 changes: 13 additions & 4 deletions examples/07-EMIT/EMIT_HFSS_Example.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import pyaedt
from pyaedt.emit_core.emit_constants import ResultType, TxRxMode

# -

# Set constant values
Expand Down Expand Up @@ -75,11 +76,15 @@

# Copy the files to the temporary working directory.

project_name = shutil.copyfile(example_project, os.path.join(temp_dir.name, file_name(example)))
project_name = shutil.copyfile(
example_project, os.path.join(temp_dir.name, file_name(example))
)
results_folder = shutil.copytree(
example_results_folder, os.path.join(temp_dir.name, results_name(example))
)
project_pdf = shutil.copyfile(example_pdf, os.path.join(temp_dir.name, pdf_name(example)))
project_pdf = shutil.copyfile(
example_pdf, os.path.join(temp_dir.name, pdf_name(example))
)

# Open the project in the working directory.

Expand All @@ -89,8 +94,12 @@
#
# Create two radios with antennas connected to each one.

rad1, ant1 = aedtapp.modeler.components.create_radio_antenna("Bluetooth Low Energy (LE)")
rad2, ant2 = aedtapp.modeler.components.create_radio_antenna("Bluetooth Low Energy (LE)")
rad1, ant1 = aedtapp.modeler.components.create_radio_antenna(
"Bluetooth Low Energy (LE)"
)
rad2, ant2 = aedtapp.modeler.components.create_radio_antenna(
"Bluetooth Low Energy (LE)"
)

# ## Define coupling among RF systems
#
Expand Down

0 comments on commit f20faa0

Please sign in to comment.