backend.Session

class backend.Session(in_background, gpus='-1', log_queue=None, timing=False, stop_task_event=<backend.utils.DummyClass object>, **kwargs)

This is the main backend process. It is initialized by main.py. The run() method is what runs in this process. This process handles all the heavy I/O and computations.

__init__(in_background, gpus='-1', log_queue=None, timing=False, stop_task_event=<backend.utils.DummyClass object>, **kwargs)

Initialize the backend. This does NOT start the process. This function simply saves the given arguments and generates all the default data for the backend.

set_callbacks(printer=<function empty_func>, print_mark_set=<function empty_func>, print_mark_del=<function empty_func>, send_request=<function empty_func>, send_async_response=<function empty_func>, connect=<function empty_func>)
set_peripherals(raw_periph=<backend.utils.DummyClass object>, finger_periph=<backend.utils.DummyClass object>, output_periph=<backend.utils.DummyClass object>, raw_plotter=<backend.utils.DummyClass object>, column_plotter=<backend.utils.DummyClass object>)
property handlers

a mapping of handlers for backend commands

property analysis_packet
get_statuses()

Get a dict of the data, decoder, and autoencoder status

read_finger_data(idx)

Reads finger data from the Glove’s serial interface into the backend’s finger_data object.

handle_async_command(async_command: common.commands.AsyncCommand)
run_py_script(filename='')
mov_detect(n_dofs=5)
load_detector_replay(filename='', erase_instead=False, use_old_format=False)
simulate_decoder_output(repetitions=1, test=False)

Generates simulated decoder output x_hat

Parameters
  • repetitions – How many times to repeat the full movement set

  • test – a boolean whether to use test or training movements file

simulate_emg(repetitions=1, test=False, shuffle=False)

Generates simulated raw EMG data.

Parameters

test – bool whether to use test or training movements file

export_results(export_name: str, analysis: bool, recalc=False, aggregate=False)
compare(**kwargs)

Generates plots comparing the data contained in the given files. Each file is a separate line. Each result is plotted separately If recalc is True, recalculate the test results with the current results settings

plot_x(x_d=None, x_hat=None, filt=True, **kwargs)
plot_current(**kwargs)

Plots the data in self.analysis_data.test_results

Parameters
  • recalc – If True, recalculate the test results with the current results settings

  • plot_separately – If True, each result will be plotted separately

  • separate_rmse – If True and plot_separately is False, then two plots will be generated: one with the RMSE results, and one with the other results

  • mov_box – If True, boxplots grouped by movement will be shown instead of regular plots. Assumes that the current results were calculated from the current self.output_dataobject, otherwise the groupings will fail

  • file_box – If True, boxplots grouped by file will be shown instead of regular plots

plot_multiple(**kwargs)

Plots the data in the analysis packet. See plot_current() for kwargs description

load_analysis_packet(filenames: list, packet_name: str, **kwargs)
load_multiple(filenames: list, update_statuses=True, **kwargs)
Loads data from multiple files.

Loads the kwargs-specified parameters (data and testing_movements are enforced) from the first file Concatenates all files into self.tester.movements, self.output_data, self.raw_data, and self.analysis_data.test_results

If update_statuses AND more than one file is being loaded, then this updates data_type, data_status, data_path,

and testing_movements_path to show that the data came from multiple files

This function updates self.*

If you don’t want it to, then stash and unstash around this function

Parameters
  • filenames – list of filenames to read from

  • update_statuses – whether or not to update statuses

  • kwargs – kwargs passed through to self.load() to get from the first filename in the list

Returns

load(filename='', use_old_format=False, inspect=False, settings=False, training_movements=False, testing_movements=False, filter=False, features=False, data=False, results=False, decoder=False, autoencoder=False, mov_detector=False, emg_sim=False, xhat_sim=False)

Load the specified data from the given filename. If use_old_format is true, the file is first converted from Sean’s old format.

save(filename='', settings=False, movement_paths=False, train_movs=False, test_movs=False, filter=False, features=False, data=False, results=False, decoder=False, autoencoder=False, mov_detector=False, emg_sim=False, xhat_sim=False, compress=False)

Save the specified data to the provided filename

store_data()
swap_data()
get(general_settings=False, raw_settings=False, output_settings=False, movements=False, data=False, connections=False, filter=False, features=False, results=False, trainer=False, collector=False, tester=False, decoder=False, autoencoder=False, paths=False, mov_detector=False, emg_sim=False, analysis=False, xhat_sim=False)

