Commit 2443e449 authored by sreekanthkura7's avatar sreekanthkura7
Browse files

Fix LengthUnit error

parent 77e61b92
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -7,12 +7,14 @@ end
% Matlab stores contiguous muti-dimensional arrays in column-major order.
% HDF5 stores them in row-major order. We want to transpose the data to agree
% with the file format's storage order.
if ~isrow(val) && ~iscolumn(val)            % Matrices
    val = permute(val, ndims(val):-1:1);
elseif ischar(val)                          % 1D char strings 
    val = permute(val, ndims(val):-1:1);
elseif ~isempty(findstr('multidim', options))   % Force multi-dimensional even if vector
if (~isrow(val) && ~iscolumn(val))              || ...      % Matrices
     ~isempty(findstr('multidim', options))      || ...      % Force multi-dimensional even if vector
     ~isempty(findstr('2D', options))                        % Force 2D even if vector
    
    val = permute(val, ndims(val):-1:1);
elseif ~isempty(findstr('2D', options))         % Force 2D even if vector
    
elseif iscolumn(val) && ischar(val)
    
    val = permute(val, ndims(val):-1:1);
    
end
+467 −0

File added.

Preview size limit exceeded, changes collapsed.

+70 −55
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ classdef ProbeClass < FileLoadSaveClass
    end
    
    
    
    methods
        
        % -------------------------------------------------------
@@ -145,15 +146,16 @@ classdef ProbeClass < FileLoadSaveClass
            if isempty(obj.sourcePos2D) && isempty(obj.detectorPos2D)
                if isempty(obj.landmarkPos3D)
                    if ~isempty(obj.sourcePos3D)
                        obj.sourcePos2D = obj.sourcePos3D(:,1:2);
                        obj.sourcePos2D = project_3D_to_2D(obj.sourcePos3D);
                    end
                    if ~isempty(obj.detectorPos3D)
                        obj.detectorPos2D = obj.detectorPos3D(:,1:2);
                        obj.detectorPos2D = project_3D_to_2D(obj.detectorPos3D);
                    end
%                     if isfield(obj,'DummyPos3D') & ~isempty(obj.DummyPos3D)
%                         obj.DummyPos2D = obj.DummyPos3D(:,1:2);
%                     end
                else
                     if ~isempty(obj.sourcePos3D) && ~isempty(obj.detectorPos3D)
                        [sphere.label, sphere.theta, sphere.phi, sphere.r, sphere.xc, sphere.yc, sphere.zc] = textread('10-5-System_Mastoids_EGI129.csd','%s %f %f %f %f %f %f','commentstyle','c++');
                        % ref pt labels used for affine transformation
                        refpts_labels = {'T7','T8','Oz','Fpz','Cz','C3','C4','Pz','Fz'};
@@ -173,7 +175,7 @@ classdef ProbeClass < FileLoadSaveClass

                        % get affine transformation
                        % probe_refps*T = sphere_refpts
                    probe_refps_pos = [probe_refps_pos ones(size(probe_refps_pos,1),1)];
                        probe_refps_pos = [probe_refps_pos(:,1:3) ones(size(probe_refps_pos,1),1)];
                        T = probe_refps_pos\sphere_refpts_pos;

                        % tranform optode positions onto unit sphere.
@@ -205,10 +207,8 @@ classdef ProbeClass < FileLoadSaveClass
                        obj.landmarkPos2D = refpts_2D.pos;

                        %%
                    if ~isempty(obj.sourcePos3D)

                        obj.sourcePos2D = convert_optodepos_to_circlular_2D_pos(obj, obj.sourcePos3D, T, norm_factor);
                    end
                    if ~isempty(obj.detectorPos3D)
                        obj.detectorPos2D = convert_optodepos_to_circlular_2D_pos(obj, obj.detectorPos3D, T, norm_factor);
                    end
%                     if isfield(obj,'DummyPos3D') & ~isempty(obj.DummyPos3D)
@@ -236,7 +236,7 @@ classdef ProbeClass < FileLoadSaveClass
        
        
        % -------------------------------------------------------
        function err = LoadHdf5(obj, fileobj, location)
        function err = LoadHdf5(obj, fileobj, location, LengthUnit)
            err = 0;
            
            % Arg 1
