common_interval.py
IntervalList
¶
Bases: SpyglassMixin
, Manual
Source code in src/spyglass/common/common_interval.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
insert_from_nwbfile(nwbf, *, nwb_file_name)
classmethod
¶
Add each entry in the NWB file epochs table to the IntervalList.
The interval list name for each epoch is set to the first tag for the epoch. If the epoch has no tags, then 'interval_x' will be used as the interval list name, where x is the index (0-indexed) of the epoch in the epochs table. The start time and stop time of the epoch are stored in the valid_times field as a numpy array of [start time, stop time] for each epoch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nwbf |
NWBFile
|
The source NWB file object. |
required |
nwb_file_name |
str
|
The file name of the NWB file, used as a primary key to the Session table. |
required |
Source code in src/spyglass/common/common_interval.py
plot_intervals(figsize=(20, 5), return_fig=False)
¶
Plot the intervals in the interval list.
Source code in src/spyglass/common/common_interval.py
plot_epoch_pos_raw_intervals(figsize=(20, 5), return_fig=False)
¶
Plot an epoch's position, raw data, and valid times intervals.
Source code in src/spyglass/common/common_interval.py
nightly_cleanup(dry_run=True)
¶
Clean up orphaned IntervalList entries.
intervals_by_length(interval_list, min_length=0.0, max_length=10000000000.0)
¶
Select intervals of certain lengths from an interval list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval_list |
array_like
|
Each element is (start time, stop time), i.e. an interval in seconds. |
required |
min_length |
float
|
Minimum interval length in seconds. Defaults to 0.0. |
0.0
|
max_length |
float
|
Maximum interval length in seconds. Defaults to 1e10. |
10000000000.0
|
Source code in src/spyglass/common/common_interval.py
interval_list_contains_ind(interval_list, timestamps)
¶
Find indices of list of timestamps contained in an interval list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval_list |
array_like
|
Each element is (start time, stop time), i.e. an interval in seconds. |
required |
timestamps |
array_like
|
|
required |
Source code in src/spyglass/common/common_interval.py
interval_list_contains(interval_list, timestamps)
¶
Find timestamps that are contained in an interval list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval_list |
array_like
|
Each element is (start time, stop time), i.e. an interval in seconds. |
required |
timestamps |
array_like
|
|
required |
Source code in src/spyglass/common/common_interval.py
interval_list_excludes_ind(interval_list, timestamps)
¶
Find indices of timestamps that are not contained in an interval list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval_list |
array_like
|
Each element is (start time, stop time), i.e. an interval in seconds. |
required |
timestamps |
array_like
|
|
required |
Source code in src/spyglass/common/common_interval.py
interval_list_excludes(interval_list, timestamps)
¶
Find timestamps that are not contained in an interval list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval_list |
array_like
|
Each element is (start time, stop time), i.e. an interval in seconds. |
required |
timestamps |
array_like
|
|
required |
Source code in src/spyglass/common/common_interval.py
consolidate_intervals(interval_list)
¶
Consolidate overlapping intervals in an interval list.
Source code in src/spyglass/common/common_interval.py
interval_list_intersect(interval_list1, interval_list2, min_length=0)
¶
Finds the intersections between two interval lists
Each interval is (start time, stop time)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval_list1 |
np.array, (N,2) where N = number of intervals
|
|
required |
interval_list2 |
np.array, (N,2) where N = number of intervals
|
|
required |
min_length |
float, optional.
|
Minimum length of intervals to include, default 0 |
0
|
Returns:
Name | Type | Description |
---|---|---|
interval_list |
(array, (N, 2))
|
|
Source code in src/spyglass/common/common_interval.py
union_adjacent_index(interval1, interval2)
¶
Union index-adjacent intervals. If not adjacent, just concatenate.
e.g. [a,b] and [b+1, c] is converted to [a,c]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval1 |
array
|
|
required |
interval2 |
array
|
|
required |
Source code in src/spyglass/common/common_interval.py
interval_list_union(interval_list1, interval_list2, min_length=0.0, max_length=10000000000.0)
¶
Finds the union (all times in one or both) for two interval lists
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval_list1 |
ndarray
|
The first interval list [start, stop] |
required |
interval_list2 |
ndarray
|
The second interval list [start, stop] |
required |
min_length |
float
|
Minimum length of interval for inclusion in output, default 0.0 |
0.0
|
max_length |
float
|
Maximum length of interval for inclusion in output, default 1e10 |
10000000000.0
|
Returns:
Type | Description |
---|---|
ndarray
|
Array of intervals [start, stop] |
Source code in src/spyglass/common/common_interval.py
interval_list_censor(interval_list, timestamps)
¶
Returns new interval list that starts/ends at first/last timestamp
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval_list |
numpy array of intervals [start, stop]
|
interval list from IntervalList valid times |
required |
timestamps |
numpy array or list
|
|
required |
Returns:
Type | Description |
---|---|
interval_list (numpy array of intervals [start, stop])
|
|
Source code in src/spyglass/common/common_interval.py
interval_from_inds(list_frames)
¶
Converts a list of indices to a list of intervals.
e.g. [2,3,4,6,7,8,9,10] -> [[2,4],[6,10]]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list_frames |
array_like of int
|
|
required |
Source code in src/spyglass/common/common_interval.py
interval_set_difference_inds(intervals1, intervals2)
¶
e.g. intervals1 = [(0, 5), (8, 10)] intervals2 = [(1, 2), (3, 4), (6, 9)]
result = [(0, 1), (4, 5), (9, 10)]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intervals1 |
_type_
|
description |
required |
intervals2 |
_type_
|
description |
required |
Returns:
Type | Description |
---|---|
_type_
|
description |
Source code in src/spyglass/common/common_interval.py
interval_list_complement(intervals1, intervals2, min_length=0.0)
¶
Finds intervals in intervals1 that are not in intervals2
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_length |
float
|
Minimum interval length in seconds. Defaults to 0.0. |
0.0
|