> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/scopeview/automation-api-and-scripting/use-python-scopeview-api/python-api-reference/comtrade.md).

# Comtrade

## Function: calculateComtradeSignalDelay

| **Section**    | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**     | <p>calculateComtradeSignalDelay method returns a map of the comtrade file names with a delay calculated in seconds.<br>The delay is calculated by having a default file (the first value in the files array), compared to the other files.<br>To calculate a delay, a match needs to be made between a signal from the default file, and a signal from the<br>rest of the list. The method tries to make a match by checking which signal names have words in common, but if no<br>similarities are made, an error will be given.<br>Manual signal matching can be made, by passing a list of tuple (pairs) of strings that represents signal names. This<br>list will contain a signal name from the default file and one from the other signal, the order of those pairs needs<br>to be the same as the order of the filenames passed.</p> |
| **Parameters** | <p><strong>files</strong> (<em>list\[str]</em>) – A list of file names or paths of the COMTRADE files used to calculate delays. The first element of this array is chosen as the default comtrade and will be compared to the others. This means that all other comtrades are delayed compared to the default.<br><strong>signal\_pairs</strong> – A list of tuples (pairs) representing signal names. The left part of this pair (index 0) is always a signal name from the default comtrade file (first file in the files parameter).</p>                                                                                                                                                                                                                                                                                                  |
| **Returns**    | A map containing the delay value for each filename. The first element will always be 0 as it is the default comtrade file. (Dict\[str, float])                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| **Raises**     | **OSError** – If any of the input files cannot be found in the current directory.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

### **Example Usage**

{% code overflow="wrap" lineNumbers="true" %}

```python
import ScopeViewApiGRPC as scopeview
scopeview.connectToScopeViewRemote()
files = [
"L35460NT120L16UPC_A/20221114_173712506.cfg",
"L35460NT120L16UPC_B/20221114_173712489.cfg",
]
# Automatic signal name matching
result = scopeview.calculateComtradeSignalDelay(files)
signal_pairs = [
("E_AN_L1421", "5 E_AN_L1421")
]
# Manual signal name matching
# The signal_pairs needs to have the default comtrade signal always on the left (value 0 of each tuples)
# The default comtrade file is always the first file in the files array (20221114_173712506.cfg in this example)
# An error will be returned if a non-existent signal name is used
result2 = scopeview.calculateComtradeSignalDelay(files, signal_pairs)
```

{% endcode %}

## Function: combineComtrade

| **Section**    | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**     | combineComtrade method combines multiple COMTRADE files into a single output file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| **Parameters** | <p><strong>inputs</strong> (<em>list</em>) – A list of file names or paths of the COMTRADE files to be combined<br><strong>output\_file</strong> (<em>str</em>) – The name or path of the output file<br><strong>parameters</strong> (<em>Dict\[str, any]</em>) – Optional parameters to combine comtrade files. See getCombineComtradeParameters to create the dict<br><strong>selected\_signals</strong> (<em>Dict\[str, List\[str]]</em>) – A map representing the signal names for each comtrade files that will be added to the output<br>of the combined files. Other signals will be discarded</p> |
| **Returns**    | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| **Raises**     | **OSError** – If any of the input files cannot be found in the current directory.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |

### **Example Usage**

{% code overflow="wrap" lineNumbers="true" %}

```python
scopeview.connectToScopeViewRemote()
files = [
"L35460NT120L16UPC_A/20221114_173712506.cfg",
"L35460NT120L16UPC_B/20221114_173712489.cfg",
]
parameters = scopeview.getCombineComtradeParameters(files)
parameters["interpolationMethod"] = "Spline"
parameters["unitConfig"][1] = "V"
parameters["sampleRate"] = 4000
scopeview.combineComtrade(files, "combined.cfg", parameters, None)
```

{% endcode %}

## Function: convertComtradeRevisionYear

