Skip to content

Commit

Permalink
REFACTOR: Homogeneize imports of extra deps (#5339)
Browse files Browse the repository at this point in the history
  • Loading branch information
SMoraisAnsys authored Oct 24, 2024
1 parent 7a666a3 commit a06a08a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import shutil
import sys
import warnings

from ansys.aedt.core.aedt_logger import pyaedt_logger as logger
from ansys.aedt.core.application.variables import decompose_variable_value
Expand All @@ -41,16 +42,22 @@
from ansys.aedt.core.visualization.plot.pyvista import ModelPlotter
from ansys.aedt.core.visualization.plot.pyvista import get_structured_mesh

np = None
pv = None

try:
import numpy as np
except ImportError: # pragma: no cover
warnings.warn(
"The NumPy module is required to run some functionalities of FfdSolutionData.\n"
"Install with \n\npip install numpy"
)
np = None

try:
import pyvista as pv
except ImportError: # pragma: no cover
warnings.warn(
"The PyVista module is required to run functionalities of FfdSolutionData.\n"
"Install with \n\npip install pyvista"
)
pv = None


Expand Down
5 changes: 5 additions & 0 deletions src/ansys/aedt/core/visualization/advanced/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import logging
import os
import re
import warnings

from ansys.aedt.core.generic.constants import CSS4_COLORS
from ansys.aedt.core.generic.constants import SI_UNITS
Expand All @@ -39,6 +40,10 @@
try:
import pyvista as pv
except ImportError: # pragma: no cover
warnings.warn(
"The PyVista module is required to run functionalities of ansys.aedt.core.visualization.advanced.misc.\n"
"Install with \n\npip install pyvista"
)
pv = None


Expand Down
32 changes: 29 additions & 3 deletions src/ansys/aedt/core/visualization/advanced/touchstone_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,38 @@
import os
import re
import subprocess
import warnings

from ansys.aedt.core.generic.aedt_versions import aedt_versions
from ansys.aedt.core.generic.general_methods import pyaedt_function_handler
import matplotlib.pyplot as plt
import numpy as np
import skrf as rf

try:
import numpy as np
except ImportError: # pragma: no cover
warnings.warn(
"The NumPy module is required to run some functionalities of TouchstoneData.\n"
"Install with \n\npip install numpy"
)
np = None

try:
import matplotlib as plt
except ImportError: # pragma: no cover
warnings.warn(
"The Matplotlib module is required to run functionalities of TouchstoneData.\n"
"Install with \n\npip install matplotlib"
)
plt = None

try:
import skrf as rf
except ImportError: # pragma: no cover
warnings.warn(
"The Scikit-rf module is required to run functionalities of TouchstoneData.\n"
"Install with \n\npip install scikit-rf"
)
rf = None


REAL_IMAG = "RI"
MAG_ANGLE = "MA"
Expand Down
9 changes: 6 additions & 3 deletions src/ansys/aedt/core/visualization/post/field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import shutil
import sys
import tempfile
import warnings

from ansys.aedt.core.generic.constants import AllowedMarkers
from ansys.aedt.core.generic.constants import EnumUnits
Expand All @@ -40,11 +41,13 @@
from ansys.aedt.core.generic.load_aedt_file import load_keyword_in_aedt_file
from ansys.aedt.core.modeler.cad.elements_3d import FacePrimitive

pd = None

try:
import pandas as pd
except ImportError:
except ImportError: # pragma: no cover
warnings.warn(
"The Matplotlib module is required to run functionalities of ansys.aedt.core.visualization.post.field_data.\n"
"Install with \n\npip install matplotlib"
)
pd = None


Expand Down
9 changes: 6 additions & 3 deletions src/ansys/aedt/core/visualization/post/field_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@
import csv
import os
import tempfile
import warnings

from ansys.aedt.core import pyaedt_function_handler
from ansys.aedt.core.generic.general_methods import open_file

pd = None

try:
import pandas as pd
except ImportError:
except ImportError: # pragma: no cover
warnings.warn(
"The Matplotlib module is required to run functionalities of FieldSummary.\n"
"Install with \n\npip install matplotlib"
)
pd = None

TOTAL_QUANTITIES = [
Expand Down

0 comments on commit a06a08a

Please sign in to comment.