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, andreserved) 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.datadoes not match the physical values passed during instantiation exactly.- Parameters:
- data
npt.NDArray[np.float64] The signal data (physical values).
- sampling_frequency
float The sampling frequency in Hz.
- label
str, default:"" The signal’s label, e.g.,
"EEG Fpz-Cz"or"Body temp".- transducer_type
str, default:"" The transducer type, e.g.,
"AgAgCl electrode".- physical_dimension
str, default:"" The physical dimension, e.g.,
"uV"or"degreeC"- physical_range
tuple[float,float], default: (-32768, 32767) The physical range given as a tuple of
(physical_min, physical_max). IfNone, this is determined from the data.- digital_range
tuple[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.- prefiltering
str, default:"" The signal prefiltering, e.g.,
"HP:0.1Hz LP:75Hz".
- data
Attributes
Numpy array containing the physical signal values as floats.
Numpy array containing the digital (uncalibrated) signal values as integers.
Digital maximum, e.g.,
2047.Digital minimum, e.g.,
-2048.The digital range as a tuple of
(digital_min, digital_max).Signal label, e.g.,
"EEG Fpz-Cz"or"Body temp".Physical dimension, e.g.,
"uV"or"degreeC.Physical maximum, e.g.,
500or40.Physical minimum, e.g.,
-500or34.The physical range as a tuple of
(physical_min, physical_max).Signal prefiltering, e.g.,
"HP:0.1Hz LP:75Hz".Reserved signal header field, always
"".Number of samples in each data record.
The sampling frequency in Hz.
Transducer type, e.g.,
"AgAgCl electrode".Methods
__init__Create an EDF signal from a hypnogram, with scaling according to EDF specs.
Get a slice of the signal data.
Get a slice of the digital signal values.
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.
- 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:
- stages
npt.NDArray[np.float64] The sleep stages, coded as integer numbers.
- stage_duration
float, default:30 The duration of each sleep stage in seconds, used to set the sampling frequency to its inverse.
- label
str, default:"" The signal’s label.
- stages
- Returns:
References
[1]
- 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.
- 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.
- property samples_per_data_record[source]#
Number of samples in each data record.
For newly instantiated
EdfSignalobjects, this is only set onceEdf.write()is called.
- update_data(data, *, keep_physical_range=False, sampling_frequency=None)[source]#
Overwrite physical signal values with an array of equal length.
- Parameters:
- data
npt.NDArray[np.float64] The new physical data.
- keep_physical_rangebool, default:
False If
True, thephysical_rangeis not modified to accomodate the new data.- sampling_frequency
float|None, default:None If not
None, thesampling_frequencyis updated to the new value. The new data must match the expected length for the new sampling frequency.
- data