fmri-physio-log


Namefmri-physio-log JSON
Version 0.3.2 PyPI version JSON
download
home_pagehttps://github.com/andrewrosss/fmri-physio-log
SummaryParse Siemens PMU files
upload_time2024-01-23 03:41:02
maintainer
docs_urlNone
authorAndrew Ross
requires_python>=3.8.1,<4.0.0
licenseMIT
keywords mri siemens pmu
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # fmri-physio-log

Parse Siemens PMU files

[![PyPI Version](https://img.shields.io/pypi/v/fmri-physio-log.svg)](https://pypi.org/project/fmri-physio-log/) [![Tests](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/test.yaml/badge.svg)](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/test.yaml) [![Code Style](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/linter.yaml/badge.svg)](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/linter.yaml) [![Type Check](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/type-check.yaml/badge.svg)](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/type-check.yaml)

## Installation

```bash
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:

```text
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:

```python
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

```python
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)

```python
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:

- [https://cfn.upenn.edu/aguirre/wiki/doku.php?id=public:pulse-oximetry_during_fmri_scanning#pulse-ox_data](https://cfn.upenn.edu/aguirre/wiki/doku.php?id=public:pulse-oximetry_during_fmri_scanning#pulse-ox_data)
- [https://wiki.humanconnectome.org/display/PublicData/Understanding+Timing+Information+in+HCP+Physiological+Monitoring+Files](https://wiki.humanconnectome.org/display/PublicData/Understanding+Timing+Information+in+HCP+Physiological+Monitoring+Files)
- [https://gitlab.ethz.ch/physio/physio-doc/-/wikis/MANUAL_PART_READIN#manual-recording](https://gitlab.ethz.ch/physio/physio-doc/-/wikis/MANUAL_PART_READIN#manual-recording)
- [https://gist.github.com/rtrhd/6172344](https://gist.github.com/rtrhd/6172344)

## Contributing

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/andrewrosss/fmri-physio-log",
    "name": "fmri-physio-log",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.1,<4.0.0",
    "maintainer_email": "",
    "keywords": "mri,siemens,pmu",
    "author": "Andrew Ross",
    "author_email": "andrew.ross.mail@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/11/e3/bae4bc4d5b39c52a89b236d42079079c2e452ceb160be91830cbf2734921/fmri_physio_log-0.3.2.tar.gz",
    "platform": null,
    "description": "# fmri-physio-log\n\nParse Siemens PMU files\n\n[![PyPI Version](https://img.shields.io/pypi/v/fmri-physio-log.svg)](https://pypi.org/project/fmri-physio-log/) [![Tests](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/test.yaml/badge.svg)](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/test.yaml) [![Code Style](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/linter.yaml/badge.svg)](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/linter.yaml) [![Type Check](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/type-check.yaml/badge.svg)](https://github.com/andrewrosss/fmri-physio-log/actions/workflows/type-check.yaml)\n\n## Installation\n\n```bash\npip install fmri-physio-log\n```\n\n## Overview\n\nThis 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:\n\n```text\n1 8 20 2 367 508 520 532 638 708 790 5000 1037 1108 1072 1190 1413 5003\nECG  Freq Per: 0 0\nPULS Freq Per: 72 823\nRESP Freq Per: 0 0\nEXT  Freq Per: 0 0\nECG  Min Max Avg StdDiff: 0 0 0 0\nPULS Min Max Avg StdDiff: 355 1646 795 5\nRESP Min Max Avg StdDiff: 0 0 0 0\nEXT  Min Max Avg StdDiff: 0 0 0 0\nNrTrig NrMP NrArr AcqWin: 0 0 0 0\nLogStartMDHTime:  36632877\nLogStopMDHTime:   39805825\nLogStartMPCUTime: 36632400\nLogStopMPCUTime:  39804637\n6003\n```\n\n## Usage\n\nBy default, `PhysioLog` takes a string as the only parameter:\n\n```python\nimport fmri_physio_log as fpl\n\nCONTENT = \"\"\"\\\n1 8 20 2 5002 LOGVERSION 102 6002 5002 TRIGGERMETHOD 10 6002 367 508 520 532 638 708 790 5000 1037 1108 5002\n data that spans multiple lines ...\n6002 1072 1190 1413 5003\nECG  Freq Per: 0 0\nPULS Freq Per: 72 823\nRESP Freq Per: 0 0\nEXT  Freq Per: 0 0\nECG  Min Max Avg StdDiff: 0 0 0 0\nPULS Min Max Avg StdDiff: 355 1646 795 5\nRESP Min Max Avg StdDiff: 0 0 0 0\nEXT  Min Max Avg StdDiff: 0 0 0 0\nNrTrig NrMP NrArr AcqWin: 0 0 0 0\nLogStartMDHTime:  36632877\nLogStopMDHTime:   39805825\nLogStartMPCUTime: 36632400\nLogStopMPCUTime:  39804637\n6003\n\"\"\"\n\nlog = fpl.PhysioLog.from_string(CONTENT)\n\nlog.ts  # [367, 508, 520, 532, 638, 708, 790, 1037, 1108, 1072, 1190, 1413]\nlog.rate  # 20\nlog.params  # (1, 8, 20, 2)\nlog.info  # ['LOGVERSION 102', 'TRIGGERMETHOD 10', 'data that spans multiple lines ...']\n\nlog.ecg  # MeasurementSummary(freq=0, per=0, min=0, max=0, avg=0, std_diff=0)\nlog.puls  # MeasurementSummary(freq=72, per=823, min=355, max=1646, avg=795, std_diff=5)\nlog.resp  # MeasurementSummary(freq=0, per=0, min=0, max=0, avg=0, std_diff=0)\nlog.ext  # MeasurementSummary(freq=0, per=0, min=0, max=0, avg=0, std_diff=0)\nlog.ext2 # None - since no EXT2 data in this file; otherwise MeasurementSummary\n\nlog.nr  # NrSummary(nr_trig=0, nr_m_p=0, nr_arr=0, acq_win=0)\n\nlog.mdh  # LogTime(start=36632877, stop=39805825)\nlog.mpcu  # LogTime(start=36632400, stop=39804637)\n\n# For convenience the start and stop times are available\n# as python datetime.time objects as well\nlog.mdh.start_time  # datetime.time(10, 10, 32, 877000)\nlog.mdh.stop_time  # datetime.time(11, 3, 25, 825000)\nlog.mpcu.start_time  # datetime.time(10, 10, 32, 400000)\nlog.mpcu.stop_time  # datetime.time(11, 3, 24, 637000)\n```\n\n### From an open file\n\nA `PhysioLog` object can also be instantiated from an open file\n\n```python\nimport fmri_physio_log as fpl\n\nwith open(\"sample.puls\", \"r\") as f:\n    log = fpl.PhysioLog.from_file(f)\n```\n\n### From a path\n\nA `PhysioLog` object can also be instantiated from a file path (either as a string or a `pathlib.Path` object)\n\n```python\nfrom pathlib import Path\n\nimport fmri_physio_log as fpl\n\n# path as string\npath_s = \"/path/to/my/file.resp\"\nlog = fpl.PhysioLog.from_filename(path_s)\n\n# path as pathlib.Path object\npath = Path(path_s)\nlog = fpl.PhysioLog.from_filename(path)\n```\n\n## Implementation References\n\nThe following sources were referenced in constructing the grammar:\n\n- [https://cfn.upenn.edu/aguirre/wiki/doku.php?id=public:pulse-oximetry_during_fmri_scanning#pulse-ox_data](https://cfn.upenn.edu/aguirre/wiki/doku.php?id=public:pulse-oximetry_during_fmri_scanning#pulse-ox_data)\n- [https://wiki.humanconnectome.org/display/PublicData/Understanding+Timing+Information+in+HCP+Physiological+Monitoring+Files](https://wiki.humanconnectome.org/display/PublicData/Understanding+Timing+Information+in+HCP+Physiological+Monitoring+Files)\n- [https://gitlab.ethz.ch/physio/physio-doc/-/wikis/MANUAL_PART_READIN#manual-recording](https://gitlab.ethz.ch/physio/physio-doc/-/wikis/MANUAL_PART_READIN#manual-recording)\n- [https://gist.github.com/rtrhd/6172344](https://gist.github.com/rtrhd/6172344)\n\n## Contributing\n\n1. Have or install a recent version of `poetry` (version >= 1.1)\n1. Fork the repo\n1. Setup a virtual environment (however you prefer)\n1. Run `poetry install`\n1. Run `pre-commit install`\n1. Add your changes (adding/updating tests is always nice too)\n1. Commit your changes + push to your fork\n1. Open a PR\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Parse Siemens PMU files",
    "version": "0.3.2",
    "project_urls": {
        "Documentation": "https://github.com/andrewrosss/fmri-physio-log",
        "Homepage": "https://github.com/andrewrosss/fmri-physio-log",
        "Repository": "https://github.com/andrewrosss/fmri-physio-log"
    },
    "split_keywords": [
        "mri",
        "siemens",
        "pmu"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "453ecefc967e3ad668cdf9d6f9a103eb2d509829bc4b56efd574d54fa1d06371",
                "md5": "5b5cb5e8fb745c28741742b1655f116f",
                "sha256": "49f58a76efae80f5694faab3a2fd1b560abaae0252bae4a7cf91e2a6cd7dc333"
            },
            "downloads": -1,
            "filename": "fmri_physio_log-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5b5cb5e8fb745c28741742b1655f116f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.1,<4.0.0",
            "size": 33726,
            "upload_time": "2024-01-23T03:41:00",
            "upload_time_iso_8601": "2024-01-23T03:41:00.560480Z",
            "url": "https://files.pythonhosted.org/packages/45/3e/cefc967e3ad668cdf9d6f9a103eb2d509829bc4b56efd574d54fa1d06371/fmri_physio_log-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "11e3bae4bc4d5b39c52a89b236d42079079c2e452ceb160be91830cbf2734921",
                "md5": "1787f7118014c37545eba140748f003c",
                "sha256": "0eec6fa4eb075f01ba0f9aeec81cbf51d8c3656f165af4453cc786d5c1ef034b"
            },
            "downloads": -1,
            "filename": "fmri_physio_log-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "1787f7118014c37545eba140748f003c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.1,<4.0.0",
            "size": 34376,
            "upload_time": "2024-01-23T03:41:02",
            "upload_time_iso_8601": "2024-01-23T03:41:02.217168Z",
            "url": "https://files.pythonhosted.org/packages/11/e3/bae4bc4d5b39c52a89b236d42079079c2e452ceb160be91830cbf2734921/fmri_physio_log-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-23 03:41:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "andrewrosss",
    "github_project": "fmri-physio-log",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fmri-physio-log"
}
        
Elapsed time: 0.25006s