API Reference#

exception nkpy.CorruptionError#

Exception raised when reading an Excel file fails.

This is fixed by opening the file with Excel manually and saving it with no modifications (CTRL+S).

class nkpy.EEGFile(path, start, end, exam_number)#

Represent an eeg file in the Nihon Kohden’s NeuroWorkbench database.

These do not need to be created manually, and are instead returned by the read_excel() and read_excels() functions.

Parameters:
  • path (Path)

  • start (datetime)

  • end (datetime)

  • exam_number (str)

path#

Full path to the eeg file.

Type:

pathlib.Path

start#

Start time of the recording.

Type:

datetime.datetime

end#

End time of the recording.

Type:

datetime.datetime

exam_number#

The exam number of the EEG recording

Type:

str

class nkpy.Patient(patient_id, patient_name, sex, birth_date, eegs=<factory>, videos=<factory>)#

Represent a patient in the Nihon Kohden’ NeuroWorkbench database.

These do not need to be created manually, and are instead returned by the read_excel() and read_excels() functions.

Parameters:
patient_id#

CHUM’s patient ID (usually in the format Sxxxxxxxx with x being digits).

Type:

str

patient_name#

The name of the patient, in the LAST NAME, FIRST NAME format.

Type:

str

sex#

Biological sex of the patient (“Male”, “Female”, “Unknown”).

Type:

str

birth_date#

The date of birth of the patient.

Type:

datetime.datetime

eegs#

A list of EEGFile, containing information about every EEG recording.

Type:

list[EEGFile]

videos#

A list of VideoFile, containing information about every video recording.

Type:

list[VideoFile]

class nkpy.VideoFile(path, start, end, clipped)#

Represent a video file in the Nihon Kohden’s NeuroWorkbench database.

These do not need to be created manually, and are instead returned by the read_excel() and read_excels() functions.

Parameters:
  • path (Path)

  • start (datetime)

  • end (datetime)

  • clipped (bool)

path#

Full path to the video file.

Type:

pathlib.Path

start#

Start time of the recording.

Type:

datetime.datetime

end#

End time of the recording.

Type:

datetime.datetime

clipped#

If the video is a clipped event (True) or a full recording (False).

Type:

bool

nkpy.get_patient_eegs(patient, before=None, after=None)#

Select the eegs from a Patient that are within a time range.

Parameters:
  • patient (Patient) – The Patient object from which we want to select the EEGFile.

  • before (datetime.datetime | None, optional) – The datetime.datetime which we want the eegs that are before that moment. If None, select all eegs up to the end of the recordings. By default None.

  • after (datetime.datetime | None, optional) – The datetime.datetime which we want the eegs that are after that moment. If None, select all eegs from the start of the recordings. By default None.

Returns:

List of the selected EEGFile.

Return type:

list[EEGFile]

nkpy.get_patient_videos(patient, before=None, after=None)#

Select the videos from a Patient that are within a time range.

Parameters:
  • patient (Patient) – The Patient object from which we want to select the VideoFile.

  • before (datetime.datetime | None, optional) – The datetime.datetime which we want the videos that are before that moment. If None, select all videos up to the end of the recordings. By default None.

  • after (datetime.datetime | None, optional) – The datetime.datetime which we want the videos that are after that moment. If No``None``ne, select all videos from the start of the recordings. By default None.

Returns:

List of the selected VideoFile.

Return type:

list[VideoFile]

nkpy.read_excel(filename)#

Read an Excel sheet exported from Nihon Kohden’s NeuroWorkbench

Parameters:

filename (str | pathlib.Path) – The path to the Excel file, exported from NeuroWorkbench.

Returns:

A dictionnary of patient IDs to Patient objects.

Return type:

PatientDict

Raises:

CorruptionError – Can happen in some cases where the Excel file cannot be read. It can be fixed by opening the file in Excel, and saving it as-is (CTRL+S).

nkpy.read_excels(*filenames)#

Read multiple Excel files exported from Nihon Kohden’s NeuroWorkbench and return the data into a single PatientDict.

Parameters:

*filenames (str | pathlib.Path) – A sequence of paths to the Excel files, exported from NeuroWorkbench.

Returns:

A dictionnary of patient IDs to Patient objects.

Return type:

PatientDict

Raises:

CorruptionError – Can happen in some cases where the Excel file cannot be read. It can be fixed by opening the file in Excel, and saving it as-is (CTRL+S).

type nkpy.PatientDict#

A type alias for dict[str, Patient]