Closed nathanielatom closed 1 month ago
Update: it is possible to read directly in python (3.8) with the underlying functions in the readPhilipsExports
module. Here's an example function that reads .data and .list files directly in python.
import numpy as np
from collections import namedtuple
RawData = namedtuple('RawData', ['header', 'k_space', 'k_space_legend', 'noise', 'noise_legend', 'phase_correction', 'phase_correction_legend'])
def read_philips(filename, **kwargs):
"""
Reads raw Philips MRI k-space and header data from the specified file(s).
Parameters
----------
filename : str
The path to the .data file to be read. The filename should have a corresponding .list file.
**kwargs : dict
Additional keyword arguments to be passed to the `philips.fileIO.readPhilipsExports.readData` function,
including `chop_ky`, `prop_TSE`, `prop_GRASE` boolean arguments, which default to False.
Returns
-------
RawData: namedtuple containing the following ordered attributes:
- header: The header information from the corresponding .list file.
- k_space: The k-space data as a multidimensional complex64 numpy array.
- k_space_legend: A list containing the legend for the k-space data axes.
- noise: The noise data as a multidimensional complex64 numpy array.
- noise_legend: A list containing the legend for the noise data axes.
- phase_correction: The phase correction data as a multidimensional complex64 numpy array.
- phase_correction_legend: A list containing the legend for the phase correction data axes.
Notes
-----
This function uses the closed source `philips.fileIO.readPhilipsExports` module to read the data.
Available at: https://github.com/gpilab/philips-data-reader
"""
try:
import philips.fileIO.readPhilipsExports as phil
except ImportError as error:
if 'bad magic number' in str(error):
message = 'Please ensure you are using Python 3.8'
raise ImportError(message) from error
raise error
except ModuleNotFoundError as error:
message = ('Please download the philips-data-reader binary from:'
'https://github.com/gpilab/philips-data-reader')
raise ModuleNotFoundError(message) from error
kwargs.setdefault('chop_ky', False)
kwargs.setdefault('prop_TSE', False)
kwargs.setdefault('prop_GRASE', False)
kwargs.setdefault('cur_coil', -1)
kwargs.setdefault('cur_loc', -1)
data = phil.readData(filename, filename.replace('.data', '.list'), **kwargs)
k_space = np.squeeze(data[0].view(np.complex64))
k_space_legend = data[4].tolist()
noise = data[1].view(np.complex64)
noise_legend = data[5].tolist()
phase_correction = np.squeeze(data[2].view(np.complex64))
phase_correction_legend = data[6].tolist()
header = data[3]
return RawData(header, k_space, k_space_legend, noise, noise_legend, phase_correction, phase_correction_legend)
Hi! With gpi 1.4.8 the following command gets an error from being unable to find the ReadPhilips node (despite LIB_DIRS in .gpirc being correctly configured to specify the
~/.miniconda/envs/gpi/lib/gpi
folder).gpi --nogui ~/.miniconda/envs/gpi/lib/gpi/philips/networks/readPhilips_Imaging_raw.net -s filename:raw_000.data --log=debug
When I create my own network in the GUI, I can export .npz files (but I can't attach a String to the input filename for ReadPhilips to run as command for batch processing). Any chance there's a python-importable function to get the arrays and dicts directly in code without ever using GPI?
Here's the output: