Skip to content

Python application to track physiological parameters during surgery

License

Notifications You must be signed in to change notification settings

MarinManuel/PhysioMonitor

Repository files navigation

PhysioMonitor

Python application to track physiological parameters during surgery.

It logs information about the subject of the experiment Mouse dialog screenshot and the drugs to be injected during the surgery. Note that the software has the ability to control syringe pumps to perform injections with the click of a button. Drug configuration dialog screenshot

Main screen showing the controls to inject drugs, and the graphs showing the physiological parameters logged during the surgery screenshot of the main window

Main window showing all the information automatically saved to a text log file. MainWindow-log

Configuration

The software needs a configuration file in JSON format to run. The global structure of the file is:

{
  "base-folder": str,
    The folder in which the logs are going to be saved
  "create-sub-folder": true|false,
    Whether to create a separate sub-folder for every day of experiment. If `true`, a new folder with the name 
    'YYYY-MM-DD/' will be created in base-folder
  "log-filename": str,
    This is the name of the file in which the surgical log 
    is saved (without path)
  "measurements-output-period-min": float,
    The period (in minutes) with which the trend measurements are written to the log file
  "acquisition-modules": list,
    This is a list of modules used for data acquisition.
    See list of supported modules and configuration options below
  "channels": list,
    List of channels and their configuration. See below for details
  "syringe-pump": 
    "serial-ports": list,
      This is a list of serial ports to open in order to communicate with the syringe pump(s).
      Contains a list of parameters to pass to serial.Serial(). See https://pythonhosted.org/pyserial/pyserial_api.html#native-ports
      for a complete list.
    "pumps": list
      List of syringe pumps and their configuration. See list of supported
      modules and their configuration below.
}

Data acquisition modules

Each element of the list must contain the following items:

{
  "module-name": str;
    Name of the module to use. See the list below
  "sampling-rate": float;
    Sampling rate for the acquisition (in Hz)
  "module-args": section;
    Section containing the parameters needed to create the modules. See below for each module's options.
}

Available data acquisition modules are:

"demo"

This module is intended for testing and debugging. It is a dummy modules that does not require external hardware. It reads a CSV file (or any file that can be parsed by numpy.loadtxt), and outputs the content at the given sampling rate.

The arguments to supply in "module-args" are:

  • filename - the path to the file to read (default ./media/file_streamer_data.txt)
  • genfromtxt_kws - optional arguments passed to numpy.genfromtxt. See the documentation for a list of possible arguments.

"nidaqmx"

This module allows the use of NI cards supported by the nidaqmx python library. Currently, only tested on Windows.

The arguments to supply in "module-args" are:

  • device - the name of the physical device to use (e.g. "Dev1")
  • channels- a list of physical channels to sample from (e.g. ["ai0","ai7","ai2"])
  • input_modes - a list (same length as channels) of terminal configurations (e.g. ["RSE", "MRSE", "DEFAULT"]). Valid configurations are DEFAULT, RSE, NRSE, DIFFERENTIAL and PSEUDODIFFERENTIAL.
  • buffer_size - size of the buffer used to store the data in between each read (default 1000).

"mcc"

This module allows the use of Measurement Computing devices supported by the MCC Universal Library (uldaq).

The arguments to supply in "module-args" are:

  • device - the device number (e.g. 0). This corresponds to the index of the device as returned by uldaq.get_daq_device_inventory(InterfaceType.ANY). See the documentation on device discovery for more information.
  • channels - a list of channel numbers to sample from (e.g. [0, 7, 3]).
  • input_modes - a list (same length as channels) of input modes (e.g. ['SINGLE_ENDED','SINGLE_ENDED','DIFFERENTIAL']). Valid input modes are DIFFERENTIAL,SINGLE_ENDED, and PSEUDO_DIFFERENTIAL.
  • input_ranges - a list (same length as channels) of input range (e.g. ['BIP5VOLTS', 'BIP10VOLTS', 'UNI10VOLTS']). See the documentation for a list of valid input ranges.
  • buffer_size - size of the buffer used to store the data in between each read (default 1000).

"comedi"

No longer supported under Python 3

Channel configuration

