mopipe.core.analysis.pipeline
pipeline.py
This module contains the Pipeline class, which is used to run a series of analysis steps (segments) on the data.
Pipeline Objects
class Pipeline(t.MutableSequence[Segment])
Pipeline
A pipeline is a series of segments that are run on the data.
__init__
def __init__(segments: t.Optional[t.MutableSequence[Segment]] = None) -> None
Initialize a Pipeline.
segments
@property
def segments() -> t.MutableSequence[Segment]
The segments in the pipeline.
segment
def segment(index: int) -> Segment
Get a segment from the pipeline.
add_segment
def add_segment(segment: Segment) -> int
Add a segment to the pipeline.
run
def run(**kwargs) -> t.Any
Run the pipeline.
mopipe.core.analysis
mopipe.core.common.datastructs
datastructs.py
This module contains the data structures used by the mopipe package.
DataLevel Objects
class DataLevel(IntEnum)
DataLevel
Enum for the different levels of data that can be read by the mopipe package.
EnumContainsMeta Objects
class EnumContainsMeta(EnumMeta)
ExtendedStrEnum
This is an extension of the StrEnum class from the enum module. It adds the contains method, which allows checking if a string is a valid member of the enum.
It also adds the getitem method, which allows getting the value of a member from its name, or if you already pass in a value, it will return the value.
MocapMetadataEntries Objects
class MocapMetadataEntries(StrEnum, metaclass=EnumContainsMeta)
MocapMetadata
Common metadata for all MoCap data, and their transformed names. This allows a common interface for all MoCap data.
mopipe.core.common.qtm
TrajectoryType Objects
class TrajectoryType(Enum)
TrajectoryType
Enum for the different types of trajectories that can be exported by QTM.
from_str
@staticmethod
def from_str(string: str) -> "TrajectoryType"
Convert string to TrajectoryType.
Parameters
string : str String to convert to TrajectoryType.
Returns
TrajectoryType TrajectoryType corresponding to string.
parse_time_stamp
def parse_time_stamp(time_stamp: list[str]) -> tuple[datetime, float]
Parse the time stamp from a list of strings.
Parameters
time_stamp : List[str] List of strings containing the time stamp.
Returns
Tuple[datetime, float] Tuple containing the time stamp and ?????.
parse_event
def parse_event(event: list[str]) -> tuple[int, float]
Parse the event data from a list of strings.
Parameters
event : List[str] List of strings containing the event.
Returns
Tuple[float, float] Tuple containing the index and elapsed time.
parse_marker_names
def parse_marker_names(marker_names: list[str]) -> list[str]
Parse the marker names from a list of strings.
Parameters
marker_names : List[str] List of strings containing the marker names.
Returns
List[str] List containing the marker names.
parse_trajectory_types
def parse_trajectory_types(
trajectory_types: list[str]) -> list[TrajectoryType]
Parse the trajectory types from a list of strings.
Parameters
trajectory_types : List[str] List of strings containing the trajectory types.
Returns
List[TrajectoryType] List containing the trajectory types.
parse_metadata_row
def parse_metadata_row(key: str, values: list[t.Any]) -> tuple[str, t.Any]
Parse a metadata row and return the key and value.
Parameters
key : str The key of the metadata row. values : List[Any] The values of the metadata row.
Returns
Tuple[str, Any] Tuple containing the key and value of the metadata row.
mopipe.core.common.util
util.py
Common utility functions.
maybe_generate_id
def maybe_generate_id(_id: t.Optional[str] = None,
prefix: t.Optional[str] = None,
suffix: t.Optional[str] = None) -> str
Generate a random id if not provided.
This provides a fluid interface for generating unique ids for various classes. Sometimes, a user may want to provide their own id, and if so, this function will simply return the id they provided. If no id is provided, a random id will be generated.
Parameters
_id : str, optional The id to use. prefix : str, optional The prefix to use for the id. suffix : str, optional The suffix to use for the id.
Returns
str The id.
mopipe.core.common
mopipe.core.data.collator
collator.py
This module contains the Mocap Data Collator class, which is used to collate data from multiple sources and save it.
MocapDataCollator Objects
class MocapDataCollator()
MocapDataCollator
The MocapDataCollator class is used to collate data from multiple sources and save it.
__init__
def __init__(output_dir: Path, output_name: str)
Initialize the MocapDataCollator.
Parameters
output_dir : Path The directory to save the collated data in. output_name : str The base name to save the collated data under. level : DataLevel The level of the data to be read.
readers
@property
def readers() -> list[AbstractReader]
The readers to be used to read the data.
output_dir
@property
def output_dir() -> Path
The directory to save the collated data in.
output_name
@property
def output_name() -> str
The name to save the collated data under.
add_reader
def add_reader(reader: AbstractReader) -> int
Add a reader to the collator.
Parameters
reader : AbstractReader The reader to be added.
Returns
int The reader index.
collate
def collate() -> DataFrame
Collate the data from the readers.
Returns
DataFrame The collated data.
mopipe.core.data.empirical
This contains base classes for defining data associated with experiemnts
MetaData Objects
class MetaData(dict)
MetaData
Base class for all metadata associated with data.
MocapMetaData Objects
class MocapMetaData(MetaData)
MocapMetaData
This automatically transforms the keys of the metadata to the known names in MocapMetadataEntries.
EmpiricalData Objects
class EmpiricalData()
EmpiricalData
Base class for all empirical data.
DiscreteData Objects
class DiscreteData(EmpiricalData)
DiscreteData
For data that is associated with a level, but not timeseries.
TimeseriesData Objects
class TimeseriesData(EmpiricalData)
TimeseriesData
For timeserioes data that is associated with a level.
MocapTimeSeries Objects
class MocapTimeSeries(TimeseriesData)
MocapTimeSeries
For Mocap data (i.e. 3D marker positions).
mopipe.core.data.experiment
Experiment structure classes.
LDType Objects
class LDType(StrEnum)
Type of data associated with a level.
ExperimentLevel Objects
class ExperimentLevel()
Base class for experiment structure classes.
This class can be used to drop in data that applies to specific levels of an experiment, e.g. experiment-wide data, group-level, condition-level, trial-level etc.
__init__
def __init__(level_name: str,
level_id: t.Optional[str] = None,
level_metadata: t.Optional[MetaData] = None) -> None
Initialize an ExperimentLevel.
level_name
@property
def level_name() -> str
Name of the level.
level_id
@property
def level_id() -> str
ID of the level.
parent
@property
def parent() -> t.Optional["ExperimentLevel"]
Parent level.
parent
@parent.setter
def parent(parent: "ExperimentLevel") -> None
Set the parent level.
child
@property
def child() -> t.Optional["ExperimentLevel"]
Child level.
child
@child.setter
def child(child: "ExperimentLevel") -> None
Set the child level.
depth
@property
def depth() -> int
Depth of the level.
leveldata
@property
def leveldata() -> list["EmpiricalData"]
Level data.
leveldata
@leveldata.setter
def leveldata(leveldata: t.Iterable["EmpiricalData"]) -> None
Set the level data.
add_leveldata
def add_leveldata(leveldata: "EmpiricalData") -> None
Add level data to the level.
timeseries
@property
def timeseries() -> list["EmpiricalData"]
Timeseries data.
timeseries
@timeseries.setter
def timeseries(timeseries: t.Iterable["EmpiricalData"]) -> None
Set the timeseries data.
add_timeseries
def add_timeseries(timeseries: "EmpiricalData") -> None
Add a timeseries to the level.
level_metadata
@property
def level_metadata() -> "MetaData"
Level metadata.
level_metadata
@level_metadata.setter
def level_metadata(level_metadata: "MetaData") -> None
Set the level metadata.
climb
def climb() -> t.Iterator["ExperimentLevel"]
Climb the experiment structure.
descend
def descend() -> t.Iterator["ExperimentLevel"]
Descend the experiment structure.
top
def top() -> "ExperimentLevel"
Get the top level.
bottom
def bottom() -> "ExperimentLevel"
Get the bottom level.
relevel_stack
def relevel_stack()
Relevel the experiment structure.
This method will relevel the experiment structure, so that the top level is at depth 0, and each level below it is at depth 1. If the top level is not an Experiment, then the depth of the top level will be 1.
relevel_children
def relevel_children() -> None
Relevel the children of the experiment structure.
Experiment Objects
class Experiment(ExperimentLevel)
__init__
def __init__(experiment_id: str) -> None
Initialize an Experiment.
parent
@property
def parent() -> ExperimentLevel | None
Parent level.
parent
@parent.setter
def parent(parent: t.Any) -> None
Set the parent level.
Trial Objects
class Trial(ExperimentLevel)
__init__
def __init__(trial_id: str) -> None
Initialize a Trial.
child
@property
def child() -> ExperimentLevel | None
Child level.
child
@child.setter
def child(child: t.Any) -> None
Set the child level.
mopipe.core.data.reader
reader.py
This module contains the default Reader classes, including the AbstractReader base class which can be used for creating new readers.
AbstractReader Objects
class AbstractReader(ABC)
AbstractReader
Abstract base class for all Readers. Readers are used to read data from a source and return it in a pandas dataframe.
__init__
@abstractmethod
def __init__(source: t.Union[str, Path, pd.DataFrame],
name: str,
data_id: t.Optional[str] = None,
sample_rate: t.Optional[float] = None,
**kwargs)
Initialize the AbstractReader.
Parameters
source : Path or DataFrame The source of the data to be read. name : str The name of the data/experiment to be read. data_id : str, optional The id of the data to be read. If not provided, a random id will be generated. sample_rate : float, optional The sample rate of the data to be read.
source
@property
def source() -> t.Union[Path, pd.DataFrame]
The source of the data to be read.
sample_rate
@property
def sample_rate() -> t.Optional[float]
The sample rate of the data to be read.
allowed_extensions
@property
def allowed_extensions() -> list[str]
The allowed extensions for the source.
metadata
@property
def metadata() -> MetaData
The metadata for the data to be read.
name
@property
def name() -> str
The name of the data/experiment to be read.
data_id
@property
def data_id() -> str
The id of the data/experiment to be read.
read
@abstractmethod
def read() -> t.Optional[EmpiricalData]
Read the data from the source and return it as a dataframe.
MocapReader Objects
class MocapReader(AbstractReader)
MocapReader
The MocapReader class is used to read motion capture data from a source and return it as a pandas dataframe.
__init__
def __init__(source: t.Union[Path, pd.DataFrame],
name: str,
data_id: t.Optional[str] = None,
sample_rate: t.Optional[float] = None,
**kwargs)
Initialize the MocapReader.
Parameters
source : Path or DataFrame The source of the data to be read. name : str The name of the data/experiment to be read. sample_rate : float, optional The sample rate of the data to be read. level : DataLevel, optional The level of the data to be read.
metadata
@property
def metadata() -> MocapMetaData
The metadata for the data to be read.
read
def read() -> MocapTimeSeries
Read the data from the source and return it as a dataframe.
Returns
MocapTimeSeries The data read from the source.
mopipe.core.data
mopipe.core.segments.inputs
InputTypeBaseMixin Objects
class InputTypeBaseMixin(IOTypeBaseMixin)
Mixin class for all segments input types.
input_type
@property
def input_type() -> IOType
The type of the input.
validate_input
@abstractmethod
def validate_input(**kwargs) -> bool
Validate the input.
UnivariateSeriesInput Objects
class UnivariateSeriesInput(InputTypeBaseMixin)
Mixin class for univariate series input segments.
validate_input
def validate_input(**kwargs) -> bool
Validate the input.
MultivariateSeriesInput Objects
class MultivariateSeriesInput(InputTypeBaseMixin)
Mixin class for multivariate series input segments.
validate_input
def validate_input(**kwargs) -> bool
Validate the input.
SingleValueInput Objects
class SingleValueInput(InputTypeBaseMixin)
Mixin class for single value input segments.
validate_input
def validate_input(**kwargs) -> bool
Validate the input.
MultiValueInput Objects
class MultiValueInput(InputTypeBaseMixin)
Mixin class for multiple values input segments.
validate_input
def validate_input(**kwargs) -> bool
Validate the input.
SingleNumericValueInput Objects
class SingleNumericValueInput(InputTypeBaseMixin)
Mixin class for single numeric value input segments.
validate_input
def validate_input(**kwargs) -> bool
Validate the input.
AnySeriesInput Objects
class AnySeriesInput(InputTypeBaseMixin)
Mixin class for any series input segments.
validate_input
def validate_input(**kwargs) -> bool
Validate the input.
AnyNumericInput Objects
class AnyNumericInput(InputTypeBaseMixin)
Mixin class for any numeric input segments.
validate_input
def validate_input(**kwargs) -> bool
Validate the input.
AnyInput Objects
class AnyInput(InputTypeBaseMixin)
Mixin class for any input segments.
validate_input
def validate_input(**kwargs) -> bool
Validate the input.
OtherInput Objects
class OtherInput(InputTypeBaseMixin)
Mixin class for other input segments.
validate_input
def validate_input(**kwargs) -> bool
Validate the input.
mopipe.core.segments.io
IOType Objects
class IOType(Enum)
Type of segment inputs/outputs.
This is used to determine whether a segment can be run on a given input, or if the output of a segment can be used as input to another.
IOTypeBaseMixin Objects
class IOTypeBaseMixin()
Mixin class for all segments input/output types.
mopipe.core.segments.outputs
OutputTypeBaseMixin Objects
class OutputTypeBaseMixin(IOTypeBaseMixin)
Mixin class for all segments output types.
output_type
@property
def output_type() -> IOType
The type of the output.
validate_output
@abstractmethod
def validate_output(output: t.Any) -> bool
Validate the output.
UnivariateSeriesOutput Objects
class UnivariateSeriesOutput(OutputTypeBaseMixin)
Mixin class for univariate series output segments.
validate_output
def validate_output(output: t.Any) -> bool
Validate the output.
MultivariateSeriesOutput Objects
class MultivariateSeriesOutput(OutputTypeBaseMixin)
Mixin class for multivariate series output segments.
validate_output
def validate_output(output: t.Any) -> bool
Validate the output.
SingleValueOutput Objects
class SingleValueOutput(OutputTypeBaseMixin)
Mixin class for single value output segments.
validate_output
def validate_output(output: t.Any) -> bool
Validate the output.
MultiValueOutput Objects
class MultiValueOutput(OutputTypeBaseMixin)
Mixin class for multiple values output segments.
validate_output
def validate_output(output: t.Any) -> bool
Validate the output.
SingleNumericValueOutput Objects
class SingleNumericValueOutput(OutputTypeBaseMixin)
Mixin class for single numeric value output segments.
validate_output
def validate_output(output: t.Any) -> bool
Validate the output.
AnySeriesOutput Objects
class AnySeriesOutput(OutputTypeBaseMixin)
Mixin class for any series output segments.
validate_output
def validate_output(output: t.Any) -> bool
Validate the output.
AnyNumericOutput Objects
class AnyNumericOutput(OutputTypeBaseMixin)
Mixin class for any numeric output segments.
validate_output
def validate_output(output: t.Any) -> bool
Validate the output.
AnyOutput Objects
class AnyOutput(OutputTypeBaseMixin)
Mixin class for any output segments.
validate_output
def validate_output(output: t.Any) -> bool
Validate the output.
OtherOutput Objects
class OtherOutput(OutputTypeBaseMixin)
Mixin class for other output segments.
validate_output
def validate_output(output: t.Any) -> bool
Validate the output.
mopipe.core.segments.preprocessor
mopipe.core.segments.seg
seg.py
Base segment class for all pipeline steps.
Segment Objects
class Segment(metaclass=SegmentMeta)
Base class for all pipeline steps.
__init__
def __init__(name: str, segment_id: t.Optional[str] = None) -> None
Initialize a Segment.
name
@property
def name() -> str
The name of the segment.
segment_id
@property
def segment_id() -> str
The id of the segment.
validate_input
@abstractmethod
def validate_input(**kwargs) -> bool
Validate the input.
validate_output
@abstractmethod
def validate_output(output: t.Any) -> bool
Validate the output.
process
@abstractmethod
def process(x: t.Any, **kwargs) -> t.Any
Process the inputs and return the output.
input_type
@property
@abstractmethod
def input_type() -> IOType
The type of the input.
output_type
@property
@abstractmethod
def output_type() -> IOType
The type of the output.
segment_type
@property
@abstractmethod
def segment_type() -> SegmentType
The type of the segment.
__call__
def __call__(**kwargs) -> t.Any
Process the inputs and return the output.
mopipe.core.segments.segmenttypes
SegmentType Objects
class SegmentType(Enum)
Type of segment.
SegmentTypeMixin Objects
class SegmentTypeMixin()
Mixin class for all segments types.
segment_type
@property
def segment_type() -> SegmentType
The type of the segment.
PreprocessorType Objects
class PreprocessorType(SegmentTypeMixin)
Mixin class for preprocessing segments.
SummaryType Objects
class SummaryType(SegmentTypeMixin)
Mixin class for summary segments.
TransformType Objects
class TransformType(SegmentTypeMixin)
Mixin class for transform segments.
AnalysisType Objects
class AnalysisType(SegmentTypeMixin)
Mixin class for analysis segments.
VisualizationType Objects
class VisualizationType(SegmentTypeMixin)
Mixin class for visualization segments.
WriteType Objects
class WriteType(SegmentTypeMixin)
Mixin class for write segments.
OtherType Objects
class OtherType(SegmentTypeMixin)
Mixin class for other segments.