class floodlight.core.code.Code(code, name, definitions=None, framerate=None)[source]

Fragment of continuous signal encoding one game state. Core class of floodlight.

  • code (np.ndarray) – One-dimensional array with codes describing a sequence of play.

  • name (str) – Name of encoded game state (e.g. ‘possession’).

  • definitions (dict, optional) – Dictionary of the form {token: definition} where each code category is defined or explained.

  • framerate (int, optional) – Temporal resolution of data in frames per second/Hertz.


token (list) – A list of all tokens used in game code, in ascending order.


Finds all sequences of consecutive appearances for each token and returns their start and end indices.


return_type ({‘dict’, ‘list’}, default=’dict’) – Specifies type of the returned sequences object.


sequences – If return_type is ‘dict’, returns a dictionary of the form {token: [(sequence_start_idx, sequence_end_idx)]}. If return_type is ‘list’, returns a list of the form [(sequence_start_idx, sequence_end_idx, token)] ordered by the respective sequence start indices.

Return type

Union[Dict[Any, tuple], List[tuple]]


>>> import numpy as np
>>> from floodlight import Code
>>> code = Code(code=np.array([1, 1, 2, 1, 1, 3, 1, 1]), name="intensity")
>>> code.find_sequences()
{1: [(0, 2), (3, 5), (6, 8)], 2: [(2, 3)], 3: [(5, 6)]}
>>> code = Code(code=np.array(['A', 'A', 'H', 'H', 'H', 'H', 'A', 'A', 'A']),
...                           name="possession")
>>> code.find_sequences(return_type="list")
[(0, 2, 'A'), (2, 6, 'H'), (6, 9, 'A')]
slice(startframe=None, endframe=None, inplace=False)[source]

Return copy of object with sliced code. Mimics numpy’s array slicing.

  • startframe (int, optional) – Start of slice. Defaults to beginning of segment.

  • endframe (int, optional) – End of slice (endframe is excluded). Defaults to end of segment.

  • inplace (bool, optional) – If set to False (default), a new object is returned, otherwise the operation is performed in place on the called object.



Return type

Union[Code, None]

property token: list

A list of all tokens used in game code, in ascending order.

Return type