Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Identify coupling 5649 #5659

Merged
merged 35 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f89a5bf
Create function get_coupling_in_range() in class TouchstoneData from …
amichel0205 Jan 13, 2025
35ed10a
Create function get_coupling_in_range() in class TouchstoneData from …
amichel0205 Jan 14, 2025
6d3d39e
Merge branch 'main' into identify_coupling_5649
amichel0205 Jan 14, 2025
6599d0e
Create function get_coupling_in_range() in class TouchstoneData from …
amichel0205 Jan 15, 2025
4a09c8b
Merge branch 'main' into identify_coupling_5649
amichel0205 Jan 15, 2025
a186ce9
Adding test for function test_get_coupling_in_range() from touchstone…
amichel0205 Jan 15, 2025
4537286
CHORE: Auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 15, 2025
e491b62
Merge remote-tracking branch 'origin/identify_coupling_5649' into ide…
amichel0205 Jan 15, 2025
f790874
Merge branch 'main' into identify_coupling_5649
amichel0205 Jan 27, 2025
b07b205
merge master, update syntax
amichel0205 Jan 27, 2025
73cffd2
Update start frequency in test to 0.1Ghz
amichel0205 Jan 27, 2025
b942c8e
Merge branch 'main' into identify_coupling_5649
amichel0205 Jan 27, 2025
3b4a487
Fix test, fix codacy
amichel0205 Jan 27, 2025
f20cc25
CHORE: Auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 27, 2025
ac1d121
Merge branch 'main' into identify_coupling_5649
amichel0205 Jan 31, 2025
bbb85cc
Merge branch 'main' into identify_coupling_5649
amichel0205 Jan 31, 2025
c9ab672
Change parameter name remove plot from function
amichel0205 Jan 31, 2025
c59e834
CHORE: Auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2025
0cfe967
Modify test to achieve 100% check on test_get_coupling_in_range
amichel0205 Jan 31, 2025
ed9fb4a
Merge remote-tracking branch 'origin/identify_coupling_5649' into ide…
amichel0205 Jan 31, 2025
3530bf9
CHORE: Auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2025
17c3e46
Merge branch 'main' into identify_coupling_5649
amichel0205 Jan 31, 2025
5a9fc39
Modify test to achieve 100% check on test_get_coupling_in_range
amichel0205 Jan 31, 2025
8c8f604
CHORE: Auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2025
6725708
Change docstring
Samuelopez-ansys Feb 3, 2025
82841fe
Merge branch 'main' into identify_coupling_5649
Samuelopez-ansys Feb 3, 2025
ccddc16
Merge branch 'main' into identify_coupling_5649
amichel0205 Feb 4, 2025
c6033c4
Update src/ansys/aedt/core/visualization/advanced/touchstone_parser.py
amichel0205 Feb 4, 2025
850f53d
Update src/ansys/aedt/core/visualization/advanced/touchstone_parser.py
amichel0205 Feb 4, 2025
383b76a
Update src/ansys/aedt/core/visualization/advanced/touchstone_parser.py
amichel0205 Feb 4, 2025
52da98c
Modify test to achieve 100% check on test_get_coupling_in_range
amichel0205 Feb 4, 2025
58c6668
Modify test to achieve 100% check on test_get_coupling_in_range
amichel0205 Feb 4, 2025
3785fbb
Modify test to achieve 100% check on test_get_coupling_in_range
amichel0205 Feb 4, 2025
52e54e5
Apply suggestions from code review
Samuelopez-ansys Feb 4, 2025
6410a3d
Merge branch 'main' into identify_coupling_5649
Samuelopez-ansys Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 85 additions & 16 deletions src/ansys/aedt/core/visualization/advanced/touchstone_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from ansys.aedt.core.aedt_logger import pyaedt_logger as logger
from ansys.aedt.core.generic.aedt_versions import aedt_versions
from ansys.aedt.core.generic.general_methods import open_file
from ansys.aedt.core.generic.general_methods import pyaedt_function_handler

try:
Expand Down Expand Up @@ -111,6 +112,73 @@
rf.Network.__init__(self, touchstone_file)
self.log_x = True

