edf
Write a synthetic EDF recording, and cut or extend an existing one.
A conformance fixture must never be real data, and the package carries no
numeric dependency, so the writer is plain Python: a fixed-rate sinusoid per
channel with deterministic noise, enough for a container to read, select and
process the way it would a real night. Only what the reader in
:mod:yousleep_common.cli.manifest and every EDF library needs is written:
the fixed header, one signal header per channel, and one-second data records
of 16-bit samples. A signal may repeat its samples after a period, which is
how a recording of many hours is written at the speed of a file copy.
:func:resize_edf makes a recording of another length from a real one, by
cutting its data records or repeating them and rewriting the record count.
EdfLayout
dataclass
¶
Where an EDF file's data records are, and how long each is.
seconds
property
¶
The recording's length.
SyntheticSignal
dataclass
¶
One channel of a synthetic recording.
edf_layout(path)
¶
Read the record layout of an EDF file from its header.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the header cannot be parsed or the file holds no complete data record. |
resize_edf(source, target, *, seconds)
¶
Write a copy of an EDF recording cut or extended to a length.
The data records are copied in order, from the first again once they run
out, until the copy holds the whole records nearest seconds; the
header is kept but for the record count. Every signal is carried,
selected or not, as the platform hands a container the whole file. An
annotation signal is repeated with the data, so the time-keeping of an
EDF+ file restarts where the records do.
Returns:
| Type | Description |
|---|---|
float
|
The copy's length in seconds. |
write_edf(path, signals, *, duration_seconds, seed=0, start=None)
¶
Write a synthetic EDF file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Where to write it. |
required |
signals
|
list[SyntheticSignal]
|
The channels, in file order. |
required |
duration_seconds
|
int
|
Length of the recording; one data record per second. |
required |
seed
|
int
|
Makes the samples reproducible; the same seed writes the same bytes. |
0
|
start
|
datetime | None
|
The recording's start time as written in the header. Defaults to a fixed date so two runs write identical files. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a signal has a non-positive sample rate or there are no signals. |