Name | twixtools JSON |
Version |
0.23
JSON |
| download |
home_page | None |
Summary | file reader for Siemens twix(.dat)-files |
upload_time | 2025-02-12 09:35:21 |
maintainer | None |
docs_url | None |
author | None |
requires_python | <4,>=3.8 |
license | MIT License
Copyright (c) 2021 Philipp Ehses
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
keywords |
twix
siemens
mri
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# twixtools
[](https://github.com/pehses/twixtools/actions/workflows/test_action.yml)
### Purpose
twixtools provide reading and limited writing capability of Siemens MRI raw data files (.dat).
### Installation
Navigate to the twixtools folder in an open terminal and install twixtools with pip:
pip install .
Installation through `python setup.py install` is currently not possible.
### Demo code
A jupyter notebook that demonstrates the basic functionality of the `read_twix`, `map_twix`, and `write_twix` tools can be found in `demo/recon_example.ipynb`.
## read_twix: "low-level" access to twix data
The raw data file can be parsed using the read_twix function:
```python
import twixtools
multi_twix = twixtools.read_twix(filename)
```
The function returns a list of individual measurements (of length >=1). The last measurement usually corresponds to the imaging scan, earlier measurements often include calibration data. Each measurement contains a python dict() with the following entries:
* 'mdb': measurement data divided into blocks (return type: list)
* 'hdr': dict of parsed protocol header strings (each dict element contains another dict with protocol information)
* 'hdr_str': dict of original protocol header strings (divided into different protocol types)
- note that this is the protocol information that is used for twix file writing (by `write_twix`), so make sure to make necessary adjustments here and not in ['hdr']
* 'pmu': physiological (PMU) data (if available and parse_pmu is set to True)
* ('raidfile_hdr': required for twix file writing, otherwise of little importance)
Each invididual 'mdb' in the list of mdbs consists of a data and a header (line counters and such) part, which can be accessed as follows:
```python
mdb = multi_twix[-1]['mdb'][0] # first mdb element of last measurement
mdb.data # data of first mdb (may or may not be imaging data)
mdb.mdh # full miniheader information stored as a numpy dtype object
```
Different data types can be distinguished by returning a list of active flags, or by directly checking whether the data is assumed to be from an imaging scan (and not from a calibration scan such as a phase correction scan or a noise measurement):
```python
mdb.get_active_flags() # get all active MDH flags
mdb.is_image_scan() # check if this an image scan (True or False)
```
Line Counters can be accessed as follows:
```python
mdb.cLin # returns line number
mdb.cPar # returns partition number
mdb.c<tab> # with line completion enabled, this should give you a list of all counters
```
The full minidata header (mdh) information is stored in a `mdb.mdh` special numpy dtype object. You can print a list of its entry names by printing `mdb.mdh.dtype.names`.
### Example code
```python
import numpy as np
import twixtools
# read all image data from file
def read_image_data(filename):
out = list()
for mdb in twixtools.read_twix(filename)[-1]['mdb']:
if mdb.is_image_scan():
out.append(mdb.data)
return np.asarray(out) # 3D numpy array [acquisition_counter, n_channel, n_column]
# read image data from list of mdbs and sort into 3d k-space (+ coil dim.)
def import_kspace(mdb_list)
image_mdbs = []
for mdb in mdb_list:
if mdb.is_image_scan():
image_mdbs.append(mdb)
n_line = 1 + max([mdb.cLin for mdb in image_mdbs])
n_part = 1 + max([mdb.cPar for mdb in image_mdbs])
n_channel, n_column = image_mdbs[0].data.shape
out = np.zeros([n_part, n_line, n_channel, n_column], dtype=np.complex64)
for mdb in image_mdbs:
# '+=' takes care of averaging, but careful in case of other counters (e.g. echoes)
out[mdb.cPar, mdb.cLin] += mdb.data
return out # 4D numpy array [n_part, n_line, n_channel, n_column]
```
## map_twix: "high level" access to twix data
`map_twix` is a high-level function that takes the data obtained from `read_twix` (in the form of `Mdb` objects), and maps it to multi-dimensional "k-space" arrays. These `twix_array` objects are generated for different data types (image/noise adjust/phase-correction/... scan) and can be accessed with `numpy.ndarray` array-slicing syntax.
Optional flags control additional feature and also have an impact on size and shape of the multidimensional arrays. The following flags are currently available (stored in the `flags` dict within each `twix_array` object):
* `average`: dict of bools that determines which dimensions should be averaged.
* `squeeze_ave_dims`: bool that determines whether averaged dimensions should be removed/squeezed from the array's shape.
* `remove_os`: oversampling removal. Reduces the number of columns by a factor of two.
* `regrid`: bool that controls ramp-sampling regridding (if applicable)
* `skip_empty_lead`: skips to first line & partition that is found in mdb list (e.g. if first line counter is 10, the output array starts at line counter 10).
* `zf_missing_lines`: zero-fill k-space to include lines and partitions that are higher than the maximum counter found in the mdb list, but are still within the k-space matrix according to the twix header.
If available, physiological (PMU) data is stored in the returned dict under the 'pmu' key.
For example code, please look at the `demo/recon_example.ipynb` jupyter file.
## Acknowledgements
The protocol header parsing code originates from William Clarke's excellent pymapvbvd project (https://github.com/wexeee/pymapvbvd).
Raw data
{
"_id": null,
"home_page": null,
"name": "twixtools",
"maintainer": null,
"docs_url": null,
"requires_python": "<4,>=3.8",
"maintainer_email": null,
"keywords": "twix, siemens, mri",
"author": null,
"author_email": "Philipp Ehses <philipp.ehses@dzne.de>",
"download_url": "https://files.pythonhosted.org/packages/74/d0/872ff966d4ab0e861686658d6bd7eaff31dfb1faf465eb827bf2d7f187d9/twixtools-0.23.tar.gz",
"platform": null,
"description": "# twixtools\n\n[](https://github.com/pehses/twixtools/actions/workflows/test_action.yml)\n\n### Purpose\n\ntwixtools provide reading and limited writing capability of Siemens MRI raw data files (.dat).\n\n\n### Installation\n\nNavigate to the twixtools folder in an open terminal and install twixtools with pip:\n\n pip install .\n\nInstallation through `python setup.py install` is currently not possible.\n\n\n### Demo code\n\nA jupyter notebook that demonstrates the basic functionality of the `read_twix`, `map_twix`, and `write_twix` tools can be found in `demo/recon_example.ipynb`.\n\n\n## read_twix: \"low-level\" access to twix data\n\nThe raw data file can be parsed using the read_twix function:\n\n```python\nimport twixtools\nmulti_twix = twixtools.read_twix(filename)\n```\n\nThe function returns a list of individual measurements (of length >=1). The last measurement usually corresponds to the imaging scan, earlier measurements often include calibration data. Each measurement contains a python dict() with the following entries:\n\n* 'mdb': measurement data divided into blocks (return type: list)\n* 'hdr': dict of parsed protocol header strings (each dict element contains another dict with protocol information)\n* 'hdr_str': dict of original protocol header strings (divided into different protocol types)\n - note that this is the protocol information that is used for twix file writing (by `write_twix`), so make sure to make necessary adjustments here and not in ['hdr']\n* 'pmu': physiological (PMU) data (if available and parse_pmu is set to True)\n* ('raidfile_hdr': required for twix file writing, otherwise of little importance)\n\n\nEach invididual 'mdb' in the list of mdbs consists of a data and a header (line counters and such) part, which can be accessed as follows:\n\n```python\nmdb = multi_twix[-1]['mdb'][0] # first mdb element of last measurement\nmdb.data # data of first mdb (may or may not be imaging data)\nmdb.mdh # full miniheader information stored as a numpy dtype object\n ```\n\nDifferent data types can be distinguished by returning a list of active flags, or by directly checking whether the data is assumed to be from an imaging scan (and not from a calibration scan such as a phase correction scan or a noise measurement):\n\n```python\nmdb.get_active_flags() # get all active MDH flags\nmdb.is_image_scan() # check if this an image scan (True or False)\n```\n\nLine Counters can be accessed as follows:\n```python\nmdb.cLin # returns line number\nmdb.cPar # returns partition number\nmdb.c<tab> # with line completion enabled, this should give you a list of all counters\n```\n\nThe full minidata header (mdh) information is stored in a `mdb.mdh` special numpy dtype object. You can print a list of its entry names by printing `mdb.mdh.dtype.names`.\n\n\n### Example code\n```python\nimport numpy as np\nimport twixtools\n\n# read all image data from file\ndef read_image_data(filename):\n out = list()\n for mdb in twixtools.read_twix(filename)[-1]['mdb']:\n if mdb.is_image_scan():\n out.append(mdb.data)\n return np.asarray(out) # 3D numpy array [acquisition_counter, n_channel, n_column]\n\n\n# read image data from list of mdbs and sort into 3d k-space (+ coil dim.)\ndef import_kspace(mdb_list)\n image_mdbs = []\n for mdb in mdb_list:\n if mdb.is_image_scan():\n image_mdbs.append(mdb)\n\n n_line = 1 + max([mdb.cLin for mdb in image_mdbs])\n n_part = 1 + max([mdb.cPar for mdb in image_mdbs])\n n_channel, n_column = image_mdbs[0].data.shape\n\n out = np.zeros([n_part, n_line, n_channel, n_column], dtype=np.complex64)\n for mdb in image_mdbs:\n # '+=' takes care of averaging, but careful in case of other counters (e.g. echoes)\n out[mdb.cPar, mdb.cLin] += mdb.data\n\n return out # 4D numpy array [n_part, n_line, n_channel, n_column]\n```\n\n## map_twix: \"high level\" access to twix data\n`map_twix` is a high-level function that takes the data obtained from `read_twix` (in the form of `Mdb` objects), and maps it to multi-dimensional \"k-space\" arrays. These `twix_array` objects are generated for different data types (image/noise adjust/phase-correction/... scan) and can be accessed with `numpy.ndarray` array-slicing syntax.\n\n\nOptional flags control additional feature and also have an impact on size and shape of the multidimensional arrays. The following flags are currently available (stored in the `flags` dict within each `twix_array` object):\n * `average`: dict of bools that determines which dimensions should be averaged.\n * `squeeze_ave_dims`: bool that determines whether averaged dimensions should be removed/squeezed from the array's shape.\n * `remove_os`: oversampling removal. Reduces the number of columns by a factor of two.\n * `regrid`: bool that controls ramp-sampling regridding (if applicable)\n * `skip_empty_lead`: skips to first line & partition that is found in mdb list (e.g. if first line counter is 10, the output array starts at line counter 10).\n * `zf_missing_lines`: zero-fill k-space to include lines and partitions that are higher than the maximum counter found in the mdb list, but are still within the k-space matrix according to the twix header.\n\nIf available, physiological (PMU) data is stored in the returned dict under the 'pmu' key.\n\nFor example code, please look at the `demo/recon_example.ipynb` jupyter file.\n\n## Acknowledgements\n\nThe protocol header parsing code originates from William Clarke's excellent pymapvbvd project (https://github.com/wexeee/pymapvbvd).\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2021 Philipp Ehses\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n ",
"summary": "file reader for Siemens twix(.dat)-files",
"version": "0.23",
"project_urls": {
"Homepage": "https://github.com/pehses/twixtools",
"Issues": "https://github.com/pehses/twixtools/issues"
},
"split_keywords": [
"twix",
" siemens",
" mri"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "5da664f52aed4a94a54a5c0037511433587a6b72d1d7d2cadf0cf967b6360112",
"md5": "8575c2324715d298c09a6d458ef82e37",
"sha256": "46ac4212d276a7b248a0bef41e97b9fade8f8011fb2db15a4fb9e0703aa98908"
},
"downloads": -1,
"filename": "twixtools-0.23-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8575c2324715d298c09a6d458ef82e37",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4,>=3.8",
"size": 36225,
"upload_time": "2025-02-12T09:35:20",
"upload_time_iso_8601": "2025-02-12T09:35:20.156152Z",
"url": "https://files.pythonhosted.org/packages/5d/a6/64f52aed4a94a54a5c0037511433587a6b72d1d7d2cadf0cf967b6360112/twixtools-0.23-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "74d0872ff966d4ab0e861686658d6bd7eaff31dfb1faf465eb827bf2d7f187d9",
"md5": "491b3dda0d40c4aef172d7b4c6ced64d",
"sha256": "8d6c99077a722e1f718cf46044f03b3a3d139ee35caadd6eda71ede54fbb924c"
},
"downloads": -1,
"filename": "twixtools-0.23.tar.gz",
"has_sig": false,
"md5_digest": "491b3dda0d40c4aef172d7b4c6ced64d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.8",
"size": 1746142,
"upload_time": "2025-02-12T09:35:21",
"upload_time_iso_8601": "2025-02-12T09:35:21.637495Z",
"url": "https://files.pythonhosted.org/packages/74/d0/872ff966d4ab0e861686658d6bd7eaff31dfb1faf465eb827bf2d7f187d9/twixtools-0.23.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-12 09:35:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pehses",
"github_project": "twixtools",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "twixtools"
}