[ismrmrd] 146/177: Working matlab generate data set example.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:02:13 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag v1.1.0.beta.1
in repository ismrmrd.

commit f89ca8ceadebb1ac48111142774d0fa0e47843b3
Author: Souheil Inati <souheil.inati at nih.gov>
Date:   Thu Oct 16 22:17:20 2014 -0400

    Working matlab generate data set example.
---
 examples/matlab/test_create_dataset.m | 110 ++++++++++++----------------------
 matlab/+ismrmrd/+xml/serialize.m      |  48 ++++++++-------
 matlab/+ismrmrd/Dataset.m             |  26 ++++----
 3 files changed, 76 insertions(+), 108 deletions(-)

diff --git a/examples/matlab/test_create_dataset.m b/examples/matlab/test_create_dataset.m
index ceeff32..8fe20b7 100644
--- a/examples/matlab/test_create_dataset.m
+++ b/examples/matlab/test_create_dataset.m
@@ -5,13 +5,13 @@
 % data from 4 coils from a single slice object that looks like a square
 
 % File Name
-filename = 'testdata.h5';
+filename = 'matlabtestdata.h5';
 
 % Create an empty ismrmrd dataset
 if exist(filename,'file')
     error(['File ' filename ' already exists.  Please remove first'])
 end
-dset = ismrmrd.IsmrmrdDataset(filename);
+dset = ismrmrd.Dataset(filename);
 
 % Synthesize the object
 nX = 256;
@@ -93,78 +93,44 @@ end % rep loop
 %%%%%%%%%%%%%%%%%%%%%%%%
 %% Fill the xml header %
 %%%%%%%%%%%%%%%%%%%%%%%%
-
-%% Experimental Conditions
-expcond = org.ismrm.ismrmrd.ExperimentalConditionsType;
-expcond.setH1ResonanceFrequencyHz(128000000); % 3T
-dset.xmlhdr.setExperimentalConditions(expcond);
-
-%% Acquisition System Information
-acqsysinfo = org.ismrm.ismrmrd.AcquisitionSystemInformationType;
-acqsysinfo.setReceiverChannels(java.lang.Integer(nCoils));
-dset.xmlhdr.setAcquisitionSystemInformation(acqsysinfo);
-
-%% The Encoding
-encoding = org.ismrm.ismrmrd.Encoding;
-encoding.setTrajectory(org.ismrm.ismrmrd.TrajectoryType.CARTESIAN);
-
-% Encoded Space
-fov = org.ismrm.ismrmrd.FieldOfViewMm;
-fov.setX(256);
-fov.setX(256);
-fov.setZ(5);
-matrix = org.ismrm.ismrmrd.MatrixSize;
-matrix.setX(size(K,1));
-matrix.setY(size(K,2));
-matrix.setZ(1);
-encodedspace = org.ismrm.ismrmrd.EncodingSpaceType;
-encodedspace.setMatrixSize(matrix);
-encodedspace.setFieldOfViewMm(fov);
-encoding.setEncodedSpace(encodedspace);
-
+% We create a matlab struct and then serialize it to xml.
+% Look at the xml schema to see what the field names should be
+
+header = [];
+
+% Experimental Conditions (Required)
+header.experimentalConditions.H1resonanceFrequency_Hz = 128000000; % 3T
+
+% Acquisition System Information (Optional)
+header.acquisitionSystemInformation.systemVendor = 'ISMRMRD Labs';
+header.acquisitionSystemInformation.systemModel = 'Virtual Scanner';
+header.acquisitionSystemInformation.receiverChannels = nCoils;
+
+% The Encoding (Required)
+header.encoding.trajectory = 'cartesian';
+header.encoding.encodedSpace.fieldOfView_mm.x = 256;
+header.encoding.encodedSpace.fieldOfView_mm.y = 256;
+header.encoding.encodedSpace.fieldOfView_mm.z = 5;
+header.encoding.encodedSpace.matrixSize.x = size(K,1);
+header.encoding.encodedSpace.matrixSize.y = size(K,2);
+header.encoding.encodedSpace.matrixSize.z = 1;
 % Recon Space
