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")
- classmethod create(path: Path | str, *, version: str = '5.0.2', overwrite: bool = False) WorkspaceFile#
Create a new PSCAD Workspace file (
*.pswx)Added in version 1.4.0.
- 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 version_number: tuple[int, ...]#
The PSCAD workspace file version number tuple (read-only)
Added in version 1.4.0.
- 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.
Changed in version 1.4.0: Returns a
Parameters51if the workspace version is 5.1 or higher
- 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.
- create(namespace: str, **kwargs) SimulationTaskNode#
Create a new simulation set task
Added in version 1.4.0.
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).
Changed in version 1.4.0: Removed simulationset & namespace parameters
- property overrides: Overrides#
The simulation set task’s project overrides accessor
Added in version 1.4.0.
- class Overrides#
Project overrides for a simulation set’s task (read/write).
Each attribute has a corresponding
override_{name}boolean attribute. Assigning a value to any of the base attributes will simultaneously set the corresponding override attribute toTrue, where as assigningNoneto the attribute will set the override toFalseinstead.When an override attribute is set to
False, the corresponding base attribute will returnNone.Added in version 1.4.0.
- override_duration#
- override_manual_start#
- override_only_in_use_channels#
- override_plot_step#
- override_remove_snapshot_offset#
- override_run_config#
- override_run_count#
- override_save_channels#
- override_save_channels_file#
- override_snap_time#
- override_snapshot_file#
- override_start_method#
- override_startup_inputfile#
- override_state_animation#
- override_time_step#
- override_timed_snapshots#
- property layer_overrides: MutableMapping[str, str]#
The simulation set task’s layer overrides.
The layer overrides behave as a dictionary of layer name and layer states.
Note
The layer overrides are part of the workspace, and are accessed without referencing the project file. Layer names and custom layer states are not verified to exist.
Examples:
# Get an existing simulation set task simset1 = workspace.simulation_set['simset1'] task = simset1.task.create['prj1'] # Add or alter existing layer overrides task.layer_overrides['Layer1'] = 'Enabled' task.layer_overrides['Layer2'] = 'Disabled' task.layer_overrides['Layer3'] = 'Invisible' task.layer_overrides['Layer4'] = 'MyCustomState' # Remove an existing override if 'Layer5' in task.layer_overrides: del task.layer_overrides['Layer5']
Added in version 1.4.0.