.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\07-EMIT\ComputeInterferenceType.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_07-EMIT_ComputeInterferenceType.py: EMIT: Classify interference type -------------------------------- This example shows how you can use PyAEDT to load an existing AEDT project with an EMIT design and analyze the results to classify the worst-case interference. .. GENERATED FROM PYTHON SOURCE LINES 9-12 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports. .. GENERATED FROM PYTHON SOURCE LINES 12-20 .. code-block:: Python import sys from pyaedt.emit_core.emit_constants import InterfererType, ResultType, TxRxMode from pyaedt import Emit import pyaedt import os import pyaedt.generic.constants as consts import subprocess .. GENERATED FROM PYTHON SOURCE LINES 21-24 Set AEDT version ~~~~~~~~~~~~~~~~ Set AEDT version. .. GENERATED FROM PYTHON SOURCE LINES 24-55 .. code-block:: Python aedt_version = "2024.1" # Check to see which Python libraries have been installed reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) installed_packages = [r.decode().split('==')[0] for r in reqs.split()] # Install required packages if they are not installed def install(package): subprocess.check_call([sys.executable, '-m', 'pip', 'install', package]) # Install plotly library (if needed) to display legend and scenario matrix results (internet connection needed) required_packages = ['plotly'] for package in required_packages: if package not in installed_packages: install(package) # Import plotly library import plotly.graph_objects as go # Define colors for tables table_colors = {"green": '#7d73ca', "yellow": '#d359a2', "orange": '#ff6361', "red": '#ffa600', "white": '#ffffff'} header_color = 'grey' # Check for if emit version is compatible if aedt_version <= "2023.1": print("Warning: this example requires AEDT 2023.2 or later.") sys.exit() .. GENERATED FROM PYTHON SOURCE LINES 56-60 Launch AEDT with EMIT ~~~~~~~~~~~~~~~~~~~~~ Launch AEDT with EMIT. The ``Desktop`` class initializes AEDT and starts it on the specified version and in the specified graphical mode. .. GENERATED FROM PYTHON SOURCE LINES 60-81 .. code-block:: Python non_graphical = False new_thread = True desktop = pyaedt.launch_desktop(aedt_version, non_graphical=non_graphical, new_desktop_session=new_thread) path_to_desktop_project = pyaedt.downloads.download_file("emit", "interference.aedtz") emitapp = Emit(non_graphical=False, new_desktop_session=False, projectname=path_to_desktop_project) # Get all the radios in the project # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Get lists of all transmitters and receivers in the project. rev = emitapp.results.analyze() tx_interferer = InterfererType().TRANSMITTERS rx_radios = rev.get_receiver_names() tx_radios = rev.get_interferer_names(tx_interferer) domain = emitapp.results.interaction_domain() if tx_radios is None or rx_radios is None: print("No receivers or transmitters are in the design.") sys.exit() .. rst-class:: sphx-glr-script-out .. code-block:: none C:\actions-runner\_work\_tool\Python\3.10.9\x64\lib\subprocess.py:1072: ResourceWarning: subprocess 4552 is still running _warn("subprocess %s is still running" % self.pid, C:\actions-runner\_work\pyaedt\pyaedt\.venv\lib\site-packages\pyaedt\generic\settings.py:383: ResourceWarning: unclosed file <_io.TextIOWrapper name='D:\\Temp\\pyaedt_ansys.log' mode='a' encoding='cp1252'> self._logger = val .. GENERATED FROM PYTHON SOURCE LINES 82-87 Classify the interference ~~~~~~~~~~~~~~~~~~~~~~~~~ Iterate over all the transmitters and receivers and compute the power at the input to each receiver due to each of the transmitters. Computes which, if any, type of interference occurred. .. GENERATED FROM PYTHON SOURCE LINES 87-92 .. code-block:: Python power_matrix = [] all_colors = [] all_colors, power_matrix = rev.interference_type_classification(domain, use_filter=False, filter_list=[]) .. GENERATED FROM PYTHON SOURCE LINES 93-98 Save project and close AEDT ~~~~~~~~~~~~~~~~~~~~~~~~~~~ After the simulation completes, you can close AEDT or release it using the :func:`pyaedt.Desktop.force_close_desktop` method. All methods provide for saving the project before closing. .. GENERATED FROM PYTHON SOURCE LINES 98-103 .. code-block:: Python emitapp.save_project() emitapp.release_desktop() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 104-110 Create a scenario matrix view ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a scenario matrix view with the transmitters defined across the top 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. .. GENERATED FROM PYTHON SOURCE LINES 110-156 .. code-block:: Python def create_scenario_view(emis, colors, tx_radios, rx_radios): """Create a scenario matrix-like table with the higher received power for each Tx-Rx radio combination. The colors used for the scenario matrix view are based on the interference type.""" all_colors = [] for color in colors: col = [] for cell in color: col.append(table_colors[cell]) all_colors.append(col) fig = go.Figure(data=[go.Table( header=dict( values=['Tx/Rx', '{}'.format(tx_radios[0]), '{}'.format(tx_radios[1])], line_color='darkslategray', fill_color='grey', align=['left', 'center'], font=dict(color='white', size=16) ), cells=dict( values=[ rx_radios, emis[0], emis[1]], line_color='darkslategray', fill_color=['white', all_colors[0], all_colors[1]], align=['left', 'center'], height=25, font=dict( color=['darkslategray', 'black'], size=15) ) )]) fig.update_layout( title=dict( text='Interference Type Classification', font=dict(color='darkslategray', size=20), x=0.5 ), width=600 ) fig.show() .. GENERATED FROM PYTHON SOURCE LINES 157-161 Generate a legend ~~~~~~~~~~~~~~~~~ Define the interference types and colors used to display the results of the analysis. .. GENERATED FROM PYTHON SOURCE LINES 161-202 .. code-block:: Python def create_legend_table(): """Create a table showing the interference types.""" classifications = ['In-band/In-band', 'Out-of-band/In-band', 'In-band/Out-of-band', 'Out-of-band/Out-of-band'] fig = go.Figure(data=[go.Table( header=dict( values=['Interference Type (Source/Victim)'], line_color='darkslategray', fill_color=header_color, align=['center'], font=dict(color='white', size=16) ), cells=dict( values=[classifications], line_color='darkslategray', fill_color=[[table_colors['red'], table_colors['orange'], table_colors['yellow'], table_colors['green']]], align=['center'], height=25, font=dict( color=['darkslategray', 'black'], size=15) ) )]) fig.update_layout( title=dict( text='Interference Type Classification', font=dict(color='darkslategray', size=20), x=0.5 ), width=600 ) fig.show() if os.getenv("PYAEDT_DOC_GENERATION", "False") != "1": # Create a scenario view for all the interference types create_scenario_view(power_matrix, all_colors, tx_radios, rx_radios) # Create a legend for the interference types create_legend_table() .. rst-class:: sphx-glr-timing **Total running time of the script:** (9 minutes 1.441 seconds) .. _sphx_glr_download_examples_07-EMIT_ComputeInterferenceType.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ComputeInterferenceType.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ComputeInterferenceType.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_