sleepless.data.utils#

Common utilities.

Functions

chan_list_to_dict(chan_list)

Handle list which are a mix of channel type and channel names.

get_samples_weights(dataset)

Compute the weights of all the samples of the dataset to balance the cross-entropy criterion.

plot_PSG_and_annotation(raw_obj, annot_obj)

Plot raw signal with annotation using MNE plot function.

saving_preprocess(dataset)

Classes

ComposeTransform(transforms)

ListSampleDataset(sample, normalize, pick_chan)

PyTorch dataset wrapper around Sample list.

sleepless.data.utils.plot_PSG_and_annotation(raw_obj, annot_obj)[source]#

Plot raw signal with annotation using MNE plot function.

class sleepless.data.utils.ComposeTransform(transforms)[source]#

Bases: object

sleepless.data.utils.saving_preprocess(dataset)[source]#
class sleepless.data.utils.ListSampleDataset(sample, normalize, pick_chan, n_past_epochs=0)[source]#

Bases: Dataset

PyTorch dataset wrapper around Sample list. This Class takes a py:class:DelayedSample`or :py:class:`Sample object and generate a object as torch.utils.data.dataset.Dataset where every sample of the dataset is defined as a list. It supports indexing such that dataset[i] can be used to get the i-th sample.

Parameters:
  • sample (DelayedSample | Sample) – sample to be wrap into the dataset object

  • normalize (bool) – if set to True, we remove the mean of data, and divided them by the standard deviation (it is done epoch (window) wise)

  • pick_chan (Optional[dict[str, bool | list[str]]]) – the channel type (e.g. “eeg”,”eog”) or name (e.g. “Fpz-Cz”) whom extract the features, if None default compute features for all EEG channels.

  • n_past_epochs (int) – it indicates how many past epochs to concatenate to the current sample epoch. E.g. if n_past_epochs = 1, then one past epoch is concatenated to the current.

sleepless.data.utils.get_samples_weights(dataset)[source]#

Compute the weights of all the samples of the dataset to balance the cross-entropy criterion. This function takes as input a torch.utils.data.dataset.Dataset and computes the weights to balance each class in the dataset and the datasets themselves if we have a ConcatDataset.

Parameters:

dataset (ConcatDataset | Dataset) – torch.utils.data.dataset.Dataset An instance of torch.utils.data.dataset.Dataset ConcatDataset are supported

Returns:

torch.Tensor the weights for all the samples in the dataset given as input

sleepless.data.utils.chan_list_to_dict(chan_list)[source]#

Handle list which are a mix of channel type and channel names. To be use then with the mne.pick_types()

Parameters:

chan_list (list[str]) – list of channel which can be channel type or channel names

Return type:

dict[str, bool | list[str]]

Returns:

dictionary where recognized channel types are assigned as key and their value set to true and other channels are expected to be channel names and are placed in a list, the key of this list is “include”. See mne.pick_types() for more information