[ismrmrd] 10/16: Updated xml de/serialization to handle the coil labels and fixed a few bugs.

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


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

ghisvail-guest pushed a commit to annotated tag v1.2.0
in repository ismrmrd.

commit 08d74caf9299c6f580acad2b229b09daf85a6225
Author: Souheil Inati <souheil.inati at nih.gov>
Date:   Thu Dec 18 12:54:18 2014 -0500

    Updated xml de/serialization to handle the coil labels and fixed a few bugs.
---
 matlab/+ismrmrd/+xml/deserialize.m | 133 ++++++-------------------------------
 matlab/+ismrmrd/+xml/serialize.m   | 129 +++++++++++++++++++++--------------
 2 files changed, 100 insertions(+), 162 deletions(-)

diff --git a/matlab/+ismrmrd/+xml/deserialize.m b/matlab/+ismrmrd/+xml/deserialize.m
index d52b8b0..d0b5b96 100644
--- a/matlab/+ismrmrd/+xml/deserialize.m
+++ b/matlab/+ismrmrd/+xml/deserialize.m
@@ -45,7 +45,7 @@ for n = 1:numChildNodes
             info.encoding = struct('encodedSpace',struct,'reconSpace',struct, ...
                 'encodingLimits', struct, 'trajectory', '', ...
                 'trajectoryDescription', struct,  ...
-                'parallelImaging', struct, 'echoTrainLength', 0);
+                'parallelImaging', struct, 'echoTrainLength', []);
         end
         temp = parseNode(theChild);
         fnames = fieldnames(temp);
@@ -55,6 +55,17 @@ for n = 1:numChildNodes
         continue;
     end
     
+    % kspace_encoding_step_1/2 can be either part of the acceleration
+    % factor or part of the encoding limits.
+    if (strcmp(name, 'kspace_encoding_step_1') || strcmp(name, 'kspace_encoding_step_2'))
+        if strcmp(char(theChild.getParentNode.getNodeName),'encodingLimits') 
+            info.(name) = parseNode(theChild);
+        else
+            info.(name) = str2num(getTextContent(theChild));
+        end
+        continue;
+    end
+        
     if isCompoundType(name)        
         if num == 1
             info.(name) = parseNode(theChild);
@@ -143,12 +154,12 @@ function status = isCompoundType(name)
 
     % treat encoding separately
     headerNodeNames = { ...
-        'version', ...
         'subjectInformation', ...
         'studyInformation', ...
         'measurementInformation', ...
         'acquisitionSystemInformation', ...
         'experimentalConditions', ...
+        'coilLabel', ...
         'encoding', ...
         'sequenceParameters', ...
         'userParameters', ...
@@ -159,6 +170,8 @@ function status = isCompoundType(name)
         'encodingLimits', ...
         'trajectoryDescription', ...
         'echoTrainLength', ...
+        'parallelImaging', ...
+        'accelerationFactor', ...
         'matrixSize', ...
         'fieldOfView_mm', ...
         'kspace_encoding_step_0', ...
@@ -183,7 +196,7 @@ function status = isNumericalType(name)
       'initialSeriesNumber', ...
       'systemFieldStrength_T', ...
       'relativeReceiverNoiseBandwidth', ...
-      'receiverChannels', ...
+      'receiverChannels', 'coilNumber', ...
       'H1resonanceFrequency_Hz', ...
       'TR', ...
       'TE', ...
@@ -217,9 +230,10 @@ function status = isStringType(name)
       'systemModel', ...
       'institutionName', ...
       'stationName', ...
-      'trajectory'};
-      %'calibrationMode',...
-      %'interleavingDimension'};
+      'trajectory', ...
+      'coilName', ...
+      'calibrationMode',...
+      'interleavingDimension'};
 
       status = ismember(name, headerStringTypes);
 end
@@ -243,110 +257,3 @@ function status = isUserParameterType(name)
 
     status = ismember(name, typeNames);
 end