| **Section**    | **Description**                                                                                                                                                                                                                                                                                                                                          |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**     | <p>convertComtradeRevisionYearRequest takes the filepath of a comtrade file and it's desired revision year.<br>The method then converts the file and overwrites it at the same filepath given.<br>If no newFilepath is given, the method will override the given filepath to its converted format.</p>                                                   |
| **Parameters** | <p><strong>filepath</strong> (<em>str</em>) – The filepath of the comtrade file.<br><strong>version</strong> (<em>int</em>) – The desired COMTRADE version (1991, 1997, 2013, etc.).<br><strong>newFilepath</strong> (<em>str</em>) – The desired location to write the converted comtrade file. This filepath needs to be absolute and is optional.</p> |
| **Returns**    | None                                                                                                                                                                                                                                                                                                                                                     |
| **Raises**     | **OSError** – If the input file cannot be found in the current directory.                                                                                                                                                                                                                                                                                |

### **Example Usage**

{% code overflow="wrap" lineNumbers="true" %}

```python
convertComtradeRevisionYear("file1.cfg", 2013)
```

{% endcode %}

## Function: findSynchronizableComtradeSignalPairs

| **Section**    | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**     | <p>findSynchronizableComtradeSignalPairs method parses the list of COMTRADE files and returns a list of pair of signals.<br>The first file in the files array passed to the method is chosen as the default file for synchronization.<br>Each pair that is returned has the list of default signals on the left and the list of synchronizable signals on the right.<br>The user then has to choose only 1 signal per pair to make a synchronization.</p> |
| **Parameters** | **files** (*list\[str]*) – A list of file names or paths of the COMTRADE files to be parsed into pairs. The first file in the array is the default file. Minimum length of 2.                                                                                                                                                                                                                                                                             |
| **Returns**    | The list of pairs containing the multiple signal names to choose from. (list\[tuple\[list\[str], list\[str]]])                                                                                                                                                                                                                                                                                                                                            |
| **Raises**     | **OSError** – If any of the input files cannot be found in the current directory.                                                                                                                                                                                                                                                                                                                                                                         |

### **Example Usage**

{% code overflow="wrap" lineNumbers="true" %}

```python
synchronizationPairs = findSynchronizableComtradeSignalPairs(["file1.cfg", "file2.cfg"])
```

{% endcode %}

## Function: getCombineComtradeParameters

| **Section**    | **Description**                                                                                                                                                                                                                                                                                |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**     | <p>getCombineComtradeParameters returns a dictionnary of properties used to combine comtrade files. There is an optional<br>list of comtrade files parameter that can be passed and the method will try to return a parameter dictionnary<br>that is configured with those COMTRADE files.</p> |
| **Parameters** | **files** (*list*) – A list of file names or paths of the COMTRADE files to be combined                                                                                                                                                                                                        |
| **Returns**    | A dictionnary containing the parameters used to combine comtrade files (Dict\[str, any])                                                                                                                                                                                                       |
| **Raises**     | **OSError** – If any of the files cannot be found in the current directory.                                                                                                                                                                                                                    |

### **Example Usage**

{% code overflow="wrap" lineNumbers="true" %}

```python
getCombineComtradeParameters(["file1.cfg", "file2.cfg"])
```

{% endcode %}

## Function: getComtradeSignals

| **Section**    | **Description**                                                                                                                                                                                                                                                                                                                                                                                                           |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**     | <p>getComtradeSignals returns a map of list of strings that represents the signals inside the given comtrade files.<br>Each comtrade file has a list of signals. This is because comtrade files can have the same signals name, so a map<br>is used to differenciate the signal names from those files.<br>This can then be used to combine comtrade files and only write the requested signals to the combined file.</p> |
| **Parameters** | **files** (*list*) – A list of file names or paths of the COMTRADE files to be combined                                                                                                                                                                                                                                                                                                                                   |
| **Returns**    | A map of list of strings containing the signals for each comtrade file (Dict\[str, list\[str]])                                                                                                                                                                                                                                                                                                                           |
| **Raises**     | **OSError** – If any of the files cannot be found in the current directory.                                                                                                                                                                                                                                                                                                                                               |

### **Example Usage**

{% code overflow="wrap" lineNumbers="true" %}

```python
getComtradeSignals(["file1.cfg", "file2.cfg"])
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/scopeview/automation-api-and-scripting/use-python-scopeview-api/python-api-reference/comtrade.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
