[ismrmrd] 204/281: Added type and size checking to the matlab API for acquisition headers.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:01:15 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag ismrmrd0.5
in repository ismrmrd.
commit e6ddcc1bf3599e22c6e849ca5c0a273801abe001
Author: Souheil Inati <souheil.inati at nih.gov>
Date: Wed Feb 12 10:48:39 2014 -0500
Added type and size checking to the matlab API for acquisition headers.
---
examples/matlab/test_create_dataset.m | 8 +-
matlab/+ismrmrd/AcquisitionHeader.m | 189 +++++++++++++++++++++++++++++++++-
matlab/+ismrmrd/IsmrmrdDataset.m | 5 +-
3 files changed, 195 insertions(+), 7 deletions(-)
diff --git a/examples/matlab/test_create_dataset.m b/examples/matlab/test_create_dataset.m
index a9c17f8..ceeff32 100644
--- a/examples/matlab/test_create_dataset.m
+++ b/examples/matlab/test_create_dataset.m
@@ -50,13 +50,13 @@ end
acqblock = ismrmrd.Acquisition(nY);
% Set the header elements that don't change
-acqblock.head.version(:) = 1.0;
+acqblock.head.version(:) = 1;
acqblock.head.number_of_samples(:) = nX;
acqblock.head.center_sample(:) = floor(nX/2);
acqblock.head.active_channels(:) = nCoils;
-acqblock.head.read_dir = repmat(single([1 0 0]'),[1 nY]);
-acqblock.head.phase_dir = repmat(single([0 1 0]'),[1 nY]);
-acqblock.head.slice_dir = repmat(single([0 0 1]'),[1 nY]);
+acqblock.head.read_dir = repmat([1 0 0]',[1 nY]);
+acqblock.head.phase_dir = repmat([0 1 0]',[1 nY]);
+acqblock.head.slice_dir = repmat([0 0 1]',[1 nY]);
% Loop over the acquisitions, set the header, set the data and append
for rep = 1:nReps
diff --git a/matlab/+ismrmrd/AcquisitionHeader.m b/matlab/+ismrmrd/AcquisitionHeader.m
index bce8023..db8ccb9 100644
--- a/matlab/+ismrmrd/AcquisitionHeader.m
+++ b/matlab/+ismrmrd/AcquisitionHeader.m
@@ -77,6 +77,8 @@ classdef AcquisitionHeader < handle
methods
function obj = AcquisitionHeader(arg)
+ % Constructor
+
switch nargin
case 0
% No argument constructor
@@ -106,7 +108,10 @@ classdef AcquisitionHeader < handle
end
function nacq = getNumber(obj)
+ % Return the number of headers
+
nacq = length(obj.version);
+
end
function hdr = select(obj, range)
@@ -155,6 +160,7 @@ classdef AcquisitionHeader < handle
function extend(obj,N)
% Extend with blank header
+
range = obj.getNumber + (1:N);
obj.version(1,range) = zeros(1,N,'uint16');
obj.flags(1,range) = zeros(1,N,'uint64');
@@ -192,6 +198,8 @@ classdef AcquisitionHeader < handle
end
function append(obj, head)
+ % Append a header
+
Nstart = obj.getNumber + 1;
Nend = obj.getNumber + length(head.version);
Nrange = Nstart:Nend;
@@ -231,6 +239,8 @@ classdef AcquisitionHeader < handle
end
function fromStruct(obj, hdr)
+ % Convert a struct to the object
+
%warning! no error checking
obj.version = hdr.version;
obj.flags = hdr.flags;
@@ -268,6 +278,8 @@ classdef AcquisitionHeader < handle
end
function hdr = toStruct(obj)
+ % Convert the object to a plain struct
+
%warning! no error checking
hdr = struct();
hdr.version = obj.version;
@@ -307,7 +319,7 @@ classdef AcquisitionHeader < handle
function fromBytes(obj, bytearray)
% Convert from a byte array to an ISMRMRD AcquisitionHeader
- % This conforms to the memory layout of the C-struct
+ % This conforms to the memory layout of the C-struct
if size(bytearray,1) ~= 360
error('Wrong number of bytes for AcquisitionHeader.')
@@ -353,7 +365,7 @@ classdef AcquisitionHeader < handle
function bytes = toBytes(obj)
% Convert to an ISMRMRD AcquisitionHeader to a byte array
- % This conforms to the memory layout of the C-struct
+ % This conforms to the memory layout of the C-struct
N = obj.getNumber;
bytes = zeros(360,N,'uint8');
@@ -397,7 +409,180 @@ classdef AcquisitionHeader < handle
end
end
+ function obj = check(obj)
+ % Check and fix the obj types
+
+ % Check the number of elements for each entry
+ N = obj.getNumber();
+ if (size(obj.flags) ~= N)
+ error('Size of flags is not correct.');
+ end
+ if ((size(obj.measurement_uid,1) ~= 1) || ...
+ (size(obj.measurement_uid,2) ~= N))
+ error('Size of measurement_uid is not correct.');
+ end
+ if ((size(obj.scan_counter,1) ~= 1) || ...
+ (size(obj.scan_counter,2) ~= N))
+ error('Size of scan_counter is not correct.');
+ end
+ if ((size(obj.acquisition_time_stamp,1) ~= 1) || ...
+ (size(obj.acquisition_time_stamp,2) ~= N))
+ error('Size of acquisition_time_stamp is not correct.');
+ end
+ if ((size(obj.physiology_time_stamp,1) ~= 3) || ...
+ (size(obj.physiology_time_stamp,2) ~= N))
+ error('Size of physiology_time_stamp is not correct.');
+ end
+ if ((size(obj.number_of_samples,1) ~= 1) || ...
+ (size(obj.number_of_samples,2) ~= N))
+ error('Size of number_of_samples is not correct.');
+ end
+
+ if ((size(obj.available_channels,1) ~= 1) || ...
+ (size(obj.available_channels,2) ~= N))
+ error('Size of available_channels is not correct.');
+ end
+ if ((size(obj.active_channels,1) ~= 1) || ...
+ (size(obj.active_channels,2) ~= N))
+ error('Size of active_channels is not correct.');
+ end
+ if ((size(obj.channel_mask,1) ~= 16) || ...
+ (size(obj.channel_mask,2) ~= N))
+ error('Size of channel_mask is not correct.');
+ end
+ if ((size(obj.discard_pre,1) ~= 1) || ...
+ (size(obj.discard_pre,2) ~= N))
+ error('Size of discard_pre is not correct.');
+ end
+ if ((size(obj.discard_post,1) ~= 1) || ...
+ (size(obj.discard_post,2) ~= N))
+ error('Size of discard_post is not correct.');
+ end
+ if ((size(obj.center_sample,1) ~= 1) || ...
+ (size(obj.center_sample,2) ~= N))
+ error('Size of center_sample is not correct.');
+ end
+ if ((size(obj.encoding_space_ref,1) ~= 1) || ...
+ (size(obj.encoding_space_ref,2) ~= N))
+ error('Size of encoding_space_ref is not correct.');
+ end
+ if ((size(obj.trajectory_dimensions,1) ~= 1) || ...
+ (size(obj.trajectory_dimensions,2) ~= N))
+ error('Size of trajectory_dimensions is not correct.');
+ end
+ if ((size(obj.sample_time_us,1) ~= 1) || ...
+ (size(obj.sample_time_us,2) ~= N))
+ error('Size of sample_time_us is not correct.');
+ end
+ if ((size(obj.position,1) ~= 3) || ...
+ (size(obj.position,2) ~= N))
+ error('Size of position is not correct.');
+ end
+ if ((size(obj.read_dir,1) ~= 3) || ...
+ (size(obj.read_dir,2) ~= N))
+ error('Size of read_dir is not correct.');
+ end
+ if ((size(obj.phase_dir,1) ~= 3) || ...
+ (size(obj.phase_dir,2) ~= N))
+ error('Size of phase_dir is not correct.');
+ end
+ if ((size(obj.slice_dir,1) ~= 3) || ...
+ (size(obj.slice_dir,2) ~= N))
+ error('Size of slice_dir is not correct.');
+ end
+ if ((size(obj.patient_table_position,1) ~= 3) || ...
+ (size(obj.patient_table_position,2) ~= N))
+ error('Size of patient_table_position is not correct.');
+ end
+ if ((size(obj.idx.kspace_encode_step_1,1) ~= 1) || ...
+ (size(obj.idx.kspace_encode_step_1,2) ~= N))
+ error('Size of kspace_encode_step_1 is not correct.');
+ end
+ if ((size(obj.idx.kspace_encode_step_2,1) ~= 1) || ...
+ (size(obj.idx.kspace_encode_step_2,2) ~= N))
+ error('Size of kspace_encode_step_2 is not correct.');
+ end
+ if ((size(obj.idx.average,1) ~= 1) || ...
+ (size(obj.idx.average,2) ~= N))
+ error('Size of idx.average is not correct.');
+ end
+ if ((size(obj.idx.slice,1) ~= 1) || ...
+ (size(obj.idx.slice,2) ~= N))
+ error('Size of idx.slice is not correct.');
+ end
+ if ((size(obj.idx.contrast,1) ~= 1) || ...
+ (size(obj.idx.contrast,2) ~= N))
+ error('Size of idx.contrast is not correct.');
+ end
+ if ((size(obj.idx.phase,1) ~= 1) || ...
+ (size(obj.idx.phase,2) ~= N))
+ error('Size of idx.phase is not correct.');
+ end
+ if ((size(obj.idx.repetition,1) ~= 1) || ...
+ (size(obj.idx.repetition,2) ~= N))
+ error('Size of idx.repetition is not correct.');
+ end
+ if ((size(obj.idx.set,1) ~= 1) || ...
+ (size(obj.idx.set,2) ~= N))
+ error('Size of idx.set is not correct.');
+ end
+ if ((size(obj.idx.segment,1) ~= 1) || ...
+ (size(obj.idx.segment,2) ~= N))
+ error('Size of idx.segment is not correct.');
+ end
+ if ((size(obj.idx.user,1) ~= 8) || ...
+ (size(obj.idx.user,2) ~= N))
+ error('Size of idx.user is not correct.');
+ end
+ if ((size(obj.user_int,1) ~= 8) || ...
+ (size(obj.user_int,2) ~= N))
+ error('Size of user_int is not correct.');
+ end
+ if ((size(obj.user_float,1) ~= 8) || ...
+ (size(obj.user_float,2) ~= N))
+ error('Size of user_float is not correct.');
+ end
+
+ % Fix the type of all the elements
+ obj.version = uint16(obj.version);
+ obj.flags = uint64(obj.flags);
+ obj.measurement_uid = uint32(obj.measurement_uid);
+ obj.scan_counter = uint32(obj.scan_counter);
+ obj.acquisition_time_stamp = uint32(obj.acquisition_time_stamp);
+ obj.physiology_time_stamp = uint32(obj.physiology_time_stamp);
+ obj.number_of_samples = uint16(obj.number_of_samples);
+ obj.available_channels = uint16(obj.available_channels);
+ obj.active_channels = uint16(obj.active_channels);
+ obj.channel_mask = uint64(obj.channel_mask);
+ obj.discard_pre = uint16(obj.discard_pre);
+ obj.discard_post = uint16(obj.discard_post);
+ obj.center_sample = uint16(obj.center_sample);
+ obj.encoding_space_ref = uint16(obj.encoding_space_ref);
+ obj.trajectory_dimensions = uint16(obj.trajectory_dimensions);
+ obj.sample_time_us = single(obj.sample_time_us);
+ obj.position = single(obj.position);
+ obj.read_dir = single(obj.read_dir);
+ obj.phase_dir = single(obj.phase_dir);
+ obj.slice_dir = single(obj.slice_dir);
+ obj.patient_table_position = single(obj.patient_table_position);
+ obj.idx.kspace_encode_step_1 = uint16(obj.idx.kspace_encode_step_1);
+ obj.idx.kspace_encode_step_2 = uint16(obj.idx.kspace_encode_step_2);
+ obj.idx.average = uint16(obj.idx.average);
+ obj.idx.slice = uint16(obj.idx.slice);
+ obj.idx.contrast = uint16(obj.idx.contrast);
+ obj.idx.phase = uint16(obj.idx.phase);
+ obj.idx.repetition = uint16(obj.idx.repetition);
+ obj.idx.set = uint16(obj.idx.set);
+ obj.idx.segment = uint16(obj.idx.segment);
+ obj.idx.user = uint16(obj.idx.user);
+ obj.user_int = int32(obj.user_int);
+ obj.user_float = single(obj.user_float);
+
+ end
+
function ret = flagIsSet(obj, flag, range)
+ % bool = obj.flagIsSet(flag, range)
+
if nargin < 3
range = 1:obj.getNumber;
end
diff --git a/matlab/+ismrmrd/IsmrmrdDataset.m b/matlab/+ismrmrd/IsmrmrdDataset.m
index da55be2..71793bb 100644
--- a/matlab/+ismrmrd/IsmrmrdDataset.m
+++ b/matlab/+ismrmrd/IsmrmrdDataset.m
@@ -267,8 +267,11 @@ classdef IsmrmrdDataset
% Mem space
mem_space_id = H5S.create_simple(2,[N 1],[]);
+ % Check and fix the acquisition header types
+ acq.head = acq.head.check();
+ % TODO: Error checking on the sizes of the data and trajectories.
+
% Pack the acquisition into the correct struct for writing
- % TODO: Error checking.
d = struct();
d.head = acq.head.toStruct();
d.traj = acq.trajToFloat();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/ismrmrd.git
More information about the debian-science-commits
mailing list