-% 
-%   <xs:complexType name="encoding">
-%     <xs:all>
-%       <xs:element maxOccurs="1" minOccurs="1" name="encodedSpace" type="encodingSpaceType"/>
-%       <xs:element maxOccurs="1" minOccurs="1" name="reconSpace" type="encodingSpaceType"/>
-%       <xs:element maxOccurs="1" minOccurs="1" name="encodingLimits" type="encodingLimitsType"/>
-%       <xs:element maxOccurs="1" minOccurs="1" name="trajectory" type="trajectoryType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="trajectoryDescription" type="trajectoryDescriptionType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="parallelImaging" type="parallelImagingType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="echoTrainLength" type="xs:long"/>
-%     </xs:all>
-%   </xs:complexType>
-% 
-%   <xs:complexType name="encodingSpaceType">
-%     <xs:all>
-%       <xs:element maxOccurs="1" minOccurs="1" name="matrixSize" type="matrixSize"/>
-%       <xs:element maxOccurs="1" minOccurs="1" name="fieldOfView_mm" type="fieldOfView_mm"/>
-%     </xs:all>
-%   </xs:complexType>
-% 
-%   <xs:complexType name="matrixSize">
-%     <xs:sequence>
-%       <xs:element default="1" maxOccurs="1" minOccurs="1" name="x" type="xs:unsignedShort"/>
-%       <xs:element default="1" maxOccurs="1" minOccurs="1" name="y" type="xs:unsignedShort"/>
-%       <xs:element default="1" maxOccurs="1" minOccurs="1" name="z" type="xs:unsignedShort"/>
-%     </xs:sequence>
-%   </xs:complexType>
-% 
-%   <xs:complexType name="fieldOfView_mm">
-%     <xs:sequence>
-%       <xs:element maxOccurs="1" minOccurs="1" name="x" type="xs:float"/>
-%       <xs:element maxOccurs="1" minOccurs="1" name="y" type="xs:float"/>
-%       <xs:element maxOccurs="1" minOccurs="1" name="z" type="xs:float"/>
-%     </xs:sequence>
-%   </xs:complexType>
-% 
-%   <xs:complexType name="limitType">
-%     <xs:all>
-%       <xs:element default="0" name="minimum" type="xs:unsignedShort"/>
-%       <xs:element default="0" name="maximum" type="xs:unsignedShort"/>
-%       <xs:element default="0" name="center" type="xs:unsignedShort"/>
-%     </xs:all>
-%   </xs:complexType>
-% 
-%   <xs:complexType name="encodingLimitsType">
-%     <xs:all>
-%       <xs:element maxOccurs="1" minOccurs="0" name="kspace_encoding_step_0" type="limitType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="kspace_encoding_step_1" type="limitType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="kspace_encoding_step_2" type="limitType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="average" type="limitType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="slice" type="limitType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="contrast" type="limitType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="phase" type="limitType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="repetition" type="limitType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="set" type="limitType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="segment" type="limitType"/>
-%     </xs:all>
-%   </xs:complexType>
-% 
-%   <xs:simpleType name="trajectoryType">
-%     <xs:restriction base="xs:string">
-%       <xs:enumeration value="cartesian"/>
-%       <xs:enumeration value="epi"/>
-%       <xs:enumeration value="radial"/>
-%       <xs:enumeration value="goldenangle"/>
-%       <xs:enumeration value="spiral"/>
-%       <xs:enumeration value="other"/>
-%     </xs:restriction>
-%   </xs:simpleType>
-% 
-%   <xs:complexType name="trajectoryDescriptionType">
-%     <xs:sequence>
-%       <xs:element maxOccurs="1" minOccurs="1" name="identifier" type="xs:string"/>
-%       <xs:element maxOccurs="unbounded" minOccurs="0" name="userParameterLong" type="userParameterLongType"/>
-%       <xs:element maxOccurs="unbounded" minOccurs="0" name="userParameterDouble" type="userParameterDoubleType"/>
-%       <xs:element maxOccurs="1" minOccurs="0" name="comment" type="xs:string"/>
-%     </xs:sequence>
-%   </xs:complexType>
-
-% 
-%   <xs:complexType name="userParameterLongType">
-%     <xs:all>
-%       <xs:element name="name" type="xs:string"/>
-%       <xs:element name="value" type="xs:long"/>
-%     </xs:all>
-%   </xs:complexType>
-% 
-%   <xs:complexType name="userParameterDoubleType">
-%     <xs:all>
-%       <xs:element name="name" type="xs:string"/>
-%       <xs:element name="value" type="xs:double"/>
-%     </xs:all>
-%   </xs:complexType>
-% 
-%   <xs:complexType name="userParameterStringType">
-%     <xs:all>
-%       <xs:element name="name" type="xs:string"/>
-%       <xs:element name="value" type="xs:string"/>
-%     </xs:all>
-%   </xs:complexType>
-% 
-%   <xs:complexType name="userParameterBase64Type">
-%     <xs:all>
-%       <xs:element name="name" type="xs:string"/>
-%       <xs:element name="value" type="xs:base64Binary"/>
-%     </xs:all>
-%   </xs:complexType>
diff --git a/matlab/+ismrmrd/+xml/serialize.m b/matlab/+ismrmrd/+xml/serialize.m
index 7ef8a06..7eb5740 100644
--- a/matlab/+ismrmrd/+xml/serialize.m
+++ b/matlab/+ismrmrd/+xml/serialize.m
@@ -8,9 +8,8 @@ docRootNode.setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance'
 docRootNode.setAttribute('xmlns:xs','http://www.w3.org/2001/XMLSchema');
 
 docRootNode.setAttribute('xsi:schemaLocation','http://www.ismrm.org/ISMRMRD ismrmrd.xsd');
