nnsa.io package
Submodules
nnsa.io.hdf5 module
Module related to writing/reading HDF5 files.
Functions:
|
Read a dictionary saved to an hdf5 file by write_dict_to_hdf5(). |
|
Write a dictionary to a HDF5. |
- nnsa.io.hdf5.read_dict_from_hdf5(f, target)[source]
Read a dictionary saved to an hdf5 file by write_dict_to_hdf5().
- Parameters:
f (h5py._hl.files.File) – file object to an open hdf5 file.
target (str) – path/group in the hdf5 file where the dict is saved.
- Returns:
(dict) – (unflattened) dictionary as read from the hdf5.
- nnsa.io.hdf5.write_dict_to_hdf5(f, d, target)[source]
Write a dictionary to a HDF5.
Flatten the dictionary
Create a hdf5 group, whose attributes will hold (flattened) key and value pairs.
Create a hdf5 group, whose attributes will hold key and type(value).__name__ pairs.
Save the values and the value types as attributes to the corresponding hdf5 group.
Read a dictionary with read_dict_from_hdf5.
- Parameters:
f (h5py._hl.files.File) – file object to an open hdf5 file.
d (dict) – dict to save.
target (str) – path/group to be created in the hdf5 file where the dict will be saved. Note that the target group may not already exists, otherwise a ValueError is raised when attempting to (re)create it.
nnsa.io.readers module
Module for reading data files (builds on edfreadpy).
Supports EDF, EDF+, EDF+D, EDF+C.
Classes:
|
Child of edfreadpy.EdfReader, which includes interfaces to load data into nnsa containers. |
- class nnsa.io.readers.EdfReader(filepath)[source]
Bases:
EdfReaderChild of edfreadpy.EdfReader, which includes interfaces to load data into nnsa containers.
- Parameters:
filepath (str) – path to the EDF(+) file to read (see edfreadpy.EdfReader).
Methods:
read_bp_dataset([begin, end, patterns])Read all blood-pressure signals into a Dataset object.
read_eeg_dataset([channels, begin, end, ...])Read EEG data from the EDF file as TimeSeries object per EEG channel and return them collectively in an EegDataset object.
read_rso2_dataset(**kwargs)Read all NIRS-related signals into a Dataset object.
read_spo2_dataset(**kwargs)Read all arterial oxygen-related signals into a Dataset object.
read_temperature(**kwargs)Read temperature signal into a TimeSeries object.
read_time_series(channel[, begin, end, ...])Return time series object for given channel.
- read_bp_dataset(begin=0, end=None, patterns=None, **kwargs)[source]
Read all blood-pressure signals into a Dataset object.
- Parameters:
begin (float, optional) – begin time (in seconds) of the signal to read. By default reading starts at the beginning of the signal (i.e. at 0 seconds).
end (float, optional) – end time (in seconds) of the signal to read. By default reading ends at the end of the signal.
patterns (list) – optional list of patterns to look for in the EDF signal labels. If None, a default list of patterns will be used.
**kwargs (optional) – optional additional keyword arguments for self.read_time_series.
- Returns:
(nnsa.BaseDataset or list) – nnsa BaseDataset containing the signals from the EDF file. In case of EDF+D file and output == ‘all’, a list with BaseDataset objects is returned.
- read_eeg_dataset(channels=None, begin=0, end=None, exclude_channels=None, discontinuous_mode='longest', verbose=0, **kwargs)[source]
Read EEG data from the EDF file as TimeSeries object per EEG channel and return them collectively in an EegDataset object.
- Parameters:
channels (list, optional) – list of signal labels, specifying which channels to read. If None, all EEG channels are read. Default is None.
begin (float, optional) – begin time (in seconds) of the signal to read. By default reading starts at the beginning of the signal (i.e. at 0 seconds).
end (float, optional) – end time (in seconds) of the signal to read. By default reading ends at the end of the signal.
exclude_channels (list, optional) – list of signal labels, specifying which EEG channels not to read. If None, no EEG channels are excluded. Default is None.
discontinuous_mode (str, optional) – how to handle discontinuous data (EDF+D). If ‘longest’, return the longest continuous segment. If ‘all’, return a list of all continuous segments. If ‘fill’ or ‘full’, merge all sements filling up the gaps with nan. If ‘ignore’, the discontinuous signal is returned as if it is continuous. See also self._handle_discontinuous_signal(). Defaults to ‘longest’.
verbose (int) – verbosity level. If 1, a progress bar is shown.
**kwargs (optional) – optional keyword arguments for specifying TimeSeries parameters.
- Returns:
(nnsa.EegDataset or list) – nnsa EegDataset containing the EEG signals from the EDF file. In case of EDF+D file and output == ‘all’, a list with EegDataset objects is returned.
- read_rso2_dataset(**kwargs)[source]
Read all NIRS-related signals into a Dataset object.
- Parameters:
kwargs – optional keyword arguments for self.read_time_series().
- Returns:
(nnsa.OxygenDataset) – Dataset object with all NIRS signals.
- read_spo2_dataset(**kwargs)[source]
Read all arterial oxygen-related signals into a Dataset object.
- Parameters:
kwargs – optional keyword arguments for TimeSeries.
- Returns:
(nnsa.OxygenDataset) – Dataset object with all SaO2 signals.
- read_temperature(**kwargs)[source]
Read temperature signal into a TimeSeries object.
Raises an error if none or more than 1 temprature signal is found.
- Parameters:
kwargs – optional keyword arguments for self.read_time_series().
- Returns:
(nnsa.TimeSeries) – TimeSeries with temparature signal.
- read_time_series(channel, begin=0, end=None, discontinuous_mode='longest', efficiency='speed', **kwargs)[source]
Return time series object for given channel.
- Parameters:
channel (int or str) – the channel specifying the signal to read. May either be an integer specifying the order in which the signal appeard in the EDF file (i.e. index), or a string specifying the signal label.
begin (float, optional) – begin time (in seconds) of the signal to read. By default reading starts at the beginning of the signal (i.e. at 0 seconds).
end (float, optional) – end time (in seconds) of the signal to read. By default reading ends at the end of the signal.
discontinuous_mode (str, optional) – how to handle discontinuous data (EDF+D). If ‘longest’, return the longest continuous segment. If ‘all’, return a list of all continuous segments. If ‘fill’ or ‘full’, merge all sements filling up the gaps with nan. If ‘ignore’, the distontinuous signal is returned as if it is continuous. See also self._handle_discontinuous_signal(). Defaults to ‘longest’.
efficiency (str, optional) – the algorithm to use for reading: ‘speed’ uses an algorithm optimized for speed when loading a large portion of the signal (see _read_digital_data_max_speed), ‘memory’ uses an algorithm that requires the least amount of memory (see _read_digital_data_min_memory). Note that the ‘memory’ option may be faster than the ‘speed’ option when reading only a small part of the signal. However, when reading multiple times from the same file (e.g. read multiple signals), ‘speed’ is probably fastest, even when reading only small parts, since this algorithm stores the raw data of the entire file in memory the first time it’s called.
**kwargs (optional) – optional keyword arguments for the TimeSeries object.
- Returns:
(nnsa.TimeSeries or list) – TimeSeries object that holds the (specified part of the) data of the specified channel. In case of EDF+D file and output == ‘all’, a list with TimeSeries objects is returned.
nnsa.io.routines module
Code with some common routines.
Functions:
|
Helper function to read annotations from an EDF+ file as annotated by KL (using **). |
|
Helper function to read sleep labels from a dataframe for the preterm dataset. |
- nnsa.io.routines.read_annotation_set_KL(filepath)[source]
Helper function to read annotations from an EDF+ file as annotated by KL (using **).
- Parameters:
filepath (str) – filepath of the EDF+.
- Returns:
annotation_set (nnsa.AnnotationSet) – object containing the annotations from KL.
- nnsa.io.routines.read_annotation_set_preterm(df, filename, include_dubious_qs=False, training_only=False)[source]
Helper function to read sleep labels from a dataframe for the preterm dataset.
- Parameters:
df (pd.DataFrame) – dataframe with the contents of the xlsx file with the sleep labels (e.g. QS_labels_preterm_dataset.xlsx).
filename (str) – the EDF filename to extract the sleep labels of. This EDF filename should be in the dataframe as column ‘Filename’.
include_dubious_qs (bool, optional) – include the dubious QS segments (Dubious QS column in xlsx). Defaults to False.
training_only (bool, optional) – use only the QS segments used for training (Training column in xlsx). Defaults to False.
- Returns:
annotation_set (nnsa.AnnotationSet) – object containing the annotations.
Module contents
Package for reading/writing data files.