The PSCAD Application#
- class mhi.pscad.PSCAD#
The PSCAD Application
This proxy is used to communicate with a running PSCAD Application, and may only be created via one of the following methods:
Configuration#
Application Settings#
- PSCAD.settings() Dict[str, Any]#
- PSCAD.settings(settings: Dict[str, Any] | None = None, **kwargs) None
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.
- PSCAD.setting_range(setting: str) Tuple | Set | range | None#
Get legal values for a setting.
The function may return:
a
tuple,set, or afrozensetof legal values,a
range()of legal values (integer settings),a
Tuple[float, float]representing minimum and maximum values (real & complex settings),Noneif the setting does not have a defined rangean exception if no such setting exists
- Parameters:
setting (str) – A PSCAD setting name
- Returns:
The valid values or range the setting may take on.
Examples:
>>> pscad.setting_range('agent_show') (False, True) >>> pscad.setting_range('autosave_interval') {'15_MINUTES', '1_HOUR', 'NO_ACTION', '5_MINUTES'} >>> pscad.setting_range('SocketPortBase') range(30000, 40000, 1000) >>> pscad.setting_range('backup_folder') >>> pscad.setting_range('python_version') Traceback (most recent call last): ... ValueError: No such setting
Added in version 2.1.
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.flags() Dict[str, bool]#
- PSCAD.flags(flags: Dict[str, bool] | None = None, **kwargs) None
Retrieve or set application flags
If no flags are given, the value of all flags is returned. Otherwise, the specified flags are set or cleared.
- Parameters:
flags (dict) – The flags to set or clear (optional).
**kwargs – Flags to set or clear as key=value pairs (optional)
Examples:
pscad.flags({"silence": True, "load-meta-files": False}) pscad.flags(silence=True, load_meta_files=False)
Properties#
Added in version 2.0.
- PSCAD.version#
The PSCAD version string. (Read-only)
- PSCAD.examples_folder#
The PSCAD “Examples Directory”. (Read-only)
Licensing#
Certificate#
- PSCAD.login(username: str, password: str, remember: bool = False)#
Attempt to log in to a MyCentre account, for licensing.
- PSCAD.logged_in() bool#
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() bool#
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(*, refresh: bool = False) Dict[int, Certificate]#
Retrieve a list of license certificates available to the user.
- Returns:
A dictionary of
certificates, keyed byCertificate.id().
- PSCAD.get_current_certificate() Certificate | None#
Retrieve the Certificate currently being held.
- Returns:
The
Certificatebeing held, or None
- PSCAD.get_certificate(certificate: Certificate) int#
Attempt to acquire the given license certificate.
- Parameters:
certificate – the
Certificateto be acquired.
Legacy#
Workspace Commands#
Changed in version 2.0: These methods used to be under the Workspace object
- PSCAD.new_workspace(filename: str | PurePath = '~\\Documents\\NewWorkspace.pswx', folder: str | PurePath | None = None) None#
Unload the current workspace, and create a new one.
- Parameters:
Warning
If popup dialogs are being silenced, all unsaved changes will be unconditionally lost.
Changed in version 2.0: Added
filename&folderparameters.
- PSCAD.save_workspace(filename: str | None = None, folder: str | None = None, save_projects: bool = True) None#
Save the current workspace, possibly as a new workspace.
- PSCAD.workspace_dir#
Return the current workspace directory
- PSCAD.workspace_name#
Return the current workspace name
- PSCAD.workspace_path#
Return the current workspace path
- PSCAD.is_dirty() bool#
Determine whether the workspace has been modified since the last time it was saved.
- Returns:
True if the workspace has unsaved changes, False otherwise.
- PSCAD.load(*filenames: str, handler=None, folder: str | None = None) None#
Load a workspace, or one or more projects into the current workspace.
- Parameters:
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(r'tutorial\vdiv.pscx', folder=pscad.examples_folder) >>> vdiv = pscad.project('vdiv') >>> vdiv.parameters()['description'] 'Single Phase Voltage Divider'
Note
In the common case of loading a workspace immediately after launching PSCAD, it is better to pass that workspace to the
launch()command:pscad = mhi.pscad.launch(load=r'c:\path\to\workspace.pswx')This avoids restoring a previous workspace, which then must be unloaded prior to loading the desired one.
Changed in version 2.0: Added
folderparameter.
- PSCAD.projects() List[Dict[str, str]]#
List all currently loaded libraries and cases.
- Returns:
The
name,typeanddescriptionof each project in the workspace.- Return type:
List[dict]
With only the master library loaded:
>>> pscad.projects() [{'name': 'master', 'type': 'Library', 'description': 'Master Library'}]
Instead of a
name,type, anddescriptiondictionary,cases()may be used to retrieve all the case projects, andlibraries()to retrieve all the library projects.Changed in version 2.0: Was
PSCAD.list_projects().
- PSCAD.project_names() List[str]#
List all currently loaded library and case names.
- Returns:
The
nameof each project in the workspace.- Return type:
List[str]
With only the master library loaded:
>>> pscad.project_names() ['master']
Added in version 2.9.6.
- PSCAD.cases() List[Project]#
List all currently loaded cases.
- Returns:
A list of case projects.
- Return type:
List[Project]
Added in version 2.6.
- PSCAD.libraries() List[Project]#
List all currently loaded libraries.
- Returns:
A list of library projects.
- Return type:
List[Project]
Added in version 2.6.
- PSCAD.project(name: str) Project#
Retrieve a controller for a named project in the workspace.
- Parameters:
name (str) – The name of the library or case. The directory and filename extension must not be included.
- Returns:
A
projectcontroller.
>>> master = pscad.project('master') >>> master.parameters()['description'] 'Master Library'
- PSCAD.create_library(filename: str, folder: str | None = None) Project#
Create a new library project in the workspace.
- Parameters:
- Returns:
The newly created library.
Added in version 2.0: Replaces
PSCAD.create_project(2, name, folder)
Build & Run Commands#
Changed in version 2.0: These methods used to be under the Workspace object
Simulation Sets#
Changed in version 2.0: These methods used to be under the Workspace object
- PSCAD.simulation_sets() List[str]#
List all simulations set names.
- Returns:
A names of all simulation sets in the workspace.
- Return type:
List[str]
Changed in version 2.0: Replaces
Workspace.list_simulation_sets()
- PSCAD.create_simulation_set(set_name: str) SimulationSet#
Create a new simulation set.
- Parameters:
set_name (str) – Name of the new simulation set.
- PSCAD.simulation_set(set_name: str) SimulationSet#
Retrieve a controller proxy for the given simulation set.
- Parameters:
set_name (str) – Name of the simulation set.
- Returns:
The named simulation set.
- Return type:
Changed in version 2.0: Replaces
Workspace.simulation_set(set_name)
Parameter Grid#
Added in version 2.8.1.
- PSCAD.parameter_grid#
The Parameter Grid interface object.
Example:
# Load simulations sets into parameter grid, & export the grid to a file pscad.parameter_grid.view_simulation_sets() pscad.parameter_grid.save("sim_sets.csv")
The following methods are defined on the interface object
- ParameterGrid.view(subject: Component | Definition | Project) None#
Load subject into the parameter grid.
The property grid is able to view and modify several components at once.
If the subject is a component or component definition, all of the instances of that component are loaded into the parameter grid.
If the subject is a project, all of the corresponding project types (libraries or cases) are loaded into the parameter grid.
- ParameterGrid.view_libraries() None#
Load all libraries into the parameter grid.
Note: The ‘master’ library is always omitted.
- ParameterGrid.view_simulation_sets() None#
Load all simulation sets into the property grid.
This allows for viewing / editing multiple simulation sets in the workspace at once.
- ParameterGrid.view_simulation_tasks() None#
Load all simulation tasks into the property grid.
This allows for viewing / editing multiple simulation tasks in the workspace at once.
- ParameterGrid.view_simulation_task_overrides() None#
Load simulation tasks’ project overrides into the property grid.
This allows for viewing / editing multiple sets of project overrides in the workspace at once.
- ParameterGrid.view_simulation_task_layers(scope: Project | str) None#
Load simulation tasks’ layers configurations into the property grid.
This allows for viewing / editing multiple sets of layers configurations in the workspace at once.
- Parameters:
scope – The project object or a project name
Search Results#
Subscriptions#
These methods are used to get asynchronous events from the PSCAD application.
- PSCAD.subscriptions() Set[str]#
Returns the set of event-names which can be
subscribedto.- Returns:
Event names which can be subscribed to.
- Return type:
Set[str]
Added in version 2.0.
- PSCAD.subscribed(name: str) bool#
Determine if the given event is being subscribed to.
- Returns:
True if the given event is subscribed to, False otherwise.
- PSCAD.subscribe(name: str, handler=None) 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.
Keys & Mouse#
Keystroke Events#
Changed in version 2.0: These methods used to be under the KeyStrokes object
- PSCAD.typing(data: str, cooked: bool = False)#
Send a series of keystrokes to type in the application.
Since pressing and holding certain keys will change the meaning of other keypresses, modifier prefixes are used to indicate which keys must be pressed and released around another key: ‘!’ is for SHIFT, ‘@’ is for ALT, and ‘#’ is for CTRL.
By default, this method will “cook” strings, adding the appropriate modifiers to turn a character into a series of modified keypress. If cooked=True is specified, the given string must already contain the required modifiers.
Raw
Cooked
He said, ‘How & why?’
!he said, ‘!how !7 why!/’
Mouse Events#
Changed in version 2.0: These methods used to be under the MouseEvents object
Termination#
- PSCAD.quit()#
Terminate the PSCAD application