@pyaedt_function_handler()
def get_coupling_in_range(
self, start_frequency=1e9, low_loss=-40, high_loss=-60, frequency_sample=5, output_file=None
):
"""Get coupling losses, excluding return loss, that has at least one frequency point between a range of
losses.

Parameters
----------
start_frequency : float, optional
Specify frequency value below which not check will be done. The default is ``1e9``.
low_loss: float, optional
Specify range lower loss. The default is ``-40``.
high_loss: float, optional
Specify range higher loss. The default is ``-60``.
frequency_sample : integer, optional
Specify frequency sample at which coupling check will be done. The default is ``5``.
output_file : path, optional
Output file path to save where identified coupling will be listed. The default is ``None``.

Returns
-------
list
List of S parameters in the range [high_loss, low_loss] to plot.

"""

nb_freq = self.frequency.npoints
k = 0
k_start = 0

# identify frequency index at which to start the check
while k < nb_freq:
if self.frequency.f[k] >= start_frequency:
k_start = k
break
else:
k = k + 1

port_names = self.port_names
nb_port = len(port_names)
s_db = self.s_db[:, :, :]
temp_list = []
temp_file = []

for i in range(nb_port):
for j in range(i, nb_port):
if i == j:
continue
for k in range(k_start, nb_freq, frequency_sample):
loss = s_db[k, i, j]
if high_loss < loss < low_loss:
temp_list.append((i, j))
sxy = f"S({self.port_names[i]} , {self.port_names[j]})"
line = f"{sxy} Loss = {loss:.2f} dB Freq = {(self.f[k] * 1e-9):.3f} GHz\n"
temp_file.append(line)
break
if output_file is not None:
if os.path.exists(output_file):
logger.info("File " + output_file + " exist and we be replace by new one.")
with open_file(output_file, "w") as f:
for s in temp_file:
f.write(s)
logger.info("File " + output_file + " created.")

Check warning on line 178 in src/ansys/aedt/core/visualization/advanced/touchstone_parser.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/advanced/touchstone_parser.py#L174-L178

Added lines #L174 - L178 were not covered by tests

return temp_list

@pyaedt_function_handler()
def get_insertion_loss_index(self, threshold=-3):
"""Get all insertion losses.
Expand All @@ -120,12 +188,12 @@
Parameters
----------
threshold : float, int, optional
Threshold to determine shorted ports in dB. Default value is ``3``.
Threshold to determine shorted ports in dB. The default is ``-3``.
amichel0205 marked this conversation as resolved.
Show resolved Hide resolved
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
list
List of index couples representing Insertion Losses of excitations.
List of index couples representing insertion losses of excitations.

"""
temp_list = []
Expand All @@ -149,7 +217,7 @@
Parameters
----------
threshold : float, int, optional
Threshold to determine shorted ports in dB. Default value is ``3``.
Threshold to determine shorted ports in dB. The default value is ``-3``.
plot : bool, optional
Whether to plot. The default is ``True``.

Expand All @@ -171,9 +239,9 @@
Parameters
----------
index_couples : list, optional
List of indexes couple to plot. Default is ``None`` to plot all ``port_tuples``.
List of indexes couple to plot. The default is ``None`` to plot all ``port_tuples``.
amichel0205 marked this conversation as resolved.
Show resolved Hide resolved
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved
show : bool
Whether to plot. Default is ``True``.
Whether to plot. The default value is ``True``.

Returns
-------
Expand Down Expand Up @@ -250,7 +318,7 @@

@pyaedt_function_handler()
def get_return_loss_index(self, excitation_name_prefix=""):
"""Get the list of all the Returnloss from a list of excitations.
"""Get the list of all the return loss from a list of excitations.

If no excitation is provided it will provide a full list of return losses.

Expand All @@ -260,7 +328,7 @@
Parameters
----------
excitation_name_prefix :str, optional
Prefix of the excitation. Default value is ``""``.
Prefix of the excitation. The default value is ``""``.

Returns
-------
Expand All @@ -279,7 +347,7 @@

@pyaedt_function_handler()
def get_insertion_loss_index_from_prefix(self, tx_prefix, rx_prefix):
"""Get the list of all the Insertion Losses from prefix.
"""Get the list of all the insertion losses from prefix.

