Skip to content

MRIFiles ​

MRIFiles handles raw data files, for example ISMRMRD files (ISMRMRDFile) and Bruker datasets (BrukerFile). MRIFiles depends on MRIBase. It has to be loaded with using MRIFiles, because MRIReco does not depend on it. The guide Load and Save Raw Data shows how to use these file types.

ISMRMRD Files ​

MRIFiles.ISMRMRDFile Type
julia
ISMRMRDFile(filename::String)

reference to the file filename in the ISMRMRD format, an HDF5 file with an XML header and the acquired profiles. Creating an ISMRMRDFile does not open the file. RawAcquisitionData and AcquisitionData read the file, and MRIFiles.save writes it.

Examples

julia
f = ISMRMRDFile("scan.h5")
raw = RawAcquisitionData(f)
MRIFiles.save(ISMRMRDFile("copy.h5"), raw)
source
MRIBase.RawAcquisitionData Method
julia
RawAcquisitionData(f::ISMRMRDFile, dataset="dataset"; slice=nothing, repetition=nothing, contrast=nothing)

reads the ISMRMRDFile f and stores the result in a RawAcquisitionData object. With slice, repetition or contrast, only the profiles whose encoding counter has the given value, or one of the given values, are read. The counters start at 0.

source
MRIBase.AcquisitionData Method
julia
AcquisitionData(f::ISMRMRDFile, dataset="dataset")

reads the ISMRMRDFile f and converts the result into an AcquisitionData object, as AcquisitionData(RawAcquisitionData(f, dataset)) does. All profiles are read, also noise measurements, which can then take the place of image profiles in the k-space data, see Select and Prepare Profiles. To select or remove profiles before the conversion, for example with remove_raw_by_flags, or to pass keyword arguments to the conversion, read the file with RawAcquisitionData first.

source
FileIO.save Method
julia
save(f::ISMRMRDFile, acq::RawAcquisitionData, dataset="dataset")

writes the raw data acq to the ISMRMRD file f: the header parameters acq.params as the XML header and the profiles as the acquisitions of the HDF5 group dataset. An existing file is replaced as a whole, together with its other groups. Header parameters that MRIFiles does not know are left out, and elements that the ISMRMRD schema requires, such as reconSpace and encodingLimits, are written only if acq.params has their values, which raw data from a Bruker dataset doesn't. MRIFiles does not export save, a function of FileIO, so call it as MRIFiles.save. To save AcquisitionData, convert it with RawAcquisitionData first.

source

Bruker Datasets ​

MRIFiles.BrukerFile Type
julia
BrukerFile(path::String; maxEntriesAcqp=2000)

reference to a Bruker ParaVision dataset, the folder path of one scan. The folder contains the parameter files acqp and method, the raw data (fid for ParaVision 6, rawdata.job0 for ParaVision 360) and the reconstructions of the scanner in the subfolder pdata. Creating a BrukerFile reads nothing.

b[name] returns the parameter name as JcampdxFile reads it, for example a string or an array of strings, or an empty string if the parameter is not found. If the file of the parameter was not read yet, it is read first: acqp for names starting with ACQ or GO and for NA, NR, NI, NSLICES and SW, the file visu_pars of the first reconstruction for names starting with Visu, mpi.par for names starting with CONFIG, and method for other names. Other parameters of acqp, such as SW_h, are therefore found only after acqp was read, and other names with fewer than three characters, such as RG, throw a BoundsError until then. Only the first maxEntriesAcqp - 1 parameters of acqp are read.

b[name, procno] returns a parameter of the reconstruction pdata/procno, read from its file visu_pars for names starting with Visu, from reco for names starting with reco in any case and from methreco for names starting with PVM. The parameters of all reconstructions read so far are kept together: a parameter that pdata/procno lacks, or a procno without visu_pars, returns the value of a reconstruction read before, and only a parameter that none of them has throws a KeyError. reco, of which only the first 12 parameters are read, and methreco are read only for the first procno asked for.

Read the raw data with RawAcquisitionData and the images of the scanner with recoData.

Examples

julia
b = BrukerFile("study/12")
b["PVM_Matrix"]       # matrix size, for example ["128", "128"]
raw = RawAcquisitionData(b)
source
MRIBase.RawAcquisitionData Method
julia
RawAcquisitionData(b::BrukerFile)

reads the raw data of the Bruker dataset b into a RawAcquisitionData object. Data from ParaVision 360 is read with RawAcquisitionDataFid_360. From other versions, such as ParaVision 6, scans whose ACQ_protocol_name is UTE3D are read with RawAcquisitionData_3DUTE and other scans as Cartesian data from the file fid. Scans whose ACQ_protocol_name is SPIRAL are not supported: for them, the function returns the contents of rawdata.job0 as an array. The header parameters, such as the matrix size and the field of view, come from the parameter files, also from visu_pars, so the subfolder pdata has to exist. For Cartesian data of ParaVision 6, the encoded size is the acquired size from ACQ_size, which can be smaller than the image size PVM_Matrix of the scanner's reconstruction. Each profile holds one readout of all receive channels.

