The pyedb.generic.general_methods library#

Summary#

installed_ansys_em_versions

Scan environment variables and return a dict

get_filename_without_extension

Get the filename without its extension.

env_path

Get the path of the version environment variable for an AEDT version.

get_version_and_release

env_value

Get the name of the version environment variable for an AEDT version.

generate_unique_name

Generate a new name given a root name and optional suffix.

normalize_path

Normalize path separators.

check_numeric_equivalence

Check if two numeric values are equivalent to within a relative tolerance.

check_and_download_file

Check if a file is remote and either download it or return the path.

check_if_path_exists

Check whether a path exists or not local or remote machine (for remote sessions only).

check_and_download_folder

Check if a folder is remote and either download it or return the path.

open_file

Open a file and return the object.

get_string_version

env_path_student

Get the path of the version environment variable for an AEDT student version.

env_value_student

Get the name of the version environment variable for an AEDT student version.

generate_unique_folder_name

Generate a new AEDT folder name given a rootname.

generate_unique_project_name

Generate a new AEDT project name given a rootname.

time_fn

isclose

is_number

is_array

is_project_locked

Check if an AEDT project lock file exists.

remove_project_lock

Check if an AEDT project exists and try to remove the lock file.

read_csv

Read information from a CSV file and return a list.

read_csv_pandas

Read information from a CSV file and return a list.

read_tab

Read information from a TAB file and return a list.

read_xlsx

Read information from an XLSX file and return a list.

write_csv

filter_tuple

Filter a tuple of two elements with two search keywords.

filter_string

Filter a string

recursive_glob

Get a list of files matching a pattern, searching recursively from a start path.

number_aware_string_key

Get a key for sorting strings that treats embedded digit sequences as integers.

compute_fft

Compute FFT of input transient data.

parse_excitation_file

Parse a csv file and convert data in list that can be applied to Hfss and Hfss3dLayout sources.

tech_to_control_file

Convert a TECH file to an XML file for use in a GDS or DXF import.

install_with_pip

Install a new package using pip.

Module detail#

general_methods.installed_ansys_em_versions() Dict[str, str]#

Scan environment variables and return a dict {version: installation_path} for every ANSYS EM release found. Versions are ordered from oldest → latest (latest appears last).

general_methods.get_filename_without_extension(path)#

Get the filename without its extension.

Parameters:
pathstr

Path for the file.

Returns:
str

Name for the file, excluding its extension.

general_methods.env_path(input_version)#

Get the path of the version environment variable for an AEDT version.

Parameters:
input_versionstr

AEDT version.

Returns:
str

Path for the version environment variable.

Examples

>>> env_path_student("2021.2")
"C:/Program Files/ANSYSEM/ANSYSEM2021.2/Win64"
general_methods.get_version_and_release(input_version)#
general_methods.env_value(input_version)#

Get the name of the version environment variable for an AEDT version.

Parameters:
input_versionstr

AEDT version.

Returns:
str

Name for the version environment variable.

Examples

>>> env_value("2021.2")
"ANSYSEM_ROOT211"
general_methods.generate_unique_name(rootname, suffix='', n=6)#

Generate a new name given a root name and optional suffix.

Parameters:
rootname

Root name to add random characters to.

suffixstr

Suffix to add. The default is ''.

nint

Number of random characters to add to the name. The default value is 6.

Returns:
str

Newly generated name.

general_methods.normalize_path(path_in, sep=None)#

Normalize path separators.

Parameters:
path_instr

Path to normalize.

sepstr, optional

Separator.

Returns:
str

Path normalized to new separator.

general_methods.check_numeric_equivalence(a, b, relative_tolerance=1e-07)#

Check if two numeric values are equivalent to within a relative tolerance.

Returns:
bool

True if the two passed values are equivalent.

general_methods.check_and_download_file(local_path, remote_path, overwrite=True)#

Check if a file is remote and either download it or return the path.

Parameters:
local_pathstr

Local path to save the file to.

remote_pathstr

Path to the remote file.

overwritebool

Whether to overwrite the file if it already exits locally. The default is True.

Returns:
str
general_methods.check_if_path_exists(path)#

Check whether a path exists or not local or remote machine (for remote sessions only).

Parameters:
pathstr

Local or remote path to check.

Returns:
bool
general_methods.check_and_download_folder(local_path, remote_path, overwrite=True)#

Check if a folder is remote and either download it or return the path.

Parameters:
local_pathstr

Local path to save the folder to.

remote_pathstr

Path to the remote folder.

overwritebool

Whether to overwrite the folder if it already exits locally. The default is True.

Returns:
str
general_methods.open_file(file_path, file_options='r')#

Open a file and return the object.

Parameters:
file_pathstr

Full absolute path to the file (either local or remote).

file_optionsstr, optional

Options for opening the file.

Returns:
object

Opened file.

general_methods.get_string_version(input_version)#
general_methods.env_path_student(input_version)#

Get the path of the version environment variable for an AEDT student version.

Parameters:
input_versionstr

AEDT student version.

Returns:
str

Path for the student version environment variable.

Examples

>>> env_path_student("2021.2")
"C:/Program Files/ANSYSEM/ANSYSEM2021.2/Win64"
general_methods.env_value_student(input_version)#

Get the name of the version environment variable for an AEDT student version.

Parameters:
input_versionstr

AEDT student version.

Returns:
str

Name for the student version environment variable.