Each channel is configured by the following intructions:

  • acquisition-module-index - int - Index of the acquisition module to use for this channel (as defined by its position in the list of acquisition modules declared in the section "Data acquisition modules")
  • channel-index - int - Index corresponding to this channel's data in the relevant stream. WARNING: this is not the physical channel number as entered in channel list in the acquisition configuration, but the index of the channel in the list of channels.
  • window-size - float - Width of the window of data to display (in seconds).
  • label - string - Channel title.
  • units - string - Real world unit for the channel.
  • scale - float - used to convert the value in volts to the value in real worl units: Units = scale x volts + offset.
  • offset - float - used to convert the value in volts to the value in real worl units: Units = scale x volts + offset.
  • autoscale - true/false - Whether to automatically adjust the y-axis limit to fit with the data limits.
  • ymin - float - Lower y-axis limit. Only usefull if autoscale is off.
  • ymax - float - Upper y-axis linit. Only usefull if autoscale is off.
  • line-color - variable - color of the data line. Accepts any argument that can be passed to pyqtgraph.mkColor()
  • line-width - float - line thickness.
  • persistence - int - Number of past traces to keep. Older traces fade towards the background color.
  • trigger-mode - string - Sets whether new data is shown immediately upon reaching the right-hand side of the screen ('AUTO'), or whether the waveform must first cross a threshold value (see below) in the upward ('RISING') or downward direction ('FALLING').
  • trigger-level - float - Threshold value (in channel units).
  • auto-trigger-level - true/false - Whether the trigger threshold is automatically calculated based on the historical data. The value is calculated as 75% of the range of the data if the threshold mode is RISING, and 25% of the range if it is FALLING.
  • trend-window-size - float - Width of the window of trend data (in seconds).
  • trend-period - Period over which to calculate the trend value (in seconds).
  • trend-function - string - Function used to calculate the trend value. Valid values are:
    • 'HR' calculates heart rate based on QRS detection
    • 'max' returns the maximum of the data,
    • 'min' returns the minimum of the data,
    • 'lastPeak' returns the value of the latest detected peak in the data,
    • 'avgPeak' returns the average of the peak values detected in the data,
    • 'average' returns the average of the data
  • trend-function-args - arguments passed to trend-function. See the code for the trend_* functions in the GUI.scope module.
  • trend-units - string - Units of the trend data
  • trend-autoscale - true/false - Whether to automatically adjust the y-axis limit of the trend window to fit with the data limits.
  • trend-ymin - float - Lower y-axis limit of the trend window. Only usefull if autoscale is off.
  • trend-ymax - float - Lower y-axis limit of the trend window. Only usefull if autoscale is off.
  • alarm-enabled - true/false - Whether an alarm should sound when the trend data is outside the lower and higher limits.
  • alarm-low - float - The lower threshold for the alarm.
  • alarm-high - float - the upper threshold for the alarm.
  • alarm-sound-file - string - path to an OGG or a WAV sound file that is being played when the alarm is triggered.
  • alarmBGColor - var - Color of the window when the alarm is triggered.

Syringe Pumps

PhysioMonitor can control serial pumps through serial communication. Currently, the following models are supported:

Parameters:

serial-ports

list of serial ports to open. Each of the element contains parameters that can be passed to serial.Serial().

pumps

Each element of the list must contain the following items:

{
  "display-name": str,
    Name of the pump, displayed in various places in the GUI
  "module-name": str,
    Name of the module to use. One of "demo", "aladdin" or "model11plus".
  "serial-port": int,
    index of the serial port to use to control that syringe pump.
  "module-args": section,
    Section containing the parameters needed to create the modules. See below for each module's options.
}

Available modules are:

"dummy"

Fake pump, for testing purposes. "module-args" is empty

"aladdin"

Module for Aladdin syringe pumps.

The arguments to supply in "module-args" are:

  • adress: unique network address to identify the pump to the computer. Network addresses are from 00 to 99. If the network consists of only 1 pump, set the pump’s address to 0.

"modell11plus"

Module for Harvard Apparatus Model 11 plus (old model). "module-args" is empty.

"Harvard11ElitePump"

Module for Harvard Apparatus Model 11 Elite Single "module-args" is empty.

Installation

  1. create a virtual environement for PhysioMonitor:
$ python3 -m venv ~/physio-env
  1. clone the repository
$ git clone https://github.com/MarinManuel/PhysioMonitor.git
  1. install pre-requisites
$ physio-venv/bin/pip install -r PhysioMonitor/requirements.txt 
  1. edit PhysioMonitor.json
  2. run PhysioMonitor
cd ~/PhysioMonitor
~/physio-venv/bin/python ./PhysioMonitor.py -c ./PhysioMonitor.json

Install NI acquisition card

PhysioMonitor should work with any NI instrument card that works with the nidaqmx python module.

  1. Install the NI linux driver. See instruction at this location.
sudo apt install ./ni-ubuntu2004firstlook-drivers-stream.deb
sudo apt update
sudo apt install ni-daqmx
sudo dkms autoinstall
  1. reboot

About

Python application to track physiological parameters during surgery

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published