-% docRootNode.setAttribute('version','1');
 
-% append_optional(docNode,docRootNode,header,'version', at int2str)
+append_optional(docNode,docRootNode,header,'version', at int2str)
 
 if isfield(header,'subjectInformation')
     subjectInformation = header.subjectInformation;
@@ -49,24 +48,27 @@ if isfield(header,'measurementInformation')
     append_optional(docNode,measurementInformationNode,measurementInformation,'protocolName');
     append_optional(docNode,measurementInformationNode,measurementInformation,'seriesDescription');
     
-    
-    measurementDependency = measurementInformation.measurementDependency;
-    for dep = measurementDependency(:)
-        node = docNode.createElement('measurementDependency');
-        append_node(docNode,node,dep,'dependencyType');
-        append_node(docNode,node,dep,'measurementID');
-        measurementInformationNode.appendChild(node)
+    if isfield(measurementInformation, 'measurementDependency')
+        measurementDependency = measurementInformation.measurementDependency;
+        for dep = measurementDependency(:)
+            node = docNode.createElement('measurementDependency');
+            append_node(docNode,node,dep,'dependencyType');
+            append_node(docNode,node,dep,'measurementID');
+            measurementInformationNode.appendChild(node)
+        end
     end
-       
+    
     append_optional(docNode,measurementInformationNode,measurementInformation,'seriesInstanceUIDRoot');
     append_optional(docNode,measurementInformationNode,measurementInformation,'frameOfReferenceUID');
     
-    referencedImageSequence = measurementInformation.referencedImageSequence;
-    referencedImageSequenceNode = docNode.createElement('referencedImageSequence');
-    for ref = referencedImageSequence(:)
-        append_node(docNode,referencedImageSequenceNode,ref,'referencedSOPInstanceUID');
+    if isfield(measurementInformation, 'referencedImageSequence')
+        referencedImageSequence = measurementInformation.referencedImageSequence;
+        referencedImageSequenceNode = docNode.createElement('referencedImageSequence');
+        for ref = referencedImageSequence(:)
+            append_node(docNode,referencedImageSequenceNode,ref,'referencedSOPInstanceUID');
+        end
     end
-   
+    
     docRootNode.appendChild(measurementInformationNode);
 end
 
@@ -78,6 +80,17 @@ if isfield(header,'acquisitionSystemInformation')
     append_optional(docNode,acquisitionSystemInformationNode,acquisitionSystemInformation,'systemFieldStrength_T', at num2str);
     append_optional(docNode,acquisitionSystemInformationNode,acquisitionSystemInformation,'relativeReceiverNoiseBandwidth', at num2str);
     append_optional(docNode,acquisitionSystemInformationNode,acquisitionSystemInformation,'receiverChannels', at int2str);
+    
+    if isfield(acquisitionSystemInformation, 'coilLabel')
+        coilLabel = acquisitionSystemInformation.coilLabel;
+        for coil = 1:length(coilLabel)
+            coilLabelNode = docNode.createElement('coilLabel');
+            append_node(docNode,coilLabelNode,coilLabel(coil),'coilNumber', at num2str);
+            append_node(docNode,coilLabelNode,coilLabel(coil),'coilName');
+            acquisitionSystemInformationNode.appendChild(coilLabelNode);
+        end
+    end
+
     append_optional(docNode,acquisitionSystemInformationNode,acquisitionSystemInformation,'institutionName');
     append_optional(docNode,acquisitionSystemInformationNode,acquisitionSystemInformation,'stationName', at num2str);
     docRootNode.appendChild(acquisitionSystemInformationNode);
@@ -115,31 +128,40 @@ for enc = header.encoding(:)
     append_node(docNode,node,enc,'trajectory');
     node.appendChild(n2);
     
+    % sometimes the encoding has the fields, but they are empty
     if isfield(enc,'trajectoryDescription')
