Workspace#
The PSCAD Workspace file is an XML document which contains:
the workspace parameters,
the workspace project files:
libraries,
cases,
the workspace simulations sets.
Workspace File#
- class mhi.xml.pscad.workspace.WorkspaceFile(path: Path | str | None = None)#
A PSCAD Workspace XML File
An existing workspace is read by specifying an existing workspace file in the constructor:
from mhi.xml.pscad import WorkspaceFile ws = WorkspaceFile(r"C:\Workspace\Path\TheWorkspace.pswx")
Since project files are located relative to the workspace, to create a new workspace the directory of the new workspace is required. Specifying a directory, instead of a file, creates an empty workspace:
from mhi.xml.pscad import WorkspaceFile ws = WorkspaceFile(r"C:\Workspace\Path") ... ws.save_as("TheWorkspace.pswx")
- property path: Path | None#
The path of the XML document (read-only)
Note
The path is None if it has not been read from an actual file.
- save()#
Write the updated XML document back to the file it was read from.
- save_as(path: Path | str) None#
Write the workspace XML document to a new location.
Note
This updates the “read-only” name, path, and folder properties.
- add_project(project_or_path: ProjectFile | PathLike | str) None#
Add a project to the workspace
- property project: ProjectMapping#
The workspace’s “Project” dictionary.
It is used to find the workspace’s projects:
from mhi.xml.pscad import WorkspaceFile examples_folder = r"C:\Users\Public\Documents\PSCAD\5.0.2\Examples" ws = WorkspaceFile(rf"{examples_folder}\tutorial\Tutorial.pswx") vdiv = ws.project["vdiv"].open()
Note
A ProjectNode must be ‘opened’ to access the corresponding Project.
- property simulation_set: SimulationSetMapping#
The workspace’s simulation set dictionary.
It is used to access the workspace’s simulation sets:
from mhi.xml.pscad import WorkspaceFile workspace = ... default_simset = workspace.simulation_set["default"] base_simset = workspace.simulation_set.create("base")
Projects#
- class mhi.xml.pscad.workspace.ProjectMapping(workspace_file: WorkspaceFile)#
The workspace’s
ProjectNodedictionary.The ProjectNode dictionary contains the libraries and cases in the workspace (excluding the Master Library). The dictionary may be iterated over to obtain each ProjectNode within, or it may be indexed by namespace to obtain a specific one:
workspace = ... for prj_name, prj_node in workspace.project.items(): print(prj_name, prj_node.path) tutorial_ws = ... vdiv_node = tutorial_ws.project['vdiv']
A project may be added to the workspace by assigning a path to a new namespace, or removed by deleting the entry:
del workspace.project['old_library'] workspace.project['new_library'] = Path(r"C:\Path\to\new_library.pslx")
Project#
- class mhi.xml.pscad.workspace.ProjectNode#
A project within a workspace.
Note
This ProjectNode only represents an entry within the
WorkspaceFile. It must beopenedto obtain the actualProjectFile.- open() ProjectFile#
Open the project’s XML file
Simulation Sets#
- class mhi.xml.pscad.workspace.SimulationSetMapping(workspace_file: WorkspaceFile)#
The workspace’s
SimulationSetNodedictionary.The dictionary contains the simulation sets in the workspace. The dictionary may be iterated over to obtain each SimulationSetNode within, or it may be indexed by name to obtain a specific one:
workspace = ... for simset in workspace.simulation_set.values(): print(simset.name) default_ss = workspace.simulation_set['default']
New simulation sets may be created using the
create()method:simset1 = workspace.simulation_set.create('simset1')
A simulation set may be removed from the workspace by deleting the entry:
del workspace.simulation_set['simset1']
- create(name: str) SimulationSetNode#
Create a new simulation set
Simulation Set#
- class mhi.xml.pscad.workspace.SimulationSetNode#
A simulation set element.
- property task: TaskMapping#
The simulation set’s task dictionary.
- parameters(name='Default') Parameters#
The simultaion set’s parameters structure.
- class Parameters#
The simulation set’s parameters (read/write)
Simulation Set Tasks#
- class mhi.xml.pscad.workspace.TaskMapping(simset: SimulationSetNode)#
A simulation set’s task dictionary.
Simulation Set Task#
- class mhi.xml.pscad.workspace.SimulationTaskNode#
A simulation set’s task element.
- parameters(name='Options') Parameters#
The simulation set task’s parameters structure.
- class Parameters#
Parameters of a simulation set’s task (read/write).