AcquisitionData does not accept a BrukerFile; convert the result with AcquisitionData(RawAcquisitionData(b)).

source
MRIFiles.RawAcquisitionDataFid_360 Function
julia
RawAcquisitionDataFid_360(b::BrukerFile)

reads Cartesian raw data of ParaVision 360 from the file rawdata.job0 of the Bruker dataset b into a RawAcquisitionData object. The matrix size is PVM_Matrix times PVM_AntiAlias, and the k-space position of each profile is taken from PVM_EncGenSteps1 and PVM_EncGenSteps2, so scans with undersampled phase encoding are read as well. RawAcquisitionData(b) calls this function for all ParaVision 360 datasets.

source
MRIFiles.RawAcquisitionData_3DUTE Function
julia
RawAcquisitionData_3DUTE(b::BrukerFile)

reads a 3D UTE scan of ParaVision 6 from the files fid and traj of the Bruker dataset b into a RawAcquisitionData object with the trajectory "custom". Each profile holds one center-out radial spoke together with its k-space positions. RawAcquisitionData(b) calls this function for scans whose ACQ_protocol_name is UTE3D; call it directly for 3D UTE scans of ParaVision 6 with another protocol name.

source
MRIFiles.recoData Function
julia
recoData(f::BrukerFile, procno::Int=1)

reads the images that the scanner reconstructed from the file pdata/procno/2dseq of the Bruker dataset f and returns them as an Array{Float32} of size (VisuCoreSize..., VisuCoreFrameCount). The values are returned as stored, without the scaling of each frame by f["VisuCoreDataSlope", procno] and f["VisuCoreDataOffs", procno] (value = stored value × slope + offset). The frames are in the order of the file, with the first frame group of VisuFGOrderDesc varying fastest: for a complex reconstruction with the frame groups FG_COIL and FG_COMPLEX, all real frames come first. VisuCoreDiskSliceOrder is not applied, so the slices can be in reverse order, and the dimensions follow the layout of 2dseq, which can differ from the order of PVM_Matrix. If the file does not exist, recoData logs an error and returns nothing.

source
MRIFiles.JcampdxFile Type
julia
JcampdxFile()

empty set of parameters from files in the JCAMP-DX format, which Bruker ParaVision uses for its parameter files, for example acqp, method and visu_pars. read(j, filename) adds the parameters of a file to j and returns j, and read(j, filename, keylist) adds only the parameters named in keylist. Reading a file stops before the parameter VisuAcqFrameTime, so it and the parameters after it are missing.

j[name], haskey(j, name) and get(j, name, default) work as for a dictionary. A value is a string for a single value and an array of strings for an array, whose dimensions are those of the file in reverse order; for an array of tuples, each entry is a vector of the values of a tuple, with numbers as Float64. A string in angle brackets on the line of its name keeps the brackets, for example "<Bruker:RARE>", while an array of strings in angle brackets is read as its first string only, without the brackets. BrukerFile reads its parameter files with JcampdxFile.

source

Other Formats ​

MRIFiles.CFLFile Type
julia
CFLFile(filenameBase::String)

reference to an array stored in the format of the BART toolbox: the file filenameBase.hdr holds the dimensions and filenameBase.cfl the complex values in single precision. MRIFiles.load(CFLFile(filenameBase)) reads the array and returns an Array{ComplexF64} with all dimensions listed in the header. MRIFiles does not write this format.

source
MRIFiles.DFFile Type
julia
DFFile(datafilename::String, trajfilename::String)

reference to 2D non-Cartesian data stored in two binary files, trajfilename with the k-space nodes and datafilename with the samples. Both files start with four Int32 values. In the trajectory file, the second and third are the number of samples per profile and the number of profiles, followed by the nodes as Float32 values (2 × samples × profiles). In the data file, the second to fourth are the numbers of samples per profile, profiles and slices, followed by the samples as ComplexF32 values.

trajectory(f) returns the trajectory, and keyword arguments are passed on to Trajectory. MRIFiles.rawdata(f) returns the samples as an Array{ComplexF64,3}, and MRIFiles.rawdata(f, slice) those of one slice.

source
MRIFiles.readRawSiemens Function
julia
readRawSiemens(filename)

unfinished reader of Siemens raw data files: it reads only the first eight bytes of the file and no data and returns nothing, and it throws an error for files of the older VB format. Convert Siemens raw data with siemens_to_ismrmrd and read the result with ISMRMRDFile instead.

source