-        n2 = docNode.createElement('trajectoryDescription');
-        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');      
-        node.appendChild(n2);
+        if ~isempty(fieldnames(enc.trajectoryDescription))
+            n2 = docNode.createElement('trajectoryDescription');
+            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');      
+            node.appendChild(n2);
+        end
     end
     
     if isfield(enc,'parallelImaging')
-        n2 = docNode.createElement('parallelImaging');
-        
-        n3 = docNode.createElement('accelerationFactor');
-        parallelImaging = enc.parallelImaging;
-        append_node(docNode,n3,parallelImaging.accelerationFactor,'kspace_encoding_step_1', at int2str);
-        append_node(docNode,n3,parallelImaging.accelerationFactor,'kspace_encoding_step_2', at int2str);
-        n2.appendChild(n3);
-        
-        append_optional(docNode,n2,parallelImaging,'calibrationMode'); 
-        append_optional(docNode,n2,parallelImaging,'interleavingDimension', at int2str); 
-        
-        node.appendChild(n2);
+        if ~isempty(fieldnames(enc.parallelImaging))
+            n2 = docNode.createElement('parallelImaging');
+
+            n3 = docNode.createElement('accelerationFactor');
+            parallelImaging = enc.parallelImaging;
+            append_node(docNode,n3,parallelImaging.accelerationFactor,'kspace_encoding_step_1', at int2str);
+            append_node(docNode,n3,parallelImaging.accelerationFactor,'kspace_encoding_step_2', at int2str);
+            n2.appendChild(n3);
+
+            append_optional(docNode,n2,parallelImaging,'calibrationMode'); 
+            append_optional(docNode,n2,parallelImaging,'interleavingDimension', at int2str); 
+
+            node.appendChild(n2);
+        end
+    end
+    
+    if isfield(enc,'echoTrainLength')
+        if ~isempty(enc.echoTrainLength)
+            append_optional(docNode,node,enc,'echoTrainLength', at int2str);
+        end
     end
-        
-    append_optional(docNode,node,enc,'echoTrainLength', at int2str);
     
     docRootNode.appendChild(node);
     
@@ -149,11 +171,10 @@ if isfield(header,'sequenceParameters')
     n1 = docNode.createElement('sequenceParameters');
     sequenceParameters = header.sequenceParameters;
     
-    append_node(docNode,n1,sequenceParameters,'TR', at num2str);
-    append_node(docNode,n1,sequenceParameters,'TE', at num2str);
-    append_node(docNode,n1,sequenceParameters,'TI', at num2str);
-    
-    append_node(docNode,n1,sequenceParameters,'flipAngle_deg', at num2str);
+    append_optional(docNode,n1,sequenceParameters,'TR', at num2str);
+    append_optional(docNode,n1,sequenceParameters,'TE', at num2str);
+    append_optional(docNode,n1,sequenceParameters,'TI', at num2str);
+    append_optional(docNode,n1,sequenceParameters,'flipAngle_deg', at num2str);
     docRootNode.appendChild(n1);
 end
 
@@ -161,10 +182,20 @@ if isfield(header,'userParameters')
     n1 = docNode.createElement('userParameters');
     userParameters = 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');
+    if isfield(userParameters,'userParameterLong')
+        append_user_parameter(docNode,n1,userParameters,'userParameterLong', at int2str);
+    end
+    
+    if isfield(userParameters,'userParameterDouble')
+        append_user_parameter(docNode,n1,userParameters,'userParameterDouble', at num2str);
+    end
+    if isfield(userParameters,'userParameterString')
+        append_user_parameter(docNode,n1,userParameters,'userParameterString');
+    end
+    if isfield(userParameters,'userParameterBase64')
+        append_user_parameter(docNode,n1,userParameters,'userParameterBase64');
+    end
+    
     docRootNode.appendChild(n1);
 end
 xml_doc = xmlwrite(docNode);
@@ -174,17 +205,17 @@ xml_doc = xmlwrite(docNode);
 
 end
 
-function append_user_parameter(docNode,subNode,name,values,tostr)
+function append_user_parameter(docNode,subNode,values,name,tostr)
 
-for v = values(:)
+for v = 1:length(values.(name))
     n2 = docNode.createElement(name);
     
-    append_node(docNode,n2,v,'name');
+    append_node(docNode,n2,values.(name)(v),'name');
     
     if nargin > 4
-        append_node(docNode,n2,v,'value',tostr);
+        append_node(docNode,n2,values.(name)(v),'value',tostr);
     else
-        append_node(docNode,n2,v,'value');
+        append_node(docNode,n2,values.(name)(v),'value');
     end
     
     subNode.appendChild(n2);

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