The general_methods.py module#

Summary#

deprecate_kwargs

Issues deprecation warnings for arguments.

run_if_graphics_required

Check if graphics are available.

graphics_required

Decorate a method as requiring graphics.

magnitude_vector

Compute the magnitude (length) of a 2D or 3D vector using NumPy.

normalize_vector

Normalize a 2D or 3D vector to have a length of 1 using NumPy.

error_no_install

Raise error that installation was not found at a location.

retrieve_speos_install_dir

Retrieve the Speos RPC installation directory.

wavelength_to_rgb

Convert a given wavelength of light to an approximate RGB color value.

min_speos_version

Raise version warning.

Description#

General methods and helpers collection.

this includes decorator and methods

Module detail#

general_methods.deprecate_kwargs(old_arguments, removed_version='0.3.0')#

Issues deprecation warnings for arguments.

Parameters:
old_argumentsdict

key old argument value new argument name

removed_versionstr

Release version with which argument support will be removed By Default, next major release

general_methods.run_if_graphics_required(warning=False)#

Check if graphics are available.

general_methods.graphics_required(method)#

Decorate a method as requiring graphics.

Parameters:
methodcallable()

Method to decorate.

Returns:
callable()

Decorated method.

general_methods.magnitude_vector(vector)#

Compute the magnitude (length) of a 2D or 3D vector using NumPy.

Parameters:
vector: List[float]

A 2D or 3D vector as a list [x, y] or [x, y, z].

Returns:
float

The magnitude (length) of the vector.

general_methods.normalize_vector(vector)#

Normalize a 2D or 3D vector to have a length of 1 using NumPy.

Parameters:
vector: List[float]

A vector as a list [x, y] for 2D or [x, y, z] for 3D.

Returns:
List[float]

The normalized vector.

general_methods.error_no_install(install_path, version)#

Raise error that installation was not found at a location.

Parameters:
install_pathUnion[Path, str]

Installation path where the executable was expected.

versionUnion[int, str]

Ansys version number (e.g. 242).

Raises:
FileNotFoundError

Always raised to signal a missing Speos RPC installation.

general_methods.retrieve_speos_install_dir(speos_rpc_path=None, version=DEFAULT_VERSION)#

Retrieve the Speos RPC installation directory.

Resolution order: 1. Validate / normalise a caller-supplied path. 2. Discover the installation via get_available_ansys_installations(). 3. Fall back to the AWP_ROOT environment variable.

Parameters:
speos_rpc_pathOptional[Union[str, Path]]

Explicit path to the Speos RPC executable or its parent directory. When None or empty the function performs automatic discovery.

versionUnion[str, int]

Three-digit Ansys version string or integer (e.g. "242" or 242). Defaults to DEFAULT_VERSION.

Returns:
Path

Directory that contains the SpeosRPC_Server executable.

Raises:
FileNotFoundError

When no valid installation can be located.

general_methods.wavelength_to_rgb(wavelength, gamma=0.8)#

Convert a given wavelength of light to an approximate RGB color value.

The wavelength must be given in nanometers in the range from 380 nm to 750 nm. Based on the code from http://www.physics.sfasu.edu/astro/color/spectra.html

Parameters:
wavelengthfloat

Wavelength in nanometer between 380-750 nm

gammafloat

Gamma value. By default : 0.8

general_methods.min_speos_version(major, minor, service_pack)#

Raise version warning.

Parameters:
majorint

Major release version, e.g. 25

minorint

Minor release version e.g. 1

service_packint

Service Pack version e.g. 3

general_methods.GRAPHICS_ERROR = "Preview unsupported without 'ansys-tools-visualization_interface' installed. You can install...#
general_methods.VERSION_ERROR = 'The pySpeos feature : {feature_name} needs a Speos Version of {version} or higher.'#