Workspace & Projects¶
Workspace¶
-
class
mhrc.automation.workspace.
Workspace
(pscad)¶ This class is responsible for interacting with the PSCAD “Workspace”.
The Workspace object must be retrieved from an instance of the PSCAD controller, using the
PSCAD.workspace()
method.workspace = pscad.workspace()
Configuration¶
-
Workspace.
parameters
(parameters=None, **kwargs)¶ Get or set the current workspace’s options
Workspace options are usually set through the “Workspace Options…” menu on the Workspace panel, but they can be retrieved or modified with this function.
Parameters: - parameters (dict) – A dictionary of option name=value pairs
- **kwargs – One or more name=value keyword options
While option values are always returned as strings, they may be given as string, integer or boolean values.
Enable compile auto-save and set auto-save interval to 15 minutes:
workspace.parameters(compile_save_enable=True, autosave_interval=15)
To retrive all of the workspace options, pass in no arguments:
>>> workspace.parameters() {'compile_save_enable': 'false', 'autosave_interval': '0', ... }
Warning
It is possible to set options to invalid values. Operation of PSCAD is undefined when illegal values have be used.
For example, the legal values for
autosave_interval
are 0, 5, 15, and 60. If it is set to a different value, such as 10, PSCAD will show the autosave interval asNever
.
-
Workspace.
is_dirty
()¶ Determine whether the workspace has been modified since the last time it was saved.
Returns: True if the workspace has unsaved changes, False otherwise.
Projects¶
In PSCAD, the term “Project” refers to both PSCAD Libraries (*.pslx) as well as PSCAD Cases (*.pscx).
-
Workspace.
projects
()¶ List all currently loaded libraries and cases.
Returns: The name
,type
anddescription
of each project in the workspace.Return type: List[dict] With only the master library loaded:
>>> workspace.projects() [{'name': 'master', 'type': 'Library', 'description': 'Master Library'}]
-
Workspace.
project
(project_name)¶ Retrieve a controller for a named project in the workspace.
Parameters: project_name (str) – The name of the library or case. The directory and filename extension must not be included. Returns: A project
controller.>>> master = workspace.project('master') >>> master.parameters()['description'] 'Master Library'
-
Workspace.
create_project
(prj_type, name, path)¶ Create a new project in the workspace.
Parameters: - prj_type (int) – Project type. Use 1 -> case, 2 -> library
- name (str) – Name of the project.
- path (str) – Path to directory where project will be stored.
Returns: A project controller for the newly created project.
Simulation Sets¶
-
Workspace.
list_simulation_sets
()¶ List all simulations set names.
Returns: A names of all simulation sets in the workspace. Return type: List[str]
-
Workspace.
create_simulation_set
(set_name)¶ Create a new simulation set.
Parameters: set_name (str) – Name of the new simulation set.
-
Workspace.
remove_simulation_set
(set_name)¶ Remove an existing simulation set.
Parameters: set_name (str) – Name of the simulation set to remove.
-
Workspace.
simulation_set
(set_name)¶ Retrieve a controller proxy for the given simulation set.
Parameters: set_name (str) – Name of the simulation set. Returns: A controller proxy for the simulation set.
Projects¶
In PSCAD, a Project may refer to a Library (.pslx) or a `Case` (.pscx). A Library will contain component definitions and/or code which may be used in other libraries and cases. A Case is a runnable simulation that may reference other libraries.
The Master Library is a library which is automatically loaded into every
workspace
.
-
class
mhrc.automation.project.
ProjectCommands
¶ A Project Controller
Once loaded into the
Workspace
, a project must be referenced through a project controller object by callingPSCAD.project()
passing in the appropriate project name:>>> master_library = pscad.project('master') # Get master library project
Management¶
-
ProjectCommands.
focus
()¶ Switch PSCAD’s focus to this project.
-
ProjectCommands.
parameters
(parameters=None, **kwargs)¶ Get or set project parameters
Parameters: - parameters (dict) – A dictionary of name=value parameters
- **kwargs – Zero or more name=value keyword parameters
Returns: A dictionary of current parameters, if no parameters were given.
¶ Param Name Type Description time_duration float Duration of run description str Description MrunType int Run config 0=Standalone, 1=Master, 2=Slave startup_filename str Start up snapshot file name PlotType int Save Channels to disk 0=No, 1=Yes snapshot_filename str Save snapshot as text SnapTime float Snapshot time as a real number SnapType int Timed Snapshot: 0=None, 1=Single, 2=Incremental (same file), 3=Incremental (multiple file) StartType int Start simulation: 0=Standard, 1=From Snapshot File Source str Additional Source files Mruns int Number of multiple runs output_filename str Name of data file, with .out extension sample_step float Channel plot step time_step float Solution time step
-
ProjectCommands.
set_parameters
(parameters=None, **kwargs)¶ Set project parameters
The names of the parameters which are to be changed are tested against the set of existing parameters. If an unknown parameter is found, no action is performed and False is returned.
Parameters: - parameters (dict) – A dictionary of name=value parameters
- **kwargs – Zero or more name=value keyword parameters
Returns: True if all parameter names are valid, False otherwise.
-
ProjectCommands.
save
()¶ Save changes made to this project
-
ProjectCommands.
save_as
(name)¶ Save this project to a new name or location.
Parameters: name (str) – The filename to store project to.
-
ProjectCommands.
is_dirty
()¶ Check if the project contains unsaved changes
Returns: True, if unsaved changes exist, False otherwise.
Build & Run¶
-
ProjectCommands.
build
()¶ Build the current project
-
ProjectCommands.
run
(consumer=None)¶ Build and run this project.
Parameters: consumer – handler for events generated by the build/run (optional). Note
A library cannot be run; only a case can be run.
-
ProjectCommands.
pause
()¶ Pause the currently running projects.
Note
All projects being run will be paused, not just this project.
-
ProjectCommands.
stop
()¶ End the currently running projects.
Note
All projects being run will be terminated, not just this project.
-
ProjectCommands.
messages
()¶ Retrieve the load/build messages
Returns: A list of messages associated with the project. Return type: List[tuple] Each message is a named tuple composed of:
text The message text label Kind of message, such as build or load status Type of messages, such as normal, warning, or error. scope Project to which the message applies name Component which caused the message link Id of the component which caused the message group Group id of the message pscad.load( os.path.join(examples_dir, r'tutorial\vdiv.pscx') ) vdiv = pscad.project('vdiv') vdiv.build() for msg in vdiv.messages(): print(msg.text)
-
ProjectCommands.
get_output_text
()¶ Retrieve the output (run messages) for the project
Returns: The output messages Return type: str pscad.load( os.path.join(examples_dir, r'tutorial\vdiv.pscx') ) vdiv = pscad.project('vdiv') vdiv.run() print(vdiv.get_output_text())
-
ProjectCommands.
clean
()¶ Clean the current project
Scenarios¶
-
ProjectCommands.
list_scenarios
()¶ List the scenarios which exist in the project.
Returns: List of scenario names. Return type: List[str]
-
ProjectCommands.
scenario
(name=None)¶ Get or set the current scenario.
Parameters: name (str) – Name of scenario to switch to (optional). Returns: The name of the (now) current scenario. Return type: str
-
ProjectCommands.
save_as_scenario
(name)¶ Save the current configuration under the given scenario name.
Parameters: name (str) – Name of scenario to create or overwrite.
Layers¶
-
ProjectCommands.
set_layer
(name, state)¶ Set the state of a layer
Parameters: - name (str) – Name of the layer to alter.
- state (str) – One of “enabled”, “disabled” or “invisible”.
-
ProjectCommands.
create_layer
(name)¶ Create a new layer
Parameters: name (str) – Name of the layer to create.
-
ProjectCommands.
delete_layer
(name)¶ Delete an existing layer
Parameters: name (str) – Name of the layer to delete.
Definitions¶
-
ProjectCommands.
list_definitions
()¶ Retrieve a list of all definitions contained in the project.
Returns: A list of all of the Definition
names.Return type: List[str]
-
ProjectCommands.
get_definition
(name)¶ Retrieve the given named definition from the project.
Parameters: name (str) – The name of the definition. Returns: The named Definition
.
-
ProjectCommands.
delete_definition
(name)¶ Delete the given named
Definition
.Parameters: name (str) – The name of the definition to delete.
-
ProjectCommands.
delete_definition_instances
(name)¶ Delete all instances of the given
Definition
.Parameters: name (str) – The name of the Definition
whose instances are to be deleted.
Parameter Grid¶
-
ProjectCommands.
export_parameter_grid
(name)¶ Export parameters to a CSV file.
Parameters: name (str) – Filename of the CSV file to write.
-
ProjectCommands.
import_parameter_grid
(name)¶ Import parameters from a CSV file.
Parameters: name (str) – Filename of the CSV file to read.
Finding Canvases¶
-
ProjectCommands.
user_canvas
(name)¶ Retrieve a controller for the canvas of a user component.
Parameters: name (str) – Definition name of the user component. Returns: A user canvas controller proxy object. Getting the main page of a project:
main = project.user_canvas('Main')
Finding Components¶
Note
After using user_canvas()
to obtain the relevant
canvas, it is usually simplier to use UserCanvas.find()
,
UserCanvas.find_first()
or UserCanvas.find_all()
methods to
find a component of interest, rather than use a component Id for locate
the component.
-
ProjectCommands.
user_cmp
(defn, iid)¶ Retrieve a controller for a user component
Parameters: - defn (str) – Name of user component to find the component inside.
- iid (int) – Id attribute of the component.
-
ProjectCommands.
slider
(defn, *iid)¶ Retrieve a controller for a Slider
Since this component can exist inside a control panel, the *iid list must include the entire chain of Id attributes.
Parameters: - defn (str) – Name of user component to find the component inside.
- *iid (int) – Id attributes of the control panel and slider.
-
ProjectCommands.
switch
(defn, *iid)¶ Retrieve a controller for a Switch
Since this component can exist inside a control panel, the *iid list must include the entire chain of Id attributes.
Parameters: - defn (str) – Name of user component to find the component inside.
- *iid (int) – Id attributes of the control panel and Switch.
Retrieve a controller for a Button
Since this component can exist inside a control panel, the *iid list must include the entire chain of Id attributes.
Parameters: - defn (str) – Name of user component to find the component inside.
- *iid (int) – Id attributes of the control panel and Button.
-
ProjectCommands.
selector
(defn, *iid)¶ Retrieve a controller for a Selector
Since this component can exist inside a control panel, the *iid list must include the entire chain of Id attributes.
Parameters: - defn (str) – Name of user component to find the component inside.
- *iid (int) – Id attributes of the control panel and Selector.
-
ProjectCommands.
overlay_graph
(defn, *iid)¶ Retrieve a controller for an Overlay Graph
Since this component can exist inside a Graph Frame, the *iid list must include the entire chain of Id attributes.
Parameters: - defn (str) – Name of user component to find the component inside.
- *iid (int) – Id attributes of the Graph Frame and Overlay Graph.
-
ProjectCommands.
graph_frame
(defn, iid)¶ Retrieve a controller for a Graph Frame
Parameters: - defn (str) – Name of user component to find the component inside.
- iid (int) – Id attribute of the Graph Frame.