Skip to main content

Library to read and create Riscure Inspector trace set files (.trs)

Project description

Inspector Trace Set .trs file support in Python

Riscure Inspector uses the .trs file format to save and read traces from disk. To better assist reading and writing trace set files from third parties, Riscure published this Python library.

Quick start

This library supports reading and writing of .trs files, but it does not (yet) support modifying existing .trs files. Both the TrcFile and the Trace class emulate all the functionality of a list, so slice to your heart's content!

Installation

This library is available on PyPi for Python 3 and up. Just add trsfile to your requirements.txt or install it via the command line:

pip install trsfile

Reading .trs files

import trsfile

with trsfile.open('new.trs') as trs_file:
	# Show all headers
	for header, value in trs_file.headers.items():
		print(header, '=', value)
	print()

	# Iterate over the first 25 traces
	for i, trace in enumerate(trs_file[0:25]):
		print('Trace {0:d} contains {1:d} samples'.format(i, len(trace)))
		print('  - minimum value in trace: {0:f}'.format(min(trace)))
		print('  - maximum value in trace: {0:f}'.format(max(trace)))

Creating .trs files

import random, os
from trsfile import trs_create, Trace, SampleCoding, TracePadding, Header

with trs_create('new.trs', TracePadding.PAD, force_overwrite = True) as trs_file:
	# Extend the trace file with 100 traces with each 1000 samples
	trs_file.extend([
		Trace(
			SampleCoding.FLOAT,
			[random.uniform(-255, 255) for _ in range(0, 1000)],
			data = os.urandom(16)
		)
		for _ in range(0, 100)]
	)

	# Replace 5 traces (the slice [0:10:2]) with random length traces.
	# Because we are creating using the TracePadding.PAD mode, all traces
	# will be padded to the trace with the biggest length.
	trs_file[0:10:2] = [
		Trace(
			SampleCoding.FLOAT,
			[random.uniform(0, 255) for _ in range(0, random.randrange(1000))],
			data = os.urandom(16),
			title = 'Clipped trace'
		)
		for _ in range(0, 5)
	]

	# Lets delete 10 traces as they are supposedly malformed :)
	del trs_file[40:50]

	# Finally, change some headers, all available headers are defined in the Header class
	trs_file.headers[Header.LABEL_X] = 'Time'
	trs_file.headers[Header.LABEL_Y] = 'Voltage'
	trs_file.headers[Header.DESCRIPTION] = 'Traces created for some purpose!'

	print('Total length of new trace set: {0:d}'.format(len(trs_file)))

Documentation

The full documentation is available in the doc folder with a readable version on readthedocs.

Testing

The library supports Python unittest module and the tests can be executed with the following command:

python -m unittest

License

BSD 3-Clause Clear License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trsfile-0.1.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trsfile-0.1.1-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file trsfile-0.1.1.tar.gz.

File metadata

  • Download URL: trsfile-0.1.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3

File hashes

Hashes for trsfile-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e9af09276f9e6be58b140decb18de0222750eb04c2c1aff72cd0e38122600169
MD5 e9fe425c4987b4c1114d457808d7371c
BLAKE2b-256 6912a8b116d6a65865d190c84daeef823b0cadabbf97e85e7480190069169b94

See more details on using hashes here.

File details

Details for the file trsfile-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: trsfile-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3

File hashes

Hashes for trsfile-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d4a3307f0032f75d15525632bebf7fbcc1d776d272518f0cf9251b9840a31d2c
MD5 3d0c71b2e709541366d72e8adc7876a3
BLAKE2b-256 35c2a08fb9546cf0f554967d9a5d74da8d021c1a46b8e96c1b20766eadc600ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page