Parameters
----------
Expand Down Expand Up @@ -314,7 +382,7 @@
Parameters
----------
tx_prefix :str, optional
Prefix for TX (eg. "DIE"). Default value is ``""``.
Prefix for TX (eg. "DIE"). The default value is ``""``.

Returns
-------
Expand Down Expand Up @@ -347,7 +415,7 @@
rx_prefix : str
prefix for RX (eg. "BGA")
skip_same_index_couples : bool
Boolean ignore TX and RX couple with same index. The default value is ``True``.
Boolean ignore TX and RX couple with same index. The default is ``True``.
amichel0205 marked this conversation as resolved.
Show resolved Hide resolved
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
Expand All @@ -369,7 +437,7 @@
Parameters
----------
tx_prefix: str, optional
Prefix for TX. Default value is ``""``.
Prefix for TX. The default is ``""``.
amichel0205 marked this conversation as resolved.
Show resolved Hide resolved
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
Expand Down Expand Up @@ -415,15 +483,16 @@
Parameters
----------
freq_min : float, optional
Minimum frequency to analyze in GHz (None to 0). Default value is ``None``.
Minimum frequency to analyze in GHz (None to 0). The default is ``None``.
amichel0205 marked this conversation as resolved.
Show resolved Hide resolved
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved
freq_max : float, optional
Maximum frequency to analyze in GHz (None to max freq). Default value is ``None``.
Maximum frequency to analyze in GHz (None to max freq). The default value is ``None``.
worst_is_higher : bool
Worst curve is the one with higher mean value. Default value is ``True``.
Worst curve is the one with higher mean value. The default value is ``True``.
curve_list : list
List of [m,n] index of curves on which to search. None to search on all curves. Default value is ``None``.
List of [m,n] index of curves on which to search. None to search on all curves.
The default value is ``None``.
plot : bool, optional
Whether to plot or not the chart.
Whether to plot or not the chart. The default is ``True``.
amichel0205 marked this conversation as resolved.
Show resolved Hide resolved
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
Expand Down
10 changes: 10 additions & 0 deletions tests/system/general/example_models/T44/_causality.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
8 8
0 -1 0 0.126414 0 0 0 0
-1 0 0.126414 0 0 0 0 0
0 0.126414 0 -1 0 0 0 0
0.126414 0 -1 0 0 0 0 0
0 0 0 0 0 -1 0 0.126414
0 0 0 0 -1 0 0.126414 0
0 0 0 0 0 0.126414 0 -1
0 0 0 0 0.126414 0 -1 0

17 changes: 17 additions & 0 deletions tests/system/general/example_models/T44/_fwslog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
genequiv:progress 0:
genequiv:message Reading input data:
genequiv:message Checking passivity.
genequiv:message Input data is passive for all frequencies.
genequiv:message Checking causality. Reconstruction error tolerance: 0.01
genequiv:progress 5:
genequiv:message Fastfit does not support fit by entry!:
genequiv:progress 5:
genequiv:message Switching to rational fit! :
genequiv:progress 5:
genequiv:message starting:
genequiv:progress 95:
genequiv:message ending:
genequiv:message Causality check is inconclusive: Please add more frequency samples.

genequiv:progress 100:
genequiv:message Exiting with return code 0:
10 changes: 10 additions & 0 deletions tests/system/general/test_44_TouchstoneParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ def test_03_check_touchstone_file(self):
elif v and v[0] == "causality":
assert not v[1]

def test_get_coupling_in_range(self, local_scratch):
touchstone_file = os.path.join(test_T44_dir, "port_order_1234.s8p")
output_file = os.path.join(self.local_scratch.path, "test_44_gcir.log")
ts = TouchstoneData(touchstone_file=touchstone_file)
res = ts.get_coupling_in_range(
start_frequency=1e9, high_loss=-60, low_loss=-40, frequency_sample=5, output_file=output_file
)

assert isinstance(res, list)


def test_get_mixed_mode_touchstone_data_failure(touchstone_file, caplog: pytest.LogCaptureFixture):
ts = TouchstoneData(touchstone_file=touchstone_file)
Expand Down
Loading