How to deal with "invalid_times" in a ecephys_session

I get the following warning when loading certain Neuropixels recording sessions (e.g. session 715093703 in the Visual Coding dataset).

allensdk/brain_observatory/ecephys/ecephys_session.py:1093: UserWarning: Session includes invalid time intervals that could be accessed with the attribute ‘invalid_times’, Spikes within these intervals are invalid and may need to be excluded from the analysis.

I assume this is normal and expected, but is there a longer explanation / tutorial on how I should be filtering out these invalid_times? I see that session.invalid_times gives me some information about these invalid times… Does session.presentationwise_spike_counts(...) exclude these or return nan? I am just looking to understand the default settings a bit better. Are there any relevant helper functions in the SDK that can help me filter out these intervals appropriately?

The reasons for the invalid times are documented in the white paper associated with this data release (“invalid intervals” section).

To summarize, there are three situations where these occur:

  • The stimulus monitor displayed one or more longer-than-expected frames. In this case, the neural data is accurate, but any stimulus-related analysis will be flawed (7 affected sessions).
  • One probe temporarily stopped sending data. This will cause a gap in spike times for that probe, without affecting any other probes (13 affected sessions).
  • All probe amplifiers momentarily saturate, causing a brief gap in spike times, and large artifacts in the LFP data (2 affected sessions).

Because these occur so rarely, we’ve chosen to ignore them in the built-in methods for aligning spikes to stimuli. In order to exclude these segments from analysis, you could filter out trials from the stimulus table with a start_time or stop_time that overlaps with any of the invalid intervals. Then you can pass the indices of the filtered table to, e.g., session.presentationwise_spike_counts.

2 Likes