-% (same as encoding space)
-encoding.setReconSpace(encodedspace);
-
+% (in this case same as encoding space)
+header.encoding.reconSpace = header.encoding.encodedSpace;
 % Encoding Limits
-% Be careful!!! All of the XML Header stuff is  JAVA so it is
-% being done with objects.  Make sure that you
-% create one object per thing you care about
-encodinglimits = org.ismrm.ismrmrd.EncodingLimitsType;
-
-limitsa = org.ismrm.ismrmrd.LimitType;
-limitsa.setMinimum(0);
-limitsa.setCenter(floor(size(K,1)/2)); 
-limitsa.setMaximum(size(K,1)-1); 
-encodinglimits.setKspaceEncodingStep0(limitsa);
-
-limitsb = org.ismrm.ismrmrd.LimitType;
-limitsb.setMinimum(0);
-limitsb.setCenter(floor(size(K,2)/2)); 
-limitsb.setMaximum(size(K,2)-1); 
-encodinglimits.setKspaceEncodingStep1(limitsb);
-
-limitsc = org.ismrm.ismrmrd.LimitType;
-limitsc.setMinimum(0);
-limitsc.setCenter(floor(nReps/2)); 
-limitsc.setMaximum(nReps-1);
-encodinglimits.setRepetition(limitsc);
-
-% All the rest are zero and we can use the same one for all of them
-limits = org.ismrm.ismrmrd.LimitType;
-limits.setMinimum(0);
-limits.setCenter(0); 
-limits.setMaximum(0);
-encodinglimits.setAverage(limits);
-encodinglimits.setContrast(limits);
-encodinglimits.setKspaceEncodingStep2(limits);
-encodinglimits.setPhase(limits);
-encodinglimits.setSegment(limits);
-encodinglimits.setSet(limits);
-encodinglimits.setSlice(limits);
-% Stuff
-encoding.setEncodingLimits(encodinglimits);
-dset.xmlhdr.getEncoding.add(encoding);
+header.encoding.encodingLimits.kspace_encoding_step_0.minimum = 0;
+header.encoding.encodingLimits.kspace_encoding_step_0.maximum = size(K,1)-1;
+header.encoding.encodingLimits.kspace_encoding_step_0.center = floor(size(K,1)/2);
+header.encoding.encodingLimits.kspace_encoding_step_1.minimum = 0;
+header.encoding.encodingLimits.kspace_encoding_step_1.maximum = size(K,2)-1;
+header.encoding.encodingLimits.kspace_encoding_step_1.center = floor(size(K,2)/2);
+header.encoding.encodingLimits.repetition.minimum = 0;
+header.encoding.encodingLimits.repetition.maximum = nReps-1;
+header.encoding.encodingLimits.repetition.center = 0;
+
+%% Serialize and write to the data set
+xmlstring = ismrmrd.xml.serialize(header);
+dset.writexml(xmlstring);
 
 %% Write the dataset
 dset.close();
diff --git a/matlab/+ismrmrd/+xml/serialize.m b/matlab/+ismrmrd/+xml/serialize.m
index f75a4dd..28611f6 100644
--- a/matlab/+ismrmrd/+xml/serialize.m
+++ b/matlab/+ismrmrd/+xml/serialize.m
@@ -84,7 +84,7 @@ if isfield(header,'acquisitionSystemInformation')
 end
 
 experimentalConditions = header.experimentalConditions;
-experimentalConditionsNode = docNode.createElement('experimentalConditionsNode');
+experimentalConditionsNode = docNode.createElement('experimentalConditions');
 append_node(docNode,experimentalConditionsNode,experimentalConditions,'H1resonanceFrequency_Hz', at int2str);
 docRootNode.appendChild(experimentalConditionsNode);
 
@@ -100,23 +100,23 @@ for enc = header.encoding(:)
     
     n2 = docNode.createElement('encodingLimits');
     
