diff --git a/Tests/GUI/DMachineSetup/PWSlot/test_PWSlot25.py b/Tests/GUI/DMachineSetup/PWSlot/test_PWSlot25.py index fc558deab..8cb9d6243 100644 --- a/Tests/GUI/DMachineSetup/PWSlot/test_PWSlot25.py +++ b/Tests/GUI/DMachineSetup/PWSlot/test_PWSlot25.py @@ -140,17 +140,17 @@ def test_check(self): self.test_obj.slot = SlotW25(Zs=4, H2=0.11, H1=0, W4=0.1, W3=0.16) assert ( self.widget.check(self.test_obj) - == "You must have H1>0 (use Slot 24 for H1=0)" + == "You must have H1>0 (use Slot 25 for H1=0)" ) self.test_obj.slot = SlotW25(Zs=4, H2=0, H1=0.11, W4=0.1, W3=0.16) assert ( self.widget.check(self.test_obj) - == "You must have H2>0 (use Slot 24 for H2=0)" + == "You must have H2>0 (use Slot 25 for H2=0)" ) self.test_obj.slot = SlotW25(Zs=4, H2=0.12, H1=0.11, W4=0.1, W3=0.1) assert ( self.widget.check(self.test_obj) - == "You must have W4 != W3 (use Slot 24 for W4=W3)" + == "You must have W4 != W3 (use Slot 25 for W4=W3)" ) def test_set_wedge(self): @@ -182,6 +182,6 @@ def test_set_wedge(self): a = TestPWSlot25() a.setup_class() a.setup_method() - a.test_init() + a.test_check() a.teardown_class() print("Done") diff --git a/Tests/GUI/DMatLib/test_Workflow_Matlib.py b/Tests/GUI/DMatLib/test_Workflow_Matlib.py index ab2bc80d8..9eca0d06a 100644 --- a/Tests/GUI/DMatLib/test_Workflow_Matlib.py +++ b/Tests/GUI/DMatLib/test_Workflow_Matlib.py @@ -341,6 +341,38 @@ def test_new_machine_material(self): # Close the dialog dialog.close() + def test_copy_machine_material(self): + """Copy a material for the machine and check changes in the GUI""" + # Check initial state + assert self.widget.machine.rotor.hole[0].magnet_0.mat_type.struct.rho == 7500 + assert not isfile(join(WS_path, "MagnetPrius_old.json")) + # Open DMatlib + self.widget.nav_step.setCurrentRow(6) # Hole material + assert isinstance(self.widget.w_step, SMHoleMag) + w_mat = self.widget.w_step.tab_hole.widget(0).w_hole.w_mat_1 + assert w_mat.current_dialog is None + w_mat.b_matlib.clicked.emit() + assert isinstance(w_mat.current_dialog, DMatLib) + dialog = w_mat.current_dialog + assert dialog.is_lib_mat is False + assert dialog.nav_mat_mach.currentRow() == 1 + assert dialog.nav_mat.count() == 4 + assert dialog.nav_mat_mach.count() == 2 + assert dialog.w_setup.le_name.text() == "MagnetPrius_old" + + # Copy MagnetPrius_old material once + dialog.b_copy.clicked.emit() + assert dialog.w_setup.le_name.text() == "MagnetPrius_old_copy" + dialog.w_setup.b_save.clicked.emit() + + # Copy MagnetPrius_old material twice + dialog.b_copy.clicked.emit() + assert dialog.w_setup.le_name.text() == "MagnetPrius_old_copy_2" + dialog.w_setup.b_save.clicked.emit() + + # Close the dialog + dialog.close() + def test_rename_matlib(self): """rename a material in the Library and check changes in machine""" # Check initial state @@ -622,9 +654,10 @@ def test_edit_machine_to_library(self): # a.test_rename_machine_material() # a.test_rename_matlib() # a.test_new_machine_material() + a.test_copy_machine_material() # a.test_new_matlib() # a.test_edit_machine_to_library() - a.test_edit_matlib_to_machine() + # a.test_edit_matlib_to_machine() # a.test_edit_machine_material_several() # a.test_edit_machine_material() # a.test_edit_matlib() diff --git a/Tests/Methods/Machine/test_desc_dict.py b/Tests/Methods/Machine/test_desc_dict.py index d5ea6642a..53ad0362f 100644 --- a/Tests/Methods/Machine/test_desc_dict.py +++ b/Tests/Methods/Machine/test_desc_dict.py @@ -12,8 +12,8 @@ @pytest.mark.SCIM def test_desc_SCIM(): """Check that the description of a SCIM is correct""" - SCIM_001 = load(join(DATA_DIR, "Machine", "Railway_Traction.json")) - desc_dict = SCIM_001.comp_desc_dict() + Railway_Traction = load(join(DATA_DIR, "Machine", "Railway_Traction.json")) + desc_dict = Railway_Traction.comp_desc_dict() assert len(desc_dict) == 9 assert desc_dict[0]["name"] == "Type" assert desc_dict[0]["value"] == "SCIM" diff --git a/Tests/Plot/Schematics/test_hole_convention.py b/Tests/Plot/Schematics/test_hole_convention.py index 4109a4f8b..64b71eab9 100644 --- a/Tests/Plot/Schematics/test_hole_convention.py +++ b/Tests/Plot/Schematics/test_hole_convention.py @@ -18,6 +18,7 @@ def test_plot_radius(): """Plot the min/max radius of the Hole""" + plt.close("all") BMW = load(join(DATA_DIR, "Machine", "BMW_i3.json")) # Modification for better visualization @@ -25,10 +26,7 @@ def test_plot_radius(): for surf in BMW.rotor.hole[0].surf_list: surf.translate(-5e-3) - BMW.rotor.plot(is_show_fig=False) - fig = plt.gcf() - ax = plt.gca() - + fig, ax = BMW.rotor.plot(is_show_fig=False, edgecolor="k") # Top and Bottom arc (Rint, Rext) = BMW.rotor.hole[0].comp_radius() line = Arc1( @@ -59,16 +57,16 @@ def test_plot_radius(): ) # Adding Label Zref = Rext * exp(1j * pi / 2) - plt.plot(Zref.real, Zref.imag, "xr") - plt.text( + ax.plot(Zref.real, Zref.imag, "xr") + ax.text( Zref.real, Zref.imag + 1e-3, "Rext", weight="bold", ) Zref = Rint * exp(1j * pi / 2) - plt.plot(Zref.real, Zref.imag, "xr") - plt.text( + ax.plot(Zref.real, Zref.imag, "xr") + ax.text( Zref.real, Zref.imag + 1e-3, "Rint", @@ -85,6 +83,7 @@ def test_plot_radius(): fig.savefig(join(save_path, "Schematics", "Hole_radius.png")) # plt.show() + plt.close(fig=fig) def test_plot_magnet_id(): @@ -114,7 +113,7 @@ def test_plot_magnet_id(): ) ) - rotor.plot(is_show_fig=False) + fig, ax = rotor.plot(is_show_fig=False, edgecolor="k") # Adding label surf_list = rotor.hole[0].build_geometry() @@ -122,13 +121,12 @@ def test_plot_magnet_id(): label_dict = decode_label(surf.label) if HOLEM_LAB in label_dict["surf_type"]: Zref = surf.point_ref * exp(1j * pi / 2) - plt.text( + ax.text( Zref.real - 5e-3, Zref.imag, "magnet_" + str(label_dict["T_id"]), weight="bold", ) - ax = plt.gca() ax.set_xlim(-30e-3, 30e-3) ax.set_ylim(50e-3, 90e-3) @@ -138,8 +136,8 @@ def test_plot_magnet_id(): ax.get_legend().remove() ax.set_title("") - fig = plt.gcf() fig.savefig(join(save_path, "Schematics", "Hole_magnet_id.png")) + plt.close(fig=fig) def test_plot_hole_RTS(): @@ -188,24 +186,21 @@ def test_plot_hole_RTS(): ) ) - rotor.plot( - is_show_fig=False - ) # , save_path=join(save_path, "Shematics", "Hole_RTS.png")) + fig, ax = rotor.plot(is_show_fig=False, edgecolor="k") # Adding label surf_list = rotor.hole[0].build_geometry() surf_list.extend(rotor.hole[1].build_geometry()) for surf in surf_list: Zref = surf.point_ref * exp(1j * pi / 2) - plt.plot(Zref.real, Zref.imag, "xr") + ax.plot(Zref.real, Zref.imag, "xr") label_dict = decode_label(surf.label) - plt.text( + ax.text( Zref.real, Zref.imag, label_dict["surf_type"][4:] + "_" + label_dict["index"], weight="bold", ) - ax = plt.gca() ax.set_xlim(-30e-3, 30e-3) ax.set_ylim(50e-3, 90e-3) # Set figure to full screen for readibility @@ -216,11 +211,12 @@ def test_plot_hole_RTS(): ax.set_axis_off() ax.get_legend().remove() ax.set_title("") - fig = plt.gcf() fig.savefig(join(save_path, "Schematics", "Hole_RTS.png")) + plt.close(fig=fig) if __name__ == "__main__": test_plot_radius() - # test_plot_magnet_id() - # test_plot_hole_RTS() + test_plot_magnet_id() + test_plot_hole_RTS() + print("Done") diff --git a/Tests/Simulation/test_StructElmer.py b/Tests/Simulation/test_StructElmer.py index 52b37fcce..56496f529 100644 --- a/Tests/Simulation/test_StructElmer.py +++ b/Tests/Simulation/test_StructElmer.py @@ -1,7 +1,7 @@ from os.path import join from numpy import pi import pytest -from Tests import save_path, TEST_DATA_DIR +from Tests import save_validation_path as save_path, TEST_DATA_DIR from pyleecan.Classes.OPdq import OPdq from pyleecan.definitions import DATA_DIR @@ -17,7 +17,7 @@ # get the machine machine_1 = load(join(DATA_DIR, "Machine", "Toyota_Prius.json")) - +save_path = join(save_path, "StructElmer") # mesh settings, original line label names have to be used (not the translated) n1 = 3 n2 = 20 diff --git a/Tests/Simulation/test_post_var_simu.py b/Tests/Simulation/test_post_var_simu.py index 4b3f334be..1630efad0 100644 --- a/Tests/Simulation/test_post_var_simu.py +++ b/Tests/Simulation/test_post_var_simu.py @@ -4,7 +4,7 @@ from copy import copy from numpy import sqrt - +import numpy as np from pyleecan.Classes.HoleM51 import HoleM51 from pyleecan.Classes.HoleM52 import HoleM52 from pyleecan.Classes.HoleM53 import HoleM53 diff --git a/Tests/Validation/Optimization/test_Binh_and_Korn_Bayes.py b/Tests/Validation/Optimization/test_Binh_and_Korn_Bayes.py index d88b5fec6..c55c53348 100644 --- a/Tests/Validation/Optimization/test_Binh_and_Korn_Bayes.py +++ b/Tests/Validation/Optimization/test_Binh_and_Korn_Bayes.py @@ -39,10 +39,9 @@ @pytest.mark.periodicity @pytest.mark.SingleOP def test_Binh_and_Korn(): - SCIM_001 = load(join(DATA_DIR, "Machine", "SCIM_001.json")) # Defining reference Output # Definition of the enforced output of the electrical module - SCIM_001 = load(join(DATA_DIR, "Machine", "SCIM_001.json")) + Railway_Traction = load(join(DATA_DIR, "Machine", "Railway_Traction.json")) Nt = 2 N0 = 3000 Is = ImportMatrixVal( @@ -60,7 +59,7 @@ def test_Binh_and_Korn(): Na_tot = 64 # Definition of the simulation - simu = Simu1(name="test_Binh_and_Korn_Bayes", machine=SCIM_001) + simu = Simu1(name="test_Binh_and_Korn_Bayes", machine=Railway_Traction) simu.input = InputCurrent( Is=Is, diff --git a/Tests/Validation/Optimization/test_opti_datakeeper_list.py b/Tests/Validation/Optimization/test_opti_datakeeper_list.py index eff0227eb..72c496fb3 100644 --- a/Tests/Validation/Optimization/test_opti_datakeeper_list.py +++ b/Tests/Validation/Optimization/test_opti_datakeeper_list.py @@ -28,10 +28,10 @@ def test_opti_datakeeper_list(): # Defining reference Output # Definition of the enforced output of the electrical module - SCIM_001 = load(join(DATA_DIR, "Machine", "Railway_Traction.json")) + Railway_Traction = load(join(DATA_DIR, "Machine", "Railway_Traction.json")) # Definition of the simulation - simu = Simu1(name="test_opti_datakeeper_list", machine=SCIM_001) + simu = Simu1(name="test_opti_datakeeper_list", machine=Railway_Traction) # Design variable my_vars = [ diff --git a/Tests/Validation/Optimization/test_zdt3_Bayes.py b/Tests/Validation/Optimization/test_zdt3_Bayes.py index 591eb9e11..61394aa1d 100644 --- a/Tests/Validation/Optimization/test_zdt3_Bayes.py +++ b/Tests/Validation/Optimization/test_zdt3_Bayes.py @@ -35,7 +35,7 @@ @pytest.mark.SingleOP def test_zdt3_Bayes(): # ### Defining reference Output - SCIM_001 = load(join(DATA_DIR, "Machine", "SCIM_001.json")) + Railway_Traction = load(join(DATA_DIR, "Machine", "Railway_Traction.json")) # Definition of the enforced output of the electrical module Nt = 2 @@ -55,7 +55,7 @@ def test_zdt3_Bayes(): Na_tot = 64 # Definition of the simulation - simu = Simu1(name="test_zdt3", machine=SCIM_001) + simu = Simu1(name="test_zdt3", machine=Railway_Traction) simu.input = InputCurrent( Is=Is, diff --git a/pyleecan/Functions/Optimization/evaluate.py b/pyleecan/Functions/Optimization/evaluate.py index 69cc2fb8c..b1f2387b2 100644 --- a/pyleecan/Functions/Optimization/evaluate.py +++ b/pyleecan/Functions/Optimization/evaluate.py @@ -11,6 +11,7 @@ from os import stat, remove from datetime import datetime from numpy import nan +import numpy as np def evaluate(solver, indiv): diff --git a/pyleecan/Functions/Simulation/VarSimu/run_multisim_step.py b/pyleecan/Functions/Simulation/VarSimu/run_multisim_step.py index 548b70d5f..b79c567db 100644 --- a/pyleecan/Functions/Simulation/VarSimu/run_multisim_step.py +++ b/pyleecan/Functions/Simulation/VarSimu/run_multisim_step.py @@ -1,5 +1,5 @@ from numpy import ndarray, min as np_min, max as np_max - +import numpy as np from SciDataTool import VectorField, Data from ....Functions.Load.import_class import import_class from ....Functions.Simulation.VarSimu.log_datakeeper_step_result import ( diff --git a/pyleecan/GUI/Dialog/DMatLib/DMatLib.py b/pyleecan/GUI/Dialog/DMatLib/DMatLib.py index e8a7cf689..5c670709c 100644 --- a/pyleecan/GUI/Dialog/DMatLib/DMatLib.py +++ b/pyleecan/GUI/Dialog/DMatLib/DMatLib.py @@ -309,11 +309,19 @@ def new_material(self, is_copy=True): # Adapt name to be unique name_list = [mat.name for mat in self.material_dict[LIB_KEY]] name_list.extend([mat.name for mat in self.material_dict[MACH_KEY]]) + + # Renaming the material so that we have "_copy","_copy_2","_copy_3"... if new_mat.name in name_list: - index = 1 - while new_mat.name + "_" + str(index) in name_list: - index += 1 - new_mat.name = new_mat.name + "_" + str(index) + # Adding number after copy + if new_mat.name[-4:] == "copy": + new_mat.name = new_mat.name + "_2" + # Setting the index after the current one + else: + index = 1 + while int(new_mat.name[-1]) >= index: + index += 1 + new_mat.name = new_mat.name[:-1] + new_mat.name = new_mat.name + str(index) new_mat.path = join(dirname(new_mat.path), new_mat.name + ".json") # Save if in MatLib diff --git a/pyleecan/GUI/Tools/WTableData/DTableData.py b/pyleecan/GUI/Tools/WTableData/DTableData.py index d7da5fb7b..226d133bb 100644 --- a/pyleecan/GUI/Tools/WTableData/DTableData.py +++ b/pyleecan/GUI/Tools/WTableData/DTableData.py @@ -343,15 +343,15 @@ def s_plot(self): # Data in line fig, axes = plt.subplots() axes.plot(data[0, :], data[1, :]) - plt.ylabel(self.col_header[1]) - plt.xlabel(self.col_header[0]) + axes.set_xlabel(self.col_header[0]) + axes.set_ylabel(self.col_header[1]) fig.show() elif len(data.shape) == 2 and data.shape[1] == 2: # Data in column fig, axes = plt.subplots() axes.plot(data[:, 0], data[:, 1]) - plt.ylabel(self.col_header[1]) - plt.xlabel(self.col_header[0]) + axes.set_xlabel(self.col_header[0]) + axes.set_ylabel(self.col_header[1]) fig.show() if self.col_header is not None: fig.canvas.manager.set_window_title(self.col_header[0] + " plot") diff --git a/pyleecan/Methods/Geometry/SurfLine/plot_lines.py b/pyleecan/Methods/Geometry/SurfLine/plot_lines.py index 8d7eed54f..6c86be5a8 100644 --- a/pyleecan/Methods/Geometry/SurfLine/plot_lines.py +++ b/pyleecan/Methods/Geometry/SurfLine/plot_lines.py @@ -1,12 +1,9 @@ -# -*- coding: utf-8 -*- - -from matplotlib.pyplot import axis, legend from numpy import real, imag from ....Functions.init_fig import init_fig -def plot_lines(self, fig=None, is_show_fig=True): +def plot_lines(self, fig=None, ax=None, is_show_fig=True): """Plot the SurfLine-Contour in a matplotlib fig (For plotting unclosed contour, for Polygon use plot method from Surface object) @@ -14,20 +11,24 @@ def plot_lines(self, fig=None, is_show_fig=True): ---------- self : SurfLine A SurfLine object - fig : - if None, open a new fig and plot, else add to the - current one (Default value = None) + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data is_show_fig : bool To call show at the end of the method Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ - (fig, axes, patch_leg, label_leg) = init_fig(fig) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") + (fig, ax, patch_leg, label_leg) = init_fig(fig, ax) + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") points = self.discretize(10) @@ -38,10 +39,11 @@ def plot_lines(self, fig=None, is_show_fig=True): y1 = imag(z1) x2 = real(z2) y2 = imag(z2) - axes.plot([x1, x2], [y1, y2], "k") + ax.plot([x1, x2], [y1, y2], "k") # Axis Setup - axis("equal") + ax.axis("equal") if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Geometry/SurfRing/plot_lines.py b/pyleecan/Methods/Geometry/SurfRing/plot_lines.py index 9d31442f7..c65d7df0e 100644 --- a/pyleecan/Methods/Geometry/SurfRing/plot_lines.py +++ b/pyleecan/Methods/Geometry/SurfRing/plot_lines.py @@ -1,10 +1,9 @@ -from matplotlib.pyplot import axis, legend from numpy import real, imag from ....Functions.init_fig import init_fig -def plot_lines(self, fig=None): +def plot_lines(self, fig=None, ax=None): """Plot the SurfRing-Contour in a matplotlib fig (For plotting unclosed contour, for Polygon use plot method from Surface object) @@ -12,18 +11,22 @@ def plot_lines(self, fig=None): ---------- self : SurfRing A SurfRing object - fig : - if None, open a new fig and plot, else add to the - current one (Default value = None) + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ - (fig, axes, patch_leg, label_leg) = init_fig(fig) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") + (fig, ax, patch_leg, label_leg) = init_fig(fig, ax) + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") points = self.out_surf.discretize(10) for idx in range(len(points) - 1): @@ -33,7 +36,7 @@ def plot_lines(self, fig=None): y1 = imag(z1) x2 = real(z2) y2 = imag(z2) - axes.plot([x1, x2], [y1, y2], "k") + ax.plot([x1, x2], [y1, y2], "k") points = self.in_surf.discretize(10) for idx in range(len(points) - 1): @@ -43,9 +46,10 @@ def plot_lines(self, fig=None): y1 = imag(z1) x2 = real(z2) y2 = imag(z2) - axes.plot([x1, x2], [y1, y2], "k") + ax.plot([x1, x2], [y1, y2], "k") # Axis Setup - axis("equal") + ax.axis("equal") fig.show() + return fig, ax diff --git a/pyleecan/Methods/Geometry/Surface/plot.py b/pyleecan/Methods/Geometry/Surface/plot.py index 9e0deecf8..bf2da05a1 100644 --- a/pyleecan/Methods/Geometry/Surface/plot.py +++ b/pyleecan/Methods/Geometry/Surface/plot.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from matplotlib.pyplot import axis, legend - from ....Functions.init_fig import init_fig from ....definitions import config_dict @@ -18,6 +14,7 @@ def plot( is_edge_only=False, linestyle=None, is_disp_point_ref=False, + is_disp_line_index=False, is_show_fig=True, ): """Plot the Surface patch in a matplotlib fig @@ -39,28 +36,39 @@ def plot( Line style of the edge {'-', '--', '-.', ':', '', (offset, on-off-seq), ...} is_disp_point_ref : bool True to add the point_ref + is_disp_line_index : bool + True to add the index of the lines is_show_fig : bool To call show at the end of the methods Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ - (fig, axes, patch_leg, label_leg) = init_fig(fig, ax) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") + (fig, ax, patch_leg, label_leg) = init_fig(fig, ax) + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") patches = self.get_patches( color=color, edgecolor=edgecolor, is_edge_only=is_edge_only, linestyle=linestyle ) for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) if is_disp_point_ref: - axes.plot(self.point_ref.real, self.point_ref.imag, "kx") + ax.plot(self.point_ref.real, self.point_ref.imag, "kx") + + if is_disp_line_index: + for ii, line in enumerate(self.get_lines()): + mid = line.get_middle() + ax.text(mid.real, mid.imag, str(ii)) # Axis Setup - axes.axis("equal") + ax.axis("equal") if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Machine/CondType11/plot.py b/pyleecan/Methods/Machine/CondType11/plot.py index 33246955a..e3d4d124b 100644 --- a/pyleecan/Methods/Machine/CondType11/plot.py +++ b/pyleecan/Methods/Machine/CondType11/plot.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from matplotlib.patches import Patch, Rectangle -from matplotlib.pyplot import axis, legend, subplots +from ....Functions.init_fig import init_fig from ....definitions import config_dict COND_COLOR = config_dict["PLOT"]["COLOR_DICT"]["PHASE_COLORS"][0].copy() @@ -11,7 +11,7 @@ INS_COLOR[3] = 1 -def plot(self, is_show_fig=True): +def plot(self, is_show_fig=True, fig=None, ax=None): """Plot a Conductor in a matplotlib fig Parameters @@ -20,10 +20,17 @@ def plot(self, is_show_fig=True): A CondType11 object is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ patches_list = [] @@ -44,12 +51,12 @@ def plot(self, is_show_fig=True): ) # Display - fig, ax = subplots() + (fig, ax, _, _) = init_fig(fig=fig, ax=ax) for patch in patches_list: ax.add_patch(patch) # Axis Setup - axis("equal") + ax.axis("equal") # The conductor is centered ax.set_xlim(0 - Wcond / 10, Wcond * 11.0 / 10.0) @@ -65,6 +72,7 @@ def plot(self, is_show_fig=True): patch_leg.append(Patch(color=COND_COLOR)) label_leg.append("Active wire section") - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Machine/CondType11/plot_schematics.py b/pyleecan/Methods/Machine/CondType11/plot_schematics.py index 56788039b..01486f9ba 100644 --- a/pyleecan/Methods/Machine/CondType11/plot_schematics.py +++ b/pyleecan/Methods/Machine/CondType11/plot_schematics.py @@ -1,10 +1,5 @@ import matplotlib.pyplot as plt -from numpy import pi, exp - -from ....Classes.Arc1 import Arc1 -from ....Classes.LamSlot import LamSlot from ....Classes.Segment import Segment -from ....definitions import config_dict from ....Functions.Plot import ( ARROW_COLOR, ARROW_WIDTH, @@ -28,6 +23,8 @@ def plot_schematics( is_add_main_line=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -45,6 +42,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Use some default parameter @@ -58,12 +66,12 @@ def plot_schematics( is_add_main_line=is_add_main_line, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot - self.plot(is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = self.plot(is_show_fig=False, fig=fig, ax=ax) # center slot on Ox axis # Adding schematics if is_add_schematics: @@ -169,7 +177,7 @@ def plot_schematics( W = self.comp_width() * 1.1 H = self.comp_height() * 1.1 - plt.axis("equal") + ax.axis("equal") ax.set_xlim(-W * 0.1, W) ax.set_ylim(-H * 0.1, H) manager = plt.get_current_fig_manager() @@ -182,7 +190,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Machine/CondType12/plot.py b/pyleecan/Methods/Machine/CondType12/plot.py index c7cdcdacf..65d32b167 100644 --- a/pyleecan/Methods/Machine/CondType12/plot.py +++ b/pyleecan/Methods/Machine/CondType12/plot.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- - from matplotlib.patches import Circle, Patch -from matplotlib.pyplot import axis, legend, subplots +from ....Functions.init_fig import init_fig from numpy import exp, pi, sqrt from ....definitions import config_dict @@ -15,7 +13,7 @@ COND_INS_COLOR[3] = 1 -def plot(self, is_show_fig=True): +def plot(self, is_show_fig=True, fig=None, ax=None): """Plot a Conductor in a matplotlib fig Parameters @@ -24,10 +22,17 @@ def plot(self, is_show_fig=True): A CondType12 object is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot Raises _______ @@ -79,12 +84,12 @@ def plot(self, is_show_fig=True): patches_list.append(Circle(center, self.Wwire / 2, color=COND_COLOR)) # Display - fig, ax = subplots() + (fig, ax, _, _) = init_fig(fig=fig, ax=ax) for patch in patches_list: ax.add_patch(patch) # Axis Setup - axis("equal") + ax.axis("equal") # The conductor is centered ax_lim = self.Wins_cond / 2 + self.Wins_cond / 10 @@ -101,9 +106,10 @@ def plot(self, is_show_fig=True): patch_leg.append(Patch(color=COND_COLOR)) label_leg.append("Active wire section") - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax class NotPlotableError(Exception): diff --git a/pyleecan/Methods/Machine/CondType12/plot_schematics.py b/pyleecan/Methods/Machine/CondType12/plot_schematics.py index 9a8a0435d..71f116ccb 100644 --- a/pyleecan/Methods/Machine/CondType12/plot_schematics.py +++ b/pyleecan/Methods/Machine/CondType12/plot_schematics.py @@ -1,10 +1,5 @@ import matplotlib.pyplot as plt -from numpy import pi, exp - -from ....Classes.Arc1 import Arc1 -from ....Classes.LamSlot import LamSlot from ....Classes.Segment import Segment -from ....definitions import config_dict from ....Functions.Plot import ( ARROW_COLOR, ARROW_WIDTH, @@ -28,6 +23,8 @@ def plot_schematics( is_add_main_line=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -45,6 +42,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Use some default parameter @@ -56,12 +64,12 @@ def plot_schematics( is_add_main_line=is_add_main_line, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot - self.plot(is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = self.plot(is_show_fig=False, fig=fig, ax=ax) # center slot on Ox axis a = self.Wwire / 2 + self.Wins_wire # Adding schematics @@ -117,7 +125,7 @@ def plot_schematics( # Zooming and cleaning W = self.comp_width() * 1.05 - plt.axis("equal") + ax.axis("equal") ax.set_xlim(-W / 2, W / 2) ax.set_ylim(-W / 2, W / 2) manager = plt.get_current_fig_manager() @@ -130,7 +138,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Machine/CondType13/plot.py b/pyleecan/Methods/Machine/CondType13/plot.py index 51aa45add..ae9a68173 100644 --- a/pyleecan/Methods/Machine/CondType13/plot.py +++ b/pyleecan/Methods/Machine/CondType13/plot.py @@ -1,8 +1,5 @@ -# -*- coding: utf-8 -*- - -from matplotlib.patches import Patch, Rectangle -from matplotlib.pyplot import axis, legend, subplots from ....definitions import config_dict +from ....Functions.init_fig import init_fig COND_COLOR = config_dict["PLOT"]["COLOR_DICT"]["PHASE_COLORS"][0].copy() INS_COLOR = config_dict["PLOT"]["COLOR_DICT"]["PHASE_COLORS"][1].copy() @@ -11,7 +8,7 @@ INS_COLOR[3] = 1 -def plot(self, is_show_fig=True): +def plot(self, is_show_fig=True, fig=None, ax=None): """Plot a Conductor in a matplotlib fig Parameters @@ -20,6 +17,10 @@ def plot(self, is_show_fig=True): A CondType13 object is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data Returns ------- @@ -69,6 +70,7 @@ def plot(self, is_show_fig=True): # patch_leg.append(Patch(color=COND_COLOR)) # label_leg.append("Active wire section") - # legend(patch_leg, label_leg) + # ax.legend(patch_leg, label_leg) # if is_show_fig: # fig.show() + # return fig, ax diff --git a/pyleecan/Methods/Machine/CondType13/plot_schematics.py b/pyleecan/Methods/Machine/CondType13/plot_schematics.py index 4ac68fadc..445ffac5b 100644 --- a/pyleecan/Methods/Machine/CondType13/plot_schematics.py +++ b/pyleecan/Methods/Machine/CondType13/plot_schematics.py @@ -1,6 +1,6 @@ import matplotlib.pyplot as plt from numpy import pi, exp - +from ....Functions.init_fig import init_fig from ....Classes.Arc1 import Arc1 from ....Classes.LamSlot import LamSlot from ....Classes.Segment import Segment @@ -28,6 +28,8 @@ def plot_schematics( is_add_main_line=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -45,6 +47,10 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data """ # TODO diff --git a/pyleecan/Methods/Machine/CondType21/plot.py b/pyleecan/Methods/Machine/CondType21/plot.py index d392d39f6..8109b3e41 100644 --- a/pyleecan/Methods/Machine/CondType21/plot.py +++ b/pyleecan/Methods/Machine/CondType21/plot.py @@ -1,20 +1,25 @@ -# -*- coding: utf-8 -*- - from matplotlib.patches import Patch, Rectangle -from matplotlib.pyplot import axis, legend, subplots +from ....Functions.init_fig import init_fig -def plot(self): +def plot(self, fig=None, ax=None): """Plot a Conductor in a matplotlib fig Parameters ---------- self : CondType21 A CondType21 object + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ patches_list = [] @@ -30,12 +35,12 @@ def plot(self): ) # Display - fig, ax = subplots() + (fig, ax, _, _) = init_fig(fig=fig, ax=ax) for patch in patches_list: ax.add_patch(patch) # Axis Setup - axis("equal") + ax.axis("equal") # The conductor is centered ax.set_xlim(0 - Wcond / 10, Wcond * 11.0 / 10.0) @@ -50,5 +55,6 @@ def plot(self): patch_leg.append(Patch(color="r")) label_leg.append("Active bar section") - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) fig.show() + return fig, ax diff --git a/pyleecan/Methods/Machine/Frame/plot.py b/pyleecan/Methods/Machine/Frame/plot.py index 0cf6c2cc7..7cb5470ca 100644 --- a/pyleecan/Methods/Machine/Frame/plot.py +++ b/pyleecan/Methods/Machine/Frame/plot.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- - from matplotlib.patches import Patch -from matplotlib.pyplot import axis from ....Functions.init_fig import init_fig from ....definitions import config_dict @@ -17,6 +14,7 @@ def plot( alpha=0, delta=0, is_edge_only=False, + edgecolor=None, is_show_fig=True, ): """Plot the Frame in a matplotlib fig @@ -37,40 +35,47 @@ def plot( Complex value for translation is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True is_show_fig : bool To call show at the end of the method Returns ------- - None - + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # plot only if the frame has a height >0 if self.comp_height_eq() != 0: - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta) patches = list() for surf in surf_list: patches.extend( - surf.get_patches(color=FRAME_COLOR, is_edge_only=is_edge_only) + surf.get_patches( + color=FRAME_COLOR, is_edge_only=is_edge_only, edgecolor=edgecolor + ) ) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") - axes.set_title("Frame") + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") + ax.set_title("Frame") for patch in patches: - axes.add_patch(patch) - axis("equal") + ax.add_patch(patch) + ax.axis("equal") # The Lamination is centered in the figure Lim = self.Rext * 1.1 - axes.set_xlim(-Lim, Lim, auto=True) - axes.set_ylim(-Lim, Lim, auto=True) + ax.set_xlim(-Lim, Lim, auto=True) + ax.set_ylim(-Lim, Lim, auto=True) if not is_edge_only: patch_leg.append(Patch(color=FRAME_COLOR)) label_leg.append("Frame") - axes.legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Machine/LamHole/plot.py b/pyleecan/Methods/Machine/LamHole/plot.py index 7fe639664..36dc62a04 100644 --- a/pyleecan/Methods/Machine/LamHole/plot.py +++ b/pyleecan/Methods/Machine/LamHole/plot.py @@ -1,9 +1,6 @@ -# -*- coding: utf-8 -*- - from numpy import exp, pi import matplotlib.pyplot as plt -from matplotlib.patches import Circle, Patch -from matplotlib.pyplot import axis, legend +from matplotlib.patches import Patch from ....definitions import config_dict from ....Functions.init_fig import init_fig @@ -13,6 +10,8 @@ MAGNET_COLOR = config_dict["PLOT"]["COLOR_DICT"]["MAGNET_COLOR"] ROTOR_COLOR = config_dict["PLOT"]["COLOR_DICT"]["ROTOR_COLOR"] STATOR_COLOR = config_dict["PLOT"]["COLOR_DICT"]["STATOR_COLOR"] +VENT_COLOR = config_dict["PLOT"]["COLOR_DICT"]["VENT_COLOR"] +VENT_EDGE = config_dict["PLOT"]["COLOR_DICT"]["VENT_EDGE"] def plot( @@ -24,7 +23,8 @@ def plot( alpha=0, delta=0, is_edge_only=False, - is_add_arrow=True, + edgecolor=None, + is_add_arrow=False, is_show_fig=True, win_title=None, ): @@ -48,6 +48,8 @@ def plot( complex for translation (Default value = 0) is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True is_add_arrow : bool To add an arrow for the magnetization is_show_fig : bool @@ -57,7 +59,10 @@ def plot( Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Lamination bore @@ -74,21 +79,35 @@ def plot( for surf in surf_list: label_dict = decode_label(surf.label) if LAM_LAB in label_dict["surf_type"]: - patches.extend(surf.get_patches(color=lam_color, is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches( + color=lam_color, is_edge_only=is_edge_only, edgecolor=edgecolor + ) + ) elif HOLEM_LAB in label_dict["surf_type"] and not is_lam_only: patches.extend( - surf.get_patches(color=MAGNET_COLOR, is_edge_only=is_edge_only) + surf.get_patches( + color=MAGNET_COLOR, is_edge_only=is_edge_only, edgecolor=edgecolor + ) + ) + elif surf.label is not None and "Ventilation_" in surf.label: + patches.extend( + surf.get_patches( + color=VENT_COLOR, edgecolor=edgecolor, is_edge_only=is_edge_only + ) ) else: - patches.extend(surf.get_patches(is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches(is_edge_only=is_edge_only, edgecolor=edgecolor) + ) - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Add Magnetization arrow if is_add_arrow: @@ -119,7 +138,7 @@ def plot( Z2 = ( mag_surf.point_ref + H / 5 * exp(1j * (mag_dir + off)) ) * exp(1j * (ii * 2 * pi / Zh + pi / Zh)) - axes.annotate( + ax.annotate( text="", xy=(Z2.real, Z2.imag), xytext=(Z1.real, Z1.imag), @@ -127,12 +146,12 @@ def plot( ) # Axis Setup - axes.axis("equal") + ax.axis("equal") # The Lamination is centered in the figure Lim = self.Rext * 1.5 - axes.set_xlim(-Lim, Lim) - axes.set_ylim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) # Window title if ( @@ -152,14 +171,15 @@ def plot( if self.is_stator: patch_leg.append(Patch(color=STATOR_COLOR)) label_leg.append("Stator") - axes.set_title("Stator with Interior Magnet") + ax.set_title("Stator with Interior Magnet") else: patch_leg.append(Patch(color=ROTOR_COLOR)) label_leg.append("Rotor") - axes.set_title("Rotor with Interior Magnet") + ax.set_title("Rotor with Interior Magnet") if not is_lam_only: patch_leg.append(Patch(color=MAGNET_COLOR)) label_leg.append("Magnet") - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Machine/LamSlot/plot.py b/pyleecan/Methods/Machine/LamSlot/plot.py index 39f460761..e5dac094e 100644 --- a/pyleecan/Methods/Machine/LamSlot/plot.py +++ b/pyleecan/Methods/Machine/LamSlot/plot.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- - from matplotlib.patches import Patch -from matplotlib.pyplot import axis, legend from ....Functions.init_fig import init_fig from ....definitions import config_dict @@ -19,6 +16,8 @@ def plot( alpha=0, delta=0, is_edge_only=False, + edgecolor=None, + is_add_arrow=False, is_display=True, is_show_fig=True, ): @@ -42,14 +41,24 @@ def plot( Complex value for translation is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True is_display : bool False to return the patches is_show_fig : bool To call show at the end of the method + Returns ------- patches : list List of Patches + + or + + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ if self.is_stator: @@ -57,44 +66,51 @@ def plot( else: lam_color = ROTOR_COLOR - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta) patches = list() for surf in surf_list: if "Lamination" in surf.label: - patches.extend(surf.get_patches(color=lam_color, is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches( + color=lam_color, is_edge_only=is_edge_only, edgecolor=edgecolor + ) + ) else: - patches.extend(surf.get_patches(is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches(is_edge_only=is_edge_only, edgecolor=edgecolor) + ) # Display the result if is_display: - (fig, axes, patch_leg, label_leg) = init_fig(fig) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") + (fig, ax, patch_leg, label_leg) = init_fig(fig) + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Axis Setup - axes.axis("equal") + ax.axis("equal") # The Lamination is centered in the figure Lim = self.Rext * 1.5 - axes.set_xlim(-Lim, Lim) - axes.set_ylim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) # Add the legend if not is_edge_only: if self.is_stator and "Stator" not in label_leg: patch_leg.append(Patch(color=STATOR_COLOR)) label_leg.append("Stator") - axes.set_title("Stator with empty slot") + ax.set_title("Stator with empty slot") elif not self.is_stator and "Rotor" not in label_leg: patch_leg.append(Patch(color=ROTOR_COLOR)) label_leg.append("Rotor") - axes.set_title("Rotor with empty slot") + ax.set_title("Rotor with empty slot") - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax else: return patches diff --git a/pyleecan/Methods/Machine/LamSlotMag/plot.py b/pyleecan/Methods/Machine/LamSlotMag/plot.py index 68d5f6021..65b16176c 100644 --- a/pyleecan/Methods/Machine/LamSlotMag/plot.py +++ b/pyleecan/Methods/Machine/LamSlotMag/plot.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- - from matplotlib.patches import Patch -from matplotlib.pyplot import axis, legend import matplotlib.pyplot as plt from ....Functions.init_fig import init_fig from ....definitions import config_dict @@ -21,8 +18,11 @@ def plot( alpha=0, delta=0, is_edge_only=False, + edgecolor=None, + is_add_arrow=False, is_show_fig=True, win_title=None, + is_legend=True, ): """Plot a Lamination with Magnets in a matplotlib fig @@ -44,14 +44,21 @@ def plot( Complex value for translation is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True is_show_fig : bool To call show at the end of the method win_title : str Window title + is_legend : bool + True to add the legend Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ if self.is_stator: @@ -61,7 +68,7 @@ def plot( Lam_Name = "Rotor" lam_color = ROTOR_COLOR - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") # Get the lamination surfaces surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta) @@ -69,28 +76,38 @@ def plot( for surf in surf_list: label_dict = decode_label(surf.label) if LAM_LAB in label_dict["surf_type"]: - patches.extend(surf.get_patches(color=lam_color, is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches( + color=lam_color, is_edge_only=is_edge_only, edgecolor=edgecolor + ) + ) elif MAG_LAB in label_dict["surf_type"]: if not is_lam_only: patches.extend( - surf.get_patches(color=MAGNET_COLOR, is_edge_only=is_edge_only) + surf.get_patches( + color=MAGNET_COLOR, + is_edge_only=is_edge_only, + edgecolor=edgecolor, + ) ) else: - patches.extend(surf.get_patches(is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches(is_edge_only=is_edge_only, edgecolor=edgecolor) + ) # Display the result - (fig, axes, patch_leg, label_leg) = init_fig(fig) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") + (fig, ax, patch_leg, label_leg) = init_fig(fig) + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Axis Setup - axes.axis("equal") + ax.axis("equal") # The Lamination is centered in the figure Lim = self.Rext * 1.5 - axes.set_xlim(-Lim, Lim) - axes.set_ylim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) # Window title if ( @@ -110,14 +127,17 @@ def plot( if self.is_stator: patch_leg.append(Patch(color=STATOR_COLOR)) label_leg.append("Stator") - axes.set_title("Stator with Magnet") + ax.set_title("Stator with Magnet") else: patch_leg.append(Patch(color=ROTOR_COLOR)) label_leg.append("Rotor") - axes.set_title("Rotor with Magnet") + ax.set_title("Rotor with Magnet") if not is_lam_only: patch_leg.append(Patch(color=MAGNET_COLOR)) label_leg.append("Magnet") - legend(patch_leg, label_leg) + + if is_legend: + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Machine/LamSlotMulti/plot.py b/pyleecan/Methods/Machine/LamSlotMulti/plot.py index 8691609e1..a2d23d1ce 100644 --- a/pyleecan/Methods/Machine/LamSlotMulti/plot.py +++ b/pyleecan/Methods/Machine/LamSlotMulti/plot.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- - from matplotlib.patches import Patch -from matplotlib.pyplot import axis, legend from ....Functions.labels import decode_label, LAM_LAB from ....Functions.init_fig import init_fig @@ -20,6 +17,8 @@ def plot( alpha=0, delta=0, is_edge_only=False, + edgecolor=None, + is_add_arrow=False, is_display=True, is_show_fig=True, ): @@ -43,14 +42,19 @@ def plot( Complex value for translation is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True is_display : bool False to return the patches is_show_fig : bool To call show at the end of the method + Returns ------- - patches : list - List of Patches + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ if self.is_stator: @@ -58,45 +62,52 @@ def plot( else: lam_color = ROTOR_COLOR - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta) patches = list() for surf in surf_list: label_dict = decode_label(surf.label) if LAM_LAB in label_dict["surf_type"]: - patches.extend(surf.get_patches(color=lam_color, is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches( + color=lam_color, is_edge_only=is_edge_only, edgecolor=edgecolor + ) + ) else: - patches.extend(surf.get_patches(is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches(is_edge_only=is_edge_only, edgecolor=edgecolor) + ) # Display the result if is_display: - (fig, axes, patch_leg, label_leg) = init_fig(fig) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") + (fig, ax, patch_leg, label_leg) = init_fig(fig) + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Axis Setup - axes.axis("equal") + ax.axis("equal") # The Lamination is centered in the figure Lim = self.Rext * 1.5 - axes.set_xlim(-Lim, Lim) - axes.set_ylim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) # Add the legend if not is_edge_only: if self.is_stator: patch_leg.append(Patch(color=STATOR_COLOR)) label_leg.append("Stator") - axes.set_title("Stator with empty slot") + ax.set_title("Stator with empty slot") else: patch_leg.append(Patch(color=ROTOR_COLOR)) label_leg.append("Rotor") - axes.set_title("Rotor with empty slot") + ax.set_title("Rotor with empty slot") - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax else: return patches diff --git a/pyleecan/Methods/Machine/LamSlotMultiWind/plot.py b/pyleecan/Methods/Machine/LamSlotMultiWind/plot.py index f8fd2ecaa..e4adfdb37 100644 --- a/pyleecan/Methods/Machine/LamSlotMultiWind/plot.py +++ b/pyleecan/Methods/Machine/LamSlotMultiWind/plot.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- - from matplotlib.patches import Patch -from matplotlib.pyplot import axis, legend import matplotlib.pyplot as plt from ....Functions.labels import decode_label, WIND_LAB, BAR_LAB, LAM_LAB @@ -27,6 +24,8 @@ def plot( alpha=0, delta=0, is_edge_only=False, + edgecolor=None, + is_add_arrow=False, is_display=True, is_add_sign=False, is_show_fig=True, @@ -53,14 +52,21 @@ def plot( Complex value for translation is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True is_display : bool False to return the patches is_show_fig : bool To call show at the end of the method + Returns ------- patches : list List of Patches + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ if self.is_stator: @@ -68,7 +74,7 @@ def plot( else: lam_color = ROTOR_COLOR - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") # getting the number of phases and winding connection matrix if self.winding is not None: @@ -92,7 +98,11 @@ def plot( for surf in surf_list: label_dict = decode_label(surf.label) if LAM_LAB in label_dict["surf_type"]: - patches.extend(surf.get_patches(color=lam_color, is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches( + color=lam_color, is_edge_only=is_edge_only, edgecolor=edgecolor + ) + ) elif WIND_LAB in label_dict["surf_type"] or BAR_LAB in label_dict["surf_type"]: if not is_lam_only: color, sign = find_wind_phase_color(wind_mat=wind_mat, label=surf.label) @@ -104,22 +114,27 @@ def plot( hatch = None patches.extend( surf.get_patches( - color=color, is_edge_only=is_edge_only, hatch=hatch + color=color, + is_edge_only=is_edge_only, + hatch=hatch, + edgecolor=edgecolor, ) ) else: - patches.extend(surf.get_patches(is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches(is_edge_only=is_edge_only, edgecolor=edgecolor) + ) # Display the result if is_display: - (fig, axes, patch_leg, label_leg) = init_fig(fig) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") + (fig, ax, patch_leg, label_leg) = init_fig(fig) + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Axis Setup - axes.axis("equal") + ax.axis("equal") # Window title if self.is_stator: @@ -140,19 +155,19 @@ def plot( # The Lamination is centered in the figure Lim = self.Rext * 1.5 - axes.set_xlim(-Lim, Lim) - axes.set_ylim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) # Add the legend if not is_edge_only: if self.is_stator and "Stator" not in label_leg: patch_leg.append(Patch(color=STATOR_COLOR)) label_leg.append("Stator") - axes.set_title("Stator with empty slot") + ax.set_title("Stator with empty slot") elif not self.is_stator and "Rotor" not in label_leg: patch_leg.append(Patch(color=ROTOR_COLOR)) label_leg.append("Rotor") - axes.set_title("Rotor with Winding") + ax.set_title("Rotor with Winding") # Add the winding legend only if needed if not is_lam_only: if isinstance(self.winding, WindingSC): @@ -180,12 +195,13 @@ def plot( Patch(color=PHASE_COLORS[index], hatch=MINUS_HATCH) ) label_leg.append(phase_name[ii] + " -") - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax else: return patches diff --git a/pyleecan/Methods/Machine/LamSlotWind/plot.py b/pyleecan/Methods/Machine/LamSlotWind/plot.py index c776165d1..229e88e8d 100644 --- a/pyleecan/Methods/Machine/LamSlotWind/plot.py +++ b/pyleecan/Methods/Machine/LamSlotWind/plot.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- - from matplotlib.patches import Patch -from matplotlib.pyplot import axis, legend import matplotlib.pyplot as plt from ....Functions.labels import decode_label, WIND_LAB, BAR_LAB, LAM_LAB, WEDGE_LAB @@ -10,7 +7,6 @@ from ....Functions.init_fig import init_fig from ....definitions import config_dict from ....Classes.WindingSC import WindingSC -from ....Classes.Winding import Winding PHASE_COLORS = config_dict["PLOT"]["COLOR_DICT"]["PHASE_COLORS"] ROTOR_COLOR = config_dict["PLOT"]["COLOR_DICT"]["ROTOR_COLOR"] @@ -31,11 +27,14 @@ def plot( alpha=0, delta=0, is_edge_only=False, + edgecolor=None, + is_add_arrow=False, is_display=True, is_add_sign=True, is_show_fig=True, save_path=None, win_title=None, + is_legend=True, ): """Plot the Lamination in a matplotlib fig @@ -57,6 +56,8 @@ def plot( Complex value for translation is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True is_display : bool False to return the patches is_add_sign : bool @@ -67,10 +68,17 @@ def plot( full path including folder, name and extension of the file to save if save_path is not None win_title : str Title for the window + is_legend : bool + True to add the legend + Returns ------- patches : list List of Patches + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ if self.is_stator: color_lam = STATOR_COLOR @@ -100,7 +108,11 @@ def plot( for surf in surf_list: label_dict = decode_label(surf.label) if LAM_LAB in label_dict["surf_type"]: - patches.extend(surf.get_patches(color_lam, is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches( + color_lam, is_edge_only=is_edge_only, edgecolor=edgecolor + ) + ) elif WIND_LAB in label_dict["surf_type"] or BAR_LAB in label_dict["surf_type"]: if not is_lam_only: color, sign = find_wind_phase_color(wind_mat=wind_mat, label=surf.label) @@ -112,23 +124,30 @@ def plot( hatch = None patches.extend( surf.get_patches( - color=color, is_edge_only=is_edge_only, hatch=hatch + color=color, + is_edge_only=is_edge_only, + hatch=hatch, + edgecolor=edgecolor, ) ) elif WEDGE_LAB in label_dict["surf_type"] and not is_lam_only: patches.extend(surf.get_patches(WEDGE_COLOR, is_edge_only=is_edge_only)) else: - patches.extend(surf.get_patches(is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches(is_edge_only=is_edge_only, edgecolor=edgecolor) + ) if is_display: + # Display the result - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") + + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Axis Setup - axes.axis("equal") + ax.axis("equal") # Window title if self.is_stator: @@ -149,19 +168,22 @@ def plot( # The Lamination is centered in the figure Lim = self.Rext * 1.5 - axes.set_xlim(-Lim, Lim) - axes.set_ylim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) + + title = None # Add the legend if not is_edge_only: if self.is_stator and "Stator" not in label_leg: patch_leg.append(Patch(color=STATOR_COLOR)) label_leg.append("Stator") - axes.set_title("Stator with Winding") + title = "Stator with winding" elif not self.is_stator and "Rotor" not in label_leg: patch_leg.append(Patch(color=ROTOR_COLOR)) label_leg.append("Rotor") - axes.set_title("Rotor with Winding") + title = "Rotor with winding" + ax.set_title(title) # Add the wedges legend only if needed if ( self.slot is not None @@ -197,11 +219,15 @@ def plot( Patch(color=PHASE_COLORS[index], hatch=MINUS_HATCH) ) label_leg.append(phase_name[ii] + " -") - legend(patch_leg, label_leg) + + if is_legend: + ax.legend(patch_leg, label_leg) + if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax else: return patches diff --git a/pyleecan/Methods/Machine/LamSlotWind/plot_winding.py b/pyleecan/Methods/Machine/LamSlotWind/plot_winding.py index 0cced73ea..74b7c59c3 100644 --- a/pyleecan/Methods/Machine/LamSlotWind/plot_winding.py +++ b/pyleecan/Methods/Machine/LamSlotWind/plot_winding.py @@ -2,7 +2,7 @@ from matplotlib.lines import Line2D import matplotlib.pyplot as plt -from matplotlib.pyplot import axis, legend, plot, subplots, title +from matplotlib.pyplot import plot, subplots from numpy import array, linspace, meshgrid from ....Functions.Winding.gen_phase_list import gen_color, gen_name @@ -118,9 +118,9 @@ def plot_winding( else: Lam_Name = "Rotor" if all_slot or Nperw == 1: - title(Lam_Name + "'s Winding (every slot)") + ax.set_title(Lam_Name + "'s Winding (every slot)") else: - title(Lam_Name + "'s Winding (periodicity 1/" + str(Nperw) + ")") + ax.set_title(Lam_Name + "'s Winding (periodicity 1/" + str(Nperw) + ")") # Window title if ( @@ -135,7 +135,7 @@ def plot_winding( if manager is not None: manager.set_window_title(win_title) - axis("equal") + ax.axis("equal") ax.get_yaxis().set_visible(False) # Legend qs @@ -168,11 +168,12 @@ def plot_winding( ) label_leg.append(qs_name[q] + "-") - legend(sym_leg, label_leg, ncol=2) + ax.legend(sym_leg, label_leg, ncol=2) if is_show_fig: fig.show() if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) + return fig, ax diff --git a/pyleecan/Methods/Machine/LamSquirrelCage/plot.py b/pyleecan/Methods/Machine/LamSquirrelCage/plot.py index 5847dc0f8..d8c0f6fa2 100644 --- a/pyleecan/Methods/Machine/LamSquirrelCage/plot.py +++ b/pyleecan/Methods/Machine/LamSquirrelCage/plot.py @@ -1,8 +1,4 @@ -# -*- coding: utf-8 -*- - -from matplotlib.patches import Patch, Polygon, Wedge -from matplotlib.pyplot import axis, legend -from numpy import array, exp, pi +from matplotlib.patches import Patch, Wedge from ....Classes.LamSlotWind import LamSlotWind from ....Functions.init_fig import init_fig from ....definitions import config_dict @@ -20,6 +16,8 @@ def plot( alpha=0, delta=0, is_edge_only=False, + edgecolor=None, + is_add_arrow=False, is_show_fig=True, ): """Plot the Lamination in a matplotlib fig @@ -42,22 +40,27 @@ def plot( Complex value for translation is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True is_show_fig : bool To call show at the end of the method Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Lamination and ventilation ducts patches - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") # Plot the lamination LamSlotWind.plot( self, fig=fig, - ax=axes, + ax=ax, is_lam_only=is_lam_only, sym=sym, alpha=alpha, @@ -67,7 +70,7 @@ def plot( ) # init figure again to get updated label_leg and patch_leg - (fig, axes, patch_leg, label_leg) = init_fig(fig, ax=axes) + (fig, ax, patch_leg, label_leg) = init_fig(fig, ax=ax) # setup the patch of the short circuit ring if needed patches = list() @@ -88,27 +91,28 @@ def plot( pass # Display the result - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") - axes.set_title("Squirrel Cage Rotor") + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") + ax.set_title("Squirrel Cage Rotor") # Axis Setup - axes.axis("equal") + ax.axis("equal") Lim = self.Rext * 1.5 - axes.set_xlim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) if sym == 1: - axes.set_ylim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) else: - axes.set_ylim(-Lim * 0.3, Lim) + ax.set_ylim(-Lim * 0.3, Lim) if not is_lam_only: # Add the short ciruit ring to the fig for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) if "Short Circuit Ring" not in label_leg: patch_leg.append(Patch(color=SCR_COLOR)) label_leg.append("Short Circuit Ring") - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Machine/LamSquirrelCage/plot_schematics_scr.py b/pyleecan/Methods/Machine/LamSquirrelCage/plot_schematics_scr.py index 69b17ecd4..e1c9a1dc3 100644 --- a/pyleecan/Methods/Machine/LamSquirrelCage/plot_schematics_scr.py +++ b/pyleecan/Methods/Machine/LamSquirrelCage/plot_schematics_scr.py @@ -31,6 +31,8 @@ def plot_schematics_scr( is_add_main_line=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the short circuit ring @@ -48,6 +50,17 @@ def plot_schematics_scr( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Use some default parameter @@ -69,12 +82,12 @@ def plot_schematics_scr( is_add_main_line=is_add_main_line, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot - self.plot_side(is_show_fig=False) - fig = plt.gcf() - ax = plt.gca() + fig, ax = self.plot_side(is_show_fig=False, fig=fig, ax=ax) Lt = self.comp_length() Hs = self.slot.comp_height() Ha = self.slot.comp_height_active() @@ -168,7 +181,7 @@ def plot_schematics_scr( linewidth=MAIN_LINE_WIDTH, ) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Lt / 4, (Lt / 2 + Le + Lscr) * 1.1) # ax.set_ylim(-self.Rext, self.Rext) manager = plt.get_current_fig_manager() @@ -181,7 +194,8 @@ def plot_schematics_scr( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Machine/LamSquirrelCage/plot_side.py b/pyleecan/Methods/Machine/LamSquirrelCage/plot_side.py index 9f0f956e8..d8a90febd 100644 --- a/pyleecan/Methods/Machine/LamSquirrelCage/plot_side.py +++ b/pyleecan/Methods/Machine/LamSquirrelCage/plot_side.py @@ -28,11 +28,14 @@ def plot_side(self, fig=None, ax=None, is_show_fig=True, save_path=None): Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Lamination and ventilation ducts patches - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax) + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax) patches = list() # List of patches to draw the lamination if self.is_stator: @@ -143,14 +146,14 @@ def plot_side(self, fig=None, ax=None, is_show_fig=True, save_path=None): ) # Display the result - axes.set_xlabel("[m]") - axes.set_ylabel("[m]") + ax.set_xlabel("[m]") + ax.set_ylabel("[m]") for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Axis Setup - axes.axis("equal") - axes.set_title("Squirrel Cage Rotor side view") + ax.axis("equal") + ax.set_title("Squirrel Cage Rotor side view") # Set legend if self.is_stator: patch_leg.append(Patch(color=STATOR_COLOR)) @@ -162,9 +165,10 @@ def plot_side(self, fig=None, ax=None, is_show_fig=True, save_path=None): label_leg.append("Bar") patch_leg.append(Patch(color=SCR_COLOR)) label_leg.append("Short Circuit Ring") - axes.legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) + return fig, ax diff --git a/pyleecan/Methods/Machine/LamSquirrelCageMag/plot.py b/pyleecan/Methods/Machine/LamSquirrelCageMag/plot.py index f2245bcfb..3f5a329c4 100644 --- a/pyleecan/Methods/Machine/LamSquirrelCageMag/plot.py +++ b/pyleecan/Methods/Machine/LamSquirrelCageMag/plot.py @@ -1,8 +1,4 @@ -# -*- coding: utf-8 -*- - -from matplotlib.patches import Patch, Polygon, Wedge -from matplotlib.pyplot import axis, legend -from numpy import array, exp, pi +from matplotlib.patches import Patch from ....Functions.labels import decode_label, HOLEM_LAB, HOLEV_LAB from ....Functions.init_fig import init_fig @@ -22,6 +18,8 @@ def plot( alpha=0, delta=0, is_edge_only=False, + edgecolor=None, + is_add_arrow=False, is_show_fig=True, ): """Plot the Lamination in a matplotlib fig @@ -44,16 +42,21 @@ def plot( Complex value for translation is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True is_show_fig : bool To call show at the end of the method Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Lamination and ventilation ducts patches - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") # Plot the lamination super(type(self), self).plot( @@ -67,7 +70,7 @@ def plot( ) # init figure again to get updated label_leg and patch_leg - (fig, axes, patch_leg, label_leg) = init_fig(fig) + (fig, ax, patch_leg, label_leg) = init_fig(fig) # Add Hole related surfaces surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta) @@ -76,26 +79,30 @@ def plot( label_dict = decode_label(surf.label) if HOLEM_LAB in label_dict["surf_type"] and not is_lam_only: patches.extend( - surf.get_patches(color=MAGNET_COLOR, is_edge_only=is_edge_only) + surf.get_patches( + color=MAGNET_COLOR, is_edge_only=is_edge_only, edgecolor=edgecolor + ) ) elif HOLEV_LAB in label_dict["surf_type"]: - patches.extend(surf.get_patches(is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches(is_edge_only=is_edge_only, edgecolor=edgecolor) + ) for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Display the result - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") - axes.set_title("Squirrel Cage Rotor with Magnets") + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") + ax.set_title("Squirrel Cage Rotor with Magnets") # Axis Setup - axes.axis("equal") + ax.axis("equal") Lim = self.Rext * 1.5 - axes.set_xlim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) if sym == 1: - axes.set_ylim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) else: - axes.set_ylim(-Lim * 0.3, Lim) + ax.set_ylim(-Lim * 0.3, Lim) if not is_lam_only: # Add the short ciruit ring to the fig @@ -105,6 +112,7 @@ def plot( if "Magnet" not in label_leg: patch_leg.append(Patch(color=MAGNET_COLOR)) label_leg.append("Magnet") - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Machine/Lamination/plot.py b/pyleecan/Methods/Machine/Lamination/plot.py index acd68a0c2..49f4af4ea 100644 --- a/pyleecan/Methods/Machine/Lamination/plot.py +++ b/pyleecan/Methods/Machine/Lamination/plot.py @@ -1,8 +1,5 @@ -# -*- coding: utf-8 -*- - import matplotlib.pyplot as plt from matplotlib.patches import Patch -from matplotlib.pyplot import axis, legend from ....Functions.init_fig import init_fig from ....definitions import config_dict @@ -22,6 +19,8 @@ def plot( alpha=0, delta=0, is_edge_only=False, + edgecolor=None, + is_add_arrow=False, is_show_fig=True, save_path=None, ): @@ -45,6 +44,8 @@ def plot( Complex value for translation is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True is_show_fig : bool To call show at the end of the method save_path : str @@ -52,13 +53,16 @@ def plot( Returns ------- - + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ if self.is_stator: lam_color = STATOR_COLOR else: lam_color = ROTOR_COLOR - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta) patches = list() @@ -66,44 +70,53 @@ def plot( # Color Selection for Lamination for surf in surf_list: if surf.label is not None and "Lamination" in surf.label: - patches.extend(surf.get_patches(color=lam_color, is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches( + color=lam_color, is_edge_only=is_edge_only, edgecolor=edgecolor + ) + ) elif surf.label is not None and "Ventilation_" in surf.label: patches.extend( surf.get_patches( - color=VENT_COLOR, edgecolor=VENT_EDGE, is_edge_only=is_edge_only + color=VENT_COLOR, edgecolor=edgecolor, is_edge_only=is_edge_only ) ) else: - patches.extend(surf.get_patches(is_edge_only=is_edge_only)) + patches.extend( + surf.get_patches(is_edge_only=is_edge_only, edgecolor=edgecolor) + ) # Display the result - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Axis Setup - axes.axis("equal") + ax.axis("equal") # The Lamination is centered in the figure Lim = self.Rext * 1.5 - axes.set_xlim(-Lim, Lim) - axes.set_ylim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) + + title = None # Adding legend if not is_edge_only: if self.is_stator: patch_leg.append(Patch(color=STATOR_COLOR)) label_leg.append("Stator") - axes.set_title("Stator without slot") + title = "Stator without slot" else: patch_leg.append(Patch(color=ROTOR_COLOR)) label_leg.append("Rotor") - axes.set_title("Rotor without slot") - - legend(patch_leg, label_leg) + title = "Rotor without slot" + ax.set_title(title) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) + return fig, ax diff --git a/pyleecan/Methods/Machine/Machine/plot.py b/pyleecan/Methods/Machine/Machine/plot.py index 88a2be18a..0d61471f7 100644 --- a/pyleecan/Methods/Machine/Machine/plot.py +++ b/pyleecan/Methods/Machine/Machine/plot.py @@ -1,6 +1,11 @@ -# -*- coding: utf-8 -*- import matplotlib.pyplot as plt from ....Functions.init_fig import init_fig +from matplotlib.patches import Patch +from ....definitions import config_dict + +REF_EDGE_COLOR = "k" +COMP_EDGE_COLOR = "r--" +PATCH_COLOR_ALPHA = config_dict["PLOT"]["COLOR_DICT"]["PATCH_COLOR_ALPHA"] def plot( @@ -11,10 +16,14 @@ def plot( alpha=0, delta=0, is_edge_only=False, + edgecolor=None, + is_add_arrow=False, comp_machine=None, + comp_legend=None, is_show_fig=True, save_path=None, win_title=None, + fig_title=None, is_max_sym=False, ): """Plot the Machine in a matplotlib fig @@ -35,23 +44,37 @@ def plot( Complex value for translation is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True comp_machine : Machine A machine to plot in transparency on top of the self machine + comp_legend : str + Name of the compare machine to set in the legeng (comp_machine != None) is_show_fig : bool To call show at the end of the method save_path : str full path including folder, name and extension of the file to save if save_path is not None win_title : str Name of the Window (default machine name) + fig_title : str + Name of the figure (default machine name) is_max_sym : bool True: overwrite sym parameter with max periodicity of the machine + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ + # Get maximum symetry for plot if is_max_sym: pera, is_apera = self.comp_periodicity_spatial() sym = 2 * pera if is_apera else pera - (fig, ax, _, _) = init_fig(fig=fig, ax=ax, shape="rectangle") + (fig, ax, _, _) = init_fig(fig=fig, ax=ax, shape="square") # Call each plot method to properly set the legend if self.frame is not None: @@ -62,6 +85,7 @@ def plot( alpha=alpha, delta=delta, is_edge_only=is_edge_only, + edgecolor=edgecolor, is_show_fig=False, ) Wfra = self.frame.comp_height_eq() @@ -80,10 +104,12 @@ def plot( alpha=alpha, delta=delta, is_edge_only=is_edge_only, + edgecolor=edgecolor, + is_add_arrow=is_add_arrow, is_show_fig=False, ) - if lam_list[0].Rint > 0 and self.shaft is not None: + if lam_list[0].Rint > 0 and self.shaft is not None and self.shaft.Drsh is not None: self.shaft.plot( fig=fig, ax=ax, @@ -91,11 +117,10 @@ def plot( alpha=alpha, delta=delta, is_edge_only=is_edge_only, + edgecolor=edgecolor, is_show_fig=False, ) - Lim = (Rext + Wfra) * 1.5 # Axes limit for plot - if comp_machine is not None: comp_machine.rotor.plot( fig, @@ -104,6 +129,8 @@ def plot( alpha=alpha, delta=delta, is_edge_only=True, + edgecolor=COMP_EDGE_COLOR, + is_add_arrow=is_add_arrow, is_show_fig=is_show_fig, ) comp_machine.stator.plot( @@ -113,19 +140,40 @@ def plot( alpha=alpha, delta=delta, is_edge_only=True, + edgecolor=COMP_EDGE_COLOR, + is_add_arrow=is_add_arrow, is_show_fig=is_show_fig, ) - - ax.set_xlabel("(m)") - ax.set_ylabel("(m)") - ax.set_title(self.name) + patch_leg = [ + Patch(facecolor=PATCH_COLOR_ALPHA, edgecolor="k"), + Patch(facecolor=PATCH_COLOR_ALPHA, edgecolor="r", linestyle="--"), + ] + if comp_legend is None: + comp_legend = "Compared machine" + label_leg = ["Reference", comp_legend] + ax.set_axis_off() + ax.legend(patch_leg, label_leg) + + ax.set_xlabel("Position along x-axis [m]") + ax.set_ylabel("Position along y-axis [m]") + if fig_title is None: + fig_title = self.name + ax.set_title(fig_title) # Axis Setup - plt.axis("equal") + ax.axis("equal") # The Lamination is centered in the figure - ax.set_xlim(-Lim, Lim) - ax.set_ylim(-Lim, Lim) + Lim = (Rext + Wfra) * 1.5 # Axes limit for plot + if sym > 2: + ax.set_xlim(-Lim * 0.1, Lim) + ax.set_ylim(-Lim * 0.1, Lim) + elif sym == 2: + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim * 0.1, Lim) + else: + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) # Set Windows title if self.name not in ["", None] and win_title is None: @@ -133,7 +181,7 @@ def plot( if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() @@ -142,3 +190,4 @@ def plot( manager = plt.get_current_fig_manager() if manager is not None: manager.set_window_title(win_title) + return fig, ax diff --git a/pyleecan/Methods/Machine/Machine/plot_anim_rotor.py b/pyleecan/Methods/Machine/Machine/plot_anim_rotor.py index fb9d8137e..59cf28510 100644 --- a/pyleecan/Methods/Machine/Machine/plot_anim_rotor.py +++ b/pyleecan/Methods/Machine/Machine/plot_anim_rotor.py @@ -1,8 +1,8 @@ from numpy import pi import matplotlib.pyplot as plt import matplotlib.animation as animation -from matplotlib.pyplot import axis, subplots -from matplotlib.patches import Polygon, Circle +from matplotlib.pyplot import subplots +from matplotlib.patches import Polygon def plot_anim_rotor(self, Nframe, Tanim, Nrot=1, is_loop=True): @@ -30,7 +30,7 @@ def plot_anim_rotor(self, Nframe, Tanim, Nrot=1, is_loop=True): axes.set_title("Machine") # Axis Setup - axis("equal") + axes.axis("equal") # The Lamination is centered in the figure Lim = (self.stator.Rext) * 1.5 # Axes limit for plot diff --git a/pyleecan/Methods/Machine/Shaft/plot.py b/pyleecan/Methods/Machine/Shaft/plot.py index 3dc354eaf..a99d06188 100644 --- a/pyleecan/Methods/Machine/Shaft/plot.py +++ b/pyleecan/Methods/Machine/Shaft/plot.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- - from matplotlib.patches import Patch -from matplotlib.pyplot import axis, legend from ....Functions.init_fig import init_fig from ....definitions import config_dict @@ -17,6 +14,7 @@ def plot( alpha=0, delta=0, is_edge_only=False, + edgecolor=None, is_show_fig=True, ): """Plot the Shaft in a matplotlib fig @@ -37,37 +35,47 @@ def plot( Complex value for translation is_edge_only: bool To plot transparent Patches + edgecolor: + Color of the edges if is_edge_only=True is_show_fig : bool To call show at the end of the method Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ - (fig, axes, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") + (fig, ax, patch_leg, label_leg) = init_fig(fig=fig, ax=ax, shape="rectangle") # Get the shaft surface(s) surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta) patches = list() for surf in surf_list: - patches.extend(surf.get_patches(color=SHAFT_COLOR, is_edge_only=is_edge_only)) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") - axes.set_title("Shaft") + patches.extend( + surf.get_patches( + color=SHAFT_COLOR, is_edge_only=is_edge_only, edgecolor=edgecolor + ) + ) + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") + ax.set_title("Shaft") for patch in patches: - axes.add_patch(patch) - axis("equal") + ax.add_patch(patch) + ax.axis("equal") # The Lamination is centered in the figure Lim = self.Drsh * 0.6 - axes.set_xlim(-Lim, Lim) - axes.set_ylim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) # Add legend if not is_edge_only: patch_leg.append(Patch(color=SHAFT_COLOR)) label_leg.append("Shaft") - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Optimization/OptiBayesAlgSmoot/plot_pareto.py b/pyleecan/Methods/Optimization/OptiBayesAlgSmoot/plot_pareto.py index 7799219d6..9d6b552e9 100644 --- a/pyleecan/Methods/Optimization/OptiBayesAlgSmoot/plot_pareto.py +++ b/pyleecan/Methods/Optimization/OptiBayesAlgSmoot/plot_pareto.py @@ -95,7 +95,7 @@ def plot_pareto( if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() diff --git a/pyleecan/Methods/Optimization/OptiGenAlgNsga2Deap/plot_pareto.py b/pyleecan/Methods/Optimization/OptiGenAlgNsga2Deap/plot_pareto.py index ad229f199..812173c7d 100644 --- a/pyleecan/Methods/Optimization/OptiGenAlgNsga2Deap/plot_pareto.py +++ b/pyleecan/Methods/Optimization/OptiGenAlgNsga2Deap/plot_pareto.py @@ -174,7 +174,7 @@ def hover(event): if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() diff --git a/pyleecan/Methods/Output/XOutput/plot_multi.py b/pyleecan/Methods/Output/XOutput/plot_multi.py index a619a879f..3e5bff288 100644 --- a/pyleecan/Methods/Output/XOutput/plot_multi.py +++ b/pyleecan/Methods/Output/XOutput/plot_multi.py @@ -27,15 +27,20 @@ def plot_multi( cmap=None, plot_type="point", idx=None, + fig=None, ax=None, title=None, is_show_fig=True, save_path=None, win_title=None, ): - """ - Plot data from a DataKeeper for a given parameter from a ParamExplorer + """2D Plot from a DataKeeper / OptiObjective / ParamExplorer as a function of another + DataKeeper / OptiObjective / ParamExplorer + Parameters + ---------- + self : XOutput + XOutput object x_symbol: str ParamExplorer or DataKeeper symbol y_symbol: str @@ -48,18 +53,25 @@ def plot_multi( scatter or plot to chose plot type idx: slice To plot only some data - ax: matplotlib.pyplot.Axe - To put the plot in a specific ax + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + ax on which to plot the data title: str Figure or subfigure title according to ax is_show_fig : bool True to show figure after plot save_path : str full path of the png file where the figure is saved if save_path is not None + win_title : str + Title of the plot window Returns ------- - fig or ax + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot Raises ------ @@ -93,7 +105,7 @@ def plot_multi( cmap = COLORMAP # call plot_2D function - plot_2D( + fig, ax = plot_2D( Xdatas=[x_values], Ydatas=[y_values], xlabel=x_label, @@ -105,43 +117,11 @@ def plot_multi( save_path=save_path, is_show_fig=is_show_fig, win_title=win_title, + fig=fig, + ax=ax, font_name=FONT_NAME, font_size_title=FONT_SIZE_TITLE, font_size_label=FONT_SIZE_LABEL, font_size_legend=FONT_SIZE_LEGEND, ) - # RET_FIG = False - # if ax is None: - # fig, ax = plt.subplots() - # fig.suptitle(title, fontname=FONT_NAME) - # RET_FIG = True - # else: - # ax.set_title(title, fontname=FONT_NAME) - - # # plot - # if plot_type == "scatter": - # plot = ax.scatter(x_values, y_values, c=colors) - # elif plot_type == "curve": - # sort_index = np.argsort(x_values) - # plot = ax.plot(x_values[sort_index], y_values[sort_index], c=colors) - - # # add legend - # if c_symbol is not None: - # legend1 = ax.legend(*plot.legend_elements(), loc="upper right", title=c_symbol) - # ax.add_artist(legend1) - - # ax.set_xlabel(x_label, fontname=FONT_NAME) - # ax.set_ylabel(y_label, fontname=FONT_NAME) - - # if save_path is not None: - # fig.savefig(save_path) - # plt.close() - - # if is_show_fig: - # fig.show() - - # # return - # if RET_FIG: - # return fig - # else: - # return ax + return fig, ax diff --git a/pyleecan/Methods/Simulation/DataKeeper/_set_keeper.py b/pyleecan/Methods/Simulation/DataKeeper/_set_keeper.py index 90b8877e0..d37830de7 100644 --- a/pyleecan/Methods/Simulation/DataKeeper/_set_keeper.py +++ b/pyleecan/Methods/Simulation/DataKeeper/_set_keeper.py @@ -3,6 +3,10 @@ from ....Functions.path_tools import abs_file_path from ....Generator import PYTHON_DEFAULT_ENCODING +# Import numpy to be usable in the fct/lambda +import numpy as np +from numpy import sqrt, pi + def _set_keeper(self, value): """setter of keeper""" diff --git a/pyleecan/Methods/Slot/Hole/__init__.py b/pyleecan/Methods/Slot/Hole/__init__.py index 814dc8e20..8b1eec6aa 100644 --- a/pyleecan/Methods/Slot/Hole/__init__.py +++ b/pyleecan/Methods/Slot/Hole/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- -def MagnetIndexError(Exception): +class MagnetIndexError(Exception): """Raise when trying to access a non existing magnet""" + pass diff --git a/pyleecan/Methods/Slot/Hole/comp_height.py b/pyleecan/Methods/Slot/Hole/comp_height.py index dd25b50c9..307fbf831 100644 --- a/pyleecan/Methods/Slot/Hole/comp_height.py +++ b/pyleecan/Methods/Slot/Hole/comp_height.py @@ -1,9 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import cos, exp -from numpy import abs as np_abs - - def comp_height(self): """Compute the height of the Hole (Rmax-Rmin) diff --git a/pyleecan/Methods/Slot/Hole/comp_radius.py b/pyleecan/Methods/Slot/Hole/comp_radius.py index b93300c27..df0382cf8 100644 --- a/pyleecan/Methods/Slot/Hole/comp_radius.py +++ b/pyleecan/Methods/Slot/Hole/comp_radius.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import cos, exp from numpy import abs as np_abs diff --git a/pyleecan/Methods/Slot/Hole/plot.py b/pyleecan/Methods/Slot/Hole/plot.py index 2cfde5487..6758ebf63 100644 --- a/pyleecan/Methods/Slot/Hole/plot.py +++ b/pyleecan/Methods/Slot/Hole/plot.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- - from matplotlib.patches import Patch -from matplotlib.pyplot import axis, legend from numpy import exp from ....Functions.init_fig import init_fig @@ -11,12 +8,14 @@ from ....Methods import ParentMissingError MAGNET_COLOR = config_dict["PLOT"]["COLOR_DICT"]["MAGNET_COLOR"] +ARROW_COLOR = config_dict["PLOT"]["COLOR_DICT"]["STATOR_COLOR"] def plot( self, fig=None, ax=None, + title=None, display_magnet=True, is_add_arrow=False, is_add_ref=False, @@ -32,6 +31,8 @@ def plot( fig : if None, open a new fig and plot, else add to the current one (Default value = None) + title: str + Figure title display_magnet : bool if True, plot the magnet inside the hole, if there is any (Default value = True) is_add_arrow : bool @@ -43,8 +44,12 @@ def plot( Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ + display = fig is None if display: color = "k" @@ -67,14 +72,16 @@ def plot( patches.extend(surf.get_patches(color=color)) # Display the result - (fig, axes, patch_leg, label_leg) = init_fig(fig, ax) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") - axes.set_title("Hole") - + (fig, ax, patch_leg, label_leg) = init_fig(fig, ax) + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") + if title is None: + ax.set_title("Hole") + else: + ax.set_title(title) # Add all the hole (and magnet) to fig for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Magnetization if is_add_arrow: @@ -95,30 +102,31 @@ def plot( # Create arrow coordinates Z1 = mag_surf.point_ref Z2 = mag_surf.point_ref + H / 5 * exp(1j * mag_dir) - axes.annotate( + ax.annotate( text="", xy=(Z2.real, Z2.imag), xytext=(Z1.real, Z1.imag), - arrowprops=dict(arrowstyle="->", linewidth=1, color="b"), + arrowprops=dict(arrowstyle="->", linewidth=1, color=ARROW_COLOR), ) # Add reference point if is_add_ref: for surf in self.surf_list: - axes.plot(surf.point_ref.real, surf.point_ref.imag, "rx") + ax.plot(surf.point_ref.real, surf.point_ref.imag, "rx") # Axis Setup - axes.axis("equal") + ax.axis("equal") try: Lim = self.get_Rbo() * 1.2 - axes.set_xlim(-Lim, Lim) - axes.set_ylim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) except ParentMissingError: pass if display_magnet and HOLEM_LAB in [surf.label for surf in surf_hole]: patch_leg.append(Patch(color=MAGNET_COLOR)) label_leg.append("Magnet") - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/HoleM50/build_geometry.py b/pyleecan/Methods/Slot/HoleM50/build_geometry.py index 83ebf8dbe..46d00c920 100644 --- a/pyleecan/Methods/Slot/HoleM50/build_geometry.py +++ b/pyleecan/Methods/Slot/HoleM50/build_geometry.py @@ -1,6 +1,6 @@ +from ....Classes.Arc1 import Arc1 from ....Classes.Segment import Segment from ....Classes.SurfLine import SurfLine -from ....Classes.Arc1 import Arc1 from ....Functions.labels import HOLEM_LAB, MAGNET_PROP_LAB diff --git a/pyleecan/Methods/Slot/HoleM50/comp_magnetization_dict.py b/pyleecan/Methods/Slot/HoleM50/comp_magnetization_dict.py index e579ba3b9..3bb6e6821 100644 --- a/pyleecan/Methods/Slot/HoleM50/comp_magnetization_dict.py +++ b/pyleecan/Methods/Slot/HoleM50/comp_magnetization_dict.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- - from numpy import pi -from pyleecan.Classes.Segment import Segment +from ....Classes.Segment import Segment def comp_magnetization_dict(self, is_north=True): diff --git a/pyleecan/Methods/Slot/HoleM50/plot_schematics.py b/pyleecan/Methods/Slot/HoleM50/plot_schematics.py index db4ce0c65..fd6f4c4ec 100644 --- a/pyleecan/Methods/Slot/HoleM50/plot_schematics.py +++ b/pyleecan/Methods/Slot/HoleM50/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -74,7 +87,7 @@ def plot_schematics( lam = LamHole( Rint=0.05532, Rext=0.0812, is_internal=True, is_stator=False, hole=[hole] ) - hole.plot_schematics( + return hole.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -82,12 +95,14 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) elif type_add_active == 0: # Remove magnets lam = self.parent.copy() lam.hole[0].remove_magnet() - lam.hole[0].plot_schematics( + return lam.hole[0].plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -95,6 +110,8 @@ def plot_schematics( type_add_active=2, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot @@ -102,15 +119,15 @@ def plot_schematics( raise ParentMissingError("Error: The hole is not inside a Lamination") lam = self.parent alpha = pi / 2 # To rotate the schematics - lam.plot( + fig, ax = lam.plot( alpha=pi / self.Zh + alpha, is_show_fig=False, is_lam_only=type_add_active == 0, + fig=fig, + ax=ax, ) # center hole on Ox axis sp = 2 * pi / self.Zh Rbo = self.get_Rbo() - fig = plt.gcf() - ax = plt.gca() point_dict = self._comp_point_coordinate() # Adding point label @@ -396,7 +413,7 @@ def plot_schematics( Rint = self.parent.Rint Rext = self.parent.Rext - plt.axis("equal") + ax.axis("equal") ax.set_ylim(Rint, Rext) ax.set_xlim(-W, W) manager = plt.get_current_fig_manager() @@ -409,7 +426,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/HoleM51/build_geometry.py b/pyleecan/Methods/Slot/HoleM51/build_geometry.py index 546474147..d53676c34 100644 --- a/pyleecan/Methods/Slot/HoleM51/build_geometry.py +++ b/pyleecan/Methods/Slot/HoleM51/build_geometry.py @@ -1,9 +1,7 @@ -# -*- coding: utf-8 -*- - from numpy import exp, pi, cos, sin, tan -from ....Classes.Segment import Segment from ....Classes.Arc1 import Arc1 +from ....Classes.Segment import Segment from ....Classes.SurfLine import SurfLine from ....Functions.labels import HOLEV_LAB, HOLEM_LAB diff --git a/pyleecan/Methods/Slot/HoleM51/check.py b/pyleecan/Methods/Slot/HoleM51/check.py index 72f6accd9..b98f4da91 100644 --- a/pyleecan/Methods/Slot/HoleM51/check.py +++ b/pyleecan/Methods/Slot/HoleM51/check.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - -from ....Methods.Slot.Slot import SlotCheckError from numpy import pi from ....Methods.Slot.HoleM51 import * diff --git a/pyleecan/Methods/Slot/HoleM51/comp_alpha.py b/pyleecan/Methods/Slot/HoleM51/comp_alpha.py index fe0d3fd62..c24876a4c 100644 --- a/pyleecan/Methods/Slot/HoleM51/comp_alpha.py +++ b/pyleecan/Methods/Slot/HoleM51/comp_alpha.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- - -from numpy import arctan, cos, sin, pi +from numpy import arctan, cos, sin def comp_alpha(self): diff --git a/pyleecan/Methods/Slot/HoleM51/comp_magnetization_dict.py b/pyleecan/Methods/Slot/HoleM51/comp_magnetization_dict.py index 59995341e..9e97caba9 100644 --- a/pyleecan/Methods/Slot/HoleM51/comp_magnetization_dict.py +++ b/pyleecan/Methods/Slot/HoleM51/comp_magnetization_dict.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- - from numpy import pi -from pyleecan.Classes.Segment import Segment +from ....Classes.Segment import Segment def comp_magnetization_dict(self, is_north=True): diff --git a/pyleecan/Methods/Slot/HoleM51/comp_radius.py b/pyleecan/Methods/Slot/HoleM51/comp_radius.py index 8d24656cb..a6d91f671 100644 --- a/pyleecan/Methods/Slot/HoleM51/comp_radius.py +++ b/pyleecan/Methods/Slot/HoleM51/comp_radius.py @@ -1,8 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import exp - - def comp_radius(self): """Compute the radius of the min and max circle that contains the hole diff --git a/pyleecan/Methods/Slot/HoleM51/plot_schematics.py b/pyleecan/Methods/Slot/HoleM51/plot_schematics.py index fcfa6cace..82f441491 100644 --- a/pyleecan/Methods/Slot/HoleM51/plot_schematics.py +++ b/pyleecan/Methods/Slot/HoleM51/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -75,7 +88,7 @@ def plot_schematics( lam = LamHole( Rint=45e-3 / 2, Rext=81.5e-3, is_internal=True, is_stator=False, hole=[hole] ) - hole.plot_schematics( + return hole.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -83,12 +96,14 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) elif type_add_active == 0: # Remove magnets lam = self.parent.copy() lam.hole[0].remove_magnet() - lam.hole[0].plot_schematics( + return lam.hole[0].plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -96,6 +111,8 @@ def plot_schematics( type_add_active=2, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot @@ -103,15 +120,15 @@ def plot_schematics( raise ParentMissingError("Error: The hole is not inside a Lamination") lam = self.parent alpha = pi / 2 # To rotate the schematics - lam.plot( + fig, ax = lam.plot( alpha=pi / self.Zh + alpha, is_show_fig=False, is_lam_only=type_add_active == 0, + fig=fig, + ax=ax, ) # center hole on Ox axis sp = 2 * pi / self.Zh Rbo = self.get_Rbo() - fig = plt.gcf() - ax = plt.gca() point_dict = self._comp_point_coordinate() # Adding point label @@ -416,7 +433,7 @@ def plot_schematics( Rint = (point_dict["Z13"] * exp(1j * alpha)).imag * 0.9 Rext = self.parent.Rext * 1.1 - plt.axis("equal") + ax.axis("equal") ax.set_ylim(Rint, Rext) ax.set_xlim(-W, W) manager = plt.get_current_fig_manager() @@ -429,7 +446,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/HoleM52/comp_magnetization_dict.py b/pyleecan/Methods/Slot/HoleM52/comp_magnetization_dict.py index 23607229e..70ead18a2 100644 --- a/pyleecan/Methods/Slot/HoleM52/comp_magnetization_dict.py +++ b/pyleecan/Methods/Slot/HoleM52/comp_magnetization_dict.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- - from numpy import pi -from pyleecan.Classes.Segment import Segment +from ....Classes.Segment import Segment def comp_magnetization_dict(self, is_north=True): diff --git a/pyleecan/Methods/Slot/HoleM52/plot_schematics.py b/pyleecan/Methods/Slot/HoleM52/plot_schematics.py index e9be9fc6e..31c79a4a8 100644 --- a/pyleecan/Methods/Slot/HoleM52/plot_schematics.py +++ b/pyleecan/Methods/Slot/HoleM52/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamHole( Rint=45e-3 / 2, Rext=81.5e-3, is_internal=True, is_stator=False, hole=[hole] ) - hole.plot_schematics( + return hole.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,12 +83,14 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) elif type_add_active == 0: # Remove magnets lam = self.parent.copy() lam.hole[0].remove_magnet() - lam.hole[0].plot_schematics( + return lam.hole[0].plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -83,6 +98,8 @@ def plot_schematics( type_add_active=2, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot @@ -90,15 +107,15 @@ def plot_schematics( raise ParentMissingError("Error: The hole is not inside a Lamination") lam = self.parent alpha = pi / 2 # To rotate the schematics - lam.plot( + fig, ax = lam.plot( alpha=pi / self.Zh + alpha, is_show_fig=False, is_lam_only=type_add_active == 0, + fig=fig, + ax=ax, ) # center hole on Ox axis sp = 2 * pi / self.Zh Rbo = self.get_Rbo() - fig = plt.gcf() - ax = plt.gca() point_dict = self._comp_point_coordinate() # Adding point label @@ -275,7 +292,7 @@ def plot_schematics( Rint = (point_dict["Z5"] * exp(1j * alpha)).imag * 0.9 Rext = self.parent.Rext * 1.1 - plt.axis("equal") + ax.axis("equal") ax.set_ylim(Rint, Rext) ax.set_xlim(-W, W) manager = plt.get_current_fig_manager() @@ -288,7 +305,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/HoleM53/comp_magnetization_dict.py b/pyleecan/Methods/Slot/HoleM53/comp_magnetization_dict.py index 915058a8d..1c07fd12b 100644 --- a/pyleecan/Methods/Slot/HoleM53/comp_magnetization_dict.py +++ b/pyleecan/Methods/Slot/HoleM53/comp_magnetization_dict.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- - from numpy import pi -from pyleecan.Classes.Segment import Segment +from ....Classes.Segment import Segment def comp_magnetization_dict(self, is_north=True): diff --git a/pyleecan/Methods/Slot/HoleM53/plot_schematics.py b/pyleecan/Methods/Slot/HoleM53/plot_schematics.py index 89aa312a4..d2f021f71 100644 --- a/pyleecan/Methods/Slot/HoleM53/plot_schematics.py +++ b/pyleecan/Methods/Slot/HoleM53/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -72,7 +85,7 @@ def plot_schematics( lam = LamHole( Rint=0.1, Rext=0.2, is_internal=True, is_stator=False, hole=[hole] ) - hole.plot_schematics( + return hole.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -80,12 +93,14 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) elif type_add_active == 0: # Remove magnets lam = self.parent.copy() lam.hole[0].remove_magnet() - lam.hole[0].plot_schematics( + return lam.hole[0].plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -93,6 +108,8 @@ def plot_schematics( type_add_active=2, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot @@ -100,15 +117,15 @@ def plot_schematics( raise ParentMissingError("Error: The hole is not inside a Lamination") lam = self.parent alpha = pi / 2 # To rotate the schematics - lam.plot( + fig, ax = lam.plot( alpha=pi / self.Zh + alpha, is_show_fig=False, is_lam_only=type_add_active == 0, + fig=fig, + ax=ax, ) # center hole on Ox axis sp = 2 * pi / self.Zh Rbo = self.get_Rbo() - fig = plt.gcf() - ax = plt.gca() point_dict = self._comp_point_coordinate() # Adding point label @@ -324,7 +341,7 @@ def plot_schematics( Rint = point_dict["Z7"].real * 0.9 Rext = self.parent.Rext - plt.axis("equal") + ax.axis("equal") ax.set_ylim(Rint, Rext) ax.set_xlim(-W, W) manager = plt.get_current_fig_manager() @@ -337,7 +354,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/HoleM54/build_geometry.py b/pyleecan/Methods/Slot/HoleM54/build_geometry.py index 6a35f6cf2..3bf59e127 100644 --- a/pyleecan/Methods/Slot/HoleM54/build_geometry.py +++ b/pyleecan/Methods/Slot/HoleM54/build_geometry.py @@ -1,12 +1,8 @@ -# -*- coding: utf-8 -*- - from numpy import pi, exp from ....Classes.Arc1 import Arc1 from ....Classes.Arc3 import Arc3 -from ....Classes.Segment import Segment from ....Classes.SurfLine import SurfLine -from ....Functions.Geometry.inter_line_circle import inter_line_circle from ....Functions.labels import HOLEV_LAB, HOLEM_LAB diff --git a/pyleecan/Methods/Slot/HoleM54/comp_magnetization_dict.py b/pyleecan/Methods/Slot/HoleM54/comp_magnetization_dict.py index 659ea8dd2..1f0dd6788 100644 --- a/pyleecan/Methods/Slot/HoleM54/comp_magnetization_dict.py +++ b/pyleecan/Methods/Slot/HoleM54/comp_magnetization_dict.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- - from numpy import pi -from pyleecan.Classes.Segment import Segment +from ....Classes.Segment import Segment def comp_magnetization_dict(self, is_north=True): diff --git a/pyleecan/Methods/Slot/HoleM54/comp_radius.py b/pyleecan/Methods/Slot/HoleM54/comp_radius.py index 3f6dcc11d..49cf35ed0 100644 --- a/pyleecan/Methods/Slot/HoleM54/comp_radius.py +++ b/pyleecan/Methods/Slot/HoleM54/comp_radius.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import cos, exp from numpy import abs as np_abs diff --git a/pyleecan/Methods/Slot/HoleM54/plot_schematics.py b/pyleecan/Methods/Slot/HoleM54/plot_schematics.py index c16519ce9..0f70294b3 100644 --- a/pyleecan/Methods/Slot/HoleM54/plot_schematics.py +++ b/pyleecan/Methods/Slot/HoleM54/plot_schematics.py @@ -34,6 +34,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -55,6 +57,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -63,7 +76,7 @@ def plot_schematics( lam = LamHole( Rint=0.1, Rext=0.2, is_internal=True, is_stator=False, hole=[hole] ) - hole.plot_schematics( + return hole.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -71,6 +84,8 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot @@ -78,15 +93,15 @@ def plot_schematics( raise ParentMissingError("Error: The hole is not inside a Lamination") lam = self.parent alpha = pi / 2 # To rotate the schematics - lam.plot( + fig, ax = lam.plot( alpha=pi / self.Zh + alpha, is_show_fig=False, is_lam_only=type_add_active == 0, + fig=fig, + ax=ax, ) # center hole on Ox axis sp = 2 * pi / self.Zh Rbo = self.get_Rbo() - fig = plt.gcf() - ax = plt.gca() point_dict = self._comp_point_coordinate() # Adding point label @@ -229,7 +244,7 @@ def plot_schematics( Rint = point_dict["Z3"].real * 0.9 Rext = point_dict["Zc0"].real - plt.axis("equal") + ax.axis("equal") ax.set_ylim(Rint, Rext) ax.set_xlim(-W, W) manager = plt.get_current_fig_manager() @@ -242,7 +257,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/HoleM57/_comp_point_coordinate.py b/pyleecan/Methods/Slot/HoleM57/_comp_point_coordinate.py index 08c959e20..fc7902c16 100644 --- a/pyleecan/Methods/Slot/HoleM57/_comp_point_coordinate.py +++ b/pyleecan/Methods/Slot/HoleM57/_comp_point_coordinate.py @@ -1,5 +1,5 @@ from numpy import arcsin, cos, exp, angle, pi, sin, tan, array -from pyleecan.Functions.Geometry.inter_line_line import inter_line_line +from ....Functions.Geometry.inter_line_line import inter_line_line def _comp_point_coordinate(self): diff --git a/pyleecan/Methods/Slot/HoleM57/build_geometry.py b/pyleecan/Methods/Slot/HoleM57/build_geometry.py index 076abb3f6..3da5fb2d6 100644 --- a/pyleecan/Methods/Slot/HoleM57/build_geometry.py +++ b/pyleecan/Methods/Slot/HoleM57/build_geometry.py @@ -1,11 +1,8 @@ -# -*- coding: utf-8 -*- +from numpy import arcsin, cos, exp, angle, pi, sin, tan -from numpy import arcsin, cos, exp, angle, pi, sin, tan, array - -from pyleecan.Classes.Segment import Segment -from pyleecan.Classes.SurfLine import SurfLine -from pyleecan.Functions.Geometry.inter_line_line import inter_line_line -import matplotlib.pyplot as plt +from ....Classes.Segment import Segment +from ....Classes.SurfLine import SurfLine +from ....Functions.Geometry.inter_line_line import inter_line_line from ....Functions.labels import HOLEV_LAB, HOLEM_LAB diff --git a/pyleecan/Methods/Slot/HoleM57/check.py b/pyleecan/Methods/Slot/HoleM57/check.py index cfa7ada0b..53490818c 100644 --- a/pyleecan/Methods/Slot/HoleM57/check.py +++ b/pyleecan/Methods/Slot/HoleM57/check.py @@ -1,8 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, pi - -from pyleecan.Methods.Slot.Slot import SlotCheckError from ....Methods.Slot.HoleM57 import * diff --git a/pyleecan/Methods/Slot/HoleM57/comp_magnetization_dict.py b/pyleecan/Methods/Slot/HoleM57/comp_magnetization_dict.py index 291173db3..47cea4707 100644 --- a/pyleecan/Methods/Slot/HoleM57/comp_magnetization_dict.py +++ b/pyleecan/Methods/Slot/HoleM57/comp_magnetization_dict.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- - from numpy import pi -from pyleecan.Classes.Segment import Segment +from ....Classes.Segment import Segment def comp_magnetization_dict(self, is_north=True): diff --git a/pyleecan/Methods/Slot/HoleM57/plot_schematics.py b/pyleecan/Methods/Slot/HoleM57/plot_schematics.py index a384bc36f..3cf0ffe63 100644 --- a/pyleecan/Methods/Slot/HoleM57/plot_schematics.py +++ b/pyleecan/Methods/Slot/HoleM57/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -71,7 +84,7 @@ def plot_schematics( lam = LamHole( Rint=0.078, Rext=0.104, is_internal=True, is_stator=False, hole=[hole] ) - hole.plot_schematics( + return hole.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -79,12 +92,14 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) elif type_add_active == 0: # Remove magnets lam = self.parent.copy() lam.hole[0].remove_magnet() - lam.hole[0].plot_schematics( + return lam.hole[0].plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -92,6 +107,8 @@ def plot_schematics( type_add_active=2, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot @@ -99,15 +116,15 @@ def plot_schematics( raise ParentMissingError("Error: The hole is not inside a Lamination") lam = self.parent alpha = pi / 2 # To rotate the schematics - lam.plot( + fig, ax = lam.plot( alpha=pi / self.Zh + alpha, is_show_fig=False, is_lam_only=type_add_active == 0, + fig=fig, + ax=ax, ) # center hole on Ox axis sp = 2 * pi / self.Zh Rbo = self.get_Rbo() - fig = plt.gcf() - ax = plt.gca() point_dict = self._comp_point_coordinate() # Adding point label @@ -327,7 +344,7 @@ def plot_schematics( Rint = self.parent.Rint Rext = self.parent.Rext - plt.axis("equal") + ax.axis("equal") ax.set_ylim(Rint, Rext) ax.set_xlim(-W, W) manager = plt.get_current_fig_manager() @@ -340,7 +357,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/HoleM58/build_geometry.py b/pyleecan/Methods/Slot/HoleM58/build_geometry.py index c4a848492..4c51a41a0 100644 --- a/pyleecan/Methods/Slot/HoleM58/build_geometry.py +++ b/pyleecan/Methods/Slot/HoleM58/build_geometry.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- - -from numpy import exp, pi, sqrt +from numpy import exp, sqrt +from ....Classes.Arc1 import Arc1 from ....Classes.Segment import Segment from ....Classes.SurfLine import SurfLine -from ....Classes.Arc1 import Arc1 from ....Functions.labels import HOLEV_LAB, HOLEM_LAB diff --git a/pyleecan/Methods/Slot/HoleM58/check.py b/pyleecan/Methods/Slot/HoleM58/check.py index 4f756fef8..62e031b89 100644 --- a/pyleecan/Methods/Slot/HoleM58/check.py +++ b/pyleecan/Methods/Slot/HoleM58/check.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, pi - from ....Methods.Slot.Slot import SlotCheckError from ....Methods.Slot.HoleM58 import * diff --git a/pyleecan/Methods/Slot/HoleM58/comp_magnetization_dict.py b/pyleecan/Methods/Slot/HoleM58/comp_magnetization_dict.py index 8f30b3845..1c5f7bc3c 100644 --- a/pyleecan/Methods/Slot/HoleM58/comp_magnetization_dict.py +++ b/pyleecan/Methods/Slot/HoleM58/comp_magnetization_dict.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- - from numpy import pi -from pyleecan.Classes.Segment import Segment +from ....Classes.Segment import Segment def comp_magnetization_dict(self, is_north=True): diff --git a/pyleecan/Methods/Slot/HoleM58/comp_radius.py b/pyleecan/Methods/Slot/HoleM58/comp_radius.py index e3ed89bf8..ef507b288 100644 --- a/pyleecan/Methods/Slot/HoleM58/comp_radius.py +++ b/pyleecan/Methods/Slot/HoleM58/comp_radius.py @@ -1,8 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import angle, arcsin, arctan, array, cos, exp - - def comp_radius(self): """Compute the radius of the min and max circle that contains the hole diff --git a/pyleecan/Methods/Slot/HoleM58/plot_schematics.py b/pyleecan/Methods/Slot/HoleM58/plot_schematics.py index 7df06abe3..211dba3b8 100644 --- a/pyleecan/Methods/Slot/HoleM58/plot_schematics.py +++ b/pyleecan/Methods/Slot/HoleM58/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -72,7 +85,7 @@ def plot_schematics( lam = LamHole( Rint=0.021, Rext=0.075, is_internal=True, is_stator=False, hole=[hole] ) - hole.plot_schematics( + return hole.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -80,12 +93,14 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) elif type_add_active == 0: # Remove magnets lam = self.parent.copy() lam.hole[0].remove_magnet() - lam.hole[0].plot_schematics( + return lam.hole[0].plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -93,6 +108,8 @@ def plot_schematics( type_add_active=2, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot @@ -100,15 +117,15 @@ def plot_schematics( raise ParentMissingError("Error: The hole is not inside a Lamination") lam = self.parent alpha = pi / 2 # To rotate the schematics - lam.plot( + fig, ax = lam.plot( alpha=pi / self.Zh + alpha, is_show_fig=False, is_lam_only=type_add_active == 0, + fig=fig, + ax=ax, ) # center hole on Ox axis sp = 2 * pi / self.Zh Rbo = self.get_Rbo() - fig = plt.gcf() - ax = plt.gca() point_dict = self._comp_point_coordinate() # Adding point label @@ -343,7 +360,7 @@ def plot_schematics( Rint = (Rbo - self.H0 - self.H2) * 0.9 Rext = self.parent.Rext * 1.05 - plt.axis("equal") + ax.axis("equal") ax.set_ylim(Rint, Rext) ax.set_xlim(-W, W) manager = plt.get_current_fig_manager() @@ -356,7 +373,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/HoleMLSRPM/check.py b/pyleecan/Methods/Slot/HoleMLSRPM/check.py index 44987a135..c81eb8423 100644 --- a/pyleecan/Methods/Slot/HoleMLSRPM/check.py +++ b/pyleecan/Methods/Slot/HoleMLSRPM/check.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- - -from pyleecan.Methods.Slot.Slot import SlotCheckError +from ....Methods.Slot.Slot import SlotCheckError def check(self): diff --git a/pyleecan/Methods/Slot/HoleMLSRPM/comp_magnetization_dict.py b/pyleecan/Methods/Slot/HoleMLSRPM/comp_magnetization_dict.py index bbd16a4dc..067a8d62e 100644 --- a/pyleecan/Methods/Slot/HoleMLSRPM/comp_magnetization_dict.py +++ b/pyleecan/Methods/Slot/HoleMLSRPM/comp_magnetization_dict.py @@ -1,5 +1,5 @@ from numpy import pi -from pyleecan.Classes.Segment import Segment +from ....Classes.Segment import Segment def comp_magnetization_dict(self, is_north=True): diff --git a/pyleecan/Methods/Slot/HoleMLSRPM/plot_schematics.py b/pyleecan/Methods/Slot/HoleMLSRPM/plot_schematics.py index 54ee7fbde..2ce45ebf6 100644 --- a/pyleecan/Methods/Slot/HoleMLSRPM/plot_schematics.py +++ b/pyleecan/Methods/Slot/HoleMLSRPM/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Use some default parameter @@ -78,7 +91,7 @@ def plot_schematics( Wrvd=0.05, hole=[hole], ) - hole.plot_schematics( + return hole.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -86,12 +99,14 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) elif type_add_active == 0: # Remove magnets lam = self.parent.copy() lam.hole[0].remove_magnet() - lam.hole[0].plot_schematics( + return lam.hole[0].plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -99,6 +114,8 @@ def plot_schematics( type_add_active=2, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot @@ -106,15 +123,15 @@ def plot_schematics( raise ParentMissingError("Error: The hole is not inside a Lamination") lam = self.parent alpha = 0 # To rotate the schematics - lam.plot( + fig, ax = lam.plot( alpha=pi / self.Zh + alpha, is_show_fig=False, is_lam_only=type_add_active == 0, + fig=fig, + ax=ax, ) # center hole on Ox axis sp = 2 * pi / self.Zh Rbo = self.get_Rbo() - fig = plt.gcf() - ax = plt.gca() point_dict = self._comp_point_coordinate() # Adding point label @@ -336,7 +353,7 @@ def plot_schematics( Rint = self.R3 * 0.9 Rext = self.parent.Rext * 1.2 - # plt.axis("equal") + # ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -349,7 +366,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/HoleMag/comp_mass_magnet_id.py b/pyleecan/Methods/Slot/HoleMag/comp_mass_magnet_id.py index 7bcf1e9c9..cf8476010 100644 --- a/pyleecan/Methods/Slot/HoleMag/comp_mass_magnet_id.py +++ b/pyleecan/Methods/Slot/HoleMag/comp_mass_magnet_id.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - def comp_mass_magnet_id(self, index): """Compute the mass of the hole magnet of the corresponding index @@ -21,4 +18,8 @@ def comp_mass_magnet_id(self, index): if mag_list[index] is None: return 0 else: - return self.comp_surface_magnet_id(index) * mag_list[index].Lmag + if mag_list[index].Lmag is None: + Lmag = self.parent.L1 + else: + Lmag = mag_list[index].Lmag + return self.comp_surface_magnet_id(index) * Lmag diff --git a/pyleecan/Methods/Slot/HoleMag/comp_mass_magnets.py b/pyleecan/Methods/Slot/HoleMag/comp_mass_magnets.py index cedc8bc3a..e89c2c424 100644 --- a/pyleecan/Methods/Slot/HoleMag/comp_mass_magnets.py +++ b/pyleecan/Methods/Slot/HoleMag/comp_mass_magnets.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - def comp_mass_magnets(self): """Compute the mass of the hole magnets (some of them may be missing) @@ -20,6 +17,17 @@ def comp_mass_magnets(self): for ii, mag in enumerate(mag_list): if mag is not None: Smag = self.comp_surface_magnet_id(ii) - M += Smag * mag.Lmag * mag.mat_type.struct.rho + if mag.Lmag is None: + Lmag = self.parent.L1 + else: + Lmag = mag.Lmag + # Check material definition + if mag.mat_type.struct.rho is None: + raise Exception( + "Error: For magnet material " + + str(mag.mat_type.name) + + " struct.rho is not set" + ) + M += Smag * Lmag * mag.mat_type.struct.rho return M diff --git a/pyleecan/Methods/Slot/HoleMag/comp_volume_magnets.py b/pyleecan/Methods/Slot/HoleMag/comp_volume_magnets.py index 7210811c3..4ea655c33 100644 --- a/pyleecan/Methods/Slot/HoleMag/comp_volume_magnets.py +++ b/pyleecan/Methods/Slot/HoleMag/comp_volume_magnets.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - def comp_volume_magnets(self): """Compute the volume of the hole magnets (some of them may be missing) @@ -20,6 +17,10 @@ def comp_volume_magnets(self): for ii, mag in enumerate(mag_list): if mag is not None: Smag = self.comp_surface_magnet_id(ii) - V += Smag * mag.Lmag + if mag.Lmag is None: + Lmag = self.parent.L1 + else: + Lmag = mag.Lmag + V += Smag * Lmag return V diff --git a/pyleecan/Methods/Slot/HoleUD/build_geometry.py b/pyleecan/Methods/Slot/HoleUD/build_geometry.py index 95f43ea7e..0944b87b8 100644 --- a/pyleecan/Methods/Slot/HoleUD/build_geometry.py +++ b/pyleecan/Methods/Slot/HoleUD/build_geometry.py @@ -1,13 +1,4 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, arctan, cos, exp, array, angle, pi -from numpy import imag as np_imag -from scipy.optimize import fsolve - -from ....Classes.Segment import Segment -from ....Classes.SurfLine import SurfLine -from ....Classes.Arc1 import Arc1 -from ....Methods import ParentMissingError +from numpy import pi from ....Functions.labels import HOLEV_LAB, HOLEM_LAB, LAM_LAB @@ -25,7 +16,7 @@ def build_geometry(self, alpha=0, delta=0, is_simplified=False): delta : complex Complex to translate the slot (Default value = 0) is_simplified : bool - True to avoid line superposition (not used) + True to avoid line superposition (not used) Returns ------- @@ -33,7 +24,7 @@ def build_geometry(self, alpha=0, delta=0, is_simplified=False): List of SurfLine needed to draw the Hole """ - surf_list = self.surf_list + surf_list = [surf.copy() for surf in self.surf_list] # Get correct label for surfaces if self.parent is not None: @@ -61,12 +52,10 @@ def build_geometry(self, alpha=0, delta=0, is_simplified=False): hole_id += 1 # Apply the transformations - return_list = list() # Modulo on Alpha0 for sym Alpha0 = self.Alpha0 % (2 * pi / self.Zh) for surf in surf_list: - return_list.append(surf.copy()) - return_list[-1].rotate(alpha + Alpha0) - return_list[-1].translate(delta) + surf.rotate(alpha + Alpha0) + surf.translate(delta) - return return_list + return surf_list diff --git a/pyleecan/Methods/Slot/Slot/build_geometry_half_tooth.py b/pyleecan/Methods/Slot/Slot/build_geometry_half_tooth.py index e307266cd..9f7df5e13 100644 --- a/pyleecan/Methods/Slot/Slot/build_geometry_half_tooth.py +++ b/pyleecan/Methods/Slot/Slot/build_geometry_half_tooth.py @@ -1,11 +1,7 @@ -# -*- coding: utf-8 -*- -from numpy import imag, pi, exp from numpy import abs as np_abs -from ....Classes.Circle import Circle -from ....Classes.SurfLine import SurfLine -from ....Classes.Arc import Arc +from numpy import imag, pi, exp + from ....Classes.Arc1 import Arc1 -from ....Classes.Segment import Segment from ....Functions.labels import BORE_LAB, BOUNDARY_PROP_LAB diff --git a/pyleecan/Methods/Slot/Slot/comp_width_opening.py b/pyleecan/Methods/Slot/Slot/comp_width_opening.py index d52042820..abcc9ca8d 100644 --- a/pyleecan/Methods/Slot/Slot/comp_width_opening.py +++ b/pyleecan/Methods/Slot/Slot/comp_width_opening.py @@ -1,22 +1,29 @@ -# -*- coding: utf-8 -*- +from numpy import pi -def comp_width_opening(self): +def comp_width_opening(self, is_curved=False): """Compute the average opening width of the Slot Parameters ---------- self : Slot A Slot object + is_curved : bool + width opening curved or straight Returns ------- W0: float - Average opening width of the slot [m] + Average opening width of the slot [m] or [rad] """ - line_list = self.build_geometry() - Z1 = line_list[0].get_begin() - Z2 = line_list[-1].get_end() - - return abs(Z2 - Z1) + if is_curved: + R = self.get_Rbo() + alpha = self.comp_angle_opening() + Zs = self.parent.get_Zs() + return 2 * pi * R / Zs - alpha * R + else: + line_list = self.build_geometry() + Z1 = line_list[0].get_begin() + Z2 = line_list[-1].get_end() + return abs(Z2 - Z1) diff --git a/pyleecan/Methods/Slot/Slot/get_surface_tooth.py b/pyleecan/Methods/Slot/Slot/get_surface_tooth.py index 186a91c4d..29983bfb6 100644 --- a/pyleecan/Methods/Slot/Slot/get_surface_tooth.py +++ b/pyleecan/Methods/Slot/Slot/get_surface_tooth.py @@ -1,6 +1,7 @@ -# -*- coding: utf-8 -*- -from ....Classes.Segment import Segment +from numpy import exp, pi + from ....Classes.Arc1 import Arc1 +from ....Classes.Segment import Segment from ....Classes.SurfLine import SurfLine from ....Methods import ParentMissingError from ....Functions.labels import ( diff --git a/pyleecan/Methods/Slot/Slot/plot.py b/pyleecan/Methods/Slot/Slot/plot.py index 6fa4e2764..47fe95659 100644 --- a/pyleecan/Methods/Slot/Slot/plot.py +++ b/pyleecan/Methods/Slot/Slot/plot.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from matplotlib.pyplot import axis - from ....Functions.init_fig import init_fig from ....definitions import config_dict @@ -22,15 +18,18 @@ def plot(self, fig=None, ax=None): Returns ------- - None + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ surf = self.get_surface() # Display the result - (fig, axes, patch_leg, label_leg) = init_fig(fig, ax) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") - axes.set_title("Slot") + (fig, ax, patch_leg, label_leg) = init_fig(fig, ax) + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") + ax.set_title("Slot") # Add the slot to the fig if self.get_is_stator: @@ -38,8 +37,9 @@ def plot(self, fig=None, ax=None): else: patches = surf.get_patch(color=ROTOR_COLOR) for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Axis Setup - axes.axis("equal") + ax.axis("equal") fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/Slot/plot_active.py b/pyleecan/Methods/Slot/Slot/plot_active.py index 1dfba4a0b..1620babc1 100644 --- a/pyleecan/Methods/Slot/Slot/plot_active.py +++ b/pyleecan/Methods/Slot/Slot/plot_active.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- - from matplotlib.patches import Patch, Polygon -from matplotlib.pyplot import axis, legend from numpy import array, exp, pi from ....definitions import config_dict @@ -87,10 +84,10 @@ def plot_active( point_list = point_list * exp(1j * (2 * pi) / self.Zs) # Display the result - (fig, axes, patch_leg, label_leg) = init_fig(fig) - axes.set_xlabel("(m)") - axes.set_ylabel("(m)") - axes.set_title("Winding Pattern") + (fig, ax, patch_leg, label_leg) = init_fig(fig) + ax.set_xlabel("(m)") + ax.set_ylabel("(m)") + ax.set_title("Winding Pattern") # Add wedges if is_add_wedge: @@ -104,22 +101,22 @@ def plot_active( for ii in range(Zs): surf2 = surf.copy() surf2.rotate(angle=ii * (2 * pi) / self.Zs) - surf2.plot(fig=fig, ax=axes, color=WEDGE_COLOR, is_show_fig=False) + surf2.plot(fig=fig, ax=ax, color=WEDGE_COLOR, is_show_fig=False) # Remove tmp blanck wedge if to_clean: self.wedge_mat = None # Add the magnet to the fig for patch in patches: - axes.add_patch(patch) + ax.add_patch(patch) # Axis Setup - axis("equal") + ax.axis("equal") Rbo = self.get_Rbo() Lim = Rbo * 1.2 - axes.set_xlim(-Lim, Lim) - axes.set_ylim(-Lim, Lim) + ax.set_xlim(-Lim, Lim) + ax.set_ylim(-Lim, Lim) # Legend setup if wind_mat is None or len(surf_list) != Ntan * Nrad: @@ -140,9 +137,10 @@ def plot_active( patch_leg.append(Patch(color=PHASE_COLORS[index])) label_leg.append("Phase " + qs_name[ii]) - legend(patch_leg, label_leg) + ax.legend(patch_leg, label_leg) if is_show_fig: fig.show() + return fig, ax def get_color(wind_mat, Nrad, Ntan, Zs): diff --git a/pyleecan/Methods/Slot/Slot/set_label.py b/pyleecan/Methods/Slot/Slot/set_label.py index 5ac276ede..67c5ae76a 100644 --- a/pyleecan/Methods/Slot/Slot/set_label.py +++ b/pyleecan/Methods/Slot/Slot/set_label.py @@ -2,7 +2,7 @@ def set_label(self, surf_list, Nrad, Ntan, lam_label): - """Set the normalized label on the winding surface + """Set the normalized label on the active surface (internal method of build_geometry_active) Parameters diff --git a/pyleecan/Methods/Slot/Slot19/_comp_point_coordinate.py b/pyleecan/Methods/Slot/Slot19/_comp_point_coordinate.py index 402a6823e..18bfd9f09 100644 --- a/pyleecan/Methods/Slot/Slot19/_comp_point_coordinate.py +++ b/pyleecan/Methods/Slot/Slot19/_comp_point_coordinate.py @@ -1,4 +1,4 @@ -from numpy import arcsin, exp, sqrt +from numpy import exp def _comp_point_coordinate(self): diff --git a/pyleecan/Methods/Slot/Slot19/build_geometry.py b/pyleecan/Methods/Slot/Slot19/build_geometry.py index 9d2b5ac44..c5f9c1544 100644 --- a/pyleecan/Methods/Slot/Slot19/build_geometry.py +++ b/pyleecan/Methods/Slot/Slot19/build_geometry.py @@ -1,10 +1,5 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, exp, angle - -from ....Classes.Segment import Segment - from ....Classes.Arc1 import Arc1 +from ....Classes.Segment import Segment def build_geometry(self): diff --git a/pyleecan/Methods/Slot/Slot19/check.py b/pyleecan/Methods/Slot/Slot19/check.py index 18fbf1df9..4bb0da139 100644 --- a/pyleecan/Methods/Slot/Slot19/check.py +++ b/pyleecan/Methods/Slot/Slot19/check.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import pi - from ....Methods.Slot.Slot import SlotCheckError from ....Methods.Slot.Slot19 import * diff --git a/pyleecan/Methods/Slot/Slot19/comp_surface.py b/pyleecan/Methods/Slot/Slot19/comp_surface.py index 9d18e5c8e..a699b05a6 100644 --- a/pyleecan/Methods/Slot/Slot19/comp_surface.py +++ b/pyleecan/Methods/Slot/Slot19/comp_surface.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- - -from numpy import sin, pi +from numpy import sin def comp_surface(self): diff --git a/pyleecan/Methods/Slot/SlotCirc/_comp_R0.py b/pyleecan/Methods/Slot/SlotCirc/_comp_R0.py index 4e044cf4d..d28c69d14 100644 --- a/pyleecan/Methods/Slot/SlotCirc/_comp_R0.py +++ b/pyleecan/Methods/Slot/SlotCirc/_comp_R0.py @@ -1,5 +1,6 @@ from numpy import sqrt + def _comp_R0(self): """Compute the radius of the circle diff --git a/pyleecan/Methods/Slot/SlotCirc/_comp_line_dict.py b/pyleecan/Methods/Slot/SlotCirc/_comp_line_dict.py index 7a15700a5..d8bee71be 100644 --- a/pyleecan/Methods/Slot/SlotCirc/_comp_line_dict.py +++ b/pyleecan/Methods/Slot/SlotCirc/_comp_line_dict.py @@ -29,14 +29,14 @@ def _comp_line_dict(self): full_arc = Arc1( begin=point_dict["Z1"], end=point_dict["Z2"], - radius=-R0*sign, + radius=-R0 * sign, is_trigo_direction=True, ) else: full_arc = Arc1( begin=point_dict["Z1"], end=point_dict["Z2"], - radius=R0*sign, + radius=R0 * sign, is_trigo_direction=False, ) diff --git a/pyleecan/Methods/Slot/SlotCirc/comp_height.py b/pyleecan/Methods/Slot/SlotCirc/comp_height.py index dfa892b6d..4b6e68057 100644 --- a/pyleecan/Methods/Slot/SlotCirc/comp_height.py +++ b/pyleecan/Methods/Slot/SlotCirc/comp_height.py @@ -1,8 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import cos, tan - - def comp_height(self): """Compute the height of the Slot. Caution, the top of the Slot is an Arc diff --git a/pyleecan/Methods/Slot/SlotCirc/comp_surface.py b/pyleecan/Methods/Slot/SlotCirc/comp_surface.py index 5131f56e6..aa576f7a5 100644 --- a/pyleecan/Methods/Slot/SlotCirc/comp_surface.py +++ b/pyleecan/Methods/Slot/SlotCirc/comp_surface.py @@ -1,8 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import sin, tan - - def comp_surface(self): """Compute the Slot total surface (by analytical computation). Caution, the bottom of the Slot is an Arc diff --git a/pyleecan/Methods/Slot/SlotM10/plot_schematics.py b/pyleecan/Methods/Slot/SlotM10/plot_schematics.py index 0ca09f6a2..ce1336bd2 100644 --- a/pyleecan/Methods/Slot/SlotM10/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotM10/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.1, Rext=0.135, is_internal=True, is_stator=False, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = +1 @@ -183,7 +198,7 @@ def plot_schematics( W = self.W0 / 2 * 1.4 Rint, Rext = self.comp_radius() - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -196,7 +211,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotM11/get_surface_active.py b/pyleecan/Methods/Slot/SlotM11/get_surface_active.py index 42e164a21..693d81c97 100644 --- a/pyleecan/Methods/Slot/SlotM11/get_surface_active.py +++ b/pyleecan/Methods/Slot/SlotM11/get_surface_active.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import linspace, zeros - from ....Classes.Arc1 import Arc1 from ....Classes.Segment import Segment from ....Classes.SurfLine import SurfLine diff --git a/pyleecan/Methods/Slot/SlotM11/plot_schematics.py b/pyleecan/Methods/Slot/SlotM11/plot_schematics.py index 3cceed2c0..06964e40c 100644 --- a/pyleecan/Methods/Slot/SlotM11/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotM11/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.1, Rext=0.135, is_internal=True, is_stator=False, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = +1 @@ -230,7 +245,7 @@ def plot_schematics( W = point_dict["Z4"].imag * 1.2 Rint, Rext = self.comp_radius() - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -243,7 +258,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotM12/plot_schematics.py b/pyleecan/Methods/Slot/SlotM12/plot_schematics.py index 323698a99..cec86dcc2 100644 --- a/pyleecan/Methods/Slot/SlotM12/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotM12/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.1, Rext=0.135, is_internal=True, is_stator=False, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = +1 @@ -197,7 +212,7 @@ def plot_schematics( W = self.W0 / 2 * 1.4 Rint, Rext = self.comp_radius() - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -210,7 +225,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotM13/plot_schematics.py b/pyleecan/Methods/Slot/SlotM13/plot_schematics.py index 0ccff0dc4..8dc5e653c 100644 --- a/pyleecan/Methods/Slot/SlotM13/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotM13/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.1, Rext=0.135, is_internal=True, is_stator=False, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = +1 @@ -211,7 +226,7 @@ def plot_schematics( W = self.W0 / 2 * 1.4 Rint, Rext = self.comp_radius() - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -224,7 +239,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotM14/plot_schematics.py b/pyleecan/Methods/Slot/SlotM14/plot_schematics.py index 9e9455fbc..f617ca168 100644 --- a/pyleecan/Methods/Slot/SlotM14/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotM14/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -64,7 +77,7 @@ def plot_schematics( lam = LamSlot( Rint=0.1, Rext=0.135, is_internal=True, is_stator=False, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -72,15 +85,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = +1 @@ -263,7 +278,7 @@ def plot_schematics( W = point_dict["Z4"].imag * 1.2 Rint, Rext = self.comp_radius() - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -276,7 +291,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotM15/plot_schematics.py b/pyleecan/Methods/Slot/SlotM15/plot_schematics.py index e10826981..dd02d3ffe 100644 --- a/pyleecan/Methods/Slot/SlotM15/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotM15/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -65,7 +78,7 @@ def plot_schematics( Rint=40e-3, Rext=0.11, is_internal=True, is_stator=False, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -73,15 +86,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = +1 @@ -238,7 +253,7 @@ def plot_schematics( W = point_dict["Z4"].imag * 1.2 Rint, Rext = self.comp_radius() - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -251,7 +266,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotM16/plot_schematics.py b/pyleecan/Methods/Slot/SlotM16/plot_schematics.py index b32830c22..0359e3a9a 100644 --- a/pyleecan/Methods/Slot/SlotM16/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotM16/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=80e-3, Rext=240e-3, is_internal=True, is_stator=False, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = +1 @@ -182,7 +197,7 @@ def plot_schematics( W = self.W1 / 2 * 1.3 Rint, Rext = self.comp_radius() - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -195,7 +210,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotM17/plot_schematics.py b/pyleecan/Methods/Slot/SlotM17/plot_schematics.py index 601df3b48..7efa5573d 100644 --- a/pyleecan/Methods/Slot/SlotM17/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotM17/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.05, Rext=0.135, is_internal=True, is_stator=False, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis # Adding schematics if is_add_schematics: @@ -128,7 +143,7 @@ def plot_schematics( # Zooming and cleaning W = lam.Rext * 1.1 - plt.axis("equal") + ax.axis("equal") ax.set_xlim(-W, W) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -141,7 +156,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotM18/plot_schematics.py b/pyleecan/Methods/Slot/SlotM18/plot_schematics.py index 7b914f345..8448dcd3f 100644 --- a/pyleecan/Methods/Slot/SlotM18/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotM18/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.1, Rext=0.135, is_internal=True, is_stator=False, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = +1 @@ -147,7 +162,7 @@ def plot_schematics( W = point_dict["ZM3"].imag * 3 Rint, Rext = self.comp_radius() - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -160,7 +175,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotUD/build_geometry.py b/pyleecan/Methods/Slot/SlotUD/build_geometry.py index 43162fba4..fcb4b7f55 100644 --- a/pyleecan/Methods/Slot/SlotUD/build_geometry.py +++ b/pyleecan/Methods/Slot/SlotUD/build_geometry.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from ....Classes.Arc1 import Arc1 -from ....Classes.Arc3 import Arc3 from ....Classes.Segment import Segment diff --git a/pyleecan/Methods/Slot/SlotUD/get_surface_active.py b/pyleecan/Methods/Slot/SlotUD/get_surface_active.py index 0901f3339..8186ef706 100644 --- a/pyleecan/Methods/Slot/SlotUD/get_surface_active.py +++ b/pyleecan/Methods/Slot/SlotUD/get_surface_active.py @@ -22,8 +22,16 @@ def get_surface_active(self, alpha=0, delta=0): Surface corresponding to the Winding Area """ # get curve_list - line_list = self.build_geometry()[self.wind_begin_index : self.wind_end_index] - if self.type_line_wind == 0: + type_line_wind = self.type_line_wind + if self.wind_begin_index is None and self.wind_end_index is None: + # Winding not define, use complete surface + line_list = self.build_geometry() + type_line_wind = 1 # Enforce Arc1 + else: + line_list = self.build_geometry()[self.wind_begin_index : self.wind_end_index] + + # Add closing line + if type_line_wind == 0: line_list.append( Segment(begin=line_list[-1].get_end(), end=line_list[0].get_begin()) ) diff --git a/pyleecan/Methods/Slot/SlotW10/plot_schematics.py b/pyleecan/Methods/Slot/SlotW10/plot_schematics.py index a48ac7057..310de0e62 100644 --- a/pyleecan/Methods/Slot/SlotW10/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW10/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -64,7 +77,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -72,15 +85,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -217,7 +232,7 @@ def plot_schematics( Rint = min(point_dict["Z6"].real, point_dict["Z1"].real) Rext = max(point_dict["Z6"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -230,7 +245,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW11/_comp_line_dict.py b/pyleecan/Methods/Slot/SlotW11/_comp_line_dict.py index 706f411e6..789ee9c44 100644 --- a/pyleecan/Methods/Slot/SlotW11/_comp_line_dict.py +++ b/pyleecan/Methods/Slot/SlotW11/_comp_line_dict.py @@ -42,7 +42,11 @@ def _comp_line_dict(self): else: line_dict["1-2"] = None - line_dict["2-3"] = Segment(Z2, Z3) + H1 = self.get_H1() + if H1 == 0 and self.W1 == self.W0: + line_dict["2-3"] = None + else: + line_dict["2-3"] = Segment(Z2, Z3) line_dict["3-4"] = Segment(Z3, Z4) if self.R1 * 2 < self.W2: @@ -59,7 +63,10 @@ def _comp_line_dict(self): line_dict["6-7"] = None line_dict["7-8"] = Segment(Z7, Z8) - line_dict["8-9"] = Segment(Z8, Z9) + if H1 == 0 and self.W1 == self.W0: + line_dict["8-9"] = None + else: + line_dict["8-9"] = Segment(Z8, Z9) if self.H0 > 0: line_dict["9-10"] = Segment(Z9, Z10) diff --git a/pyleecan/Methods/Slot/SlotW11/plot_schematics.py b/pyleecan/Methods/Slot/SlotW11/plot_schematics.py index 2cefbbf27..21b576f62 100644 --- a/pyleecan/Methods/Slot/SlotW11/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW11/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -53,6 +55,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -63,7 +76,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -71,15 +84,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -266,7 +281,7 @@ def plot_schematics( Rint = min(point_dict["Z6"].real, point_dict["Z1"].real) Rext = max(point_dict["Z6"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -279,7 +294,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW12/plot_schematics.py b/pyleecan/Methods/Slot/SlotW12/plot_schematics.py index a1684127c..8d7bcc599 100644 --- a/pyleecan/Methods/Slot/SlotW12/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW12/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -53,6 +55,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -61,7 +74,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -69,15 +82,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -232,7 +247,7 @@ def plot_schematics( Rint = min(point_dict["Z1"].real, point_dict["Zi2"].real) Rext = max(point_dict["Z1"].real, point_dict["Zi2"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -245,7 +260,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW13/plot_schematics.py b/pyleecan/Methods/Slot/SlotW13/plot_schematics.py index 20ddba064..7516ceb72 100644 --- a/pyleecan/Methods/Slot/SlotW13/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW13/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -64,7 +77,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -72,15 +85,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -231,7 +246,7 @@ def plot_schematics( Rint = min(point_dict["Z6"].real, point_dict["Z1"].real) Rext = max(point_dict["Z6"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -244,7 +259,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW14/_comp_point_coordinate.py b/pyleecan/Methods/Slot/SlotW14/_comp_point_coordinate.py index 4c7df3592..fe0989d32 100644 --- a/pyleecan/Methods/Slot/SlotW14/_comp_point_coordinate.py +++ b/pyleecan/Methods/Slot/SlotW14/_comp_point_coordinate.py @@ -1,4 +1,4 @@ -from numpy import arcsin, cos, exp, pi, sin, tan, sqrt +from numpy import arcsin, cos, exp, pi, sin def _comp_point_coordinate(self): diff --git a/pyleecan/Methods/Slot/SlotW14/comp_height.py b/pyleecan/Methods/Slot/SlotW14/comp_height.py index 9c3584fb1..9a2469c73 100644 --- a/pyleecan/Methods/Slot/SlotW14/comp_height.py +++ b/pyleecan/Methods/Slot/SlotW14/comp_height.py @@ -1,8 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, cos, exp, pi, sin, tan - - def comp_height(self): """Compute the height of the Slot. Caution, the bottom of the Slot is an Arc diff --git a/pyleecan/Methods/Slot/SlotW14/comp_surface.py b/pyleecan/Methods/Slot/SlotW14/comp_surface.py index fac5836fb..b17bac20f 100644 --- a/pyleecan/Methods/Slot/SlotW14/comp_surface.py +++ b/pyleecan/Methods/Slot/SlotW14/comp_surface.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, cos, pi, sin +from numpy import sin def comp_surface(self): diff --git a/pyleecan/Methods/Slot/SlotW14/comp_surface_active.py b/pyleecan/Methods/Slot/SlotW14/comp_surface_active.py index 34d141603..48cde0b21 100644 --- a/pyleecan/Methods/Slot/SlotW14/comp_surface_active.py +++ b/pyleecan/Methods/Slot/SlotW14/comp_surface_active.py @@ -1,8 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, cos, exp, pi, sin, sqrt, tan - - def comp_surface_active(self): """Compute the Slot inner surface for winding (by analytical computation) diff --git a/pyleecan/Methods/Slot/SlotW14/plot_schematics.py b/pyleecan/Methods/Slot/SlotW14/plot_schematics.py index bfb13b8e0..d526782e1 100644 --- a/pyleecan/Methods/Slot/SlotW14/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW14/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.25, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -235,7 +250,7 @@ def plot_schematics( Rint = min(point_dict["Z5"].real, point_dict["Z1"].real) Rext = max(point_dict["Z5"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -248,7 +263,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW15/comp_height.py b/pyleecan/Methods/Slot/SlotW15/comp_height.py index d193190d9..6ddc16647 100644 --- a/pyleecan/Methods/Slot/SlotW15/comp_height.py +++ b/pyleecan/Methods/Slot/SlotW15/comp_height.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- -from numpy import cos - - def comp_height(self): """Compute the height of the Slot. Caution, the bottom of the Slot is an Arc diff --git a/pyleecan/Methods/Slot/SlotW15/plot_schematics.py b/pyleecan/Methods/Slot/SlotW15/plot_schematics.py index 8eb39c167..d61fe90a5 100644 --- a/pyleecan/Methods/Slot/SlotW15/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW15/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -71,7 +84,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -79,15 +92,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -368,7 +383,7 @@ def plot_schematics( Rint = min(point_dict["Z5"].real, point_dict["Z1"].real) Rext = max(point_dict["Z5"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -381,7 +396,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW16/__init__.py b/pyleecan/Methods/Slot/SlotW16/__init__.py index 65058bdc4..d5c27d05b 100644 --- a/pyleecan/Methods/Slot/SlotW16/__init__.py +++ b/pyleecan/Methods/Slot/SlotW16/__init__.py @@ -5,3 +5,9 @@ class S16OutterError(SlotCheckError): """ """ pass + + +class S16AlphaT(SlotCheckError): + """ """ + + pass diff --git a/pyleecan/Methods/Slot/SlotW16/check.py b/pyleecan/Methods/Slot/SlotW16/check.py index dccb385c5..7fc36933f 100644 --- a/pyleecan/Methods/Slot/SlotW16/check.py +++ b/pyleecan/Methods/Slot/SlotW16/check.py @@ -1,4 +1,5 @@ -from ....Methods.Slot.SlotW16 import S16OutterError +from ....Methods.Slot.SlotW16 import S16OutterError, S16AlphaT +from numpy import pi, arcsin def check(self): @@ -20,3 +21,13 @@ def check(self): """ if self.is_outwards(): raise S16OutterError("Slot 16 must be on internal lamination only") + + # Check W3 at min radius + Rbo = self.get_Rbo() + sp = 2 * pi / self.Zs # slot pitch + alphaT = 2 * arcsin(self.W3 * 0.5 / (Rbo - self.H0 - self.H2)) + + if alphaT >= sp: + raise S16AlphaT( + "Tooth is larger than the slot pitch angle: reduce W3, H2 or Zs" + ) diff --git a/pyleecan/Methods/Slot/SlotW16/plot_schematics.py b/pyleecan/Methods/Slot/SlotW16/plot_schematics.py index 21098e2ac..7ac4a5311 100644 --- a/pyleecan/Methods/Slot/SlotW16/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW16/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,13 +56,24 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter if is_default: slot = type(self)(Zs=12, W0=pi / 24, R1=20e-3, H0=20e-3, H2=80e-3, W3=30e-3) lam = LamSlot(Rint=0.135, Rext=0.3, is_internal=True, is_stator=True, slot=slot) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -68,15 +81,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -278,7 +293,7 @@ def plot_schematics( Rint = min(point_dict["Z6"].real, point_dict["Z1"].real) Rext = max(point_dict["Z6"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -291,7 +306,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW21/plot_schematics.py b/pyleecan/Methods/Slot/SlotW21/plot_schematics.py index 6ab822a2d..0f42a48fe 100644 --- a/pyleecan/Methods/Slot/SlotW21/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW21/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -64,7 +77,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -72,15 +85,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -217,7 +232,7 @@ def plot_schematics( Rint = min(point_dict["Z4"].real, point_dict["Z1"].real) Rext = max(point_dict["Z4"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -230,7 +245,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW22/plot_schematics.py b/pyleecan/Methods/Slot/SlotW22/plot_schematics.py index f28865a28..87c2ef9b9 100644 --- a/pyleecan/Methods/Slot/SlotW22/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW22/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -258,7 +273,7 @@ def plot_schematics( Rint = min(point_dict["Z4"].real, point_dict["Z1"].real) Rext = max(point_dict["Z4"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -271,7 +286,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW23/build_geometry.py b/pyleecan/Methods/Slot/SlotW23/build_geometry.py index 84ca4b689..1c016e454 100644 --- a/pyleecan/Methods/Slot/SlotW23/build_geometry.py +++ b/pyleecan/Methods/Slot/SlotW23/build_geometry.py @@ -1,10 +1,5 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, exp, angle - -from ....Classes.Segment import Segment - from ....Classes.Arc1 import Arc1 +from ....Classes.Segment import Segment def build_geometry(self): diff --git a/pyleecan/Methods/Slot/SlotW23/plot_schematics.py b/pyleecan/Methods/Slot/SlotW23/plot_schematics.py index 938463141..f6ae7abe0 100644 --- a/pyleecan/Methods/Slot/SlotW23/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW23/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -64,7 +77,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -72,15 +85,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -248,7 +263,7 @@ def plot_schematics( Rint = min(point_dict["Z4"].real, point_dict["Z1"].real) Rext = max(point_dict["Z4"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -261,7 +276,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW24/plot_schematics.py b/pyleecan/Methods/Slot/SlotW24/plot_schematics.py index 4fa71cb23..0974087c8 100644 --- a/pyleecan/Methods/Slot/SlotW24/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW24/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -198,7 +213,7 @@ def plot_schematics( Rint = min(point_dict["Z2"].real, point_dict["Z1"].real) Rext = max(point_dict["Z2"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -211,7 +226,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW25/check.py b/pyleecan/Methods/Slot/SlotW25/check.py index 2e7988626..ff9c61a39 100644 --- a/pyleecan/Methods/Slot/SlotW25/check.py +++ b/pyleecan/Methods/Slot/SlotW25/check.py @@ -28,6 +28,13 @@ def check(self): """ Rbo = self.get_Rbo() + if self.H1 == 0: + raise S25_W4CheckError("You must have H1>0 (use Slot 25 for H1=0)") + if self.H2 == 0: + raise S25_W4CheckError("You must have H2>0 (use Slot 25 for H2=0)") + if self.W4 == self.W3: + raise S25_W4CheckError("You must have W4 != W3 (use Slot 25 for W4=W3)") + if 2 * arcsin(self.W4 / (2 * Rbo)) > 2 * pi / self.Zs: raise S25_W4CheckError("The teeth are too wide, reduce Zs or W4") @@ -36,10 +43,3 @@ def check(self): and 2 * arcsin(self.W3 / (2 * Rbo - self.H2 - self.H1)) > 2 * pi / self.Zs ): raise S25_HWCheckError("The teeth are too wide, reduce Zs, H2 or W3") - - if self.H1 == 0: - raise S25_W4CheckError("You must have H1>0 (use Slot 24 for H1=0)") - if self.H2 == 0: - raise S25_W4CheckError("You must have H2>0 (use Slot 24 for H2=0)") - if self.W4 == self.W3: - raise S25_W4CheckError("You must have W4 != W3 (use Slot 24 for W4=W3)") diff --git a/pyleecan/Methods/Slot/SlotW25/plot_schematics.py b/pyleecan/Methods/Slot/SlotW25/plot_schematics.py index c378c4c3c..f6e5375f8 100644 --- a/pyleecan/Methods/Slot/SlotW25/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW25/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -237,7 +252,7 @@ def plot_schematics( Rint = min(point_dict["Z4"].real, point_dict["Z1"].real) Rext = max(point_dict["Z4"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -250,7 +265,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW26/build_geometry.py b/pyleecan/Methods/Slot/SlotW26/build_geometry.py index 307c4ef63..bd9492fde 100644 --- a/pyleecan/Methods/Slot/SlotW26/build_geometry.py +++ b/pyleecan/Methods/Slot/SlotW26/build_geometry.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, exp, sqrt - from ....Classes.Arc1 import Arc1 from ....Classes.Arc3 import Arc3 from ....Classes.Segment import Segment diff --git a/pyleecan/Methods/Slot/SlotW26/comp_height.py b/pyleecan/Methods/Slot/SlotW26/comp_height.py index 55036f9b4..bbdd5aaa2 100644 --- a/pyleecan/Methods/Slot/SlotW26/comp_height.py +++ b/pyleecan/Methods/Slot/SlotW26/comp_height.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, cos +from numpy import cos def comp_height(self): diff --git a/pyleecan/Methods/Slot/SlotW26/plot_schematics.py b/pyleecan/Methods/Slot/SlotW26/plot_schematics.py index 6f06a778c..e537186ce 100644 --- a/pyleecan/Methods/Slot/SlotW26/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW26/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -260,7 +275,7 @@ def plot_schematics( Rint = min(point_dict["Zbot"].real, point_dict["Z1"].real) Rext = max(point_dict["Zbot"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -273,7 +288,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW27/plot_schematics.py b/pyleecan/Methods/Slot/SlotW27/plot_schematics.py index 3b7ff7dfb..1a0439240 100644 --- a/pyleecan/Methods/Slot/SlotW27/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW27/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -64,7 +77,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -72,15 +85,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -228,7 +243,7 @@ def plot_schematics( Rint = min(point_dict["Z5"].real, point_dict["Z1"].real) Rext = max(point_dict["Z5"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -241,7 +256,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW28/build_geometry.py b/pyleecan/Methods/Slot/SlotW28/build_geometry.py index 93bd10ccf..375f54d8c 100644 --- a/pyleecan/Methods/Slot/SlotW28/build_geometry.py +++ b/pyleecan/Methods/Slot/SlotW28/build_geometry.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, exp, pi, sqrt - from ....Classes.Arc1 import Arc1 from ....Classes.Arc3 import Arc3 from ....Classes.Segment import Segment diff --git a/pyleecan/Methods/Slot/SlotW28/comp_height.py b/pyleecan/Methods/Slot/SlotW28/comp_height.py index 0dc84c93a..66ec5cda0 100644 --- a/pyleecan/Methods/Slot/SlotW28/comp_height.py +++ b/pyleecan/Methods/Slot/SlotW28/comp_height.py @@ -1,8 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, exp, pi, sqrt - - def comp_height(self): """Compute the height of the Slot. Caution, the bottom of the Slot is an Arc diff --git a/pyleecan/Methods/Slot/SlotW28/comp_height_active.py b/pyleecan/Methods/Slot/SlotW28/comp_height_active.py index 61835bc88..723a7b902 100644 --- a/pyleecan/Methods/Slot/SlotW28/comp_height_active.py +++ b/pyleecan/Methods/Slot/SlotW28/comp_height_active.py @@ -1,8 +1,3 @@ -# -*- coding: utf-8 -*- - -from numpy import arcsin, exp, pi, sqrt - - def comp_height_active(self): """Compute the height of the winding area diff --git a/pyleecan/Methods/Slot/SlotW28/plot_schematics.py b/pyleecan/Methods/Slot/SlotW28/plot_schematics.py index 49d67279b..e2f1c58f9 100644 --- a/pyleecan/Methods/Slot/SlotW28/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW28/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -62,7 +75,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -70,15 +83,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -263,7 +278,7 @@ def plot_schematics( Rint = min(point_dict["Z5"].real, point_dict["Z1"].real) Rext = max(point_dict["Z5"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -276,7 +291,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW29/build_geometry_active.py b/pyleecan/Methods/Slot/SlotW29/build_geometry_active.py index 17f1f09a2..b040709aa 100644 --- a/pyleecan/Methods/Slot/SlotW29/build_geometry_active.py +++ b/pyleecan/Methods/Slot/SlotW29/build_geometry_active.py @@ -1,4 +1,5 @@ from numpy import zeros, linspace + from ....Classes.Segment import Segment from ....Classes.SurfLine import SurfLine from ....Functions.labels import WIND_LAB, DRAW_PROP_LAB diff --git a/pyleecan/Methods/Slot/SlotW29/plot_schematics.py b/pyleecan/Methods/Slot/SlotW29/plot_schematics.py index b6ff5f6fb..b467de5e6 100644 --- a/pyleecan/Methods/Slot/SlotW29/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotW29/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=1, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the schematics + ax : Matplotlib.axes.Axes object + Axis containing the schematics """ # Use some default parameter @@ -64,7 +77,7 @@ def plot_schematics( lam = LamSlot( Rint=0.135, Rext=0.3, is_internal=False, is_stator=True, slot=slot ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -72,15 +85,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -225,7 +240,7 @@ def plot_schematics( Rint = min(point_dict["Z6"].real, point_dict["Z1"].real) Rext = max(point_dict["Z6"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W, W) manager = plt.get_current_fig_manager() @@ -238,7 +253,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/SlotW60/build_geometry.py b/pyleecan/Methods/Slot/SlotW60/build_geometry.py index bda97a45e..b241dd657 100644 --- a/pyleecan/Methods/Slot/SlotW60/build_geometry.py +++ b/pyleecan/Methods/Slot/SlotW60/build_geometry.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- -from ....Classes.Segment import Segment from ....Classes.Arc1 import Arc1 +from ....Classes.Segment import Segment def build_geometry(self): diff --git a/pyleecan/Methods/Slot/SlotW60/build_geometry_active.py b/pyleecan/Methods/Slot/SlotW60/build_geometry_active.py index 1b96c6d45..629f854db 100644 --- a/pyleecan/Methods/Slot/SlotW60/build_geometry_active.py +++ b/pyleecan/Methods/Slot/SlotW60/build_geometry_active.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- - from ....Methods.Slot.Slot import SlotCheckError from numpy import pi, exp + from ....Classes.Segment import Segment from ....Classes.SurfLine import SurfLine from ....Methods.Slot.SlotW60 import S60_WindError diff --git a/pyleecan/Methods/Slot/SlotW61/build_geometry.py b/pyleecan/Methods/Slot/SlotW61/build_geometry.py index ea09460d9..82d0d5486 100644 --- a/pyleecan/Methods/Slot/SlotW61/build_geometry.py +++ b/pyleecan/Methods/Slot/SlotW61/build_geometry.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- -from ....Classes.Segment import Segment from ....Classes.Arc1 import Arc1 +from ....Classes.Segment import Segment def build_geometry(self): diff --git a/pyleecan/Methods/Slot/SlotW61/build_geometry_active.py b/pyleecan/Methods/Slot/SlotW61/build_geometry_active.py index 808a8df81..68ddad80d 100644 --- a/pyleecan/Methods/Slot/SlotW61/build_geometry_active.py +++ b/pyleecan/Methods/Slot/SlotW61/build_geometry_active.py @@ -1,5 +1,5 @@ -# -*- coding: utf-8 -*- from numpy import pi, exp + from ....Classes.Segment import Segment from ....Classes.SurfLine import SurfLine from ....Methods.Slot.SlotW61 import S61_WindError diff --git a/pyleecan/Methods/Slot/SlotWLSRPM/plot_schematics.py b/pyleecan/Methods/Slot/SlotWLSRPM/plot_schematics.py index a902d183b..51a36dd8f 100644 --- a/pyleecan/Methods/Slot/SlotWLSRPM/plot_schematics.py +++ b/pyleecan/Methods/Slot/SlotWLSRPM/plot_schematics.py @@ -33,6 +33,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -54,6 +56,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Use some default parameter @@ -69,7 +82,7 @@ def plot_schematics( Wrvd=0, slot=slot, ) - slot.plot_schematics( + return slot.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -77,15 +90,17 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The slot is not inside a Lamination") lam = self.parent - lam.plot(alpha=pi / self.Zs, is_show_fig=False) # center slot on Ox axis - fig = plt.gcf() - ax = plt.gca() + fig, ax = lam.plot( + alpha=pi / self.Zs, is_show_fig=False, fig=fig, ax=ax + ) # center slot on Ox axis point_dict = self._comp_point_coordinate() if self.is_outwards(): sign = 1 @@ -215,7 +230,7 @@ def plot_schematics( Rint = min(point_dict["Z2"].real, point_dict["Z1"].real) Rext = max(point_dict["Z2"].real, point_dict["Z1"].real) - plt.axis("equal") + ax.axis("equal") ax.set_xlim(Rint, Rext) ax.set_ylim(-W * 0.9, W * 0.7) manager = plt.get_current_fig_manager() @@ -228,7 +243,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/VentilationCirc/build_geometry.py b/pyleecan/Methods/Slot/VentilationCirc/build_geometry.py index 70415ec48..85b15409b 100644 --- a/pyleecan/Methods/Slot/VentilationCirc/build_geometry.py +++ b/pyleecan/Methods/Slot/VentilationCirc/build_geometry.py @@ -1,11 +1,9 @@ -# -*- coding: utf-8 -*- - - -from ....Classes.Circle import Circle from numpy import exp, pi from ....Methods.Slot.VentilationCirc import * from ....Functions.labels import VENT_LAB +from ....Classes.Circle import Circle + def build_geometry(self, alpha=0, delta=0): """Compute the curve needed to plot the ventilations diff --git a/pyleecan/Methods/Slot/VentilationCirc/check.py b/pyleecan/Methods/Slot/VentilationCirc/check.py index b2c0932b7..95d31cc2c 100644 --- a/pyleecan/Methods/Slot/VentilationCirc/check.py +++ b/pyleecan/Methods/Slot/VentilationCirc/check.py @@ -1,5 +1,5 @@ -# -*- coding: utf-8 -*- from ....Methods.Slot.VentilationCirc import * +from numpy import int32 def check(self): @@ -23,11 +23,11 @@ def check(self): Alpha0 must be a float ot int """ - if not isinstance(self.Zh, int): + if not isinstance(self.Zh, (int, int32)): raise VentilationCircInstanceError("Zh must be an integer") - if not isinstance(self.H0, float) and not isinstance(self.H0, int): + if not isinstance(self.H0, (float, int)): raise VentilationCircInstanceError("H0 must be a float ot int ") - if not isinstance(self.D0, float) and not isinstance(self.D0, int): + if not isinstance(self.D0, (float, int)): raise VentilationCircInstanceError("D0 must be a float or int ") - if not isinstance(self.Alpha0, float) and not isinstance(self.Alpha0, int): + if not isinstance(self.Alpha0, (float, int)): raise VentilationCircInstanceError("Alpha0 must be a float ot int") diff --git a/pyleecan/Methods/Slot/VentilationCirc/plot_schematics.py b/pyleecan/Methods/Slot/VentilationCirc/plot_schematics.py index f52b69255..e5aa537eb 100644 --- a/pyleecan/Methods/Slot/VentilationCirc/plot_schematics.py +++ b/pyleecan/Methods/Slot/VentilationCirc/plot_schematics.py @@ -31,6 +31,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -52,6 +54,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Use some default parameter @@ -65,7 +78,7 @@ def plot_schematics( lam = LamHole( Rint=0.1, Rext=0.2, is_internal=True, is_stator=False, hole=[hole] ) - hole.plot_schematics( + return hole.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -73,21 +86,23 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The hole is not inside a Lamination") lam = self.parent - lam.plot( + fig, ax = lam.plot( alpha=0, is_show_fig=False, is_lam_only=True, # No magnet + fig=fig, + ax=ax, ) # center hole on Ox axis sp = 2 * pi / self.Zh Rbo = self.get_Rbo() - fig = plt.gcf() - ax = plt.gca() point_dict = self._comp_point_coordinate() # Adding point label @@ -186,7 +201,7 @@ def plot_schematics( Rint = self.parent.Rint Rext = self.parent.Rext - plt.axis("equal") + ax.axis("equal") ax.set_ylim(-Rext / 10, Rext * 0.9) ax.set_xlim(Rext / 10, Rext) manager = plt.get_current_fig_manager() @@ -199,7 +214,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/VentilationPolar/plot_schematics.py b/pyleecan/Methods/Slot/VentilationPolar/plot_schematics.py index 8e7983405..4ab384699 100644 --- a/pyleecan/Methods/Slot/VentilationPolar/plot_schematics.py +++ b/pyleecan/Methods/Slot/VentilationPolar/plot_schematics.py @@ -31,6 +31,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -52,6 +54,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Use some default parameter @@ -66,7 +79,7 @@ def plot_schematics( lam = LamHole( Rint=0.1, Rext=0.2, is_internal=True, is_stator=False, hole=[hole] ) - hole.plot_schematics( + return hole.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -74,19 +87,21 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The hole is not inside a Lamination") lam = self.parent - lam.plot( + fig, ax = lam.plot( alpha=0, is_show_fig=False, is_lam_only=True, # No magnet + fig=fig, + ax=ax, ) # center hole on Ox axis - fig = plt.gcf() - ax = plt.gca() point_dict = self._comp_point_coordinate() # Adding point label @@ -235,7 +250,7 @@ def plot_schematics( Rint = self.parent.Rint Rext = self.parent.Rext - plt.axis("equal") + ax.axis("equal") ax.set_ylim(-Rext / 10, Rext * 0.9) ax.set_xlim(Rext / 10, Rext) manager = plt.get_current_fig_manager() @@ -248,7 +263,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax diff --git a/pyleecan/Methods/Slot/VentilationTrap/plot_schematics.py b/pyleecan/Methods/Slot/VentilationTrap/plot_schematics.py index 5062c3fa9..9d2d8faf1 100644 --- a/pyleecan/Methods/Slot/VentilationTrap/plot_schematics.py +++ b/pyleecan/Methods/Slot/VentilationTrap/plot_schematics.py @@ -31,6 +31,8 @@ def plot_schematics( type_add_active=True, save_path=None, is_show_fig=True, + fig=None, + ax=None, ): """Plot the schematics of the slot @@ -52,6 +54,17 @@ def plot_schematics( full path including folder, name and extension of the file to save if save_path is not None is_show_fig : bool To call show at the end of the method + fig : Matplotlib.figure.Figure + existing figure to use if None create a new one + ax : Matplotlib.axes.Axes object + Axis on which to plot the data + + Returns + ------- + fig : Matplotlib.figure.Figure + Figure containing the plot + ax : Matplotlib.axes.Axes object + Axis containing the plot """ # Use some default parameter @@ -67,7 +80,7 @@ def plot_schematics( lam = LamHole( Rint=0.1, Rext=0.2, is_internal=True, is_stator=False, hole=[hole] ) - hole.plot_schematics( + return hole.plot_schematics( is_default=False, is_add_point_label=is_add_point_label, is_add_schematics=is_add_schematics, @@ -75,19 +88,21 @@ def plot_schematics( type_add_active=type_add_active, save_path=save_path, is_show_fig=is_show_fig, + fig=fig, + ax=ax, ) else: # Getting the main plot if self.parent is None: raise ParentMissingError("Error: The hole is not inside a Lamination") lam = self.parent - lam.plot( + fig, ax = lam.plot( alpha=0, is_show_fig=False, is_lam_only=True, # No magnet + fig=fig, + ax=ax, ) # center hole on Ox axis - fig = plt.gcf() - ax = plt.gca() point_dict = self._comp_point_coordinate() # Adding point label @@ -196,7 +211,7 @@ def plot_schematics( Rint = self.parent.Rint Rext = self.parent.Rext - plt.axis("equal") + ax.axis("equal") ax.set_ylim(-Rext / 10, Rext * 0.9) ax.set_xlim(Rext / 10, Rext) manager = plt.get_current_fig_manager() @@ -209,7 +224,8 @@ def plot_schematics( # Save / Show if save_path is not None: fig.savefig(save_path) - plt.close() + plt.close(fig=fig) if is_show_fig: fig.show() + return fig, ax