From 597ded78256c4d8b1c786558ac312e0ca524f1d9 Mon Sep 17 00:00:00 2001 From: Christopher Morrison Date: Thu, 14 Sep 2023 10:12:05 -0700 Subject: [PATCH] Add code to catch active stimulus that should be marked but fall outside of the trials. --- .../brain_observatory/behavior/stimulus_processing.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/allensdk/brain_observatory/behavior/stimulus_processing.py b/allensdk/brain_observatory/behavior/stimulus_processing.py index d28a6c386..f0c653f7d 100644 --- a/allensdk/brain_observatory/behavior/stimulus_processing.py +++ b/allensdk/brain_observatory/behavior/stimulus_processing.py @@ -696,6 +696,14 @@ def add_active_flag( & (~stim_pres_table.image_name.isna()) ) active[stim_mask] = True + + # Clean up potential stimuli that fall outside in time of the trials + # but are part of the "active" stimulus block. + if "stimulus_block" in stim_pres_table.columns: + for stim_block in stim_pres_table["stimulus_block"].unique(): + block_mask = stim_pres_table["stimulus_block"] == stim_block + if np.any(active[block_mask]): + active[block_mask] = True stim_pres_table["active"] = active return stim_pres_table