An interoperable and harmonized format for polysomnography recordings.
Project description
sleeplab-format
Sleeplab format (SLF) is a both machine and human-readable format for storing and processing polysomnography data. SLF provides reader and writer with validation of data types and structures. The goal is to make it easier to apply analytics and machine learning pipelines to multiple datasets from different sources.
Documentation
See full documentation and the paper for details.
Related tools
sleeplab-converters for converting other formats exported from PSG software to sleeplab format.
sleeplab-tf-dataset for reading data in sleeplab format as a tensorflow Dataset.
Installation
pip install sleeplab-format
Usage
import sleeplab_format as slf
import pandas as pd
from pathlib import Path
# Read a toy dataset
DS_DIR = Path('tests/datasets/dataset1')
ds = slf.reader.read_dataset(DS_DIR)
# Get the list of subjects from series1
subjects = ds.series['series1'].subjects.values()
# Flatten the nested annotations and cast Pydantic models to dicts
all_events_dict = [dict(a)
for s in subjects
for a_model in s.annotations.values()
for a in a_model.annotations
]
# Create a pandas DataFrame for analyses
event_df = pd.DataFrame(all_events_dict)
# Calculate the mean duration of hypopneas
hypopneas = event_df[event_df['name'] == 'HYPOPNEA']
mean_duration = sum(hypopneas['duration']) / len(hypopneas)
# Modify the dataset
additional_info = {'neck_size': 40.0}
ds.series['series1'].subjects['10001'].metadata.additional_info = additional_info
ds.name = 'dataset2'
# Write the modified dataset
MODIFIED_DS_DIR = Path('/tmp/datasets')
slf.writer.write_dataset(ds, MODIFIED_DS_DIR)
See the automatic sleep staging example for a full end-to-end example.
Contributing
See contributing.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sleeplab_format-0.4.1.tar.gz
.
File metadata
- Download URL: sleeplab_format-0.4.1.tar.gz
- Upload date:
- Size: 108.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16278d9f10c3baf6f09697d5c14691bfe350c936fcb60097f85c447b527470aa |
|
MD5 | 395cd1accb6e051cde4f5059fcbe1d10 |
|
BLAKE2b-256 | 1e4b2efabad72858bc4c4103ef55a0271c7f5cd2778f8bd3af9423e1173448a9 |
File details
Details for the file sleeplab_format-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: sleeplab_format-0.4.1-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab14e713abcd065f74ef467816e5d961474e5ab95e1998e131dadb25d16d5a98 |
|
MD5 | 637bad2b8ec0e5064c03ae0210fa9e39 |
|
BLAKE2b-256 | 8577109568f08fd2001b011e63a8fe18cd27ca47c6130319fd4f51b255b5254f |