Data Module

Inheritance diagram of Data

The Data.TEracsData class is the main way of loading up data from an ERACS file for use in a study. The main method to use is Data.TEracsData.Load() which takes a string to the full file path and name of the file to load. Once loaded, the data may be viewed and modified using the appropriate properties exposed by the Data.TEracsData class such as Collection.TEracsDataCollection.Busbars which is an inherited property from the parent class.


API

Import Data for access to all data-loading classes exposed by the ERACS Python Interface. An instance of the TEracsData class can be used to load and save data using multiple file formats (XML, CSV, etc.).

class TEracsData

This class should be used to load up an ERACS network ready to be passed to a calculation module

Inherits

Collection.TEracsDataCollection.

property FaultCapability

Fault Capability, determined by synchronous machines, transformer windings, transmission lines and cables in the network.

Type

int.

Writable

False.

property EracsVersion

Returns a string version of ERACS used to export the loaded data.

Example

EracsVersion => “3.11.0”

Returns

A string of the ERACS version.

GetDataFromTypecode(ATypecode, ASeqnum=None, AId=None)

Return the appropriate data list using the typecode given.

Parameters
  • ATypecode (int) – The typecode for desired element data. If the typecode is a string, it’ll be converted to an int internally, if valid.

  • ASeqnum (int) – An optional sequence number can be provided which helps refine the search further, in case there’s potentially multiple lists with the same typecode (synchronous generators and grids).

  • AId (int) – An optional id can be provided, much like the optional sequence number, to refine the search to determine the list to return.

Returns

A TEracsDataList for the specific type specified, or a tuple of all matching lists if one or the other could not be determined, or None.

Raises

TEracsArgumentError – If the typecode is unknown.

GetDataItem(ATypecode, ASeqnum)

Looks for the specified item from the appropriate data list using the typecode and sequence number provided, returns it as a Dictionary. A full list of available typecodes can be viewed here.

Parameters
  • ATypecode (int) – Must be an integer, typecode of element

  • ASeqnum (int) – Must be an integer, sequence number of specific element

Returns

Dictionary for desired data item

Raises

TEracsArgumentError – If no item exists with given typecode and sequence number.

SetValue(ATypecode, AId: str, AKey, AValue)

This helper method will find the appropriate data list from the typecode, find the appropriate element from the ID, and assign/modify a key-value pair within the element data dictionary. At the same time, it raises an event which will cause any studies to invalidate their results, since the underlying data has changed.

Parameters
  • ATypecode – The typecode of the desired element type.

  • AId (str) – The id of the desired element.

  • AKey – The key of the desired data item.

  • AValue – The value to assign to the desired data item.

Raise

TEracsArgumentError - when the data item cannot be found.

Returns

Tuple, of the before and after value.

CloseSwitch(ASwitchId)

Close the specified switch.

Parameters

ASwitchId (str) – Index of the switch to close.

OpenSwitch(ASwitchId)

Open the specified switch.

Parameters

ASwitchId (str) – Index of the switch to open.

ToggleSwitch(ASwitchId)

Toggle the specified switch.

Parameters

ASwitchId (str) – Index of the switch to toggle.

SetSwitchState(ASwitchId, AState)

When a switch needs updating/changing use this method. Each element dictionary has an internal connection indicator key, and therefore changing the state of the switch directly in the Switches list will have no effect.

Parameters
  • ASwitchId (str) – ID of the switch to change the state of.

  • AState (int) – The state to change the switch to. (0 = open, 1 = closed)

Doctest
>>> data = TEracsData()
>>> data.Switches.append(
...     {'id': 'sw1', 'swstate': 1, 'pid': 'cab1', 'ptypecode': 3, 'busbar1': 'bus1'}
... )
{'id': 'sw1', 'swstate': 1, 'pid': 'cab1', 'ptypecode': 3, 'busbar1': 'bus1', 'typecode': 'switch', 'seqnum': 1}
>>> data.Switches[0]['swstate']
1
>>> data.OpenSwitch('sw1')
>>> data.Switches[0]['swstate']
0
>>> data.CloseSwitch('sw1')
>>> data.Switches[0]['swstate']
1
GetSwitchState(ASwitchId)

Get the state of a switch.

Parameters

ASwitchId (str) – ID of the switch to get state of.

Returns

0/1 (open/closed) depending on state.

Load(AFilePathAndName, ATrySameName=True)

Load the data from a supported format (XML or CSV).

Parameters

AFilePathAndName (str) – The full path and name of file to load.

Returns

True if the file was successfully loaded.

Raises

TEracsArgumentError – If the file has an unknown extension.

Save(AFilePathAndName, AResultsCallback=None)

Save the data into a supported format (XML, CSV, JSON, SVG, HTML)

Parameters

AFilePathAndName (str) – The full path and name of file to save.

Returns

True if the file was successfully saved.

Raises

TEracsArgumentError – If the file has an unknown extension.

OpenInBrowserAsSvg(AResultsCallback=None)

Open the data in a web browser as SVG.

Parameters

AResultsCallback (Callable[[self, XmlElement], None]) – A callable method which will add results to the SVG/XML. This callback is provided in Calculations.TEracsEasy.ResultsInXml().

Returns

A Thread object which processes the SVG transformation.

Raise

Global.TEracsMissingModuleError if the lxml library is missing.

OpenInBrowserAsHtml(AResultsCallback=None)

Open the data in a web browser as HTML.

class TEracsDataConverter

This class simplifies access to certain DLLs for data conversion.

XmlToJson(AFile, ASource)

Converts XML data to JSON

Parameters
  • AFile (str) – The full path and name of Destination file.

  • ASource (str) – The full path and name of Source XML file.

Raises
  • TEracsArgumentError – If either arguments are of the incorrect type or source points to a non-existent file.

  • TEracsDllError – If the DLL is not found or loaded properly.

NameplateXmlToClassicXml(ATx, AKeyname)

Converts a transformer which uses the classic transformer format into a nameplate format (newer).

Parameters

ATx (element) – Transformer XML element in the classic format.

Returns

An XML element for the new nameplate transformer.

Raises

TEracsDllError – If the DLL is not found or loaded properly, or if it fails to return back a converted transformer.