-    append_encoding_limits(docNode,node,'kspace_encoding_step_0',enc);
-    append_encoding_limits(docNode,node,'kspace_encoding_step_1',enc);
-    append_encoding_limits(docNode,node,'kspace_encoding_step_2',enc);
-    append_encoding_limits(docNode,node,'average',enc);
-    append_encoding_limits(docNode,node,'slice',enc);
-    append_encoding_limits(docNode,node,'contrast',enc);
-    append_encoding_limits(docNode,node,'phase',enc);
-    append_encoding_limits(docNode,node,'repetition',enc);
-    append_encoding_limits(docNode,node,'set',enc);
-    append_encoding_limits(docNode,node,'segment',enc);
-    append_node(docNode,node,enc,'trajectory');
+    append_encoding_limits(docNode,n2,'kspace_encoding_step_0',enc.encodingLimits);
+    append_encoding_limits(docNode,n2,'kspace_encoding_step_1',enc.encodingLimits);
+    append_encoding_limits(docNode,n2,'kspace_encoding_step_2',enc.encodingLimits);
+    append_encoding_limits(docNode,n2,'average',enc.encodingLimits);
+    append_encoding_limits(docNode,n2,'slice',enc.encodingLimits);
+    append_encoding_limits(docNode,n2,'contrast',enc.encodingLimits);
+    append_encoding_limits(docNode,n2,'phase',enc.encodingLimits);
+    append_encoding_limits(docNode,n2,'repetition',enc.encodingLimits);
+    append_encoding_limits(docNode,n2,'set',enc.encodingLimits);
+    append_encoding_limits(docNode,n2,'segment',enc.encodingLimits);
     node.appendChild(n2);
-    
+
+    append_node(docNode,node,enc,'trajectory');
     
     if isfield(enc,'trajectoryDescription')
         n2 = docNode.createElement('trajectoryDescription');
-        append_node(docNode,node,enc.trajectoryDescription,'identifier');
+        append_node(docNode,n2,enc.trajectoryDescription,'identifier');
         append_user_parameter(docNode,n2,enc.trajectoryDescription,'userParameterLong', at int2str);
         append_user_parameter(docNode,n2,enc.trajectoryDescription,'userParameterDouble', at num2str);
         append_optional(docNode,n2,enc.trajectoryDescription,'comment');      
@@ -133,12 +133,12 @@ for enc = header.encoding(:)
         n2.appendChild(n3)
         
         append_optional(docNode,n2,parallelImaging,'calibrationMode'); 
-        append_optional(docNode,n2,parallelImaging,'interleavingDimension'); 
+        append_optional(docNode,n2,parallelImaging,'interleavingDimension', at int2str); 
         
         node.appendChild(n2)
     end
         
-    append_optional(docNode,node,enc,'echoTrainLength');
+    append_optional(docNode,node,enc,'echoTrainLength', at int2str);
     
     docRootNode.appendChild(node);
     
@@ -162,8 +162,8 @@ if isfield(header,'userParameters')
     
     append_user_parameter(docNode,n1,userParameters,'userParameterLong', at int2str);
     append_user_parameter(docNode,n1,userParameters,'userParameterDouble', at num2str);
-    append_user_parameter(docNode,n1,userParameters,'userParameterString');
-    append_user_parameter(docNode,n1,userParameters,'userParameterBase64');
+    append_user_parameter(docNode,n1,userParameters,'userParameterString', at num2str);
+    append_user_parameter(docNode,n1,userParameters,'userParameterBase64', at num2str);
     docRootNode.appendChild(n1);
 end
 xml_doc = xmlwrite(docNode);
@@ -186,7 +186,6 @@ for v = values(:)
         append_node(docNode,n2,v,'value');
     end
     
-    
     subNode.appendChild(n2);
 end
 end
@@ -216,15 +215,18 @@ function append_encoding_space(docNode,subnode,name,encodedSpace)
     append_node(docNode,n3,encodedSpace.fieldOfView_mm,'y', at num2str);
     append_node(docNode,n3,encodedSpace.fieldOfView_mm,'z', at num2str);
     n2.appendChild(n3);
-    
-       
+ 
     subnode.appendChild(n2);
 end
     
     
 function append_optional(docNode,subnode,subheader,name,tostr)
     if isfield(subheader,name)
