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 name: str#

Name of the workspace (read-only)

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.

property folder: Path#

The workspace directory (read-only)

property version: str#

PSCAD version used to create the workspace.

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.

all_exist() bool#

Verify that all projects in the workspace exist.

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 ProjectNode dictionary.

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 be opened to obtain the actual ProjectFile.

static validate_name(name: str) None#

Ensure the name is a legal PSCAD project identifier

static validate_type(kind: str) None#

Ensure the type is a legal PSCAD project type

property type: str#

Type of the project (read-only)

Either ‘library’ or ‘project’

property is_library: bool#

True if the project represents a PSCAD Library. (read-only)

property is_case: bool#

True if the project represents a PSCAD Project Case. (read-only)

property filepath: str#

The project’s filepath attribute string. (read-only)

property path: Path#

The project’s filepath, resolved relative to the workspace file. (read-only)

open() ProjectFile#

Open the project’s XML file

delete() None#

Remove this project from the workspace.

Simulation Sets#

class mhi.xml.pscad.workspace.SimulationSetMapping(workspace_file: WorkspaceFile)#

The workspace’s SimulationSetNode dictionary.

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.

property depends_on: str#

Simultaion set dependency.

namespaces() list[str]#

The project names that are part of this simulation set.

delete() None#

Remove this simulation set from the workspace

parameters(name='Default') Parameters#

The simultaion set’s parameters structure.

class Parameters#

The simulation set’s parameters (read/write)

enabled: bool#

Data descriptor for known parameters

before_run: str#

Data descriptor for known parameters

before_block: bool#

Data descriptor for known parameters

after_run: str#

Data descriptor for known parameters

after_block: bool#

Data descriptor for known parameters

Simulation Set Tasks#

class mhi.xml.pscad.workspace.TaskMapping(simset: SimulationSetNode)#

A simulation set’s task dictionary.

namespaces() list[str]#

List the namespaces of the tasks in the simulation set.

Simulation Set Task#

class mhi.xml.pscad.workspace.SimulationTaskNode#

A simulation set’s task element.

property namespace: str#

The namespace of this simulation set task.

delete() None#

Remove this simulation task from the simulation set.

parameters(name='Options') Parameters#

The simulation set task’s parameters structure.

class Parameters#

Parameters of a simulation set’s task (read/write).

simulationset: str#

Data descriptor for known parameters

namespace: str#

Data descriptor for known parameters

name: str#

Data descriptor for known parameters

ammunition: int#

Data descriptor for known parameters

volley: int#

Data descriptor for known parameters

affinity_type: int#

Data descriptor for known parameters

affinity: int#

Data descriptor for known parameters

rank_snap: bool#

Data descriptor for known parameters

substitutions: str#

Data descriptor for known parameters

clean: bool#

Data descriptor for known parameters