epiphyte.preprocessing ¶
annotation ¶
data_driven_annotation ¶
cpt ¶
Detects the changepoint in a spike train using parametric statistic testing.
Plots the results and returns the index of the breakpoint and the stat test results.
Used for demonstrating the addition of a new table to an existing database.
find_changepoint_tt ¶
find_changepoint_tt(data, verbose=False)
Detects the changepoint in a spike train using parametric statistic testing. Plots the results and returns the index of the breakpoint and the stat test results.
Accepts and runs one unit. Set up to be iterated over for the whole of a dataset of units.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
ndarray
|
spike train data (1D array-like) |
required |
verbose
|
bool
|
if True, prints detailed changepoint and t-test results |
False
|
Returns:
Name | Type | Description |
---|---|---|
taustar |
int
|
index of the determined breakpoint. |
ttest |
ttest_ind_from_stats
|
results from the scipy stats ttest (type is a specific class construction from scipy) |
Source code in epiphyte/preprocessing/annotation/data_driven_annotation/cpt.py
12 13 14 15 16 17 18 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 |
|
plot_changepoint ¶
plot_changepoint(data, taustar, ttest, save=None, filename=None, comparison_tau=None)
Plot a change point in neural activity data and annotate with statistical results.
This function visualizes time-binned neural activity and overlays vertical
lines indicating the detected change point (taustar
) and, optionally, a
second change point (comparison_tau
). It also displays the results of a
t-test as legend entries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
array - like
|
Sequence of neural activity values. |
required |
taustar
|
int
|
Detected change point index (in 1-second bins). |
required |
ttest
|
tuple
|
A tuple containing (t-statistic, p-value) from a t-test. |
required |
save
|
str
|
Directory path where plots should be saved. If None, plots are not saved. |
None
|
filename
|
str
|
Base filename (without extension) for saving plots. Required if |
None
|
comparison_tau
|
int
|
Another change point index to compare with |
None
|
Saves
{filename}_cpt.png
in thesave
directory ifsave
is provided.{filename}_cpt.svg
in thesave
directory ifsave
is provided.
Example
from scipy.stats import ttest_ind
data = [0, 1, 2, 5, 6, 7, 10, 11]
ttest = ttest_ind(data[:4], data[4:])
plot_changepoint(data, taustar=4, ttest=ttest, save="plots/", filename="session1")
Source code in epiphyte/preprocessing/annotation/data_driven_annotation/cpt.py
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 |
|
stimulus_driven_annotation ¶
movies ¶
annotation_utils ¶
Helpers for handling stimulus-driven annotations in an analysis workflows.
Provides utilities to split neural activity by label values for downstream analysis and visualization.
split_activity_by_value ¶
split_activity_by_value(binned_activity, binned_label, specific_values=None)
Split binned activity by the values in a binned label vector.
Example
For a binary label (stimulus on/off), the binned_label
vector
contains 0/1. This function returns two arrays mapping to segments
where the label is off/on, respectively. For multi-valued labels,
activity is split per unique value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
binned_activity
|
ndarray
|
Binned neural activity (shape |
required |
binned_label
|
ndarray
|
Binned label aligned to the activity (length |
required |
specific_values
|
Optional[Iterable[int]]
|
If provided, only these label values are used. |
None
|
Returns:
Type | Description |
---|---|
Dict[str, ndarray]
|
Dict[str, np.ndarray]: Mapping |
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/annotation_utils.py
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 |
|
pause_handling ¶
Helpers to handle pause intervals while binning labels and spikes.
pause_start_bin ¶
pause_start_bin(bins, start)
Find start bin index inclusive of the pause start.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bins
|
ndarray or list - like
|
bin edges (ms). |
required |
start
|
float
|
Pause start time (ms). |
required |
Returns: int: index of the start bin.
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/pause_handling.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
pause_stop_bin ¶
pause_stop_bin(bins, stop)
Find stop bin index inclusive of the pause stop.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bins
|
ndarray
|
Bin edges (ms). |
required |
stop
|
float
|
Pause stop time (ms). |
required |
Returns: int: Index of the stop bin.
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/pause_handling.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
make_pause_interval ¶
make_pause_interval(bin_start, bin_stop)
Make a list of indices spanning the pause interval (inclusive).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bin_start
|
int
|
Start bin index. |
required |
bin_stop
|
int
|
Stop bin index. |
required |
Returns: List[int]: List of indices spanning the pause interval (inclusive).
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/pause_handling.py
42 43 44 45 46 47 48 49 50 51 52 |
|
rm_pauses_bins ¶
rm_pauses_bins(bins, start, stop, return_intervals=False)
Remove bin edges that occur during paused playback.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bins
|
ndarray or list - like
|
Bin edges (ms). |
required |
start
|
ndarray or list - like
|
Pause starts (ms). |
required |
stop
|
ndarray or list - like
|
Pause stops (ms). |
required |
return_intervals
|
bool
|
If |
False
|
Returns:
Tuple[np.ndarray, List[int]]: Cleaned bins or (bins_no_pauses, removed_indices)
.
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/pause_handling.py
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 |
|
rm_pauses_spikes ¶
rm_pauses_spikes(unit, start, stop, return_intervals=False)
Remove spikes that occur during paused playback.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit
|
ndarray
|
Spike times (ms). |
required |
start
|
ndarray
|
Pause starts (ms). |
required |
stop
|
ndarray
|
Pause stops (ms). |
required |
return_intervals
|
bool
|
If |
False
|
Returns:
Tuple[np.ndarray, List[int]]: Cleaned spikes or (unit_no_pauses, removed_indices)
.
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/pause_handling.py
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 |
|
processing_labels ¶
make_label_from_start_stop_times ¶
make_label_from_start_stop_times(values, start_times, stop_times, ref_vec, default_value=0)
This function takes a vector with tuples with start and stop times and converts it to the default label
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref_vec
|
ndarray
|
reference vector, e.g. either PTS of movie or neural recording time of patient |
required |
default_value
|
int
|
default value of label, which shall be added to all gaps in start stop times |
0
|
values
|
list
|
vector with all values |
required |
start_times
|
list
|
vector with all start_times of segments |
required |
stop_times
|
list
|
vector with all stop times of segments |
required |
Returns:
list[int] | int: Label vector, or -1
on error.
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/processing_labels.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
create_xml_for_advene ¶
create_xml_for_advene(id_name, start_end_times_vector, label_name)
This function creates an XML string, which can be imported to the movie annotation tool Advene
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_name
|
str
|
name of ID in XML file |
required |
start_end_times_vector
|
list
|
input vector that contains the start and end times of the label in milliseconds |
required |
label_name
|
str
|
the name of the label how it shall be displayed in the GUI of Advene |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
an XML string that can be copied to the content.xml file and loaded to Advene |
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/processing_labels.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
start_stop_values_from_json ¶
start_stop_values_from_json(path_to_file, label_name)
This function extracts start times, stop times and values of all segments of a label from a json file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_to_file
|
str
|
path to json file |
required |
label_name
|
str
|
name of label (how it was specified in json file) |
required |
Returns: np.ndarray, np.ndarray, np.ndarray: first array: values of label, second array: start times of label segments in seconds, third array: stop times of label segments in seconds
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/processing_labels.py
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 |
|
export_labels_from_json_file ¶
export_labels_from_json_file(path_to_file, label_name, bool_save_start_end_times)
Process a json file from Advene and create a new label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_to_file
|
str
|
path to json file containing all information about the labels from Advene |
required |
label_name
|
str
|
name that was specified in Advene |
required |
bool_save_start_end_times
|
bool
|
determine whether the start and end times should be saved as a npy file |
required |
Returns: list: new label, aligned with movie (default label)
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/processing_labels.py
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 |
|
get_start_stop_times_from_label ¶
get_start_stop_times_from_label(neural_rec_time, patient_aligned_label)
This function takes the patient aligned label and extracts the start and stop times from that.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
neural_rec_time
|
array
|
neural recording time of patient |
required |
patient_aligned_label
|
array
|
patient aligned label |
required |
Returns: values (list), start times (list) and stop times (list) of label segments
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/processing_labels.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
watch_log ¶
Watch log parsing utilities for extracting PTS and CPU timestamps.
This module provides the :class:WatchLog
class to read a "watch log" file,
derive start/end times, and build aligned arrays/dataframes of presentation
timestamps (PTS) and real (CPU) times. It also includes helpers to trim the
recorded time series to a maximum movie duration.
Constants
MAX_MOVIE_TIME (int): Maximum allowable movie time (in the same units as PTS) used to filter out timestamps beyond the movie length.
Example
wl = WatchLog("/path/to/watch.log") wl.get_start_time(), wl.get_end_time() (12, 5012) wl.df_pts_cpu.head()
pts cpu_time¶
0 0.00 1234¶
1 0.04 1270¶
WatchLog ¶
Parse a watch log file and process the concurrent presentation time stamps (PTS) and the local PC (CPU) time series.
On initialization, this class:
1) Reads the provided watch log file.
2) Extracts the start and end CPU timestamps.
3) Loads all PTS/CPU rows, trims them to the maximum movie length, and
converts CPU timestamps to seconds (integer, via floor division by 1000).
4) Builds a pandas DataFrame (:attr:df_pts_cpu
) with pts
and cpu_time
.
Attributes:
Name | Type | Description |
---|---|---|
watch_log_file |
str
|
Absolute or relative path to the watch log file. |
start_time |
int
|
Start time in seconds (CPU time derived from the file). |
end_time |
int
|
End time in seconds (CPU time derived from the file). |
duration |
int
|
Duration in seconds, computed as |
pts_time_stamps |
ndarray
|
Array of PTS values (floats), possibly trimmed. |
dts_time_stamps |
ndarray
|
Array of CPU times in seconds (ints), possibly trimmed. |
excluded_indices |
list[int]
|
Indices removed when trimming to |
df_pts_cpu |
DataFrame
|
Two-column DataFrame with |
Notes
- The method :meth:
getlines
reads the log file in binary mode and returns a list of byte strings. Downstream parsing assumes whitespace- separated fields and converts to numeric types as needed. - CPU timestamps are divided by 1000 and cast to
int
, so any sub-second resolution is truncated rather than rounded.
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/watch_log.py
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
get_start_time()
Return the start CPU time (in seconds).
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Start time in seconds. |
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/watch_log.py
76 77 78 79 80 81 82 83 |
|
get_end_time()
Return the end CPU time (in seconds).
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
End time in seconds. |
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/watch_log.py
85 86 87 88 89 90 91 92 |
|
extract_start_and_end_time()
Extract the start and end CPU timestamps from the watch log.
The function reads the file in text mode, takes the second line as the
"first" data line, and scans backward from the end to find the last line
beginning with "pts"
. It returns the CPU timestamps from those two
lines, converted to seconds by dividing by 1000 and casting to int
.
Returns:
Type | Description |
---|---|
tuple[int, int]
|
tuple[int, int]: A |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the watch log file cannot be opened. |
ValueError
|
If the file does not contain expected fields/format. |
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/watch_log.py
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 |
|
get_times_from_watch_log(path_watch_log)
Extract PTS and CPU (real) times from the watch log.
The function reads raw lines via :meth:getlines
, parses the whitespace-
separated fields, and collects two arrays:
- PTS values as floats rounded to 2 decimals.
- CPU timestamps as integers (original units, not yet divided by 1000).
It then trims both arrays to the maximum movie duration via
:meth:cut_time_to_movie_pts
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_watch_log
|
str
|
Path to the watch log file to parse. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
tuple[np.ndarray, np.ndarray, list[int]]: A tuple |
ndarray
|
|
list[int]
|
|
tuple[ndarray, ndarray, list[int]]
|
|
tuple[ndarray, ndarray, list[int]]
|
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the watch log file cannot be opened. |
ValueError
|
If the log lines do not match the expected 4-field format. |
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/watch_log.py
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 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
staticmethod
¶cut_time_to_movie_pts(pts_time_stamps, cpu_time_stamps)
Trim PTS and CPU arrays to the maximum movie length.
Any PTS value strictly greater than :data:MAX_MOVIE_TIME
is excluded.
The function returns aligned arrays of the retained elements and the
list of excluded indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pts_time_stamps
|
ndarray
|
Array of PTS values (floats). |
required |
cpu_time_stamps
|
ndarray
|
Array of CPU times (ints), aligned with PTS. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
tuple[np.ndarray, np.ndarray, list[int]]: A tuple |
ndarray
|
|
list[int]
|
|
tuple[ndarray, ndarray, list[int]]
|
|
tuple[ndarray, ndarray, list[int]]
|
|
Notes
- This function assumes
pts_time_stamps
andcpu_time_stamps
are the same length and aligned 1:1.
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/watch_log.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
staticmethod
¶getlines(filename)
Read a file in binary mode and return its lines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Path to the file to read. |
required |
Returns:
Type | Description |
---|---|
list[bytes]
|
list[bytes]: Lines of the file as byte strings (no newline characters). |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the file cannot be opened. |
Source code in epiphyte/preprocessing/annotation/stimulus_driven_annotation/movies/watch_log.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
data_preprocessing ¶
binning ¶
Binning functions for spike times and labels. Pulls data from the database using pre-defined query functions.
bin_label ¶
bin_label(patient_id, session_nr, values, start_times, stop_times, bin_size, exclude_pauses)
Bin a label timeline against fixed-size bins.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patient_id
|
int
|
ID of patient. |
required |
session_nr
|
int
|
Session number for the movie watching. |
required |
values
|
ndarray
|
Values of the label per segment. |
required |
start_times
|
ndarray
|
Start times (ms) per segment. |
required |
stop_times
|
ndarray
|
Stop times (ms) per segment. |
required |
bin_size
|
int
|
Size of one bin in milliseconds. |
required |
exclude_pauses
|
bool
|
If |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Indicator vector (one value per bin). |
Source code in epiphyte/preprocessing/data_preprocessing/binning.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 |
|
bin_spikes ¶
bin_spikes(patient_id, session_nr, spike_times, bin_size, exclude_pauses, output_edges=False)
Bin spike times into fixed-size bins.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patient_id
|
int
|
ID of the patient. |
required |
session_nr
|
int
|
Session number of the experiment. |
required |
spike_times
|
ndarray
|
Spike timestamps (ms) as a vector. |
required |
bin_size
|
int
|
Bin size in milliseconds. |
required |
exclude_pauses
|
bool
|
If |
required |
output_edges
|
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
Union[ndarray, List[ndarray]]
|
Union[np.ndarray, List[np.ndarray]]: Binned spikes or |
Source code in epiphyte/preprocessing/data_preprocessing/binning.py
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 |
|
create_vectors_from_time_points ¶
Functions related to processing the db stored time points (start/stop/values) into vectors for use in analysis.
get_index_nearest_timestamp_in_vector ¶
get_index_nearest_timestamp_in_vector(vector, timestamp)
Finds the index of the value in a vector that is nearest to a given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector
|
ndarray
|
The array of timestamps to search. |
required |
timestamp
|
float
|
The target timestamp to find the nearest value to. |
required |
Returns:
int: The index of the value in vector
that is closest to timestamp
.
Example
vector = np.array([1.0, 2.5, 3.8, 5.0])
idx = get_index_nearest_timestamp_in_vector(vector, 3.0)
# idx == 1
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
get_nearest_value_from_vector ¶
get_nearest_value_from_vector(vector, timestamp)
Finds the value in a vector closest to a given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector
|
ndarray
|
Array of values to search. |
required |
timestamp
|
float
|
Target timestamp to find the nearest value to. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The value from the vector that is closest to the given timestamp. |
Example
import numpy as np
vector = np.array([1.0, 2.5, 3.8, 5.0])
get_nearest_value_from_vector(vector, 4.0)
3.8
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
create_vector_from_start_stop_times_reference_cont_watch ¶
create_vector_from_start_stop_times_reference_cont_watch(reference_vector, values, starts, stops)
Creates a vector aligned to a reference vector using provided start and stop times and corresponding values.
This function generates an indicator vector where each segment, defined by its start and stop times, is filled with the associated value. The output vector is aligned to the bins defined by the reference vector, which represents the edges of the bins.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference_vector
|
ndarray
|
Array of timestamps or bin edges to which the output vector will be aligned. |
required |
values
|
ndarray
|
Array of values to assign to each segment. |
required |
starts
|
ndarray
|
Array of start times for each segment. |
required |
stops
|
ndarray
|
Array of stop times for each segment. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Indicator vector aligned to the reference vector, with values assigned according to the specified intervals. |
Notes
Prints an error and returns -1 if the lengths of values
, starts
, and stops
do not match.
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
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 |
|
create_vector_from_start_stop_times ¶
create_vector_from_start_stop_times(patient_id, session_nr, values, starts, stops)
Less powerful version of the function create_vector_from_start_stop_times_reference_cont_watch
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patient_id
|
int
|
ID of patient |
required |
session_nr
|
int
|
unique number of session of patient |
required |
values
|
ndarray
|
array indicating all values in the right order |
required |
starts
|
ndarray
|
array indicating all start times of all segments in the right order |
required |
stops
|
ndarray
|
array indicating all stop times of all segments as a vector in the right order |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Indicator function aligned to reference vector. |
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
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 |
|
get_start_stop_times_from_label ¶
get_start_stop_times_from_label(neural_rec_time, patient_aligned_label)
This function extracts the start and stop times from a label.
patient_aligned_label
has to have the same length as neural_rec_time
The time points in the resulting vectors are in neural recording time
Parameters:
Name | Type | Description | Default |
---|---|---|---|
neural_rec_time
|
ndarray
|
array indicating neural recording time |
required |
patient_aligned_label
|
ndarray
|
array indicating label aligned to patient time |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple[list, list, list]
|
|
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
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 |
|
get_bins_excl_pauses ¶
get_bins_excl_pauses(patient_id, session_nr, neural_rec_time, bin_size)
Returns edges of bins for a given patient with the right bin size, while excluding bins where the movie was paused.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patient_id
|
int
|
ID of patient |
required |
session_nr
|
int
|
session number |
required |
neural_rec_time
|
ndarray
|
vector of neural recording time of patient |
required |
bin_size
|
int
|
size of bin in milliseconds |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Edges of bins, excluding paused intervals. |
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
create_vector_from_start_stop_times_reference ¶
create_vector_from_start_stop_times_reference(reference_vector, values, starts, stops)
Create an indicator function from values, start and stop times of a label aligned to a reference vector of time points. Used to create an indicator function (vector indicating if a labelled feature was present during the interval between two time points) from a set of bin edges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference_vector
|
ndarray
|
vector of linearly spaced time points (e.g. bin edges) |
required |
values
|
ndarray
|
values indicating presence or absence of a labeled feature |
required |
starts
|
ndarray
|
start times of the corresponding values |
required |
stops
|
ndarray
|
stop times of the corresponding values |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: indicator function vector. |
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
get_value_matching_start_point ¶
get_value_matching_start_point(time_point, values, start_times, end_times)
Finds the value in a vector that corresponds to the closest start time less than or equal to a given time point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_point
|
float
|
the time point for which the value shall be searched |
required |
values
|
ndarray
|
vector with all values |
required |
start_times
|
ndarray
|
vector with all start times |
required |
end_times
|
ndarray
|
vector with all stop times |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Value corresponding to the time point. |
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
get_value_matching_stop_point ¶
get_value_matching_stop_point(time_point, values, start_times, end_times)
Finds the value in a vector that corresponds to the closest stop time less than or equal to a given time point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_point
|
float
|
the time point for which the value shall be searched |
required |
values
|
ndarray
|
vector with all values |
required |
start_times
|
ndarray
|
vector with all start times |
required |
end_times
|
ndarray
|
vector with all stop times |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Value corresponding to the time point. |
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
get_index_matching_start_point ¶
get_index_matching_start_point(time_point, values, start_times, end_times)
Finds the index of the start point that is the closest start point smaller than 'time_point'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_point
|
float
|
the time point for which the value shall be searched |
required |
values
|
ndarray
|
vector with all values |
required |
start_times
|
ndarray
|
vector with all start times |
required |
end_times
|
ndarray
|
vector with all stop times |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
int
|
Value corresponding to the time point. |
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
get_index_matching_stop_point ¶
get_index_matching_stop_point(time_point, values, start_times, end_times)
Finds the index of the stop point that is the closest stop point greater than 'time_point'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_point
|
float
|
the time point for which the value shall be searched |
required |
values
|
ndarray
|
vector with all values |
required |
start_times
|
ndarray
|
vector with all start times |
required |
end_times
|
ndarray
|
vector with all stop times |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
int
|
Value corresponding to the time point. |
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
get_value_in_time_frame ¶
get_value_in_time_frame(time_point1, time_point2, values, start_times, end_times)
Finds the value that is most represented between two time points. Needed for creating an indicator function from a set of bin edges with a bin size longer than the frame length, as a bin could contain multiple segments with different values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_point1
|
float
|
lower bound of time frame |
required |
time_point2
|
float
|
upper bound of time frame that is regarded |
required |
values
|
ndarray
|
vector with all values |
required |
start_times
|
ndarray
|
vector with all start time points |
required |
end_times
|
ndarray
|
vector with all stop time points |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
value most represented within the time frame. |
Source code in epiphyte/preprocessing/data_preprocessing/create_vectors_from_time_points.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
data_utils ¶
I/O and time-alignment utilities for Neuralynx-like event logs.
Provides helpers to read .nev
(and mock .npy
) event files, parse
watchlogs/DAQ logs, and linearly align between local computer time and neural
recording system time.
TimeConversion ¶
Bases: object
Linear mapping between CPU time and neural recording time.
Enables conversion of stimulus timestamps (e.g., movie frames) to the spike time scale.
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
convert ¶
convert()
Compute mapping and convert watchlog times to DAQ times.
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray, np.ndarray]: |
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
convert_pauses ¶
convert_pauses()
Convert pause CPU timestamps to neural recording time.
Returns:
Type | Description |
---|---|
Tuple[List[float], List[float]]
|
Tuple[List[float], List[float]]: |
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
convert_skips ¶
convert_skips()
Detect skips and return start/stop/value segments in DAQ time.
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray, np.ndarray]: |
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
nev_read ¶
nev_read(filename)
Read event timestamps and codes from .nev
or mock .npy
file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str | Path
|
Path to |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: |
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
nev_string_read ¶
nev_string_read(filename)
Read event timestamps and strings from a .nev
file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str | Path
|
Path to |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: |
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
41 42 43 44 45 46 47 48 49 50 51 |
|
process_movie_events ¶
process_movie_events(ev_array)
Filter raw event rows to the movie-event sequence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ev_array
|
ndarray
|
|
required |
Returns: np.ndarray: Filtered movie event rows.
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
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 |
|
process_events ¶
process_events(ev_array)
Extract movie-event rows from a full event array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ev_array
|
ndarray
|
Full event array. |
required |
Returns: np.ndarray: Movie-event subset.
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
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 |
|
getlines ¶
getlines(filename)
Read a text file and return the raw lines as bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str | Path
|
Path to file. |
required |
Returns:
Type | Description |
---|---|
list[bytes]
|
list[bytes]: List of lines (bytes). |
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
read_watchlog ¶
read_watchlog(watchlogfile)
Extract PTS (s) and CPU times (µs) from a watchlog.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
watchlogfile
|
str | Path
|
Path to watchlog created by ffmpeg wrapper. |
required |
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: Tuple |
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
read_watchlog_pauses ¶
read_watchlog_pauses(watchlogfile)
Find pause segments in the watchlog.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
watchlogfile
|
str | Path
|
Path to pts/CPU watchlog. |
required |
Returns:
Tuple[List[int], List[int]]: (start_times_us, stop_times_us)
lists.
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
read_daqlog ¶
read_daqlog(daqlogfile)
Extract DAQ values and pre/post times.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
daqlogfile
|
str | Path
|
Path to DAQ log file. |
required |
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray, np.ndarray]: |
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
get_coeff ¶
get_coeff(event_mat, daqlogfile)
Fit a linear mapping from DAQ post times to event timestamps.
Loads logs, validates events, and returns slope/intercept.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_mat
|
ndarray
|
|
required |
daqlogfile
|
str | Path
|
Path to DAQ log file. |
required |
Returns:
np.ndarray: [m, b]
array such that timestamp = m*post + b
.
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
make_msec ¶
make_msec(list_usec)
Convert a list from microseconds to milliseconds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list_usec
|
list[int]
|
Times in microseconds. |
required |
Returns: list[float]: Times in milliseconds.
Source code in epiphyte/preprocessing/data_preprocessing/data_utils.py
264 265 266 267 268 269 270 271 272 273 274 |
|