Loading Trials Data

Task related behavioral data

Relevant Alf objects

  • trials

Loading

[2]:
from one.api import ONE
one = ONE()
eid = '4ecb5d24-f5cc-402c-be28-9d0f7cb14b3a'
trials = one.load_object(eid, 'trials', collection='alf')

More details

Useful modules

Exploring trials data

Example 1. Computing behavioral performance

[3]:
from brainbox.behavior.training import compute_performance

# compute performance
performance, contrasts, n_contrasts = compute_performance(trials)

# compute performance expressed as probability of choosing right
performance, contrasts, n_contrasts = compute_performance(trials, prob_right=True)

# compute performance during 0.8 biased block
performance, contrasts, n_contrasts = compute_performance(trials, block=0.8)

Example 2. Filtering trials

[4]:
from brainbox.task.trials import find_trial_ids

# find index for stim right trials ordered by trial number
trial_id, _ = find_trial_ids(trials, side='right', choice='all', order='trial num')

# find index for correct, stim left, 100% contrast trials ordered by reaction time
trial_id, _ = find_trial_ids(trials, side='left', choice='correct', contrast=[1], order='reaction time')

# find index for correct trials ordered by trial number sorted by stimulus side
trial_id, _ = find_trial_ids(trials, side='left', choice='correct', order='reaction time', sort='side')

Example 3. Plotting pyschometric curve

[5]:
from brainbox.behavior.training import plot_psychometric

fig, ax = plot_psychometric(trials)
../_images/notebooks_external_loading_trials_data_14_0.png

Example 4: Computing Task QC for session

[6]:
from ibllib.qc import task_metrics

