Ensembler¶
The Ensembler module provides a flexible framework for constructing multi-panel biomechanical visualizations from time-series data.
It is built around a modular architecture consisting of: data loading, plot specification, and pluggable rendering strategies.
Overview¶
A typical workflow is:
Load data via
EnsemblerDefine subplot configurations using
PlotSpecAssign rendering strategies (e.g., lines, mean ± SD, events)
Build and display the figure
Example¶
lines_and_events = CompositeRenderer(
IndividualLinesRenderer(),
EventOverlayRenderer()
)
ens = Ensembler(
in_folder=fld,
channels=channels,
n_rows=rows,
n_cols=cols,
subj_list=subj_list,
condition_spec=spec
)
ens.add_subplot(
PlotSpec(
'Right Knee Sagittal plane',
'Kinemat_x',
companions=['Angles_x'],
row=1,
col=1,
renderer=IndividualLinesRenderer(),
x_label='% stance',
y_label='Joint angle (deg)'
)
)
ens.add_subplot(
PlotSpec(
'Right Knee Sagittal plane (mean +/- SD)',
'Kinemat_x',
companions=['Angles_x'],
row=1,
col=2,
renderer=MeanSDRenderer(),
x_label='% stance',
y_label='Joint angle (deg)'
)
)
fig = ens.build(title='Kinemat vs Plug-in Gait')
fig.show()
Core Components¶
Ensembler¶
Plot Specification¶
- class biomechzoo.ensembler.plot_spec.PlotSpec(channel: str, condition: str = None, row: int = 1, col: int = 1, renderer: biomechzoo.ensembler.renderers.Renderer = None, events: list[str] = <factory>, companions: list[str] = <factory>, group_by: str | None = None, group_map: dict[str, str] | None=None, title: str = '', x_label: str = '', y_label: str = '')[source]¶
Bases:
object- Parameters:
- renderer: Renderer = None¶
- property all_conditions¶
Rendering System¶
Base renderers define how data is visualized.
Data Management¶
- class biomechzoo.ensembler.data_store.DataStore(fld, condition_spec=None, events=None, subj_list=None, str_match=None)[source]¶
Bases:
objectLoads, indexes and extracts relevant data and information from the zoo files.
- Parameters:
condition_spec (ConditionSpec | None)
- get_event_values(channel, condition, event_name)[source]¶
Convenience — y-only, for violin/stats renderers.
Helpers¶
- biomechzoo.ensembler.helpers.extract_subject_id(f, subj_list, str_pattern)[source]¶
Extracts the subject ID from the zoo file path and a string match using a regular expression of a known list of subject IDs. :Parameters: * f (str) – File path to the zoo file.
subj_list (list of str) – List of subject IDs.
str_pattern (list of str) – String pattern to match the subject IDs.
- Returns:
s (str or None) – Subject ID if found, otherwise None.
- class biomechzoo.ensembler.helpers.ZooEvent(x, y)[source]¶
Bases:
NamedTuple
- biomechzoo.ensembler.helpers.extract_events(ch_data, event_name)[source]¶
Extracts the named event scalers (value and frame) from a zoo file.
- biomechzoo.ensembler.helpers.compute_ensemble(arrays)[source]¶
Compute time normalized mean and standard deviation for a list of arrays.
- Parameters:
arrays (list[np.ndarray])
- Returns:
mean (array)
upper (array) – mean + std
lower (array) – mean - std
- class biomechzoo.ensembler.helpers.ConditionSource(value)[source]¶
Bases:
EnumEnum defining condition sources.
- BETWEEN = 'folder'¶
- WITHIN = 'channel'¶
- class biomechzoo.ensembler.helpers.ConditionSpec(source, conditions=<factory>, channel_map=None, base_channels=<factory>, suffix_map=None)[source]¶
Bases:
objectDescribes how the conditions are encoded in the data
- Parameters:
- source: ConditionSource¶