edfio.EdfSignal#

class edfio.EdfSignal(data, sampling_frequency, *, label='', transducer_type='', physical_dimension='', physical_range=None, digital_range=(-32768, 32767), prefiltering='')[source]#

A single EDF signal.

Attributes that might break the signal or file on modification (i.e., sampling_frequency, physical_range, digital_range, samples_per_data_record, and reserved) can not be set after instantiation.

To reduce memory consumption, signal data is always stored as a 16-bit integer array containing the digital values that would be written to the corresponding EDF file. Therefore, it is expected that EdfSignal.data does not match the physical values passed during instantiation exactly.

Parameters:
datanpt.NDArray[np.float64]

The signal data (physical values).

sampling_frequencyfloat

The sampling frequency in Hz.

labelstr, default: ""

The signal’s label, e.g., "EEG Fpz-Cz" or "Body temp".

transducer_typestr, default: ""

The transducer type, e.g., "AgAgCl electrode".

physical_dimensionstr, default: ""

The physical dimension, e.g., "uV" or "degreeC"

physical_rangetuple[float, float], default: (-32768, 32767)

The physical range given as a tuple of (physical_min, physical_max). If None, this is determined from the data.

digital_rangetuple[int, int] | None, default: None

The digital range given as a tuple of (digital_min, digital_max). Uses the maximum resolution of 16-bit integers.

prefilteringstr, default: ""

The signal prefiltering, e.g., "HP:0.1Hz LP:75Hz".

Attributes

data

Numpy array containing the physical signal values as floats.

digital

Numpy array containing the digital (uncalibrated) signal values as integers.

digital_max

Digital maximum, e.g., 2047.

digital_min

Digital minimum, e.g., -2048.

digital_range

The digital range as a tuple of (digital_min, digital_max).

label

Signal label, e.g., "EEG Fpz-Cz" or "Body temp".

physical_dimension

Physical dimension, e.g., "uV" or "degreeC.

physical_max

Physical maximum, e.g., 500 or 40.

physical_min

Physical minimum, e.g., -500 or 34.

physical_range

The physical range as a tuple of (physical_min, physical_max).

prefiltering

Signal prefiltering, e.g., "HP:0.1Hz LP:75Hz".

reserved

Reserved signal header field, always "".

samples_per_data_record

Number of samples in each data record.

sampling_frequency

The sampling frequency in Hz.

transducer_type

Transducer type, e.g., "AgAgCl electrode".

Methods

__init__

from_hypnogram

Create an EDF signal from a hypnogram, with scaling according to EDF specs.

get_data_slice

Get a slice of the signal data.

get_digital_slice

Get a slice of the digital signal values.

update_data

Overwrite physical signal values with an array of equal length.

property data[source]#

Numpy array containing the physical signal values as floats.

To simplify avoiding inconsistencies between signal data and header fields, individual values in the returned array can not be modified. Use EdfSignal.update_data() to overwrite with new physical data.

property digital[source]#

Numpy array containing the digital (uncalibrated) signal values as integers.

The values of the array may be accessed and modified directly.

For EDF these are 16-bit integers, for BDF these are 32-bit integers.

property digital_max[source]#

Digital maximum, e.g., 2047.

property digital_min[source]#

Digital minimum, e.g., -2048.

property digital_range[source]#

The digital range as a tuple of (digital_min, digital_max).

classmethod from_hypnogram(stages, stage_duration=30, *, label='')[source]#

Create an EDF signal from a hypnogram, with scaling according to EDF specs.

According to the EDF FAQ [1], use integer numbers 0, 1, 2, 3, 4, 5, 6, and 9 for sleep stages W, 1, 2, 3, 4, R, MT, und unscored, respectively. The digital range is set to (0, 9).

Parameters:
stagesnpt.NDArray[np.float64]

The sleep stages, coded as integer numbers.

stage_durationfloat, default: 30

The duration of each sleep stage in seconds, used to set the sampling frequency to its inverse.

labelstr, default: ""

The signal’s label.

Returns:
EdfSignal

The resulting EdfSignal object.

References

get_data_slice(start_second, stop_second)[source]#

Get a slice of the signal data.

If the signal has not been loaded into memory so far, only the requested slice will be read.

Parameters:
start_secondfloat

The start of the slice in seconds.

stop_secondfloat

The end of the slice in seconds.

get_digital_slice(start_second, stop_second)[source]#

Get a slice of the digital signal values.

If the signal has not been loaded into memory so far, only the requested slice will be read.

Parameters:
start_secondfloat

The start of the slice in seconds.

stop_secondfloat

The end of the slice in seconds.

property label[source]#

Signal label, e.g., "EEG Fpz-Cz" or "Body temp".

property physical_dimension[source]#

Physical dimension, e.g., "uV" or "degreeC.

property physical_max[source]#

Physical maximum, e.g., 500 or 40.

property physical_min[source]#

Physical minimum, e.g., -500 or 34.

property physical_range[source]#

The physical range as a tuple of (physical_min, physical_max).

property prefiltering[source]#

Signal prefiltering, e.g., "HP:0.1Hz LP:75Hz".

property reserved[source]#

Reserved signal header field, always "".

property samples_per_data_record[source]#

Number of samples in each data record.

For newly instantiated EdfSignal objects, this is only set once Edf.write() is called.

property sampling_frequency[source]#

The sampling frequency in Hz.

property transducer_type[source]#

Transducer type, e.g., "AgAgCl electrode".

update_data(data, *, keep_physical_range=False, sampling_frequency=None)[source]#

Overwrite physical signal values with an array of equal length.

Parameters:
datanpt.NDArray[np.float64]

The new physical data.

keep_physical_rangebool, default: False

If True, the physical_range is not modified to accomodate the new data.

sampling_frequencyfloat | None, default: None

If not None, the sampling_frequency is updated to the new value. The new data must match the expected length for the new sampling frequency.