pytcs


Namepytcs JSON
Version 0.1.1 PyPI version JSON
download
home_page
SummaryPython API for processing TwinCAT Scope data files
upload_time2023-04-04 09:49:27
maintainer
docs_urlNone
author
requires_python>=3.8
licenseBSD 3-Clause License Copyright (c) 2022, Cagtay Fabry All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords file reader twincat twincat scope
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytcs

A Python package for reading exported TwinCAT Scope Files.\
Export your TwinCAT Scope files `.svdx` to `.csv` and read them into Python.

## quickstart

Open a file and create a `pandas.DataFrame`:

```python
from pytcs import ScopeFile

sf = ScopeFile("example.csv")  # open file and read metadata
df = sf.as_pandas()  # convert to pandas DataFrame
```

## user guide

### installation

Install using `pip` or `conda/mamba`:

```
pip install pytcs
```

```
conda install pytcs
```

### loading data

To get started, open a file using `pytcs.ScopeFile`:

```python
from pytcs import ScopeFile

sf = ScopeFile("example.csv")
sf
# > <TwinCAT Scope File at 0x2a157ca9310>
# > name:    example
# > runtime: 0:00:00.999000
# > start:   2022-05-02T13:56:24.376000+00:00
# >
# > Channels:
# >   *var_REAL64: 1.0 ms [None]
# >   *var_UINT64: 1.0 ms [None]
# >   *var_UINT32: 1.0 ms [None]
# >   *var_UINT16: 1.0 ms [None]
# >   *func_units_scaled: 1.0 ms [dV]
```

You can see the list of channels contained in the file together with the sample time and the unit.
When creating a `ScopeFile` instance only the metadata about the channels is read from the file header.
The actual channel data is not loaded, indicated by the `*` in front of the channels.

You can load all or only a list of channels by using `ScopeFile.load()`

```python
sf.load()
sf
# > <TwinCAT Scope File at 0x2a157ca9310>
# > name:    example
# > runtime: 0:00:00.999000
# > start:   2022-05-02T13:56:24.376000+00:00
# >
# > Channels:
# >   var_REAL64: 1.0 ms [None]
# >   var_UINT64: 1.0 ms [None]
# >   var_UINT32: 1.0 ms [None]
# >   var_UINT16: 1.0 ms [None]
# >   func_units_scaled: 1.0 ms [dV]
```

### accessing individual channels

Individual channels can be accessed by their name:

```python
sf["func_units_scaled"]
# > ScopeChannel(name='func_units_scaled',
# >   time=array([  0.,   1.,   2., ..., 997., 998., 999.]),
# >   values=array([   10.,     0.,   -10., ..., -9960., -9970., -9980.]),
# >   sample_time=1.0, time_offset=0.0, units='dV')
```

### CSV backends

The default implementation of `pytcs` uses `pandas.read_csv` for parsing CSV files.
The `pandas` aims to provide the most flexible support for the various formatting options provided by the TwinCAT Scope export tool.

