Skip to content

import, delete, add and update traces for report #1227

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

Merged
merged 11 commits into from
Jun 1, 2022
Merged
111 changes: 89 additions & 22 deletions _unittest/test_12_PostProcessing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# standard imports
import os
import uuid

from _unittest.conftest import BasisTest
from _unittest.conftest import config
Expand Down Expand Up @@ -110,9 +111,9 @@ def test_02_export_fields(self):
plot2 = self.aedtapp.post.create_fieldplot_volume(vollist, quantity_name2, setup_name, intrinsic)

self.aedtapp.post.export_field_image_with_view(
plot2.name, plot2.plotFolder, os.path.join(self.local_scratch.path, "prova2.png")
plot2.name, plot2.plotFolder, os.path.join(self.local_scratch.path, "prova2.jpg")
)
assert os.path.exists(os.path.join(self.local_scratch.path, "prova2.png"))
assert os.path.exists(os.path.join(self.local_scratch.path, "prova2.jpg"))
assert os.path.exists(
plot2.export_image(os.path.join(self.local_scratch.path, "test_x.jpg"), orientation="top")
)
Expand Down Expand Up @@ -177,6 +178,10 @@ def test_06_export_report_to_csv(self):
self.aedtapp.post.export_report_to_csv(self.local_scratch.path, "MyTestScattering")
assert os.path.exists(os.path.join(self.local_scratch.path, "MyTestScattering.csv"))

def test_06_export_report_to_rdat(self):
self.aedtapp.post.export_report_to_file(self.local_scratch.path, "MyTestScattering", ".rdat")
assert os.path.exists(os.path.join(self.local_scratch.path, "MyTestScattering.rdat"))

def test_07_export_fields_from_Calculator(self):

