braintools.cogtask.ctx_value

Contents

braintools.cogtask.ctx_value#

braintools.cogtask.ctx_value(key, default=0)[source]#

Create a dynamic value that reads directly from context.

Parameters:
  • key (str) – Context key to read.

  • default (Any) – Default value if key not found (default 0).

Returns:

Value function (ctx, feature) -> value

Return type:

Callable[[Context, Feature], Any]

Examples

>>> from braintools.cogtask import Context, Feature, ctx_value
>>> spec = ctx_value('fixation_strength', default=1.0)
>>> ctx = Context()
>>> spec(ctx, Feature(1, 'fixation'))  # key missing: default
1.0
>>> ctx['fixation_strength'] = 0.3
>>> spec(ctx, Feature(1, 'fixation'))
0.3