Quick Start
Install
The MRD Python library requires Python >= 3.9 and NumPy >= 1.22.0.
Anaconda
We recommend using the mrd-python
Anaconda package, which can be installed using conda
or mamba
:
bash
$ mamba install ismrmrd:mrd-python
PyPI
You can also install mrd-python
from PyPI, e.g. using pip
:
bash
$ python3 -m pip install mrd-python
Reading and Writing MRD streams
To read and write MRD streams, start with the following example:
py
import mrd
# Produce Acquisitions via a Python generator - simulating a stream
def generate_data():
nreps = 2
for _ in range(nreps):
acq = mrd.Acquisition()
# Populate Acquisition
# ...
yield mrd.StreamItem.Acquisition(acq)
header = mrd.Header()
# Populate Header
# ...
with mrd.BinaryMrdWriter("test.bin") as w:
w.write_header(header)
w.write_data(generate_data())
with mrd.BinaryMrdReader("test.bin") as r:
header = r.read_header()
data_stream = r.read_data()
for item in data_stream:
# Process StreamItem (Acquisition, Image, or Waveform)
# ...
pass
Examples
See python/mrd/tools
in the MRD repository for example programs using the mrd
package.
These tools are also installed as Python modules in the mrd.tools
package when mrd-python
is installed from Anaconda or PyPI.
For example, to generate a cartesian Shepp-Logan phantom:
bash
$ python -m mrd.tools.phantom --coils 8 --matrix 256 > phantom.bin