ezmsg.sigproc.affinetransform#

Affine transformations via matrix multiplication: y = Ax or y = Ax + B.

For full matrix transformations where channels are mixed (off-diagonal weights), use AffineTransformTransformer or the AffineTransform unit.

For simple per-channel scaling and offset (diagonal weights only), use LinearTransformTransformer from ezmsg.sigproc.linear instead, which is more efficient as it avoids matrix multiplication.

Functions

affine_transform(weights, axis=None, right_multiply=True)[source]#

Perform affine transformations on streaming data.

Parameters:
  • weights (ndarray | str | Path) – An array of weights or a path to a file with weights compatible with np.loadtxt.

  • axis (str | None) – The name of the axis to apply the transformation to. Defaults to the leading (0th) axis in the array.

  • right_multiply (bool) – Set False to transpose the weights before applying.

Returns:

AffineTransformTransformer.

Return type:

AffineTransformTransformer

common_rereference(mode='mean', axis=None, include_current=True)[source]#

Perform common average referencing (CAR) on streaming data.

Parameters:
  • mode (str) – The statistical mode to apply – either “mean” or “median”

  • axis (str | None) – The name of hte axis to apply the transformation to.

  • include_current (bool) – Set False to exclude each channel from participating in the calculation of its reference.

Returns:

CommonRereferenceTransformer

Return type:

CommonRereferenceTransformer

zeros_for_noop(data, **ignore_kwargs)[source]#
Parameters:

data (ndarray[tuple[Any, ...], dtype[_ScalarT]])

Return type:

ndarray[tuple[Any, …], dtype[_ScalarT]]

Classes

class AffineTransform(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[AffineTransformSettings, AxisArray, AxisArray, AffineTransformTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of AffineTransformSettings

class AffineTransformSettings(weights, axis=None, right_multiply=True)[source]#

Bases: Settings

Settings for AffineTransform.

Parameters:
weights: ndarray | str | Path#

An array of weights or a path to a file with weights compatible with np.loadtxt.

axis: str | None = None#

The name of the axis to apply the transformation to. Defaults to the leading (0th) axis in the array.

right_multiply: bool = True#

Set False to transpose the weights before applying.

__init__(weights, axis=None, right_multiply=True)#
Parameters:
Return type:

None

class AffineTransformState[source]#

Bases: object

weights: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None = None#
new_axis: AxisBase | None = None#
class AffineTransformTransformer(*args, **kwargs)[source]#

Bases: BaseStatefulTransformer[AffineTransformSettings, AxisArray, AxisArray, AffineTransformState]

Apply affine transformation via matrix multiplication: y = Ax or y = Ax + B.

Use this transformer when you need full matrix transformations that mix channels (off-diagonal weights), such as spatial filters or projections.

For simple per-channel scaling and offset where each output channel depends only on its corresponding input channel (diagonal weight matrix), use LinearTransformTransformer instead, which is more efficient.

The weights matrix can include an offset row (stacked as [A|B]) where the input is automatically augmented with a column of ones to compute y = Ax + B.

class CommonRereference(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[CommonRereferenceSettings, AxisArray, AxisArray, CommonRereferenceTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of CommonRereferenceSettings

class CommonRereferenceSettings(mode='mean', axis=None, include_current=True)[source]#

Bases: Settings

Settings for CommonRereference

Parameters:
  • mode (str)

  • axis (str | None)

  • include_current (bool)

mode: str = 'mean'#

The statistical mode to apply – either “mean” or “median”.

axis: str | None = None#

The name of the axis to apply the transformation to.

__init__(mode='mean', axis=None, include_current=True)#
Parameters:
  • mode (str)

  • axis (str | None)

  • include_current (bool)

Return type:

None

include_current: bool = True#

Set False to exclude each channel from participating in the calculation of its reference.

class CommonRereferenceTransformer(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformer[CommonRereferenceSettings, AxisArray, AxisArray]

Parameters:

settings (SettingsType)

class AffineTransformSettings(weights, axis=None, right_multiply=True)[source]#

Bases: Settings

Settings for AffineTransform.

Parameters:
weights: ndarray | str | Path#

An array of weights or a path to a file with weights compatible with np.loadtxt.

axis: str | None = None#

The name of the axis to apply the transformation to. Defaults to the leading (0th) axis in the array.

right_multiply: bool = True#

Set False to transpose the weights before applying.

__init__(weights, axis=None, right_multiply=True)#
Parameters:
Return type:

None

class AffineTransformState[source]#

Bases: object

weights: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None = None#
new_axis: AxisBase | None = None#
class AffineTransformTransformer(*args, **kwargs)[source]#

Bases: BaseStatefulTransformer[AffineTransformSettings, AxisArray, AxisArray, AffineTransformState]

Apply affine transformation via matrix multiplication: y = Ax or y = Ax + B.

Use this transformer when you need full matrix transformations that mix channels (off-diagonal weights), such as spatial filters or projections.

For simple per-channel scaling and offset where each output channel depends only on its corresponding input channel (diagonal weight matrix), use LinearTransformTransformer instead, which is more efficient.

The weights matrix can include an offset row (stacked as [A|B]) where the input is automatically augmented with a column of ones to compute y = Ax + B.

class AffineTransform(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[AffineTransformSettings, AxisArray, AxisArray, AffineTransformTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of AffineTransformSettings

affine_transform(weights, axis=None, right_multiply=True)[source]#

Perform affine transformations on streaming data.

Parameters:
  • weights (ndarray | str | Path) – An array of weights or a path to a file with weights compatible with np.loadtxt.

  • axis (str | None) – The name of the axis to apply the transformation to. Defaults to the leading (0th) axis in the array.

  • right_multiply (bool) – Set False to transpose the weights before applying.

Returns:

AffineTransformTransformer.

Return type:

AffineTransformTransformer

zeros_for_noop(data, **ignore_kwargs)[source]#
Parameters:

data (ndarray[tuple[Any, ...], dtype[_ScalarT]])

Return type:

ndarray[tuple[Any, …], dtype[_ScalarT]]

class CommonRereferenceSettings(mode='mean', axis=None, include_current=True)[source]#

Bases: Settings

Settings for CommonRereference

Parameters:
  • mode (str)

  • axis (str | None)

  • include_current (bool)

mode: str = 'mean'#

The statistical mode to apply – either “mean” or “median”.

axis: str | None = None#

The name of the axis to apply the transformation to.

__init__(mode='mean', axis=None, include_current=True)#
Parameters:
  • mode (str)

  • axis (str | None)

  • include_current (bool)

Return type:

None

include_current: bool = True#

Set False to exclude each channel from participating in the calculation of its reference.

class CommonRereferenceTransformer(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformer[CommonRereferenceSettings, AxisArray, AxisArray]

Parameters:

settings (SettingsType)

class CommonRereference(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[CommonRereferenceSettings, AxisArray, AxisArray, CommonRereferenceTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of CommonRereferenceSettings

common_rereference(mode='mean', axis=None, include_current=True)[source]#

Perform common average referencing (CAR) on streaming data.

Parameters:
  • mode (str) – The statistical mode to apply – either “mean” or “median”

  • axis (str | None) – The name of hte axis to apply the transformation to.

  • include_current (bool) – Set False to exclude each channel from participating in the calculation of its reference.

Returns:

CommonRereferenceTransformer

Return type:

CommonRereferenceTransformer