simplemdx
A simple BTS MDX file parser and toolkit written in Python based on BeautifulSoup
- Free software: GNU General Public License v3
- Documentation: https://simplemdx.readthedocs.io.
Features
- Compatible with Python 2.7 and 3.4 onwards
- Linux, OSX and Windows support
simplemdx gives access to:
- trial MDXs (marker coordinates, emg channels, etc)
- session and patient MDXs (antropometric data, subject metadata)
- normative ENB files (joint angles normatives, emg normatives, etc)
Usage
To load the contents of a trial mdx
from simplemdx.parser import Parser
a = Parser('myfile.mdx')
Once loaded, metadata can be accessed like:
label = a.label
date = a.date
It also loads all it's streams, and names them according to their contents. The named streams can be:
- markers
- emg
- static
- cycle
Streams
Every stream has its own metadata(such as frequency, start time and number of frames
a = Parser('myfile.mdx')
m = a.markers # marker stream
m.freq
m.nFrames
m.startTime
Marker streams
Markers can be retrieved from the stream by index or label
c7 = a.markers['c7']
m = a.markers[0] # The first marker on the stream
or iterated
for marker in a.markers:
print(marker.label)
This stream can be converted to an OpenSIM .trc file like this
a.markers.toTRC()
By default, it creates a trc file with the same label as the trial mdx and all the included markers. It is important to note that it will output the largest common chunk of data (the largest interval of time for which all markers are visible). This is to avoid None data in the .trc file. One can restrict the output to certain markers and change the output filename
a.markers.toTRC(filename='my_trc_output.trc',labels=['c7','rasis','lasis'])
As a simple way to inspect the stream, one can plot it
a.markers.plot()
This will display a simple matplotlib 3D scatter plot with the markers and the references
Data items
The data for the streams inner tags are stored in DataItems. BTS follows an Item/Segment approach for storing most of it. For retrieving a segment of a marker, one can call the data attribute
c7 = a.markers['c7']
s = c7.data
data will return a Segment object, or a list of Segment objects. Each Segment has a list for each coordinate (for a marker example, X, Y and Z) and the Segment's starting frame
seg = c7.data
if isintance(seg,Segment):
print("First frame: {}".format(seg.frame))
print("X data: {}".format(seg.X))
addicionally, data can be retrieved as a continuous stream using datac instead of data. This will merge all segments into one, added a None padding. and return a single Segment starting at frame 0.
segc = c7.datac
print("X data: {}".format(seg.X))
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.