self.aedtapp.post.export_field_file_on_grid(
Expand Down Expand Up @@ -227,7 +232,7 @@ def test_08_manipulate_report(self):
assert self.aedtapp.post.rename_report("MyTestScattering", "MyNewScattering")

def test_09_manipulate_report(self):
assert self.aedtapp.post.create_report("dB(S(1,1))", variations={"Freq": ["2.5GHz", "2.6GHz"]})
assert self.aedtapp.post.create_report("dB(S(1,1))")
assert self.aedtapp.post.create_report(
expressions="MaxMagDeltaS",
variations={"Pass": ["All"]},
Expand Down Expand Up @@ -317,10 +322,77 @@ def test_09b_export_report(self): # pragma: no cover
files = self.aedtapp.export_results()
assert len(files) > 0

def test_09c_import_into_report(self):
new_report = self.aedtapp.create_scattering("import_test")
csv_file_path = self.aedtapp.post.export_report_to_csv(self.local_scratch.path, "import_test")
rdat_file_path = self.aedtapp.post.export_report_to_file(self.local_scratch.path, "import_test", ".rdat")
plot_name = new_report.plot_name

trace_names = []
trace_names.append(new_report.expressions[0])
families = {"Freq": ["All"]}
for el in self.aedtapp.available_variations.nominal_w_values_dict:
families[el] = self.aedtapp.available_variations.nominal_w_values_dict[el]

# get solution data and save in .csv file
my_data = self.aedtapp.post.get_report_data(expression=trace_names, families_dict=families)
my_data.export_data_to_csv(os.path.join(self.local_scratch.path, "output.csv"))
csv_solution_data_file_path = os.path.join(self.local_scratch.path, "output.csv")
assert not new_report.import_traces(csv_solution_data_file_path, plot_name)

# test import with correct inputs from csv
assert new_report.import_traces(csv_file_path, plot_name)
# test import with correct inputs from rdat
assert new_report.import_traces(rdat_file_path, plot_name)
# test import with not existing plot_name
if not is_ironpython:
with pytest.raises(ValueError):
new_report.import_traces(csv_file_path, "plot_name")
# test import with random file path
with pytest.raises(FileExistsError):
new_report.import_traces(str(uuid.uuid4()), plot_name)
# test import without plot_name
with pytest.raises(ValueError):
new_report.import_traces(csv_file_path, None)

def test_09d_delete_traces_from_report(self):
new_report = self.aedtapp.create_scattering("delete_traces_test")
traces_to_delete = []
traces_to_delete.append(new_report.expressions[0])
plot_name = new_report.plot_name
assert new_report.delete_traces(plot_name, traces_to_delete)
if not is_ironpython:
with pytest.raises(ValueError):
new_report.delete_traces("plot_name", traces_to_delete)
with pytest.raises(ValueError):
new_report.delete_traces(plot_name, ["V(out)_Test"])

def test_09e_add_traces_to_report(self):
new_report = self.aedtapp.create_scattering("add_traces_test")
traces = new_report.get_solution_data().expressions
assert new_report.add_trace_to_report(traces)
setup = self.aedtapp.post.plots[0].setup
variations = self.aedtapp.post.plots[0].variations["height"] = "10mm"
assert not new_report.add_trace_to_report(traces, setup, variations)
variations = self.aedtapp.post.plots[0].variations
assert new_report.add_trace_to_report(traces, setup, variations)
setup = "Transient"
assert not new_report.add_trace_to_report(traces, setup, variations)

def test_09f_update_traces_in_report(self):
new_report = self.aedtapp.create_scattering("update_traces_test")
traces = new_report.get_solution_data().expressions
assert new_report.update_trace_in_report(traces)
setup = self.aedtapp.post.plots[0].setup
variations = self.aedtapp.post.plots[0].variations["height"] = "10mm"
assert not new_report.add_trace_to_report(traces, setup, variations)
variations = self.aedtapp.post.plots[0].variations
assert new_report.update_trace_in_report(traces, setup, variations)

@pytest.mark.skipif(
config["desktopVersion"] < "2022.2", reason="Not working in non-graphical mode in version earlier than 2022.2."
)
def test_09c_create_monitor(self): # pragma: no cover
def test_09d_create_monitor(self): # pragma: no cover
assert self.aedtapp.post.create_report("dB(S(1,1))")
new_report = self.aedtapp.post.reports_by_category.modal_solution("dB(S(1,1))")
assert new_report.create()
Expand All @@ -331,15 +403,15 @@ def test_09c_create_monitor(self): # pragma: no cover
@pytest.mark.skipif(
config["build_machine"], reason="Skipped because it cannot run on build machine in non-graphical mode"
)
def test_09d_add_line_from_point(self): # pragma: no cover
def test_09e_add_line_from_point(self): # pragma: no cover
assert self.aedtapp.post.create_report("dB(S(1,1))")
new_report = self.aedtapp.post.reports_by_category.modal_solution("dB(S(1,1))")
new_report.create()
assert new_report.add_limit_line_from_points([3, 5, 5, 3], [-50, -50, -60, -60], "GHz")

@pytest.mark.skipif(
config["desktopVersion"] < "2022.2", reason="Not working in non-graphical mode in version earlier than 2022.2."
)
def test_09e_add_line_from_equation(self):
def test_09f_add_line_from_equation(self):
assert self.aedtapp.post.create_report("dB(S(1,1))")
new_report = self.aedtapp.post.reports_by_category.modal_solution("dB(S(1,1))")
assert new_report.create()
Expand All @@ -348,7 +420,7 @@ def test_09e_add_line_from_equation(self):
@pytest.mark.skipif(
config["desktopVersion"] < "2022.2", reason="Not working in non-graphical mode in version earlier than 2022.2."
)
def test_09f_edit_properties(self):
def test_09g_edit_properties(self):
report = self.aedtapp.post.create_report("dB(S(1,1))")
assert report.edit_grid()
assert report.edit_grid(minor_x=False)
Expand Down Expand Up @@ -401,7 +473,7 @@ def test_09f_edit_properties(self):
@pytest.mark.skipif(
config["desktopVersion"] < "2022.2", reason="Not working in non-graphical mode in version earlier than 2022.2."
)
def test_09g_add_line_from_point(self): # pragma: no cover
def test_09h_add_line_from_point(self): # pragma: no cover
new_report = self.aedtapp.post.reports_by_category.modal_solution("dB(S(1,1))")
new_report.create()
style = new_report.traces[0].LINESTYLE
Expand All @@ -423,7 +495,7 @@ def test_09g_add_line_from_point(self): # pragma: no cover
@pytest.mark.skipif(
config["desktopVersion"] < "2022.2", reason="Not working in non-graphical mode in version earlier than 2022.2."
)
def test_09g_add_note(self): # pragma: no cover
def test_09l_add_note(self): # pragma: no cover
new_report = self.aedtapp.post.reports_by_category.modal_solution("dB(S(1,1))")
new_report.create()

Expand All @@ -450,18 +522,13 @@ def test_12_steal_on_focus(self):
config["build_machine"], reason="Skipped because it cannot run on build machine in non-graphical mode"
)
def test_13_export_model_picture(self):
path1 = self.aedtapp.post.export_model_picture(full_name=os.path.join(self.local_scratch.path, "image.png"))
assert os.path.exists(path1)
path = self.aedtapp.post.export_model_picture(
show_axis=True, show_grid=False, show_ruler=True, show_region=False
)
path = self.aedtapp.post.export_model_picture(dir=self.local_scratch.path, name="images")
assert path
path = self.aedtapp.post.export_model_picture(selections="inner")
path = self.aedtapp.post.export_model_picture(show_axis=True, show_grid=False, show_ruler=True)
assert path
path = self.aedtapp.post.export_model_picture(orientation="top")
path = self.aedtapp.post.export_model_picture(name="Ericsson", picturename="test_picture")
assert path
self.q3dtest.analyze_nominal()
path = self.q3dtest.post.export_model_picture(field_selections="SmootQ1", orientation="top")
path = self.aedtapp.post.export_model_picture(picturename="test_picture")
assert path

@pytest.mark.skipif(is_ironpython, reason="Not running in ironpython")
Expand Down Expand Up @@ -674,11 +741,11 @@ def test_56_test_export_q3d_results(self):
new_report = self.q3dtest.post.reports_by_category.standard(self.q3dtest.get_traces_for_plot())
assert new_report.create()
self.q3dtest.modeler.create_polyline([[0, -5, 0.425], [0.5, 5, 0.5]], name="Poly1", non_model=True)
new_report = self.q3dtest.post.reports_by_category.cg_fields("SmoothQ", polyline="Poly1")
new_report = self.q3dtest.post.reports_by_category.cg_fields("SmoothQ", polyline="Polyline1")
assert new_report.create()
new_report = self.q3dtest.post.reports_by_category.rl_fields("Mag_SurfaceJac", polyline="Poly1")
new_report = self.q3dtest.post.reports_by_category.rl_fields("Mag_SurfaceJac", polyline="Polyline1")
assert new_report.create()
new_report = self.q3dtest.post.reports_by_category.dc_fields("Mag_VolumeJdc", polyline="Poly1")
new_report = self.q3dtest.post.reports_by_category.dc_fields("Mag_VolumeJdc", polyline="Polyline1")
assert new_report.create()
assert len(self.q3dtest.post.plots) == 6

Expand Down
2 changes: 1 addition & 1 deletion pyaedt/maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def eddy_effects_on(self, object_list, activate_eddy_effects=True, activate_disp
activate_eddy_effects : bool, optional
Whether to activate eddy effects. The default is ``True``.
activate_displacement_current : bool, optional
Whether to activate eddy effects. The default is ``True``.
Whether to activate the displacement current. The default is ``True``.

Returns
-------
Expand Down
136 changes: 136 additions & 0 deletions pyaedt/modules/report_templates.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import copy
import os

from pyaedt.generic.constants import LineStyle
from pyaedt.generic.constants import SymbolStyle
from pyaedt.generic.constants import TraceType
Expand Down Expand Up @@ -1269,6 +1272,139 @@ def edit_header(
]
return self._change_property("Header", "Header", props)

@pyaedt_function_handler
def import_traces(self, file_path, plot_name):
"""Import report data from a file into a specified report.

Parameters
----------
file_path : str
Input file path where extension can be ".csv", ".tab", ".dat", ".rdat".
plot_name : str
Name of the plot where file data have to be imported.
"""
if not os.path.exists(file_path):
msg = "File does not exist."
raise FileExistsError(msg)

if not plot_name:
msg = "Plot name can't be None."
raise ValueError(msg)
else:
if plot_name not in self._post.all_report_names:
msg = "Plot name provided doesn't exists in current report."
raise ValueError(msg)
self.plot_name = plot_name

split_path = os.path.splitext(file_path)
extension = split_path[1]

supported_ext = [".csv", ".tab", ".dat", ".rdat"]
if extension not in supported_ext:
msg = "Extension {} is not supported. Use one of {}".format(extension, ", ".join(supported_ext))
raise ValueError(msg)

try:
if extension == ".rdat":
self._post.oreportsetup.ImportReportDataIntoReport(self.plot_name, file_path)
else:
self._post.oreportsetup.ImportIntoReport(self.plot_name, file_path)
return True
except:
return False

@pyaedt_function_handler
def delete_traces(self, plot_name, traces_list):
"""Delete an existing trace or traces.

Parameters
----------
plot_name : str
Plot name.
traces_list : list
A specific trace or list of traces that the user wishes to delete.
"""
if plot_name not in self._post.all_report_names:
raise ValueError("Plot does not exist in current project.")

for trace in traces_list:
if trace not in self._trace_info[3]:
raise ValueError("Trace does not exist in the selected plot.")

props = []
props.append("{}:=".format(plot_name))
props.append(traces_list)
try:
self._post.oreportsetup.DeleteTraces(props)
return True
except:
return False

@pyaedt_function_handler
def add_trace_to_report(self, traces, setup_name=None, variations=None, context=None):
"""Add a trace to a specific report.

Parameters
----------
traces : list
List of traces to add.
setup_name : str, optional
Name of the setup.
variations : dict, optional
Dictionary of variations.
context : list, optional
Solution context.
"""
expr = copy.deepcopy(self.expressions)
self.expressions = traces

try:
self._post.oreportsetup.AddTraces(
self.plot_name,
setup_name if setup_name else self.setup,
context if context else self._context,
self._convert_dict_to_report_sel(variations if variations else self.variations),
self._trace_info,
)
return True
except:
return False
finally:
self.expressions = expr

@pyaedt_function_handler
def update_trace_in_report(self, traces, setup_name=None, variations=None, context=None):
"""Update a trace in a specific report.

Parameters
----------
traces : list
List of traces to add.
setup_name : str, optional
Name of the setup.
variations : dict, optional
Dictionary of variations.
context : list, optional
Solution context.
"""
expr = copy.deepcopy(self.expressions)
self.expressions = traces

try:
self._post.oreportsetup.UpdateTraces(
self.plot_name,
traces,
setup_name if setup_name else self.setup,
context if context else self._context,
self._convert_dict_to_report_sel(variations if variations else self.variations),
self._trace_info,
)
return True
except:
return False
finally:
self.expressions = expr


class Standard(CommonReport):
"""Provides a reporting class that fits most of the application's standard reports."""
Expand Down