biopsykit.io.psg module

Module for importing data recorded by a PSG system (expects .edf files).

class biopsykit.io.psg.PSGDataset(data_dict, sampling_rate_dict, start_time=None, tz=None)[source]

Bases: object

Class for loading and processing PSG data.

Parameters
classmethod from_edf_file(path, datastreams=None, tz='Europe/Berlin')[source]

Create a new Dataset from a valid .edf file.

Parameters
  • path (pathlib.Path or str) – Path to the .edf file

  • datastreams (Optional[Sequence], optional) – List of datastreams to load, by default None. If None, all datastreams are loaded.

  • tz (Optional[str], optional) – Timezone of the recording, by default “Europe/Berlin”.

Returns

PSGDataset

Return type

New Dataset instance

property start_time_unix: Optional[pandas._libs.tslibs.timestamps.Timestamp]

Start time of the recording in UTC time.

property start_time_datetime: Optional[pandas._libs.tslibs.timestamps.Timestamp]

Start time of the recording in UTC time.

property timezone: str

Timezone the dataset was recorded in.

data_as_df(index=None)[source]

Return data as one combined pandas.DataFrame.

Parameters

index (str, optional) – Specify which index should be used for the dataset. The options are: * “time”: For the time in seconds since the first sample * “utc”: For the utc time stamp of each sample * “utc_datetime”: for a pandas DateTime index in UTC time * “local_datetime”: for a pandas DateTime index in the timezone set for the session * None: For a simple index (0…N)

Returns

pd.DataFrame

Return type

Combined data as pandas DataFrame with respective index

load_ground_truth(path)[source]

Load ground truth data from a .xlsx file which can be exported from the Software Somnomedics.

Note

Other formats are not supported yet and raise a FileNotFoundError.

pathpathlib.Path or str

path to the .xlsx file

return: pd.DataFrame

ground truth data as pandas DataFrame

Parameters

path (biopsykit.utils._types.path_t) –

classmethod load_data_folder(folder_path, datastreams=None, timezone='Europe/Berlin')[source]

Load data from a folder containing a single .edf file.

Parameters
  • folder_path (pathlib.Path or str) – path to the folder containing the .edf file

  • datastreams (lst, optional) – list of datastreams to load. If None, all datastreams are loaded

  • timezone (str, optional) – timezone of the recording. If None, the timezone is set to UTC

Returns

  • data_dict (dict of datastreams)

  • fs (sampling rate)

  • start_time (start time of the recording)

Raises
classmethod load_data(path, datastreams=None, timezone='Europe/Berlin')[source]

Load PSG data from a valid .edf file.

Parameters
  • path (pathlib.Path or str) – path to the .edf file

  • datastreams (lst, optional) – list of datastreams to load. If None, all datastreams are loaded

  • timezone (str, optional) – timezone of the recording. If None, the timezone is set to UTC

Returns

  • data_dict (dict of datastreams)

  • fs (sampling rate)

  • start_time (start time of the recording)

Raises

Value Error – Not all datastreams are found in the .edf file:

classmethod load_data_raw(path, timezone='Europe/Berlin')[source]

Load PSG data from .edf file.

Parameters
  • path (pathlib.Path or str) – path to the .edf file

  • timezone (str, optional) – timezone of the recording. If None, the timezone is set to UTC

Returns

  • data (mne.io.Raw object)

  • fs (sampling rate)