utils

Classes

InvokeEvent(fn, *args, **kwargs)

Sends signals to the main QT thread from spawned message threads

Invoker

Wrapper that calls an evoked event made by InvokeEvent

Param(**kwargs)

In the future, we will implement a coherent Parameter management system

ReturnThread([group, target, name, args, …])

Thread whose .join() method returns the value from the function

Functions

coerce_discrete(df, col[, mapping])

Coerce a discrete/string column of a pandas dataframe into numeric values

find_recursive(key, dictionary)

Find all instances of a key in a dictionary, recursively.

list_subjects([pilot_db])

Given a dictionary of a pilot_db, return the subjects that are in it.

load_pilotdb([file_name, reverse])

Try to load the file_db

class Param(**kwargs)[source]

Bases: object

In the future, we will implement a coherent Parameter management system

Warning

Not Implemented.

Methods

__contains__(key)

Parameters

key

__delitem__(key)

Parameters

key

__getitem__(key)

Parameters

key

__setitem__(key, value)

Parameters
  • key

Attributes

types

Built-in mutable sequence.

Parameters

**kwargs

tag = None
type = None
types = ['int', 'bool', 'list']
__getitem__(key)[source]
Parameters

key

__setitem__(key, value)[source]
Parameters
  • key

  • value

__delitem__(key)[source]
Parameters

key

__contains__(key)[source]
Parameters

key

class InvokeEvent(fn, *args, **kwargs)[source]

Bases: PySide2.QtCore.QEvent

Sends signals to the main QT thread from spawned message threads

See stackoverflow

Accepts a function, its args and kwargs and wraps them as a QtCore.QEvent

EVENT_TYPE = PySide2.QtCore.QEvent.Type(65533)
class Invoker[source]

Bases: PySide2.QtCore.QObject

Wrapper that calls an evoked event made by InvokeEvent

Methods

event(event)

Parameters

event

event(event)[source]
Parameters

event

staticMetaObject = <PySide2.QtCore.QMetaObject object>
class ReturnThread(group=None, target=None, name=None, args=(), kwargs={}, Verbose=None)[source]

Bases: threading.Thread

Thread whose .join() method returns the value from the function thx to https://stackoverflow.com/a/6894023

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

Methods

join([timeout])

Wait until the thread terminates.

run()

Method representing the thread’s activity.

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

join(timeout=None)[source]

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

list_subjects(pilot_db=None)[source]

Given a dictionary of a pilot_db, return the subjects that are in it.

Parameters

pilot_db (dict) – a pilot_db. if None tried to load pilot_db with :method:`.load_pilotdb`

Returns

a list of currently active subjects

Return type

subjects (list)

load_pilotdb(file_name=None, reverse=False)[source]

Try to load the file_db

Parameters
  • reverse

  • file_name

Returns:

coerce_discrete(df, col, mapping={'L': 0, 'R': 1})[source]

Coerce a discrete/string column of a pandas dataframe into numeric values

Default is to map ‘L’ to 0 and ‘R’ to 1 as in the case of Left/Right 2AFC tasks

Parameters
  • df (pandas.DataFrame) – dataframe with the column to transform

  • col (str) – name of column

  • mapping (dict) – mapping of strings to numbers

Returns

transformed dataframe

Return type

df (pandas.DataFrame)

find_recursive(key, dictionary)[source]

Find all instances of a key in a dictionary, recursively.

Parameters
  • key

  • dictionary

Returns

list