Examples

>>> env_value_student("2021.2")
"ANSYSEMSV_ROOT211"
general_methods.generate_unique_folder_name(rootname=None, folder_name=None)#

Generate a new AEDT folder name given a rootname.

Parameters:
rootnamestr, optional

Root name for the new folder. The default is None.

folder_namestr, optional

Name for the new AEDT folder if one must be created.

Returns:
str
general_methods.generate_unique_project_name(rootname=None, folder_name=None, project_name=None, project_format='aedt')#

Generate a new AEDT project name given a rootname.

Parameters:
rootnamestr, optional

Root name where the new project is to be created.

folder_namestr, optional

Name of the folder to create. The default is None, in which case a random folder is created. Use "" if you do not want to create a subfolder.

project_namestr, optional

Name for the project. The default is None, in which case a random project is created. If a project with this name already exists, a new suffix is added.

project_formatstr, optional

Project format. The default is "aedt". Options are "aedt" and "aedb".

Returns:
str
general_methods.time_fn(fn, *args, **kwargs)#
general_methods.isclose(a, b, rel_tol=1e-09, abs_tol=0.0)#
general_methods.is_number(a)#
general_methods.is_array(a)#
general_methods.is_project_locked(project_path)#

Check if an AEDT project lock file exists.

Parameters:
project_pathstr

Path for the AEDT project.

Returns:
bool

True when successful, False when failed.

general_methods.remove_project_lock(project_path)#

Check if an AEDT project exists and try to remove the lock file.

Note

This operation is risky because the file could be opened in another AEDT instance.

Parameters:
project_pathstr

Path for the AEDT project.

Returns:
bool

True when successful, False when failed.

general_methods.read_csv(filename, encoding='utf-8')#

Read information from a CSV file and return a list.

Parameters:
filenamestr

Full path and name for the CSV file.

encodingstr, optional

File encoding for the CSV file. The default is "utf-8".

Returns:
list
general_methods.read_csv_pandas(filename, encoding='utf-8')#

Read information from a CSV file and return a list.

Parameters:
filenamestr

Full path and name for the CSV file.

encodingstr, optional

File encoding for the CSV file. The default is "utf-8".

Returns:
pandas.DataFrame
general_methods.read_tab(filename)#

Read information from a TAB file and return a list.

Parameters:
filenamestr

Full path and name for the TAB file.

Returns:
list
general_methods.read_xlsx(filename)#

Read information from an XLSX file and return a list.

Parameters:
filenamestr

Full path and name for the XLSX file.

Returns:
list
general_methods.write_csv(output, list_data, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)#
general_methods.filter_tuple(value, search_key1, search_key2)#

Filter a tuple of two elements with two search keywords.

general_methods.filter_string(value, search_key1)#

Filter a string

general_methods.recursive_glob(startpath, filepattern)#

Get a list of files matching a pattern, searching recursively from a start path.

Keyword Arguments: startpath – starting path (directory) filepattern – fnmatch-style filename pattern

general_methods.number_aware_string_key(s)#

Get a key for sorting strings that treats embedded digit sequences as integers.

Parameters:
sstr

String to calculate the key from.

Returns:
tuple

Tuple of key entries.

general_methods.compute_fft(time_vals, value)#

Compute FFT of input transient data.

Parameters:
time_valspandas.Series
valuepandas.Series
Returns:
tuple

Frequency and Values.

general_methods.parse_excitation_file(file_name, is_time_domain=True, x_scale=1, y_scale=1, impedance=50, data_format='Power', encoding='utf-8', out_mag='Voltage')#

Parse a csv file and convert data in list that can be applied to Hfss and Hfss3dLayout sources.

Parameters:
file_namestr

Full name of the input file.

is_time_domainbool, optional

Either if the input data is Time based or Frequency Based. Frequency based data are Mag/Phase (deg).

x_scalefloat, optional

Scaling factor for x axis.

y_scalefloat, optional

Scaling factor for y axis.

data_formatstr, optional

Either “Power”, “Current” or “Voltage”.

impedancefloat, optional

Excitation impedance. Default is 50.

encodingstr, optional

Csv file encoding.

out_magstr, optional

Output magnitude format. It can be “Voltage” or “Power” depending on Hfss solution.

Returns:
tuple

Frequency, magnitude and phase.

general_methods.tech_to_control_file(tech_path, unit='nm', control_path=None)#

Convert a TECH file to an XML file for use in a GDS or DXF import.

Parameters:
tech_pathstr

Full path to the TECH file.

unitstr, optional

Tech units. If specified in tech file this parameter will not be used. Default is "nm".

control_pathstr, optional

Path for outputting the XML file.

Returns:
str

Out xml file.

general_methods.install_with_pip(package_name, package_path=None, upgrade=False, uninstall=False)#

Install a new package using pip. This method is useful for installing a package from the AEDT Console without launching the Python environment.

Warning

Do not execute this function with untrusted function argument, environment variables or pyedb global settings. See the security guide for details.

Parameters:
package_namestr

Name of the package to install.

package_pathstr, optional

Path for the GitHub package to download and install. For example, git+https://......

upgradebool, optional

Whether to upgrade the package. The default is False.

uninstallbool, optional

Whether to install the package or uninstall the package.

general_methods.is_linux#
general_methods.is_windows#
general_methods.clamp#
general_methods.rgb_color_codes#
general_methods.online_help#