comnum.Block#

class comnum.Block#

A block of a chain: block(frame, rng) transforms the frame in place.

Subclass it and implement __call__() to write a block in Python; the frame exposes samples (read and write), sps, tx_bits, tx_symbols and constellation. A block that depends on the condition overrides bind() (with its keyword arguments, or **kwargs).

Example

>>> import comnum
>>> class Gain(comnum.Block):
...     def __call__(self, frame, rng):
...         frame.samples = 2 * frame.samples
>>> f = comnum.Frame()
>>> f.samples = [1.0]
>>> Gain()(f, comnum.Rng(0))
>>> f.samples.tolist()
[(2+0j)]
bind(condition: Mapping[str, Any] | None, *, fiber: Mapping[str, Any] | None = None, name: str | None = None, label: str | None = None, profile: bool = False, base_dir: str | PathLike[str] | None = None) → Callable[[Frame, Rng], None]#

The callable that applies the block for a condition (itself by default).

Parameters:
  • condition (dict | None) – the values of the grid variables.

  • fiber (dict | None) – the fiber of the specification, for the optical blocks.

  • name (str | None) – the name of the campaign, for the blocks that write files.

  • label (str | None) – the name of the block in the chain.

  • profile (bool) – time the blocks (chains only).

  • base_dir (str | os.PathLike | None) – the directory the relative paths of the block are resolved against (that of its specification file), for the blocks that read files.

Returns:

the block of the condition.

Return type:

Callable[[Frame, Rng], None]