diff --git a/examples/07-EMIT/ComputeInterferenceType.py b/examples/07-EMIT/ComputeInterferenceType.py index 746f0fade..e74250bb1 100644 --- a/examples/07-EMIT/ComputeInterferenceType.py +++ b/examples/07-EMIT/ComputeInterferenceType.py @@ -6,9 +6,9 @@ # # Keywords: **EMIT**, **Interference**. -# + # Perform required imports +# + import os import subprocess import sys @@ -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 # @@ -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() @@ -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 # @@ -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 # @@ -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", @@ -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 @@ -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() diff --git a/examples/07-EMIT/ComputeProtectionLevels.py b/examples/07-EMIT/ComputeProtectionLevels.py index 5545fcafe..fe544f616 100644 --- a/examples/07-EMIT/ComputeProtectionLevels.py +++ b/examples/07-EMIT/ComputeProtectionLevels.py @@ -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 # @@ -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 # @@ -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 @@ -97,7 +91,12 @@ 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 @@ -105,9 +104,12 @@ def install(package): # 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 # @@ -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. @@ -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: @@ -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"], @@ -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, ) @@ -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, ) @@ -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() diff --git a/examples/07-EMIT/EMIT_Example.py b/examples/07-EMIT/EMIT_Example.py index 5ce0aab41..09f25edad 100644 --- a/examples/07-EMIT/EMIT_Example.py +++ b/examples/07-EMIT/EMIT_Example.py @@ -17,6 +17,7 @@ import pyaedt from pyaedt.emit_core.emit_constants import ResultType, TxRxMode + # - # Set constant values diff --git a/examples/07-EMIT/EMIT_HFSS_Example.py b/examples/07-EMIT/EMIT_HFSS_Example.py index 5f28b1156..b5169c5d1 100644 --- a/examples/07-EMIT/EMIT_HFSS_Example.py +++ b/examples/07-EMIT/EMIT_HFSS_Example.py @@ -21,6 +21,7 @@ import pyaedt from pyaedt.emit_core.emit_constants import ResultType, TxRxMode + # - # Set constant values @@ -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. @@ -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 #