Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

append

append

Provide standalone DesignMatrix concatenation functions.

These functions implement the append/concatenation logic extracted from DesignMatrix methods, following the “functional core” pattern.

Methods:

NameDescription
appendConcatenate design matrices.
append_horizontalConcatenate matrices horizontally by adding columns.
append_verticalConcatenate matrices vertically with optional confound separation.
append_vertical_with_separationConcatenate vertically with automatic confound separation.
get_starting_run_idxDetermine the next run index for multi-run appending.
identify_columns_to_separateIdentify columns that need run-specific separation.
match_column_patternMatch columns against a pattern with wildcard support.

Classes

Methods

append

append(dm: DesignMatrix, other: DesignMatrix, *, axis: int = 0, keep_separate: bool = True, unique_cols: list[str] | None = None, fill_na: int | float | None = 0, as_confounds: bool = False, progress_bar: bool = False) -> DesignMatrix

Concatenate design matrices.

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixThe base design matrix.required
otherDesignMatrix, DataFrame, or listMatrix/matrices to append. For axis=1 (horizontal), also accepts a pandas or polars DataFrame (or list thereof); the new columns are treated as nuisance regressors (tracked in .confounds on the result). For axis=0 (vertical), all items must be DesignMatrix.required
axisint0 for row-wise (vertical), 1 for column-wise (horizontal).0
keep_separateboolWhether to separate confound columns across runs (only axis=0).True
unique_colslist of strAdditional columns to keep separated (supports wildcards).None
fill_naint, float, or NoneValue to fill NaN/null entries introduced by the concatenation. Pass None to preserve nulls. Default: 0.0
as_confoundsboolOnly applies to axis=1. When True, all columns contributed by other are tracked as nuisance regressors in the result’s .confounds — so they’re skipped by .convolve() and kept separate across runs in later vertical appends. Useful when other is a pre-built DesignMatrix of confounds that hasn’t already marked its columns. Default: False.False
progress_barboolPrint messages about confound separation. Default: False.False

Returns:

NameTypeDescription
DesignMatrixDesignMatrixConcatenated design matrix.

append_horizontal

append_horizontal(dm: DesignMatrix, to_append: list[DesignMatrix], fill_na: int | float | None, as_confounds: bool = False) -> DesignMatrix

Concatenate matrices horizontally by adding columns.

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixBase DesignMatrix instance.required
to_appendlist of DesignMatrixMatrices whose columns to add.required
fill_naint, float, or NoneValue to fill NaN/null entries with. Pass None to preserve nulls.required
as_confoundsboolIf True, mark all columns contributed by to_append as nuisance/confounds in the result.False

Returns:

NameTypeDescription
DesignMatrixDesignMatrixNew DesignMatrix with columns from all matrices.

append_vertical

append_vertical(dm: DesignMatrix, to_append: list[DesignMatrix], keep_separate: bool, unique_cols: list[str] | None, fill_na: int | float | None, *, progress_bar: bool) -> DesignMatrix

Concatenate matrices vertically with optional confound separation.

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixBase DesignMatrix instance.required
to_appendlist of DesignMatrixMatrices to stack below dm.required
keep_separateboolWhether to separate confound columns across runs.required
unique_colslist of strAdditional columns to keep separated (supports wildcards).required
fill_naint, float, or NoneValue to fill NaN/null entries with. Pass None to preserve nulls.required
progress_barboolPrint messages about confound separation.required

Returns:

NameTypeDescription
DesignMatrixDesignMatrixNew DesignMatrix with rows from all matrices.

append_vertical_with_separation

append_vertical_with_separation(dm: DesignMatrix, to_append: list[DesignMatrix], unique_cols: list[str] | None, fill_na: int | float | None, *, progress_bar: bool) -> DesignMatrix

Concatenate vertically with automatic confound separation.

Creates run-specific columns (e.g., .nl_r0_poly_0, .nl_r1_poly_0) that are active only in their respective runs (sparse representation).

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixBase DesignMatrix instance.required
to_appendlist of DesignMatrixMatrices to stack below dm.required
unique_colslist of strAdditional columns to keep separated (supports wildcards).required
fill_naint, float, or NoneValue to fill NaN/null entries with. Pass None to preserve nulls.required
progress_barboolPrint messages about confound separation.required

Returns:

NameTypeDescription
DesignMatrixDesignMatrixConcatenated DesignMatrix with run-separated confound columns and multi=True.

get_starting_run_idx

get_starting_run_idx(dm: DesignMatrix) -> int

Determine the next run index for multi-run appending.

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixDesignMatrix instance to inspect.required

Returns:

NameTypeDescription
intintNext run index (0 if not multi-run, max_existing_idx + 1 otherwise).

identify_columns_to_separate

identify_columns_to_separate(dm: DesignMatrix, all_dms: list[DesignMatrix], unique_cols: list[str] | None) -> set

Identify columns that need run-specific separation.

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixThe base design matrix (used for context only).required
all_dmslist of DesignMatrixAll matrices being concatenated.required
unique_colslist of strUser-specified columns to separate (supports wildcards).required

Returns:

NameTypeDescription
setsetColumn names that should be separated with run prefixes.

match_column_pattern

match_column_pattern(columns: list[str], pattern: str) -> list[str]

Match columns against a pattern with wildcard support.

Parameters:

NameTypeDescriptionDefault
columnslist of strColumn names to search.required
patternstrPattern to match (supports ‘’ as wildcard). - 'motion’ matches motion_x, motion_y - ‘*_motion’ matches x_motion, y_motion - ‘exact’ matches only ‘exact’required

Returns:

TypeDescription
list [ str ]list of str: Column names matching the pattern.