{
"cells": [
{
"cell_type": "markdown",
"id": "fc514890",
"metadata": {},
"source": [
"# Interference type classification\n",
"\n",
"This example shows how to load an existing AEDT EMIT\n",
"design and analyze the results to classify the\n",
"worst-case interference.\n",
"\n",
"Keywords: **EMIT**, **interference**."
]
},
{
"cell_type": "markdown",
"id": "ca63c52f",
"metadata": {},
"source": [
"## Perform imports and define constants"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "468185d7",
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"import tempfile\n",
"\n",
"import ansys.aedt.core\n",
"import plotly.graph_objects as go\n",
"from ansys.aedt.core import Emit\n",
"from ansys.aedt.core.emit_core.emit_constants import InterfererType\n"
]
},
{
"cell_type": "markdown",
"id": "27f9246c",
"metadata": {},
"source": [
"Define constants."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad7f491c",
"metadata": {},
"outputs": [],
"source": [
"AEDT_VERSION = \"2024.2\"\n",
"NG_MODE = False # Open AEDT UI when it is launched."
]
},
{
"cell_type": "markdown",
"id": "27a9f4a1",
"metadata": {},
"source": [
"## Create temporary directory\n",
"\n",
"Create a temporary directory where downloaded data or\n",
"dumped data can be stored.\n",
"If you'd like to retrieve the project data for subsequent use,\n",
"the temporary folder name is given by ``temp_folder.name``."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7f985e31",
"metadata": {},
"outputs": [],
"source": [
"temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")"
]
},
{
"cell_type": "markdown",
"id": "e07655db",
"metadata": {},
"source": [
"Check that EMIT 2023.2 or later is installed."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6d18f1d0",
"metadata": {},
"outputs": [],
"source": [
"if AEDT_VERSION <= \"2023.1\":\n",
" print(\"Warning: This example requires AEDT 2023.2 or later.\")\n",
" sys.exit()"
]
},
{
"cell_type": "markdown",
"id": "f2d6a32c",
"metadata": {},
"source": [
"Download project"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "05e294ec",
"metadata": {},
"outputs": [],
"source": [
"project_name = ansys.aedt.core.downloads.download_file(\n",
" \"emit\", \"interference.aedtz\", destination=temp_folder.name\n",
")"
]
},
{
"cell_type": "markdown",
"id": "1092cc6d",
"metadata": {},
"source": [
"## Launch EMIT and open project"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7bdc67f3",
"metadata": {},
"outputs": [],
"source": [
"emitapp = Emit(\n",
" non_graphical=NG_MODE, new_desktop=True, project=project_name, version=AEDT_VERSION\n",
")"
]
},
{
"cell_type": "markdown",
"id": "f1a79a41",
"metadata": {},
"source": [
"## Get lists of transmitters and receivers\n",
"\n",
"Get lists of all transmitters and receivers in the project."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "26112a2c",
"metadata": {},
"outputs": [],
"source": [
"rev = emitapp.results.analyze()\n",
"tx_interferer = InterfererType().TRANSMITTERS\n",
"rx_radios = rev.get_receiver_names()\n",
"tx_radios = rev.get_interferer_names(tx_interferer)\n",
"domain = emitapp.results.interaction_domain()\n",
"\n",
"if tx_radios is None or rx_radios is None:\n",
" print(\"No receivers or transmitters are in the design.\")\n",
" sys.exit()"
]
},
{
"cell_type": "markdown",
"id": "5ee65366",
"metadata": {},
"source": [
"## Classify the interference\n",
"\n",
"Iterate over all the transmitters and receivers and compute the power\n",
"at the input to each receiver due to each of the transmitters. Compute\n",
"which type of interference occurred, if any."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1bb7913a",
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"power_matrix = []\n",
"all_colors = []"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da469a89",
"metadata": {},
"outputs": [],
"source": [
"all_colors, power_matrix = rev.interference_type_classification(\n",
" domain, use_filter=False, filter_list=[]\n",
")"
]
},
{
"cell_type": "markdown",
"id": "1ebcfe23",
"metadata": {},
"source": [
"## Release AEDT\n",
"\n",
"Release AEDT and close the example."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "932ed753",
"metadata": {},
"outputs": [],
"source": [
"emitapp.release_desktop()"
]
},