WaterCalibration

class WaterCalibration[source]

Bases: Task

Task class for calibrating water delivery valves.

__init__() None[source]

Initializes the WaterCalibration task.

Methods

__init__()

Initializes the WaterCalibration task.

after_trial()

Executes logic after a trial completes.

close()

Cleanly closes the calibration task.

concatenate_trial_data()

Appends the current trial's data to the session DataFrame.

create_paths()

Sets up file and directory paths for the session.

create_trial()

Creates the state machine for a calibration trial.

disconnect_and_save(run_mode)

Stops the task, disconnects devices, and saves session data.

do_trial()

Executes a single trial.

execute_function(i)

Executes a registered function.

get_name()

Returns the name of the task class.

register_value(name, value)

Registers a custom value to be saved with the trial data.

run()

Runs the task in the main thread until completion or forced stop.

run_in_thread([daemon])

Runs the task in a separate background thread.

save_csv(run_mode)

Saves the session data to CSV files.

save_json(run_mode)

Saves the session settings to a JSON file.

start()

Prepares the calibration task by defining states and output actions.

start() None[source]

Prepares the calibration task by defining states and output actions.

create_trial() None[source]

Creates the state machine for a calibration trial.

Adds states for each valve to be calibrated and a final wait state.

after_trial() None[source]

Executes logic after a trial completes.

close() None[source]

Cleanly closes the calibration task.

concatenate_trial_data() None

Appends the current trial’s data to the session DataFrame.

create_paths() None

Sets up file and directory paths for the session.

disconnect_and_save(run_mode: str) Tuple[Save, float, int, int, str]

Stops the task, disconnects devices, and saves session data.

Parameters:

run_mode (str) – The mode in which the task was run (e.g., “Manual”).

Returns:

A tuple containing the save status, session duration, number of trials, water consumed, and settings string.

Return type:

Tuple[Save, float, int, int, str]

do_trial() None

Executes a single trial.

Initializes the state machine, runs it, collects data, and performs post-trial updates.

execute_function(i: int) None

Executes a registered function.

Parameters:

i (int) – The function index (1-99).

classmethod get_name() str

Returns the name of the task class.

register_value(name: str, value: Any) None

Registers a custom value to be saved with the trial data.

Parameters:
  • name (str) – The name of the value (column header).

  • value (Any) – The value to store.

run() None

Runs the task in the main thread until completion or forced stop.

run_in_thread(daemon: bool = True) None

Runs the task in a separate background thread.

Parameters:
  • daemon (bool, optional) – Whether to run as a daemon thread.

  • True. (Defaults to)

save_csv(run_mode: str) Tuple[float, int, int, bool]

Saves the session data to CSV files.

Processes raw data, saves raw and clean session files, and updates the subject’s cumulative data file.

Parameters:

run_mode (str) – The execution mode string.

Returns:

Duration, trial count, water consumed, and success status.

Return type:

Tuple[float, int, int, bool]

save_json(run_mode: str) str

Saves the session settings to a JSON file.

Parameters:

run_mode (str) – The execution mode string.

Returns:

The JSON string containing the settings.

Return type:

str