edfrd
edfrd is a Python 3 software library to read and write EDF files.
It is designed as a low-level library, that does not interpret the EDF data whenever possible. Therefore, edfrd can read files even if non-standard values are contained in the header.
Data records are loaded as int16 arrays using numpy.
Installation
pip3 install --user edfrd
Reading EDF Header and Data Records
from edfrd import read_header, read_data_records
file_path = 'PATH/TO/FILE.edf'
header = read_header(file_path)
print(header)
for data_record in read_data_records(file_path, header): # generator
# iterate through data_records
break
for signal in data_record:
# iterate through signal arrays of a single data_record
print(signal.size)
for signal_header, signal in zip(header.signals, data_record):
# iterate through signal headers and signal arrays
print(signal_header.label, signal.size)
If the header of your EDF file does not correctly specifiy the number of data records, you can use the following option to calculate it from the file size.
header = read_header(file_path, calculate_number_of_data_records=True)
You can try parsing the startdate_of_recording and starttime_of_recording as integer tuples. If parsing fails the
original string will be returned.
header = read_header(file_path, parse_date_time=True)
day, month, year = header.startdate_of_recording
hours, minutes, seconds = header.starttime_of_recording
The number of data records being read can be limited by specifying an optional start or end index.
for data_record in read_data_records(file_path, header, start=0, end=header.number_of_data_records):
break
To work with larger chunks of a signal than provided by a data record, consider creating a new numpy array as a
buffer.
import numpy as np
from edfrd import read_header, read_data_records
file_path = 'PATH/TO/FILE.edf'
header = read_header(file_path)
start, end = 2, 4
signal_index = 0
signal_header = header.signals[signal_index]
buffer_length = (end - start) * signal_header.nr_of_samples_in_each_data_record
buffer = np.empty(buffer_length, dtype=np.int16)
pointer = 0
for data_record in read_data_records(start, end):
buffer[pointer:pointer+signal_header.nr_of_samples_in_each_data_record] = data_record[signal_index]
pointer += signal_header.nr_of_samples_in_each_data_record
print(buffer)
You can also pass a file descriptor (fr) instead of a string (file_path). Note that read_data_records will
continue from the current byte position, where read_header stopped, without performing an additional seek operation.
with open(file_path, 'rb') as fr:
header = read_header(fr)
for data_record in read_data_records(fr, header):
break
Writing EDF Header and Data Records
from edfrd import read_header, read_data_records, write_header, write_data_records
file_path = 'PATH/TO/FILE.edf'
new_file_path = 'PATH/TO/NEW_FILE.edf'
header = read_header(file_path)
data_records = read_data_records(file_path, header)
write_header(file_path, header)
write_data_records(file_path, data_records)
Again, using file descriptors (fr and fw) is possible.
with open(file_path, 'rb') as fr:
header = read_header(fr)
data_records = read_data_records(fr, header)
with open(new_file_path, 'wb') as fw:
write_header(fw, header)
write_data_records(fw, data_records)
Metadata
Release files for edfrd 0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| edfrd-0.7.tar.gz | 6.9 kB | Without provenance | Details for edfrd-0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| edfrd-0.7-py3-none-any.whl | Python 3 | none | any | Details for edfrd-0.7-py3-none-any.whl |
Total release size: 14.0 kB
Release files / edfrd-0.7.tar.gz
| Download URL | edfrd-0.7.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7bb83cfe355f3a74d72484875df3040d7856f0be90f06f46901ce737389e0a3d
|
|
BLAKE2b-256 checksum How to use checksums |
cc6b397e113ae4d12f134a53cd33316f43425d8774ea0cd73ff674926027df24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.16 CPython/3.7.3 Linux/5.1.15-300.fc30.x86_64
|
Release files / edfrd-0.7-py3-none-any.whl
| Download URL | edfrd-0.7-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e11c364a75ded4b94701fef87184415bb8f04e986fe15126c6c9a95036a2f250
|
|
BLAKE2b-256 checksum How to use checksums |
64b3fb09e21c5fb091fb2b27d269654b6c0aa79f960ff916d11a90e7d0625686
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.16 CPython/3.7.3 Linux/5.1.15-300.fc30.x86_64
|
Security for edfrd 0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.