Epochs class#

class pyneon.Epochs(source: NeonStream | NeonEV, times_df: DataFrame | None = None, t_ref: ndarray | None = None, t_before: ndarray | Number | None = None, t_after: ndarray | Number | None = None, description: ndarray | str | None = None, t_ref_unit: Literal['s', 'ms', 'us', 'ns'] = 'ns', t_other_unit: Literal['s', 'ms', 'us', 'ns'] = 's', global_t_ref: int = 0)#

Class to create and manage epochs in the data streams.

Parameters:
  • source (NeonStream or NeonEV) – Data to create epochs from.

  • times_df (pandas.DataFrame, optional) –

    DataFrame containing epoch information with the following columns:

    t_ref: Reference time of the epoch, in nanoseconds.

    t_before: Time before the reference time to start the epoch, in nanoseconds.

    t_after: Time after the reference time to end the epoch, in nanoseconds.

    description: Description or label associated with the epoch.

    Must not have empty values. If provided, the rest of the parameters are ignored.

  • t_ref (numpy.ndarray, optional) – Array of reference times for the epochs. Units specified by t_ref_unit.

  • t_before (numpy.ndarray or Number, optional) – Time before the reference time to start the epoch. Could be an array of equal length as t_ref or a single number (to be repeated for all epochs). Units specified by t_other_unit.

  • t_after (numpy.ndarray or Number, optional) – Time after the reference time to end the epoch. Could be an array of equal length as t_ref or a single number (to be repeated for all epochs). Units specified by t_other_unit.

  • description (numpy.ndarray or str, optional) – Description or label associated with the epochs. Could be an array of equal length as t_ref or a single string (to be repeated for all epochs).

  • global_t_ref (int, optional) – Global reference time (in nanoseconds) to be added to t_ref. Unit is nanosecond. Defaults to 0. This is useful when the reference times are relative to a global start time (for instance pyneon.stream.NeonStream.first_ts).

  • t_ref_unit (str, optional) – Unit of time for the reference times. Default is ‘ns’.

  • t_other_unit (str, optional) – Unit of time for t_before and t_after. Default is ‘s’.

Notes

If times_df is provided, it is used to create epochs, and the other time-related parameters are ignored. Otherwise, t_ref, t_before, t_after, and description are required.

epochs#

DataFrame containing epoch information with the following columns:

t_ref (int64): Reference time of the epoch, in nanoseconds.

t_before (int64): Time before the reference time to start the epoch, in nanoseconds.

t_after (int64): Time after the reference time to end the epoch, in nanoseconds.

description (str): Description or label associated with the epoch.

data (object): DataFrame containing the data for each epoch.

Type:

pandas.DataFrame

data#

DataFrame containing the data for each epoch.

Type:

pandas.DataFrame

property t_ref: ndarray#

The reference time for each epoch in UTC nanoseconds.

property t_before: ndarray#

The time before the reference time for each epoch in nanoseconds.

property t_after: ndarray#

The time after the reference time for each epoch in nanoseconds.

property description: ndarray#

The description or label for each epoch.

property is_equal_length: bool#

Whether all epochs have the same length.

property has_overlap: bool#

Whether any adjacent epochs overlap.

to_numpy(sampling_rate=100, columns=None)#

Converts epochs into a NumPy array with dimensions (n_epochs, n_times, n_channels). Resamples epochs to a fixed sampling rate.

Parameters:
  • sampling_rate (int) – The sampling rate to resample the data to, in Hz (samples per second).

  • columns (list of str, optional) – List of column names to extract from the DataFrame. If None, all columns except ‘t_rel’ are used.

Returns:

  • epochs_np (numpy.ndarray) – NumPy array of shape (n_epochs, n_times, n_channels).

  • info (dict) – A dictionary containing: - ‘column_ids’: List of provided column names. - ‘t_rel’: The common time grid, in nanoseconds. - ‘nan_status’: String indicating whether NaN values were found in the data.

Notes

  • The time grid (t_rel) is in nanoseconds.

  • If NaN values are present after interpolation, they are noted in nan_status.

pyneon.events_to_times_df(event: NeonEV, t_before: Number, t_after: Number, t_unit: Literal['s', 'ms', 'us', 'ns'] = 's', type_name: str = 'all') DataFrame#

Construct a times_df DataFrame suitable for creating epochs from event data.

Parameters:
  • event (NeonEV) – NeonEV instance containing the event times.

  • t_before (Number) – Time before the event start time to start the epoch. Units specified by t_unit.

  • t_after (Number) – Time after the event start time to end the epoch. Units specified by t_unit.

  • t_unit (str, optional) – Unit of time for t_before and t_after. Can be ‘s’ (seconds), ‘ms’ (milliseconds), ‘us’ (microseconds), or ‘ns’ (nanoseconds). Defaults to ‘s’.

Returns:

DataFrame containing epoch information with the following columns:

t_ref: Reference time of the epoch, in nanoseconds.

t_before: Time before the reference time to start the epoch, in nanoseconds.

t_after: Time after the reference time to end the epoch, in nanoseconds.

description: Description or label associated with the epoch.

Return type:

pandas.DataFrame