To improve performance for large files, [datatable](https://github.com/h2oai/datatable) can be set as an alternative CSV backend.
Datatable can be selected by using `ScopeFile.read(..., backend="datatable")` .
However it should be considered **experimental** since some CSV formats can run into known issues and errors.
If you want to use the `datatable` backend it is recommended run detailed tests with the target format (or change the target format).

### exporting to pandas and xarray

To work with the data, convert them to a pandas or xarray object. Channels will automatically be loaded form the file when exporting to other formats.
You can select individual channels to export.

```python
sf.as_pandas(channels=["var_REAL64", "var_UINT16"])
# >                          var_REAL64  var_UINT16
# > time
# > 2022-05-02 13:56:24.376         0.0         0.0
# > 2022-05-02 13:56:24.377         1.0         1.0
# > 2022-05-02 13:56:24.378         2.0         2.0
# > 2022-05-02 13:56:24.379         3.0         3.0
# > 2022-05-02 13:56:24.380         4.0         4.0
# > ...                             ...         ...
# > 2022-05-02 13:56:25.371       995.0       995.0
# > 2022-05-02 13:56:25.372       996.0       996.0
# > 2022-05-02 13:56:25.373       997.0       997.0
# > 2022-05-02 13:56:25.374       998.0       998.0
# > 2022-05-02 13:56:25.375       999.0       999.0
# >
# > [1000 rows x 2 columns]
```

Exporting to an `xarray.Dataset` will preserve the metadata as attributes.

```python
sf.as_xarray(channels=["var_REAL64", "var_UINT16"])
# > <xarray.Dataset>
# > Dimensions:     (time: 1000)
# > Coordinates:
# >   * time        (time) datetime64[ns] 2022-05-02T13:56:24.376000 ... 2022-05-...
# > Data variables:
# >     var_REAL64  (time) float64 0.0 1.0 2.0 3.0 4.0 ... 996.0 997.0 998.0 999.0
# >     var_UINT16  (time) float64 0.0 1.0 2.0 3.0 4.0 ... 996.0 997.0 998.0 999.0
# > Attributes:
# >     ScopeName:   tc3_scope_3_4_3145_3
# >     File:        C:\Python\weldx-dev\pytcs\tests\data\tc3_scope_3_4_3145_3-Co...
# >     StartTime:   132959733843760000
# >     EndTime:     132959733853750000
# >     start_time:  2022-05-02T13:56:24.376000+00:00
# >     run_time:    0:00:00.999000
```

### dtype support

By default, all data will be read as `np.float64`.
When importing data with `ScopeFile.load` using the option `native_dtypes=True`,  imported data will be converted to their native dtypes.

| TwinCAT Scope | numpy        | IEC61131-3 |
| ------------- | ------------ | ---------- |
| BIT           | `np.bool_`   | BOOL       |
| INT8          | `np.int8`    | SINT       |
| INT16         | `np.int16`   | INT        |
| INT32         | `np.int32`   | DINT       |
| INT64         | `np.int64`   | LINT       |
| UINT8         | `np.uint8`   | USINT      |
| UINT16        | `np.uint16`  | UINT       |
| UINT32        | `np.uint32`  | UDINT      |
| UINT64        | `np.uint64`  | ULINT      |
| REAL32        | `np.float32` | REAL       |
| REAL64        | `np.float64` | LREAL      |

### export options support

The following table lists the compatible ✅ and currently uncompatible ❌ options of the ScopeExporter:

| file and value formats              |     |
| ----------------------------------- | --- |
| **ScaleValues**                     |     |
| true                                | ✅   |
| false                               | ❌   |
| **DecimalMark**                     |     |
| `.`                                 | ✅   |
| `,`                                 | ✅   |
| **Seperator**                       |     |
| Tab                                 | ✅   |
| Blank (space)                       | ❌   |
| Colon                               | ✅   |
| Semicolon                           | ✅   |
| Comma                               | ❌   |
| **ExcludeDoubleTimestamp**          |     |
| true                                | ✅   |
| false                               | ✅   |
| **SortChannels**                    |     |
| true                                | ✅   |
| false                               | ✅   |
| **FullTimeStamp**                   |     |
| true                                | ❌   |
| false                               | ✅   |
| **AdditionalEmptyLine**             |     |
| true                                | ❌   |
| false                               | ✅   |
| **ContainEOF**                      |     |
| true                                | ✅   |
| false                               | ✅   |
| **HeaderKonfiguration**             |     |
| Full Header                         | ✅   |
| **ArraySeperator**                  |     |
| Tab                                 | ✅   |
| **AdditionalArraySeperator**        |     |
| true                                | ❌   |
| false                               | ✅   |
| **IncludeTriggerInfos**             |     |
| true                                | ❌   |
| false                               | ✅   |
| **IncludeMarkerTables**             |     |
| None                                | ✅   |
| **MarkerTableOnlyIncludedChannels** |     |
| true                                | ❌   |
| false                               | ✅   |
| **MarkerTableOnlyIncludedMarker**   |     |
| true                                | ❌   |
| false                               | ✅   |

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pytcs",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "file reader,TwinCAT,TwinCAT Scope",
    "author": "",
    "author_email": "Cagtay Fabry <cagtay.fabry@bam.de>",
    "download_url": "https://files.pythonhosted.org/packages/19/52/f3f62b6c61fc62e460b8855fa0b9c410a710e1038601172d201c3688a3e7/pytcs-0.1.1.tar.gz",
    "platform": null,
    "description": "# pytcs\n\nA Python package for reading exported TwinCAT Scope Files.\\\nExport your TwinCAT Scope files `.svdx` to `.csv` and read them into Python.\n\n## quickstart\n\nOpen a file and create a `pandas.DataFrame`:\n\n```python\nfrom pytcs import ScopeFile\n\nsf = ScopeFile(\"example.csv\")  # open file and read metadata\ndf = sf.as_pandas()  # convert to pandas DataFrame\n```\n\n## user guide\n\n### installation\n\nInstall using `pip` or `conda/mamba`:\n\n```\npip install pytcs\n```\n\n```\nconda install pytcs\n```\n\n### loading data\n\nTo get started, open a file using `pytcs.ScopeFile`:\n\n```python\nfrom pytcs import ScopeFile\n\nsf = ScopeFile(\"example.csv\")\nsf\n# > <TwinCAT Scope File at 0x2a157ca9310>\n# > name:    example\n# > runtime: 0:00:00.999000\n# > start:   2022-05-02T13:56:24.376000+00:00\n# >\n# > Channels:\n# >   *var_REAL64: 1.0 ms [None]\n# >   *var_UINT64: 1.0 ms [None]\n# >   *var_UINT32: 1.0 ms [None]\n# >   *var_UINT16: 1.0 ms [None]\n# >   *func_units_scaled: 1.0 ms [dV]\n```\n\nYou can see the list of channels contained in the file together with the sample time and the unit.\nWhen creating a `ScopeFile` instance only the metadata about the channels is read from the file header.\nThe actual channel data is not loaded, indicated by the `*` in front of the channels.\n\nYou can load all or only a list of channels by using `ScopeFile.load()`\n\n```python\nsf.load()\nsf\n# > <TwinCAT Scope File at 0x2a157ca9310>\n# > name:    example\n# > runtime: 0:00:00.999000\n# > start:   2022-05-02T13:56:24.376000+00:00\n# >\n# > Channels:\n# >   var_REAL64: 1.0 ms [None]\n# >   var_UINT64: 1.0 ms [None]\n# >   var_UINT32: 1.0 ms [None]\n# >   var_UINT16: 1.0 ms [None]\n# >   func_units_scaled: 1.0 ms [dV]\n```\n\n### accessing individual channels\n\nIndividual channels can be accessed by their name:\n\n```python\nsf[\"func_units_scaled\"]\n# > ScopeChannel(name='func_units_scaled',\n# >   time=array([  0.,   1.,   2., ..., 997., 998., 999.]),\n# >   values=array([   10.,     0.,   -10., ..., -9960., -9970., -9980.]),\n# >   sample_time=1.0, time_offset=0.0, units='dV')\n```\n\n### CSV backends\n\nThe default implementation of `pytcs` uses `pandas.read_csv` for parsing CSV files.\nThe `pandas` aims to provide the most flexible support for the various formatting options provided by the TwinCAT Scope export tool.\n\nTo improve performance for large files, [datatable](https://github.com/h2oai/datatable) can be set as an alternative CSV backend.\nDatatable can be selected by using `ScopeFile.read(..., backend=\"datatable\")` .\nHowever it should be considered **experimental** since some CSV formats can run into known issues and errors.\nIf you want to use the `datatable` backend it is recommended run detailed tests with the target format (or change the target format).\n\n### exporting to pandas and xarray\n\nTo work with the data, convert them to a pandas or xarray object. Channels will automatically be loaded form the file when exporting to other formats.\nYou can select individual channels to export.\n\n```python\nsf.as_pandas(channels=[\"var_REAL64\", \"var_UINT16\"])\n# >                          var_REAL64  var_UINT16\n# > time\n# > 2022-05-02 13:56:24.376         0.0         0.0\n# > 2022-05-02 13:56:24.377         1.0         1.0\n# > 2022-05-02 13:56:24.378         2.0         2.0\n# > 2022-05-02 13:56:24.379         3.0         3.0\n# > 2022-05-02 13:56:24.380         4.0         4.0\n# > ...                             ...         ...\n# > 2022-05-02 13:56:25.371       995.0       995.0\n# > 2022-05-02 13:56:25.372       996.0       996.0\n# > 2022-05-02 13:56:25.373       997.0       997.0\n# > 2022-05-02 13:56:25.374       998.0       998.0\n# > 2022-05-02 13:56:25.375       999.0       999.0\n# >\n# > [1000 rows x 2 columns]\n```\n\nExporting to an `xarray.Dataset` will preserve the metadata as attributes.\n\n```python\nsf.as_xarray(channels=[\"var_REAL64\", \"var_UINT16\"])\n# > <xarray.Dataset>\n# > Dimensions:     (time: 1000)\n# > Coordinates:\n# >   * time        (time) datetime64[ns] 2022-05-02T13:56:24.376000 ... 2022-05-...\n# > Data variables:\n# >     var_REAL64  (time) float64 0.0 1.0 2.0 3.0 4.0 ... 996.0 997.0 998.0 999.0\n# >     var_UINT16  (time) float64 0.0 1.0 2.0 3.0 4.0 ... 996.0 997.0 998.0 999.0\n# > Attributes:\n# >     ScopeName:   tc3_scope_3_4_3145_3\n# >     File:        C:\\Python\\weldx-dev\\pytcs\\tests\\data\\tc3_scope_3_4_3145_3-Co...\n# >     StartTime:   132959733843760000\n# >     EndTime:     132959733853750000\n# >     start_time:  2022-05-02T13:56:24.376000+00:00\n# >     run_time:    0:00:00.999000\n```\n\n### dtype support\n\nBy default, all data will be read as `np.float64`.\nWhen importing data with `ScopeFile.load` using the option `native_dtypes=True`,  imported data will be converted to their native dtypes.\n\n| TwinCAT Scope | numpy        | IEC61131-3 |\n| ------------- | ------------ | ---------- |\n| BIT           | `np.bool_`   | BOOL       |\n| INT8          | `np.int8`    | SINT       |\n| INT16         | `np.int16`   | INT        |\n| INT32         | `np.int32`   | DINT       |\n| INT64         | `np.int64`   | LINT       |\n| UINT8         | `np.uint8`   | USINT      |\n| UINT16        | `np.uint16`  | UINT       |\n| UINT32        | `np.uint32`  | UDINT      |\n| UINT64        | `np.uint64`  | ULINT      |\n| REAL32        | `np.float32` | REAL       |\n| REAL64        | `np.float64` | LREAL      |\n\n### export options support\n\nThe following table lists the compatible \u2705 and currently uncompatible \u274c options of the ScopeExporter:\n\n| file and value formats              |     |\n| ----------------------------------- | --- |\n| **ScaleValues**                     |     |\n| true                                | \u2705   |\n| false                               | \u274c   |\n| **DecimalMark**                     |     |\n| `.`                                 | \u2705   |\n| `,`                                 | \u2705   |\n| **Seperator**                       |     |\n| Tab                                 | \u2705   |\n| Blank (space)                       | \u274c   |\n| Colon                               | \u2705   |\n| Semicolon                           | \u2705   |\n| Comma                               | \u274c   |\n| **ExcludeDoubleTimestamp**          |     |\n| true                                | \u2705   |\n| false                               | \u2705   |\n| **SortChannels**                    |     |\n| true                                | \u2705   |\n| false                               | \u2705   |\n| **FullTimeStamp**                   |     |\n| true                                | \u274c   |\n| false                               | \u2705   |\n| **AdditionalEmptyLine**             |     |\n| true                                | \u274c   |\n| false                               | \u2705   |\n| **ContainEOF**                      |     |\n| true                                | \u2705   |\n| false                               | \u2705   |\n| **HeaderKonfiguration**             |     |\n| Full Header                         | \u2705   |\n| **ArraySeperator**                  |     |\n| Tab                                 | \u2705   |\n| **AdditionalArraySeperator**        |     |\n| true                                | \u274c   |\n| false                               | \u2705   |\n| **IncludeTriggerInfos**             |     |\n| true                                | \u274c   |\n| false                               | \u2705   |\n| **IncludeMarkerTables**             |     |\n| None                                | \u2705   |\n| **MarkerTableOnlyIncludedChannels** |     |\n| true                                | \u274c   |\n| false                               | \u2705   |\n| **MarkerTableOnlyIncludedMarker**   |     |\n| true                                | \u274c   |\n| false                               | \u2705   |\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License  Copyright (c) 2022, Cagtay Fabry All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
    "summary": "Python API for processing TwinCAT Scope data files",
    "version": "0.1.1",
    "split_keywords": [
        "file reader",
        "twincat",
        "twincat scope"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "910bb5dc86491530ec6c9d9b610cfcd62ede516d3ed257f86b057d0f21ea872d",
                "md5": "a180cf6b4e0e91d07d97d2523b745fc8",
                "sha256": "368b18e8e7a4cdf80c58c6b298e9dcb91131f65db10abd49c270c534eeb31851"
            },
            "downloads": -1,
            "filename": "pytcs-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a180cf6b4e0e91d07d97d2523b745fc8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 15499,
            "upload_time": "2023-04-04T09:49:24",
            "upload_time_iso_8601": "2023-04-04T09:49:24.557960Z",
            "url": "https://files.pythonhosted.org/packages/91/0b/b5dc86491530ec6c9d9b610cfcd62ede516d3ed257f86b057d0f21ea872d/pytcs-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1952f3f62b6c61fc62e460b8855fa0b9c410a710e1038601172d201c3688a3e7",
                "md5": "5adc3d57626993fb14509d8dd5a57d3a",
                "sha256": "bd1768ae181408e9add1fce46e585596b6a97a33bd8a9711f365b31dd5e59f32"
            },
            "downloads": -1,
            "filename": "pytcs-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5adc3d57626993fb14509d8dd5a57d3a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 21210,
            "upload_time": "2023-04-04T09:49:27",
            "upload_time_iso_8601": "2023-04-04T09:49:27.104034Z",
            "url": "https://files.pythonhosted.org/packages/19/52/f3f62b6c61fc62e460b8855fa0b9c410a710e1038601172d201c3688a3e7/pytcs-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-04 09:49:27",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "pytcs"
}
        
Elapsed time: 0.05445s