# Path: imusim/capture/marker.py
# class MarkerCapture(object):
#     """
#     Marker trajectory data captured synchronously for one or more markers.
# 
#     @ivar sampleTimes: Sequence of times at which samples were taken.
#     """
# 
#     def __init__(self):
#         """
#         Initialise capture.
#         """
#         self._markers = dict()
# 
#     def _addMarker(self, marker):
#         self._markers[marker.id] = marker
# 
#     @property
#     def markers(self):
#         """
#         List of the markers in this capture.
#         """
#         return self._markers.values()
# 
#     def marker(self, id):
#         """
#         Get a marker by identifier.
# 
#         @return: The L{Marker} with the given identifier.
#         """
#         return self._markers[id]
# 
# class Marker3DOF(SampledPositionTrajectory, Marker):
#     """
#     A capture marker with 3DOF position samples.
#     """
#     def __init__(self, capture, id):
#         Marker.__init__(self, capture, id)
#         SampledPositionTrajectory.__init__(self)


from imusim.capture.marker import MarkerCapture, Marker3DOF
import numpy as np
    @param filename: Name of the CSV file to load.

    @return: A L{MarkerCapture} object.
    """
    # Open file to read header.
    datafile = open(filename, 'r')

    # Function to get comma-separated values from a line.
    values = lambda line: line.rstrip('\r\n').split(',')

    # Get column names.
    colnames = values(datafile.readline())

    # Get marker names.
    markernames = [n.split(':')[-2] for n in colnames[2::3]]

    # Get data.
    data = np.array([[float(v or np.nan) for v in values(line)]
        for line in datafile.readlines()]).T

    frameTimes = data[1]
    positions = data[2:].reshape((len(markernames),3,-1)) / 1000

    capture = MarkerCapture()
    capture.frameTimes = frameTimes
    capture.frameCount = len(frameTimes)
    capture.framePeriod = np.min(np.diff(frameTimes))
    capture.frameRate = 1 / capture.framePeriod

    for i, name in enumerate(markernames):

# Path: imusim/capture/marker.py
# class MarkerCapture(object):
#     """
#     Marker trajectory data captured synchronously for one or more markers.
# 
#     @ivar sampleTimes: Sequence of times at which samples were taken.
#     """
# 
#     def __init__(self):
#         """
#         Initialise capture.
#         """
#         self._markers = dict()
# 
#     def _addMarker(self, marker):
#         self._markers[marker.id] = marker
# 
#     @property
#     def markers(self):
#         """
#         List of the markers in this capture.
#         """
#         return self._markers.values()
# 
#     def marker(self, id):
#         """
#         Get a marker by identifier.
# 
#         @return: The L{Marker} with the given identifier.
#         """
#         return self._markers[id]
# 
# class Marker3DOF(SampledPositionTrajectory, Marker):
#     """
#     A capture marker with 3DOF position samples.
#     """
#     def __init__(self, capture, id):
#         Marker.__init__(self, capture, id)
#         SampledPositionTrajectory.__init__(self)


# Path: imusim/io/vicon_csv.py
from imusim.capture.marker import MarkerCapture, Marker3DOF
import numpy as np

    @param filename: Name of the CSV file to load.

    @return: A L{MarkerCapture} object.
    """
    # Open file to read header.
    datafile = open(filename, 'r')

    # Function to get comma-separated values from a line.
    values = lambda line: line.rstrip('\r\n').split(',')

    # Get column names.
    colnames = values(datafile.readline())

    # Get marker names.
    markernames = [n.split(':')[-2] for n in colnames[2::3]]

    # Get data.
    data = np.array([[float(v or np.nan) for v in values(line)]
        for line in datafile.readlines()]).T

    frameTimes = data[1]
    positions = data[2:].reshape((len(markernames),3,-1)) / 1000

    capture = MarkerCapture()
    capture.frameTimes = frameTimes
    capture.frameCount = len(frameTimes)
    capture.framePeriod = np.min(np.diff(frameTimes))
    capture.frameRate = 1 / capture.framePeriod

    for i, name in enumerate(markernames):

        marker = Marker3DOF(capture, name)