-       append_node(docNode,subnode,subheader,name,tostr);
+        if nargin > 4
+            append_node(docNode,subnode,subheader,name,tostr);
+        else
+            append_node(docNode,subnode,subheader,name);
+        end
     end       
 end
 
@@ -238,7 +240,7 @@ function append_node(docNode,subnode,subheader,name,tostr)
     else
 
         for val = subheader.(name)(:)
-            n1 = docNode.createElement(name);    
+            n1 = docNode.createElement(name);
             n1.appendChild...
                 (docNode.createTextNode(tostr(val)));        
             subnode.appendChild(n1);
diff --git a/matlab/+ismrmrd/Dataset.m b/matlab/+ismrmrd/Dataset.m
index 142e8a4..7d2475a 100644
--- a/matlab/+ismrmrd/Dataset.m
+++ b/matlab/+ismrmrd/Dataset.m
@@ -108,16 +108,16 @@ classdef Dataset
             % Matlab is having trouble writing variable length strings
             % that are longer that 512 characters.  Switched to fixed
             % length.
-            % H5T.set_size(xml_dtype,'H5T_VARIABLE');
-            H5T.set_size(xml_dtype, length(xmlstring));
+            H5T.set_size(xml_dtype,'H5T_VARIABLE');
+            %H5T.set_size(xml_dtype, length(xmlstring));
             xml_space_id = H5S.create_simple (1, 1, []);
-            xml_id = H5D.create (obj.fid, obj.xmlpath, xml_dtype, ....
+            xml_id = H5D.create(obj.fid, obj.xmlpath, xml_dtype, ....
                                  xml_space_id, 'H5P_DEFAULT');
             H5S.close(xml_space_id);
 
             % Write the data
             H5D.write(xml_id, xml_dtype, ...
-                      'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', xmlstring);
+                      'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', {xmlstring});
 
             % Close the XML
             H5D.close(xml_id);
@@ -205,13 +205,13 @@ classdef Dataset
             lapl_id=H5P.create('H5P_LINK_ACCESS');
             if (H5L.exists(obj.fid, obj.datapath, lapl_id) == 0)
                 % Data does not exist
-                %   create with rank 2, unlimited, and set the chunk size
-                dims    = [N 1];
-                maxdims = [H5ML.get_constant_value('H5S_UNLIMITED') 1];
-                file_space_id = H5S.create_simple(2, dims, maxdims);
+                %   create with rank 1, unlimited, and set the chunk size
+                dims    = [N];
+                maxdims = [H5ML.get_constant_value('H5S_UNLIMITED')];
+                file_space_id = H5S.create_simple(1, dims, maxdims);
 
                 dcpl = H5P.create('H5P_DATASET_CREATE');
-                chunk = [1 1];
+                chunk = [1];
                 H5P.set_chunk (dcpl, chunk);
                 data_id = H5D.create(obj.fid, obj.datapath, ...
                                      obj.htypes.T_Acquisition, ...
@@ -229,7 +229,7 @@ classdef Dataset
                 % Get the size, increment by N
                 H5S.get_simple_extent_dims(file_space_id);
                 [~,dims,~] = H5S.get_simple_extent_dims(file_space_id);
-                dims = [dims(1)+N, 1];
+                dims = [dims(1)+N];
                 H5D.set_extent (data_id, dims);
                 H5S.close(file_space_id);
 
@@ -241,11 +241,11 @@ classdef Dataset
             [~,dims,~] = H5S.get_simple_extent_dims(file_space_id);
 
             % Select the last N block
-            offset = [dims(1)-N 0];
-            H5S.select_hyperslab(file_space_id,'H5S_SELECT_SET',offset,[1 1],[1 1],[N 1]);
+            offset = [dims(1)-N];
+            H5S.select_hyperslab(file_space_id,'H5S_SELECT_SET',offset,[1],[1],[N]);
 
             % Mem space
-            mem_space_id = H5S.create_simple(2,[N 1],[]);
+            mem_space_id = H5S.create_simple(1,[N],[]);
 
             % Check and fix the acquisition header types
             acq.head.check();

-- 
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