ndspflow.workflows.WorkFlow

class ndspflow.workflows.WorkFlow(y_array=None, x_array=None, **kwargs)[source]

Workflow definition.

Attributes
modelslist

Fit model objects.

resultslist, optional

Attributes from model classes.

graphnetworkx.DiGraph

Directed workflow graph.

nodeslist of list

Contains order of operations as: [[node_type, function, *args, **kwargs], …]

__init__(y_array=None, x_array=None, **kwargs)[source]

Initalize object.

Parameters
y_arrayndarray, optional, default: None

Y-axis values. Usually voltage or power.

x_array1d array, optional, default: None

X-axis values. Usually time or frequency.

**kwargs

Additional keyword arguments that sub-classes need access to. See: {ndspflow.workflow.bids.BIDS, ndspflow.workflow.sim.Simulate}

Methods

__init__([y_array, x_array])

Initalize object.

create_graph([npad])

drop_x()

Clear x-array values.

drop_y()

Clear y-array values.

fit(model, *args[, axis])

Queue fit.

fit_transform(model[, y_attrs, x_attrs, ...])

Queue a model fit and transform y_array to model attributes.

fork([ind])

Queue fork.

merge()

Queue a merge.

plot([npad, ax, draw_kwargs])

Plot workflow as a directed graph.

read_bids([subject, allow_ragged, queue])

Read the BIDS directory into memory.

run([axis, attrs, flatten, n_jobs, progress])

Run workflow.

run_fit(x_array, y_array, *args[, axis])

Execute fit.

run_fit_transform(y_attrs[, x_attrs, axis, ...])

Execute a fit + transform.

run_fork([ind])

Execute fork.

run_simulate(func, *args[, operator])

Queue simulation.

run_transform(func, *args[, axis])

Execute transformation.

simulate(func, *args[, operator])

Queue simulation.

transform(func, *args[, axis])

Queue transformation.

drop_x()[source]

Clear x-array values.

drop_y()[source]

Clear y-array values.

fit(model, *args, axis=None, **kwargs)

Queue fit.

Parameters
modelclass

Model class with a .fit method that accepts {(x_array, y_array), y_array}.

args

Passed to the .fit method of the model class.

axisint, optional, default: None

Axis to fit model over.

**kwargs

Passed to the .fit method of the model class.

fit_transform(model, y_attrs=None, x_attrs=None, axis=None, queue=False, n_jobs=- 1, progress=None, fit_args=None, fit_kwargs=None)[source]

Queue a model fit and transform y_array to model attributes.

Parameters
modelclass

Model class with a .fit method that accepts {(x_array, y_array), y_array}.

y_attrsstr or list of str, optional, default: None

Model attributes to return as y_array. Required if model does not have fit_transform method.

axisint, optional, default: None

Axis to fit model over.

x_attrslist of str, optional, default: None

Model attributes to return as x_array.

n_jobsint, optional, default: -1

Number of jobs to run in parallel.

progress{None, tqdm.notebook.tqdm, tqdm.tqdm}

Progress bar.

queuebool, optional, default: False

Add to node queue if True. Otherwise, execute on call.

fit_argsdict, optional, default: False

Passed to the .fit method of the model class.

fit_kwargsdict, optional, default: False

Passed to the .fit method of the model class.

fork(ind=0)[source]

Queue fork.

Parameters
indint

Reference to fork to rewind to.

merge()[source]

Queue a merge.

plot(npad=2, ax=None, draw_kwargs=None)[source]

Plot workflow as a directed graph.

read_bids(subject=None, allow_ragged=False, queue=True)

Read the BIDS directory into memory.

Parameters
subjectint, optional, default: None

Read a single subject into memory. If None, the entire BIDS dataset is read into memory at once.

allow_raggedbool, optional, default: True

Allow and use ragged arrays if True. Otherwise assumes non-ragged and sets max output length to min raw length. Only used if ind is None.

queuebool, optional, default: True

Queue’s reading into nodes if True. Otherwise reads y_array in.

run(axis=None, attrs=None, flatten=False, n_jobs=- 1, progress=None)[source]

Run workflow.

Parameters
axisint or tuple of int, optional, default: None

Axis to pass to multiprocessing pools. Only used for 2d and greater. Identical to numpy axis arguments.

attrslist of str, optional, default: None

Model attributes to return.

flattenbool, optional, default: False

Flattens all models and attributes into a 1d array, per y_array.

n_jobsint, optional, default: -1

Number of jobs to run in parallel.

progress{None, tqdm.notebook.tqdm, tqdm.tqdm}

Progress bar.

run_fit(x_array, y_array, *args, axis=None, **kwargs)

Execute fit.

Parameters
y_arrayndarray

Y-axis values. Usually voltage or power.

x_array1d array

X-axis values. Usually time or frequency.

*args

Passed to the .fit method of the model class.

axisint, optional, default: None

Axis to fit model over.

**kwargs

Passed to the .fit method of the model class.

Notes

Pass ‘self’ to any arg or kwarg to infer its value from a instance variable.

run_fit_transform(y_attrs, x_attrs=None, axis=None, args=None, kwargs=None)[source]

Execute a fit + transform.

Parameters
y_attrsstr or list of st

Model attributes to return as y_array.

x_attrsstr or list of str, optional, default: None

Model attributes to return as x_array.

argstuple, optional, default: None

Passed to the .fit method of the model class.

axisint, optional, default: None

Axis to fit model over.

kwargsdict, optional, default: None

Passed to the .fit method of the model class.

run_fork(ind=0)[source]

Execute fork.

Parameters
indint

Reference to fork to rewind to.

run_simulate(func, *args, operator='add', **kwargs)

Queue simulation.

Parameters
funcfunction

Simulation function.

operator{‘add’, ‘mul’, ‘sub’, ‘div’} or {‘+’, ‘*’, ‘-’, ‘/’}

Operator to combine signals.

*args

Additonal positional arguments to func.

**kwargs

Addional keyword arguments to func.

run_transform(func, *args, axis=None, **kwargs)

Execute transformation.

Parameters
funcfunction

Preprocessing function (e.g. filter).

*args

Additonal positional arguments to func.

axisint or tuple of int, optional, default: None

Axis to apply the function along 1d-slices. Only used for 2d and greater. Identical to numpy axis arguments. None assumes transform requires 2d input.

**kwargs

Addional keyword arguments to func.

Notes

This is a slightly more flexible/faster version of np.apply_along_axis that also handles tuples of axes and can be applied to any series of array operations.

simulate(func, *args, operator='add', **kwargs)

Queue simulation.

Parameters
funcfunction

Simulation function.

operator{‘add’, ‘mul’, ‘sub’, ‘div’} or {‘+’, ‘*’, ‘-’, ‘/’}

Operator to combine signals.

*args

Additonal positional arguments to func.

**kwargs

Addional keyword arguments to func.

transform(func, *args, axis=None, **kwargs)

Queue transformation.

Parameters
funcfunction

Preprocessing function (e.g. filter).

*args

Additonal positional arguments to func.

axisint or tuple of int, optional, default: None
Axis to apply the function along 1d-slices. Only used for 2d and greater.

Identical to numpy axis arguments. None assumes transform requires 2d input.

**kwargs

Addional keyword arguements to func.