Python interface

To control EMode directly from a Python script, we supply a Python package called emodeconnection. This has been tested with Python versions 3.7, 3.8, 3.9, and 3.10, including the Anaconda distribution and iPython terminals. Tested Python IDEs include Notepad++/Command Prompt, PyCharm, Spyder, and Visual Studio Code.

The source code can be viewed here: emodeconnection

For more information about Python, see these links:

Setup

Install the emodeconnection Python package from the Windows command line.

pip install emodeconnection

The EMode class

class EMode(simulation_name='emode', license_type='default', save_path='.', verbose=False, roaming=False, open_existing=False, new_name=False, priority='pN')

Opens the EMode software and initializes a local simulation file. The user’s account must have an active license available to successfully run EMode. If the user has not previously logged in, this will prompt for a username and password. To reset the user profile, run EModeLogin from the the start menu.

An existing file can be opened for further analysis by specifying the input argument open_existing = True. This opened file can be copied to a new file name by specifying the input argument new_name = 'new_filename'.

Note

All EMode functions are accessible as methods of this class instance using keyword arguments for each funtion input parameter.

Parameters:
  • simulation_name (str) – Name of the simulation file. The extension ‘.eph’ will be added to this name.

  • license_type (str) – The requested license type, either ‘2D’, ‘3D’, or ‘default’. When running with ‘default’ license type, a ‘3D’ license will be initialized if it is available, otherwise a ‘2D’ license will be initialized if it is available. The ‘2D’ or ‘3D’ options will only request that specific license type if it is available.

  • save_path (str) – Name of the path where the simulation file will be created and saved.

  • verbose (bool) – Whether to run EMode in verbose mode for debugging.

  • roaming (bool) – Set the license manager to roaming mode. Normal mode (roaming = False) re-checks the license connection every 30 minutes, allowing licenses to reset after 30 minutes if the internet connection fails. Roaming mode (roaming = True) can be used to extend the license re-check to 3 days to support long simulations without continuously re-checking the license.

  • open_existing (bool) – Whether to open an existing file or to start a new simulation.

  • new_name (bool or str) – New name of opened existing file so the original file does not get modified. If False the original name is used. The extension ‘.eph’ will be added to this name.

  • priority (str) – Set the CPU process priority. ‘pH’: High; ‘pAN’: Above normal; ‘pN’: Normal; ‘pBN’: Below normal; ‘pI’: Idle.

Functions

The emodeconnection package provides access to the EMode simulation files without using an active EMode license. This is helpful for analyzing simulation data without checking out an EMode license or for sharing the EMode simulation results with a collaborator who does not have an EMode license.

open_file(simulation_name='emode')

Opens an EMode simulation file with the extension ‘.eph’ or ‘.mat’ and returns a dictionary with the file contents.

Parameters:

simulation_name (str) – Name of the simulation file. The ‘.eph’ or ‘.mat’ extension is optional to include with the name.

Returns:

Dictionary with all keys and data from the specified EMode simulation file.

Return type:

dict

get(variable, simulation_name='emode')

Returns the contents of a specified variable from an EMode simulation file with the extension ‘.eph’ or ‘.mat’.

Parameters:
  • variable (str) – Name of the variable to return from EMode.

  • simulation_name (str) – Name of the simulation file. The ‘.eph’ or ‘.mat’ extension is optional to include with the name.

Returns:

Requested item from EMode.

Return type:

int, float, str, or array-like

inspect(simulation_name='emode')

Get the names of all variables from EMode simulation file with the extension ‘.eph’ or ‘.mat’.

Parameters:

simulation_name (str) – Name of the simulation file. The ‘.eph’ or ‘.mat’ extension is optional to include with the name.

Returns:

List of names of all variables available in the EMode simulation file. Any of these variables can be extracted to the user with the get() function.

Return type:

list