.. 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-47 .. code-block:: default 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 # 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 desktop_version = "2023.2" if desktop_version <= "2023.1": print("Warning: this example requires AEDT 2023.2 or later.") sys.exit() .. GENERATED FROM PYTHON SOURCE LINES 48-52 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 52-75 .. code-block:: default non_graphical = False new_thread = True desktop = pyaedt.launch_desktop(desktop_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 Initializing new desktop! Returning found desktop with PID 17372! .. GENERATED FROM PYTHON SOURCE LINES 76-81 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 occured. .. GENERATED FROM PYTHON SOURCE LINES 81-86 .. code-block:: default power_matrix=[] all_colors=[] all_colors, power_matrix = rev.interference_type_classification(domain, use_filter = False, filter_list = []) .. GENERATED FROM PYTHON SOURCE LINES 87-92 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 92-96 .. code-block:: default emitapp.save_project() emitapp.release_desktop() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 97-103 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 103-148 .. code-block:: default 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 149-153 Generate a legend ~~~~~~~~~~~~~~~~~ Define the interference types and colors used to display the results of the analysis. .. GENERATED FROM PYTHON SOURCE LINES 153-191 .. code-block:: default 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:** (1 minutes 45.576 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-python :download:`Download Python source code: ComputeInterferenceType.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ComputeInterferenceType.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_