Skip to main content

Parse Siemens PMU files

Project description

fmri-physio-log

Parse Siemens PMU files

PyPI Version

Installation

pip install fmri-physio-log

Overview

This small library parses and loads Siemens PMU files into python. These are *.puls, *.resp, *.ecg and *.ext files produced by the Siemens Physiological Monitoring Unit (PMU) which look something like:

1 8 20 2 367 508 520 532 638 708 790 5000 1037 1108 1072 1190 1413 5003
ECG  Freq Per: 0 0
PULS Freq Per: 72 823
RESP Freq Per: 0 0
EXT  Freq Per: 0 0
ECG  Min Max Avg StdDiff: 0 0 0 0
PULS Min Max Avg StdDiff: 355 1646 795 5
RESP Min Max Avg StdDiff: 0 0 0 0
EXT  Min Max Avg StdDiff: 0 0 0 0
NrTrig NrMP NrArr AcqWin: 0 0 0 0
LogStartMDHTime:  36632877
LogStopMDHTime:   39805825
LogStartMPCUTime: 36632400
LogStopMPCUTime:  39804637
6003

Usage

By default, PhysioLog takes a string as the only parameter:

import fmri_physio_log as fpl

CONTENT = """\
1 8 20 2 5002 LOGVERSION 102 6002 5002 TRIGGERMETHOD 10 6002 367 508 520 532 638 708 790 5000 1037 1108 5002
 data that spans multiple lines ...
6002 1072 1190 1413 5003
ECG  Freq Per: 0 0
PULS Freq Per: 72 823
RESP Freq Per: 0 0
EXT  Freq Per: 0 0
ECG  Min Max Avg StdDiff: 0 0 0 0
PULS Min Max Avg StdDiff: 355 1646 795 5
RESP Min Max Avg StdDiff: 0 0 0 0
EXT  Min Max Avg StdDiff: 0 0 0 0
NrTrig NrMP NrArr AcqWin: 0 0 0 0
LogStartMDHTime:  36632877
LogStopMDHTime:   39805825
LogStartMPCUTime: 36632400
LogStopMPCUTime:  39804637
6003
"""

log = fpl.PhysioLog.from_string(CONTENT)

log.ts  # [367, 508, 520, 532, 638, 708, 790, 1037, 1108, 1072, 1190, 1413]
log.rate  # 20
log.params  # (1, 8, 20, 2)
log.info  # ['LOGVERSION 102', 'TRIGGERMETHOD 10', 'data that spans multiple lines ...']

log.ecg  # MeasurementSummary(freq=0, per=0, min=0, max=0, avg=0, std_diff=0)
log.puls  # MeasurementSummary(freq=72, per=823, min=355, max=1646, avg=795, std_diff=5)
log.resp  # MeasurementSummary(freq=0, per=0, min=0, max=0, avg=0, std_diff=0)
log.ext  # MeasurementSummary(freq=0, per=0, min=0, max=0, avg=0, std_diff=0)
log.ext2 # None - since no EXT2 data in this file; otherwise MeasurementSummary

log.nr  # NrSummary(nr_trig=0, nr_m_p=0, nr_arr=0, acq_win=0)

log.mdh  # LogTime(start=36632877, stop=39805825)
log.mpcu  # LogTime(start=36632400, stop=39804637)

# For convenience the start and stop times are available
# as python datetime.time objects as well
log.mdh.start_time  # datetime.time(10, 10, 32, 877000)
log.mdh.stop_time  # datetime.time(11, 3, 25, 825000)
log.mpcu.start_time  # datetime.time(10, 10, 32, 400000)
log.mpcu.stop_time  # datetime.time(11, 3, 24, 637000)

From an open file

A PhysioLog object can also be instantiated from an open file

import fmri_physio_log as fpl

with open("sample.puls", "r") as f:
    log = fpl.PhysioLog.from_file(f)

From a path

A PhysioLog object can also be instantiated from a file path (either as a string or a pathlib.Path object)

from pathlib import Path

import fmri_physio_log as fpl

# path as string
path_s = "/path/to/my/file.resp"
log = fpl.PhysioLog.from_filename(path_s)

# path as pathlib.Path object
path = Path(path_s)
log = fpl.PhysioLog.from_filename(path)

Implementation References

The following sources were referenced in constructing the grammar:

Contributing

  1. Have or install a recent version of poetry (version >= 1.8)
  2. Fork the repo
  3. Setup a virtual environment (however you prefer)
  4. Run poetry install
  5. Run pre-commit install
  6. Add your changes (adding/updating tests is always nice too)
  7. Commit your changes + push to your fork
  8. Open a PR

[!IMPORTANT] If you are marking changes to the grammar (src/grammar.lark), you will need to regenerate the parser (src/fmri_physio_log/_generated.py) which can be done by running lark, for example:

python -m lark.tools.standalone src/grammar.lark > src/fmri_physio_log/_generated.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fmri_physio_log-0.3.3.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

fmri_physio_log-0.3.3-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

Details for the file fmri_physio_log-0.3.3.tar.gz.

File metadata

  • Download URL: fmri_physio_log-0.3.3.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.4 Linux/6.5.0-1022-azure

File hashes

Hashes for fmri_physio_log-0.3.3.tar.gz
Algorithm Hash digest
SHA256 e9769c24b99d28f74165357ac40923e985f2406192573200170b931e81e746da
MD5 e7f1ea25622193b2eacffb539fd4914f
BLAKE2b-256 9b3ffa397c228b99f45965950edd002184cbd7e368098d3251428b8823ab7b02

See more details on using hashes here.

File details

Details for the file fmri_physio_log-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: fmri_physio_log-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 35.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.4 Linux/6.5.0-1022-azure

File hashes

Hashes for fmri_physio_log-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 475ec13f7586336e8a9dd6bb97537b062c4ed714b5623a7277dfbeeed6d3b48a
MD5 77cca8261d0f0b6915cc728acad455eb
BLAKE2b-256 6fbeee020c9f0432daa87e67bec6b4aec00b4c876989b263f891441a298b542d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page