qc = task_metrics.TaskQC(eid)
outcome, results = qc.run()
print(f'QC_status: {outcome}')
print(f'Individual QC values:')
results
2022-06-06 12:08:35.121 INFO     [task_extractors.py:78] Downloading data for session 4ecb5d24-f5cc-402c-be28-9d0f7cb14b3a
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\_spikeglx_ephysData_g0_t0.nidq.wiring.11914a2c-bf83-47b1-ab8a-b743663ac3c5.json Bytes: 380
100%|██████████████████████████████████████████████| 0.000362396240234375/0.000362396240234375 [00:00<00:00,  2.88s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe01\_spikeglx_ephysData_g0_t0.imec1.wiring.2843a6f7-c940-474d-adf2-e33829719c1d.json Bytes: 95
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_behavior_data\_iblrig_encoderPositions.raw.10a1244b-b527-4e39-ad6b-e1f64a4c3902.ssv Bytes: 3385592
100%|████████████████████████████████████████████| 9.059906005859375e-05/9.059906005859375e-05 [00:00<00:00, 22.10s/it]

  0%|                                                                           | 0/3.2287521362304688 [00:00<?, ?it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe01\_spikeglx_sync.polarities.probe01.019208f8-b757-44f3-9f8f-53f8209ba9cf.npy Bytes: 68864
100%|██████████████████████████████████████████████████████████| 0.065673828125/0.065673828125 [00:00<00:00,  5.53s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_passive_data\_iblrig_encoderEvents.raw.2b479438-2e0f-47ed-96cc-14ea415739d9.ssv Bytes: 0
0it [00:00, ?it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe01\_spikeglx_ephysData_g0_t0.imec1.ap.2a181d6a-2f34-4b30-b238-89cfc06a7189.meta Bytes: 17756
100%|██████████████████████████████████████████████| 0.016933441162109375/0.016933441162109375 [00:00<00:00,  9.51s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\_spikeglx_sync.polarities.2e0f57b0-8fc9-4d08-b16d-6b9e4009deb5.npy Bytes: 23694848
  0%|                                                                               | 0/22.59716796875 [00:00<?, ?it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe00\_spikeglx_ephysData_g0_t0.imec0.wiring.40af4a49-1b9d-45ec-b443-a151c010ea3c.json Bytes: 95


100%|████████████████████████████████████████████| 9.059906005859375e-05/9.059906005859375e-05 [00:00<00:00, 22.08s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_behavior_data\_iblrig_encoderTrialInfo.raw.40ef7f67-7d1b-4a4a-8729-b04284d9bb6f.ssv Bytes: 40206



  0%|                                                                          | 0/0.03834342956542969 [00:00<?, ?it/s]

100%|████████████████████████████████████████████████| 0.03834342956542969/0.03834342956542969 [00:00<00:00,  8.19s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe00\_spikeglx_sync.channels.probe00.4420d325-141b-4d30-8b92-0f8f545274d3.npy Bytes: 68864


  0%|                                                                               | 0/0.065673828125 [00:00<?, ?it/s]

100%|██████████████████████████████████████████████████████████| 0.065673828125/0.065673828125 [00:00<00:00,  5.68s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\_spikeglx_sync.channels.495dfc0f-3450-4f75-8629-055e16e053a3.npy Bytes: 23694848


  0%|                                                                               | 0/22.59716796875 [00:00<?, ?it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_passive_data\_iblrig_syncSquareUpdate.raw.53182d6d-61b9-4d99-8e1c-1d6245ee923a.csv Bytes: 13800



  0%|                                                                          | 0/0.01316070556640625 [00:00<?, ?it/s]
100%|██████████████████████████████████████████████████| 3.2287521362304688/3.2287521362304688 [00:05<00:00,  1.61s/it]



100%|████████████████████████████████████████████████| 0.01316070556640625/0.01316070556640625 [00:00<00:00, 10.26s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_behavior_data\_iblrig_taskSettings.raw.5c426c45-3e1f-4f90-b3f7-bca76c6e0725.json Bytes: 141300

  0%|                                                                          | 0/0.13475418090820312 [00:00<?, ?it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe00\_spikeglx_ephysData_g0_t0.imec0.lf.5c814a9b-be69-4513-8282-a8fd3d562521.meta Bytes: 13952



  0%|                                                                              | 0/0.0133056640625 [00:00<?, ?it/s]


100%|████████████████████████████████████████████████████████| 0.0133056640625/0.0133056640625 [00:00<00:00, 10.97s/it]

100%|████████████████████████████████████████████████| 0.13475418090820312/0.13475418090820312 [00:00<00:00,  4.21s/it]
 18%|████████████▏                                                        | 4.0/22.59716796875 [00:05<00:27,  1.49s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_passive_data\_iblrig_taskSettings.raw.6391acef-5176-4fa4-9452-d6f6d4951e2f.json Bytes: 167561

  0%|                                                                          | 0/0.15979862213134766 [00:00<?, ?it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\_spikeglx_ephysData_g0_t0.nidq.64924ee8-395e-41f8-ac07-c74f853a8671.meta Bytes: 1016



100%|████████████████████████████████████████████████| 0.00096893310546875/0.00096893310546875 [00:00<00:00,  2.06s/it]

100%|████████████████████████████████████████████████| 0.15979862213134766/0.15979862213134766 [00:00<00:00,  4.65s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe00\_spikeglx_sync.polarities.probe00.6a0c68d2-2728-4d3d-8422-2228fe52226b.npy Bytes: 68864

  0%|                                                                               | 0/0.065673828125 [00:00<?, ?it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_behavior_data\_iblrig_taskData.raw.7bcaf2fc-6cb0-45a4-9708-193904026721.jsonable Bytes: 15272842



  0%|                                                                           | 0/14.565317153930664 [00:00<?, ?it/s]
100%|██████████████████████████████████████████████████████████| 0.065673828125/0.065673828125 [00:00<00:00,  5.81s/it]
 35%|████████████████████████▍                                            | 8.0/22.59716796875 [00:08<00:13,  1.05it/s]

 18%|████████████▏                                                        | 4.0/22.59716796875 [00:05<00:27,  1.49s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_behavior_data\_iblrig_ambientSensorData.raw.8164342b-3289-4d70-bb85-b205b4ffbcfd.jsonable Bytes: 60810

 53%|████████████████████████████████████                                | 12.0/22.59716796875 [00:09<00:07,  1.43it/s]
100%|████████████████████████████████████████████████| 0.05799293518066406/0.05799293518066406 [00:00<00:00,  6.73s/it]
 71%|████████████████████████████████████████████████▏                   | 16.0/22.59716796875 [00:11<00:03,  1.83it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe01\_spikeglx_sync.times.probe01.92acf5ff-885c-490a-aaed-f4c522216f05.npy Bytes: 68864

  0%|                                                                               | 0/0.065673828125 [00:00<?, ?it/s]
100%|██████████████████████████████████████████████████████████| 0.065673828125/0.065673828125 [00:00<00:00,  6.95s/it]
 89%|████████████████████████████████████████████████████████████▏       | 20.0/22.59716796875 [00:12<00:01,  2.24it/s]

100%|██████████████████████████████████████████████████████████| 22.59716796875/22.59716796875 [00:12<00:00,  1.78it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_passive_data\_iblrig_stimPositionScreen.raw.97a83209-7b62-48da-805a-6fddd342f244.csv Bytes: 22308
100%|██████████████████████████████████████████████| 0.021274566650390625/0.021274566650390625 [00:00<00:00,  8.55s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_behavior_data\_iblrig_stimPositionScreen.raw.bb6bb56d-887c-4dc4-9a32-c13b4c92256e.csv Bytes: 479899
  0%|                                                                          | 0/0.45766735076904297 [00:00<?, ?it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_passive_data\_iblrig_encoderPositions.raw.c7d84d1f-7f60-417b-974a-0bb59fb88f33.ssv Bytes: 78112

  0%|                                                                            | 0/0.074493408203125 [00:00<?, ?it/s]


 27%|█████████████████▊                                               | 4.0/14.565317153930664 [00:06<00:16,  1.60s/it]
100%|████████████████████████████████████████████████████| 0.074493408203125/0.074493408203125 [00:00<00:00,  5.52s/it]


100%|████████████████████████████████████████████████| 0.45766735076904297/0.45766735076904297 [00:01<00:00,  4.22s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_behavior_data\_iblrig_encoderEvents.raw.ca99fbcf-0d9c-45ac-9e40-913c7871fb6d.ssv Bytes: 30662
100%|██████████████████████████████████████████████| 0.029241561889648438/0.029241561889648438 [00:00<00:00,  6.18s/it]



 55%|███████████████████████████████████▋                             | 8.0/14.565317153930664 [00:08<00:06,  1.00s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe00\_spikeglx_ephysData_g0_t0.imec0.ap.ea257f30-8a0f-4cde-83d2-aa4d2ce4bd23.meta Bytes: 17763
100%|████████████████████████████████████████████████| 0.01694011688232422/0.01694011688232422 [00:00<00:00, 11.22s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe00\_spikeglx_sync.times.probe00.eaa07c05-df66-42ce-ae59-326b6ac9e8f0.npy Bytes: 68864
100%|██████████████████████████████████████████████████████████| 0.065673828125/0.065673828125 [00:00<00:00,  5.55s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\_spikeglx_sync.times.eb04d3e9-5e67-4833-8321-fbccb3e9699b.npy Bytes: 23694848
  0%|                                                                               | 0/22.59716796875 [00:00<?, ?it/s]


 82%|████████████████████████████████████████████████████▋           | 12.0/14.565317153930664 [00:10<00:01,  1.35it/s]

 71%|████████████████████████████████████████████████▏                   | 16.0/22.59716796875 [00:16<00:06,  1.05it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_passive_data\_iblrig_encoderTrialInfo.raw.f6011d97-2d08-4e97-ac72-1851fd2ff73e.ssv Bytes: 13579

  0%|                                                                         | 0/0.012949943542480469 [00:00<?, ?it/s]
100%|██████████████████████████████████████████████| 0.012949943542480469/0.012949943542480469 [00:00<00:00, 14.10s/it]



100%|██████████████████████████████████████████████████| 14.565317153930664/14.565317153930664 [00:11<00:00,  1.27it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe01\_spikeglx_sync.channels.probe01.f817e793-0127-4de7-b82c-337791023dd1.npy Bytes: 68864

  0%|                                                                               | 0/0.065673828125 [00:00<?, ?it/s]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_ephys_data\probe01\_spikeglx_ephysData_g0_t0.imec1.lf.f8a46490-097a-4aa9-b93f-cbfd84e71381.meta Bytes: 13935



  0%|                                                                         | 0/0.013289451599121094 [00:00<?, ?it/s]
100%|██████████████████████████████████████████████████████████| 0.065673828125/0.065673828125 [00:00<00:00,  5.59s/it]



100%|██████████████████████████████████████████████| 0.013289451599121094/0.013289451599121094 [00:00<00:00, 10.91s/it]
Downloading: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001\raw_behavior_data\_iblrig_syncSquareUpdate.raw.f8b90888-b6cf-4462-beac-a467520e961a.csv Bytes: 411258

  0%|                                                                          | 0/0.39220619201660156 [00:00<?, ?it/s]

 89%|████████████████████████████████████████████████████████████▏       | 20.0/22.59716796875 [00:19<00:02,  1.12it/s]
100%|████████████████████████████████████████████████| 0.39220619201660156/0.39220619201660156 [00:01<00:00,  3.29s/it]


100%|██████████████████████████████████████████████████████████| 22.59716796875/22.59716796875 [00:21<00:00,  1.05it/s]
100%|██████████████████████████████████████████████████████████| 22.59716796875/22.59716796875 [00:13<00:00,  1.70it/s]
2022-06-06 12:09:10.17 INFO     [task_extractors.py:108] Loading raw data from C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001
2022-06-06 12:09:10.873 WARNING  [ephys_fpga.py:93] Keys missing from provided channel map, setting missing keys from default channel map
2022-06-06 12:09:10.887 INFO     [task_extractors.py:135] Extracting session: C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001
2022-06-06 12:09:10.892 INFO     [ephys_fpga.py:682] Extracting C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001 as ephys
2022-06-06 12:09:10.952 WARNING  [ephys_fpga.py:93] Keys missing from provided channel map, setting missing keys from default channel map
2022-06-06 12:09:11.779 INFO     [bpod_trials.py:29] Extracting C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001 as ephys
2022-06-06 12:09:11.783 INFO     [bpod_trials.py:32] ephys session on _iblrig_mrsicflogel_ephys_0
C:\Users\Mayo\iblenv\ibllib-repo\ibllib\io\raw_data_loaders.py:391: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version. Use on_bad_lines in the future.


  return pd.read_csv(file_path, sep=' ', header=None, error_bad_lines=False, **kwargs)
C:\Users\Mayo\iblenv\ibllib-repo\ibllib\io\raw_data_loaders.py:391: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version. Use on_bad_lines in the future.


  return pd.read_csv(file_path, sep=' ', header=None, error_bad_lines=False, **kwargs)
2022-06-06 12:09:14.328 INFO     [training_wheel.py:296] Wheel in rad units using X1 encoding
C:\Users\Mayo\iblenv\ibllib-repo\ibllib\io\raw_data_loaders.py:391: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version. Use on_bad_lines in the future.


  return pd.read_csv(file_path, sep=' ', header=None, error_bad_lines=False, **kwargs)
C:\Users\Mayo\iblenv\ibllib-repo\ibllib\io\raw_data_loaders.py:391: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version. Use on_bad_lines in the future.


  return pd.read_csv(file_path, sep=' ', header=None, error_bad_lines=False, **kwargs)
2022-06-06 12:09:24.924 INFO     [training_wheel.py:296] Wheel in rad units using X1 encoding
2022-06-06 12:09:33.645 INFO     [bpod_trials.py:66] session extracted

2022-06-06 12:09:33.925 INFO     [ephys_fpga.py:639] N trials: 529 bpod, 529 FPGA, 529 merged, sync 7.64233523671068 ppm
2022-06-06 12:09:34.196 INFO     [training_wheel.py:296] Wheel in rad units using X4 encoding
2022-06-06 12:09:47.977 WARNING  [training_wheel.py:368] no reliable goCue/Feedback times (both needed) for 1 trials
C:\Users\Mayo\iblenv\ibllib-repo\ibllib\io\raw_data_loaders.py:391: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version. Use on_bad_lines in the future.


  return pd.read_csv(file_path, sep=' ', header=None, error_bad_lines=False, **kwargs)
C:\Users\Mayo\iblenv\ibllib-repo\ibllib\io\raw_data_loaders.py:391: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version. Use on_bad_lines in the future.


  return pd.read_csv(file_path, sep=' ', header=None, error_bad_lines=False, **kwargs)
2022-06-06 12:09:50.10 WARNING  [task_extractors.py:190] QC extractor, missing fields filled with NaNs: ['wheel_moves_intervals', 'wheel_moves_peak_amplitude']
2022-06-06 12:09:50.11 INFO     [task_metrics.py:130] Session C:\Users\Mayo\Downloads\FlatIron\hoferlab\Subjects\SWC_043\2020-09-21\001: Running QC on behavior data...
QC_status: FAIL
Individual QC values:
Out[6]:
{'_task_audio_pre_trial': 1.0,
 '_task_correct_trial_event_sequence': 1.0,
 '_task_detected_wheel_moves': 0.9961977186311787,
 '_task_errorCue_delays': 0.9186046511627907,
 '_task_error_trial_event_sequence': 0.9767441860465116,
 '_task_goCue_delays': 1.0,
 '_task_iti_delays': 0.3314393939393939,
 '_task_n_trial_events': 0.9905482041587902,
 '_task_negative_feedback_stimOff_delays': 0.9418604651162791,
 '_task_positive_feedback_stimOff_delays': 1.0,
 '_task_response_feedback_delays': 0.996219281663516,
 '_task_response_stimFreeze_delays': 0.9847908745247148,
 '_task_reward_volume_set': 1.0,
 '_task_reward_volumes': 1.0,
 '_task_stimFreeze_delays': 0.9792060491493384,
 '_task_stimOff_delays': 0.9924385633270322,
 '_task_stimOff_itiIn_delays': 0.9980988593155894,
 '_task_stimOn_delays': 0.998109640831758,
 '_task_stimOn_goCue_delays': 0.998109640831758,
 '_task_stimulus_move_before_goCue': 0.9980988593155894,
 '_task_trial_length': 0.996219281663516,
 '_task_wheel_freeze_during_quiescence': 1.0,
 '_task_wheel_integrity': 0.999999010009791,
 '_task_wheel_move_before_feedback': 0.9961977186311787,
 '_task_wheel_move_during_closed_loop': 0.9961977186311787,
 '_task_wheel_move_during_closed_loop_bpod': 1.0,
 '_task_passed_trial_checks': 0.32325141776937616}

Information about individual qc checks can be found by looking at the docstring (replace _task with check), e.g.

[7]:
help(task_metrics.check_errorCue_delays)
Help on function check_errorCue_delays in module ibllib.qc.task_metrics:

check_errorCue_delays(data, **_)
    Check that the time difference between the error sound being triggered and
    effectively played is smaller than 1ms.
    Metric: M = errorCue_times - errorCueTrigger_times
    Criterion: 0 < M <= 0.001 s
    Units: seconds [s]

    :param data: dict of trial data with keys ('errorCue_times', 'errorCueTrigger_times',
    'intervals', 'correct')

Other relevant examples

  • COMING SOON