Returns a dict of the data specified. See the code below to determine what keys are used to hold what data.

update(update_type: Optional[common.enums.UpdateType] = None, params=None, new=False)

Update the data specified by the update_type using the give params.

If new is True, then the following data types will be created (from scratch) using the params instead of just being updated from the params:

  • train and test movements, collector, tester, trainer, decoder, autoencoder,

  • features and results -> new will add to the list

run_cmd(cmd='')

Evaluates custom python in the scope of this Backend process.

If this is just python, this will return the result if one is generated

Special commands are - p Print to the console - P Print to the gui - g define global variable - i import function - r evaluate and return

refilter_data(no_eval_results=False)

Refilter the currently loaded data

cross_validation(holdout_last=False, holdout_first=False)

runs k-fold cross validation by leaving out a repetition for testing runs eval_results for each fold

train_decoder(x=None, z=None, use_ghost=False, gradient=False, moving_dofs_only=False)

Trains the current decoder.

if gradient is false, the decoder is reset to its initial state before training and decoder.train() is called if gradient is true, the decoder is not reset and decoder.gradient_update() is called

x and z are the states and features to train on. Prompt data must be removed first. If not provided, then self.output_datawill be used. Prompt data is removed in this function.

use_ghost tells this function to use x_hat instead of x_d

moving_dofs_only (only if gradient is true and use_ghost is false and if the decoder is adaptive) - Not Supported

tells this function to only update dofs that moved according to the training movements

train_autoencoder(reset_autoencoder=True, use_stored=False)

Train the current autoencoder using the current data.

If reset_autoencoder is True, the autoencoder will be reset and will learn from scratch.

eval_results(data_obj=None, relax_pos=None, silent=False)

Calculate the test results using either the provided data or the current test data and the results specified in self.analysis_data.results

convert_file(filename: str)

Convert a file from the old format of Sean’s integrated-system repo to the new version that this program uses.

The new file is saved as <original_filename>_CONVERTED.json

replay()

Replay the currently loaded data on Mujoco or the Robotic Hand and on the EMG graphs.

test(no_eval=False)

Record test data, either live or from a file. This does either free test using the glove as the ground truth or uses movement trajectories/targets shown in Mujoco as the ground truth.

Returns the status dict of the data, decoder, and autoencoder

dual()
action_selection()
eval_as_results(n_dof, action=False, cross=False, pair=False, subset=False, holdout_last=False, processes=0)
collect()

Collect training data. This allows either free collecting data using the glove as the ground truth or using movement trajectories shown in Mujoco as the ground truth.

Returns the status dict of the data, decoder, and autoencoder

control()

Free live control of the Mujoco or Robotic hand using the current trained decoder.

Essentially runs a free test and restores all the data afterwards

Returns the status dict of the data, decoder, and autoencoder

calibrate(use_rest_data=False)
prompted_move(runner: backend.runners.Runner)

This handles showing movement trajectories or targets in Mujoco and recording the corresponding live emg data from the user.

unprompted_move(runner: backend.runners.Runner, stop_idx=None)
init_output(runner: backend.runners.Runner, stop_idx=None)backend.output.OutputParams

This initializes the output loop (defined in output_loop below) using the given movement_type

Call this function BEFORE calling output_loop() and pass the result of this function to output_loop() as the argument. The OutputParams object that this function initializes and returns is also EDITED BY THE OUTPUT_LOOP() FUNCTION, so save it in between calls to output_loop().

output_loop(params: backend.output.OutputParams, period=<SampleType.MOVE: 1>, mov_idx=0, rep_idx=0, traj=None)

This handles the recording of data and also the displaying of data to Mujoco/Robotic Hand for a singular movement repetition or replay or continuous control, testing, or collecting.

send_output(solid=None, ghost=None, prv_ghost=None, control=None, is_prompt=False, relax_pos=0)
run_command(command: common.enums.Commands, *args, **kwargs)

This simply runs the given command using the correct Backend handler method

load_all(filename, use_old_format=False)
load_data(filename, use_old_format=False)
load_decoder(filename, use_old_format=False)
load_settings(filename, use_old_format=False)
load_movements(filename, use_old_format=False)
save_all(filename, compress=False)
save_data(filename)
save_decoder(filename)
save_settings(filename)