The PSCAD Application

class mhrc.automation.pscad.PSCAD

This class is responsible for command and control of the PSCAD application.

An instance of this class would be created by the launch_pscad() command:

pscad = mhrc.automation.launch_pscad()

Configuration

PSCAD.settings(settings=None, **kwargs)

Set or retrieve PSCAD’s settings.

Parameters:
  • settings (dict) – A dictionary of setting key-values pairs
  • **kwargs – individual setting key-value pairs

If called without providing any key-value pairs, the current settings are returned. Otherwise, the given key-value pairs are set in the application’s settings.

Any unknown keys are silently ignored. The effect of setting an known key to an invalid value is undefined.

Application Flags

The following flags are supported:

Flag Name Description
silence Suppress popup dialogs which may interfere with automation.
load-meta-files Controls loading of additional project state information, such as build messages from a previous session.
PSCAD.set_flags(flags)

Set or clear one or more application flags

Parameters:flags (dict) – The flags to set or clear.

Example:

pscad.set_flags({"silence": True, "load-meta-files": False})
PSCAD.get_flags()

Retrieve the current application flags

Returns:A dictionary of the current application flags.

Example

>>> pscad.get_flags()
{'silence': True, 'load-meta-files': True}

Licensing

PSCAD.logged_in()

Returns whether or not the user is “Logged in”

Returns:True if the user is logged in, False otherwise.

Example

>>> pscad.logged_in()
True
PSCAD.licensed()

Determine whether a valid license is being held.

Returns:True if the a license is held, False otherwise.

Example

>>> pscad.licensed()
True
PSCAD.get_available_certificates()

Retrieve a list of license certificates available to the user.

Returns:A dictionary of certificates, keyed by Certificate.id().
PSCAD.get_current_certificate()

Retrieve the Certificate currently being held.

Returns:The Certificate being held, or None
PSCAD.get_certificate(certificate)

Attempt to acquire the given license certificate.

Parameters:certificate – the Certificate to be acquired.
PSCAD.release_certificate()

Releases the the currently held certificate.

Workspace Commands

PSCAD.new_workspace()

Unload the current workspace, and create a new one.

Warning

If popup dialogs are being silenced, all unsaved changes will be unconditionally lost.

PSCAD.workspace()

Retrieve a proxy controller for the PSCAD Workspace.

Returns:A Workspace controller
PSCAD.load(*filenames, handler=None)

Load a workspace, or one or more projects into the current workspace.

Parameters:
  • *filenames (str) – a list of filenames to load.
  • handler – If provided, the given handler is automatically added for the duration of the load operation. Defaults to None.

If a workspace file (*.pswx) is given, it must be the only file. Otherwise, more than one library (*.pslx) and/or case (*.pscx) may be given.

>>> pscad.load( os.path.join(examples_dir, r'tutorial\vdiv.pscx') )
>>> vdiv = pscad.project('vdiv')
>>> vdiv.parameters()['description']
'Single Phase Voltage Divider'
PSCAD.list_projects()

List all projects (libraries & cases) loaded in the current workspace.

Returns:The name, type and description of each project.
Return type:List[dict]
>>> pscad.load( os.path.join(examples_dir, r'tutorial\Tutorial.pswx') )
>>> for prj in pscad.list_projects():
...    print(prj)
{'name': 'master', 'type': 'Library', 'description': 'Master Library'}
{'name': 'chatter', 'type': 'Case', 'description': 'Simple case with chatter elimination'}
{'name': 'fft', 'type': 'Case', 'description': 'Harmonic Impedance and FFT'}
{'name': 'inputctrl', 'type': 'Case', 'description': 'Input Control Components'}
{'name': 'interpolation', 'type': 'Case', 'description': 'Simple case illustrating interpolation'}
{'name': 'legend', 'type': 'Case', 'description': 'Use of macros'}
{'name': 'vdiv', 'type': 'Case', 'description': 'Single Phase Voltage Divider'}
{'name': 'simpleac', 'type': 'Case', 'description': 'A Simple AC Power System'}
{'name': 'multirun', 'type': 'Case', 'description': 'A Simple Multiple Run Example'}
{'name': 'pagearray', 'type': 'Case', 'description': 'Page Inside a Page, Arrays'}
PSCAD.project(project_name)

Retrieve a controller for a named project (library or case) in the workspace.

Parameters:project_name (str) – Name of the library or case. The directory and filename extension must not be included.
Returns:A project controller
>>> master = pscad.project('master')
>>> master.parameters()['description']
'Master Library'

Build & Run Commands

PSCAD.build_all(handler=None)

Build all projects

PSCAD.build_current(handler=None)

Build only the current project

PSCAD.simulation_set(set_name)

Retrieve a proxy controller for a simulation set.

Parameters:set_name (str) – Name of the simulation set
Returns:A simulation set controller
PSCAD.run_all_simulation_sets(handler=None)

Run all simulations sets.

Any modified projects will be built as necessary.

PSCAD.pause_run()

Pause the currently running projects.

PSCAD.stop_run()

End the currently running projects.

PSCAD.clean_all()

Remove all temporary files used to build the case.

Subscriptions

These methods are used to get asynchronous events from the PSCAD application.

PSCAD.subscribe(name, handler=None)

Start receiving name events.

Parameters:
  • name (str) – Name of event being subscribed to, such as “load-events” or “build-events”
  • handler – Function to call when event is received.
PSCAD.unsubscribe(name)

Stop receiving and processing name events.

Parameters:name (str) – Name of event being unsubscribed from.
PSCAD.subscribed(name)

Determine if the given event is being subscribed to.

Returns:True if the given events is subscribed to, False otherwise.

Termination

PSCAD.quit()

Send the EXIT command to PSCAD.

The command will wait for at most 5 seconds for the PSCAD process to terminate. If the process is still running after 5 seconds, the operating system is asked to terminate the process.