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 and 3.8, including the Anaconda distribution. However, the iPython shell is not yet supported, so Anaconda users must change their default console preferences to run using an external system terminal. Tested Python IDEs include Notepad++/Command Prompt, PyCharm, Spyder, and Visual Studio Code.
The source code can be viewed here: emodeconnection
Setup
Install the emodeconnection
Python package from the Windows command line.
pip install emodeconnection
The EMode class
- class EMODE(simulation_name='emode', 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 their username and password. To reset the user profile, run
EMode Login
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 argumentnew_name = "new_filename"
.Depending on the options passed to the close() method, the simulation file is either deleted, saved, or converted to a MATLAB-style .mat file.
- Parameters:
simulation_name (str) – Name of the simulation file. The extension ‘.eph’ will be added to this name. Default: ‘emode’.
save_path (str) – Name of the path where the simulation file will be created and saved. Default: ‘.’.
verbose (bool) – Whether to run EMode in verbose mode for debugging. Default: False.
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. Default: False.
open_existing (bool) – Whether to open an existing file or to start a new simulation. Default: False.
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. Default: False.
priority (str) – Set the CPU process priority. ‘pH’: High; ‘pAN’: Above normal; ‘pN’: Normal; ‘pBN’: Below normal; ‘pI’: Idle. Default: ‘pN’.
- call(function, **kwargs)
Calls an EMode function with optional inputs.
- Parameters:
function (str) – Name of the function to call in EMode. See the EMode API section for the list of available functions and their corresponding inputs.
**kwargs – Keyword arguments as defined by the inputs to the specified EMode function.
- Returns:
Status: ‘OK’, ‘ERROR’, or ‘WARNING’.
- Return type:
str
- Raises:
TypeError – if function is not a str
TypeError – if **kwargs is not a str, list, int, float, numpy.int64, or numpy.float64
- get(variable)
Returns a specific variable from the EMode simulation file.
- Parameters:
variable (str) – Name of the variable to return from EMode.
- Returns:
Requested item from EMode.
- Return type:
int, float, str, or array-like
- Raises:
TypeError – if variable is not a str
- inspect()
Returns a list of all available variable names from the EMode simulation file.
- Returns:
List of names of all variables available in the current EMode session. Any of these variables can be extracted to the user with the get() method.
- Return type:
list
- close(**kwargs)
Closes the EMode connection and either saves or deletes the simulation file.
- Parameters:
**kwargs – Keyword arguments to pass to the EM_close function in EMode.
- open_file(sim)
Opens an EMode simulation file with the extension “.eph” or “.mat” and returns a dictionary with the file contents.
- Parameters:
sim (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, sim='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.
sim (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(sim='emode')
Get the names of all variables from EMode simulation file with the extension “.eph” or “.mat”.
- Parameters:
sim (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