
{
"cell_type": "markdown",
"id": "3aba2b23",
"metadata": {},
"source": [
"## Create a scenario matrix view\n",
"\n",
"Create a scenario matrix view with the transmitters defined across the top\n",
"and receivers down the left-most column. The power at the input to each\n",
"receiver is shown in each cell of the matrix and color-coded based on the\n",
"interference type.\n",
"\n",
"Set up colors to visualize results in a table."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bdada140",
"metadata": {
"lines_to_end_of_cell_marker": 2,
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"table_colors = {\n",
" \"green\": \"#7d73ca\",\n",
" \"yellow\": \"#d359a2\",\n",
" \"orange\": \"#ff6361\",\n",
" \"red\": \"#ffa600\",\n",
" \"white\": \"#ffffff\",\n",
"}\n",
"header_color = \"grey\"\n",
"\n",
"\n",
"def create_scenario_view(emis, colors, tx_radios, rx_radios):\n",
" \"\"\"Create a scenario matrix-like table with the higher received\n",
" power for each Tx-Rx radio combination. The colors\n",
" used for the scenario matrix view are based on the interference type.\"\"\"\n",
"\n",
" all_colors = []\n",
" for color in colors:\n",
" col = []\n",
" for cell in color:\n",
" col.append(table_colors[cell])\n",
" all_colors.append(col)\n",
"\n",
" fig = go.Figure(\n",
" data=[\n",
" go.Table(\n",
" header=dict(\n",
" values=[\n",
" \"Tx/Rx\",\n",
" \"{}\".format(tx_radios[0]),\n",
" \"{}\".format(tx_radios[1]),\n",
" ],\n",
" line_color=\"darkslategray\",\n",
" fill_color=\"grey\",\n",
" align=[\"left\", \"center\"],\n",
" font=dict(color=\"white\", size=16),\n",
" ),\n",
" cells=dict(\n",
" values=[rx_radios, emis[0], emis[1]],\n",
" line_color=\"darkslategray\",\n",
" fill_color=[\"white\", all_colors[0], all_colors[1]],\n",
" align=[\"left\", \"center\"],\n",
" height=25,\n",
" font=dict(color=[\"darkslategray\", \"black\"], size=15),\n",
" ),\n",
" )\n",
" ]\n",
" )\n",
" fig.update_layout(\n",
" title=dict(\n",
" text=\"Interference Type Classification\",\n",
" font=dict(color=\"darkslategray\", size=20),\n",
" x=0.5,\n",
" ),\n",
" width=600,\n",
" )\n",
" fig.show()"
]
},
{
"cell_type": "markdown",
"id": "06292eb8",
"metadata": {
"lines_to_next_cell": 2
},
"source": [
"## Create a legend\n",
"\n",
"Create a legend, defining the interference types and colors used to display the results of\n",
"the analysis."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "393b5151",
"metadata": {},
"outputs": [],
"source": [
"def create_legend_table():\n",
" \"\"\"Create a table showing the interference types.\"\"\"\n",
" classifications = [\n",
" \"In-band/In-band\",\n",
" \"Out-of-band/In-band\",\n",
" \"In-band/Out-of-band\",\n",
" \"Out-of-band/Out-of-band\",\n",
" ]\n",
" fig = go.Figure(\n",
" data=[\n",
" go.Table(\n",
" header=dict(\n",
" values=[\"Interference Type (Source/Victim)\"],\n",
" line_color=\"darkslategray\",\n",
" fill_color=header_color,\n",
" align=[\"center\"],\n",
" font=dict(color=\"white\", size=16),\n",
" ),\n",
" cells=dict(\n",
" values=[classifications],\n",
" line_color=\"darkslategray\",\n",
" fill_color=[\n",
" [\n",
" table_colors[\"red\"],\n",
" table_colors[\"orange\"],\n",
" table_colors[\"yellow\"],\n",
" table_colors[\"green\"],\n",
" ]\n",
" ],\n",
" align=[\"center\"],\n",
" height=25,\n",
" font=dict(color=[\"darkslategray\", \"black\"], size=15),\n",
" ),\n",
" )\n",
" ]\n",
" )\n",
" fig.update_layout(\n",
" title=dict(\n",
" text=\"Interference Type Classification\",\n",
" font=dict(color=\"darkslategray\", size=20),\n",
" x=0.5,\n",
" ),\n",
" width=600,\n",
" )\n",
" fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b1b1b396",
"metadata": {},
"outputs": [],
"source": [
"# Create a scenario view for all the interference types\n",
"create_scenario_view(power_matrix, all_colors, tx_radios, rx_radios)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf04a8c0",
"metadata": {},
"outputs": [],
"source": [
"# Create a legend for the interference types\n",
"create_legend_table()"
]
},
{
"cell_type": "markdown",
"id": "8e8f5784",
"metadata": {},
"source": [
"## Clean up\n",
"\n",
"All project files are saved in the folder ``temp_folder.name``.\n",
"If you've run this example as a Jupyter notebook, you\n",
"can retrieve those project files. The following cell\n",
"removes all temporary files, including the project folder."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4afee25f",
"metadata": {},
"outputs": [],
"source": [
"temp_folder.cleanup()"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
},
"nbsphinx": {
"execute": "never"
}
},
"nbformat": 4,
"nbformat_minor": 5
}