-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Labels
Description
Is your feature request related to a problem? Please describe.
The standard way to communicate invalid time intervals in NWB is the invalid_times table (see docs). Currently, the IntervalList.insert_from_nwbfile method only inserts time intervals from the epochs table, which omits potentially informative time intervals from the invalid_times table.
Describe the solution you'd like
This issue requests that the IntervalList.insert_from_nwbfile method also insert time intervals from the invalid_times table.
See example implementation below:
def insert_invalid_intervals(nwbfile_path: Path):
"""Insert invalid intervals from NWB file into SpyGlass IntervalList table.
Populates the IntervalList table with invalid intervals extracted from the
NWB file. This function ensures that periods of invalid data are properly
recorded in the database for accurate analysis.
Parameters
----------
nwbfile_path : Path
Path to the NWB file containing invalid interval data to be inserted.
File must already be copied to SpyGlass raw data directory.
"""
nwb_copy_file_name = get_nwb_copy_filename(nwbfile_path.name)
with NWBHDF5IO(nwbfile_path, "r") as io:
nwbfile = io.read()
if nwbfile.invalid_times is None:
return
invalid_times_table = nwbfile.invalid_times.to_dataframe()
inserts = invalid_times_table.apply(
lambda row: {
"nwb_file_name": nwb_copy_file_name,
"interval_list_name": f"{row.tag}_invalid_intervals" if row.tag else f"invalid_intervals",
"valid_times": np.asarray([[row.start_time, row.stop_time]]),
},
axis=1,
).tolist()
sgc.IntervalList().insert(inserts, skip_duplicates=True)Additional context
While you're at it, it might be worthwhile to include intervals from the trials table as well. But this issue is only specifically requesting the invalid_times table.