@@ -251,6 +251,19 @@ classdef ProbeClass < FileLoadSaveClass
                location = ['/',location];
            end
            
            % Arg3
            scaling = 1;
            if exist('LengthUnit','var')
                if strcmpi(LengthUnit,'m')
                    scaling = 1000;
                elseif strcmpi(LengthUnit,'cm')
                    scaling = 10;
                end
            end
            
            

              
            % Error checking            
            if ~isempty(fileobj) && ischar(fileobj)
                obj.SetFilename(fileobj);
@@ -269,12 +282,12 @@ classdef ProbeClass < FileLoadSaveClass
                % Load datasets
                obj.wavelengths               = HDF5_DatasetLoad(gid, 'wavelengths');
                obj.wavelengthsEmission       = HDF5_DatasetLoad(gid, 'wavelengthsEmission');
                obj.sourcePos2D               = HDF5_DatasetLoad(gid, 'sourcePos2D', [], '2D');
                obj.detectorPos2D             = HDF5_DatasetLoad(gid, 'detectorPos2D', [], '2D');
                obj.landmarkPos2D             = HDF5_DatasetLoad(gid, 'landmarkPos2D', [], '2D');
                obj.sourcePos3D               = HDF5_DatasetLoad(gid, 'sourcePos3D', [], '3D');
                obj.detectorPos3D             = HDF5_DatasetLoad(gid, 'detectorPos3D', [], '3D');
                obj.landmarkPos3D             = HDF5_DatasetLoad(gid, 'landmarkPos3D', [], '2D');
                obj.sourcePos2D               = HDF5_DatasetLoad(gid, 'sourcePos2D', [], '2D')*scaling;
                obj.detectorPos2D             = HDF5_DatasetLoad(gid, 'detectorPos2D', [], '2D')*scaling;
                obj.landmarkPos2D             = HDF5_DatasetLoad(gid, 'landmarkPos2D', [], '2D')*scaling;
                obj.sourcePos3D               = HDF5_DatasetLoad(gid, 'sourcePos3D', [], '3D')*scaling;
                obj.detectorPos3D             = HDF5_DatasetLoad(gid, 'detectorPos3D', [], '3D')*scaling;
                obj.landmarkPos3D             = HDF5_DatasetLoad(gid, 'landmarkPos3D', [], '2D')*scaling;
                obj.frequencies               = HDF5_DatasetLoad(gid, 'frequencies');
                obj.timeDelays                 = HDF5_DatasetLoad(gid, 'timeDelays');
                obj.timeDelayWidths            = HDF5_DatasetLoad(gid, 'timeDelayWidths');
@@ -338,6 +351,7 @@ classdef ProbeClass < FileLoadSaveClass
                fid = H5F.create(fileobj, 'H5F_ACC_TRUNC', 'H5P_DEFAULT', 'H5P_DEFAULT');
                H5F.close(fid);
            end 
            
            hdf5write_safe(fileobj, [location, '/wavelengths'], obj.wavelengths, 'array');
            hdf5write_safe(fileobj, [location, '/wavelengthsEmission'], obj.wavelengthsEmission, 'array');
            hdf5write_safe(fileobj, [location, '/sourcePos2D'], obj.sourcePos2D, 'array');
@@ -359,6 +373,7 @@ classdef ProbeClass < FileLoadSaveClass
        
        
        
        
        % ---------------------------------------------------------
        function wls = GetWls(obj)
            wls = obj.wavelengths;
+4 −1
Original line number Diff line number Diff line
@@ -464,8 +464,11 @@ classdef SnirfClass < AcqDataClass & FileLoadSaveClass
        
        % -------------------------------------------------------
        function err = LoadProbe(obj, fileobj, ~)
            % get lenth unit through class method
            LengthUnit = obj.metaDataTags.Get('LengthUnit').value;
            obj.probe = ProbeClass();
            err = obj.probe.LoadHdf5(fileobj, [obj.location, '/probe']);
            err = obj.probe.LoadHdf5(fileobj, [obj.location, '/probe'], LengthUnit);
            obj.metaDataTags.Set('LengthUnit','mm');
            
            % This is a required field. If it's empty means the whole snirf object is bad
            if isempty(obj.probe)