Commit 043e67d6 authored by jayd1860's avatar jayd1860
Browse files

v1.20.4

-- Update SnirfClass to match latest changes to SNIRF spec: sourcePos changed to sourcePos2D, detectorPos to detector2D, and a method to write/read HDF5 strings fields like sourceLabels/detectorLabels
parent ccc39212
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
function HDF5_WriteStrings(fname, location, data)

if ~exist(fname, 'file')
    fid = H5F.create(fname, 'H5F_ACC_TRUNC', 'H5P_DEFAULT', 'H5P_DEFAULT');
else
    fid = H5F.open(fname,'H5F_ACC_RDWR','H5P_DEFAULT');
end
data = cell2str_new(data);

filetype = H5T.copy('H5T_FORTRAN_S1'); 
H5T.set_size(filetype, size(data,2)); 
memtype = H5T.copy('H5T_C_S1'); 
H5T.set_size(memtype, size(data,2)); 

% Create dataspace. Setting maximum size to [] sets the maximum 
% size to be the current size. 
space = H5S.create_simple(1, size(data,1), []); 

% Create the dataset and write the string data to it. 
dset = H5D.create(fid, location, filetype, space, 'H5P_DEFAULT'); 

% Transpose the data to match the layout in the H5 file to match C 
% generated H5 file. 
H5D.write(dset, memtype, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT',  data'); 

% Close and release resources. 
H5D.close(dset); 
H5S.close(space); 
H5T.close(filetype); 
H5T.close(memtype); 
H5F.close(fid); 

+23 −21
Original line number Diff line number Diff line
@@ -8,8 +8,10 @@ if ~exist('options','var')
    options = '';
end

if iscell(val)
    HDF5_WriteStrings(fname, name, val)
else
    val = HDF5_Transpose(val, options);

    try
        if ~isempty(findstr('rw', options))
            try
@@ -30,5 +32,5 @@ try
    catch
        return;
    end

end
err = 0;
 No newline at end of file
+14 −14
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ classdef ProbeClass < FileLoadSaveClass
    properties
        wavelengths
        wavelengthsEmission
        sourcePos
        detectorPos
        sourcePos2D
        detectorPos2D
        frequency
        timeDelay
        timeDelayWidth
@@ -29,8 +29,8 @@ classdef ProbeClass < FileLoadSaveClass
                    SD = varargin{1};
                    obj.wavelengths = SD.Lambda;
                    obj.wavelengthsEmission  = [];
                    obj.sourcePos  = SD.SrcPos;
                    obj.detectorPos  = SD.DetPos;
                    obj.sourcePos2D  = SD.SrcPos;
                    obj.detectorPos2D  = SD.DetPos;
                    obj.frequency  = 1;
                    obj.timeDelay  = 0;
                    obj.timeDelayWidth  = 0;
@@ -50,8 +50,8 @@ classdef ProbeClass < FileLoadSaveClass
            else
                obj.wavelengths          = [];
                obj.wavelengthsEmission  = [];
                obj.sourcePos  = [];
                obj.detectorPos  = [];
                obj.sourcePos2D  = [];
                obj.detectorPos2D  = [];
                obj.frequency  = 1;
                obj.timeDelay  = 0;
                obj.timeDelayWidth  = 0;
@@ -99,8 +99,8 @@ classdef ProbeClass < FileLoadSaveClass
                % Load datasets
                obj.wavelengths               = HDF5_DatasetLoad(gid, 'wavelengths');
                obj.wavelengthsEmission       = HDF5_DatasetLoad(gid, 'wavelengthsEmission');
                obj.sourcePos                 = HDF5_DatasetLoad(gid, 'sourcePos', [], '2D');
                obj.detectorPos               = HDF5_DatasetLoad(gid, 'detectorPos', [], '2D');
                obj.sourcePos2D                 = HDF5_DatasetLoad(gid, 'sourcePos2D', [], '2D');
                obj.detectorPos2D               = HDF5_DatasetLoad(gid, 'detectorPos2D', [], '2D');
                obj.frequency                 = HDF5_DatasetLoad(gid, 'frequency');
                obj.timeDelay                 = HDF5_DatasetLoad(gid, 'timeDelay');
                obj.timeDelayWidth            = HDF5_DatasetLoad(gid, 'timeDelayWidth');
@@ -139,8 +139,8 @@ classdef ProbeClass < FileLoadSaveClass
            end     
            hdf5write_safe(fileobj, [location, '/wavelengths'], obj.wavelengths);
            hdf5write_safe(fileobj, [location, '/wavelengthsEmission'], obj.wavelengthsEmission);
            hdf5write_safe(fileobj, [location, '/sourcePos'], obj.sourcePos, 'rw:2D');
            hdf5write_safe(fileobj, [location, '/detectorPos'], obj.detectorPos, 'rw:2D');
            hdf5write_safe(fileobj, [location, '/sourcePos2D'], obj.sourcePos2D, 'rw:2D');
            hdf5write_safe(fileobj, [location, '/detectorPos2D'], obj.detectorPos2D, 'rw:2D');
            hdf5write_safe(fileobj, [location, '/frequency'], obj.frequency);
            hdf5write_safe(fileobj, [location, '/timeDelay'], obj.timeDelay);
            hdf5write_safe(fileobj, [location, '/timeDelayWidth'], obj.timeDelayWidth);
@@ -162,13 +162,13 @@ classdef ProbeClass < FileLoadSaveClass
        
        % ---------------------------------------------------------
        function srcpos = GetSrcPos(obj)
            srcpos = obj.sourcePos;
            srcpos = obj.sourcePos2D;
        end
        
        
        % ---------------------------------------------------------
        function detpos = GetDetPos(obj)
            detpos = obj.detectorPos;
            detpos = obj.detectorPos2D;
        end
        
        
@@ -181,10 +181,10 @@ classdef ProbeClass < FileLoadSaveClass
            if ~all(obj.wavelengthsEmission(:)==obj2.wavelengthsEmission(:))
                return;
            end
            if ~all(obj.sourcePos(:)==obj2.sourcePos(:))
            if ~all(obj.sourcePos2D(:)==obj2.sourcePos2D(:))
                return;
            end
            if ~all(obj.detectorPos(:)==obj2.detectorPos(:))
            if ~all(obj.detectorPos2D(:)==obj2.detectorPos2D(:))
                return;
            end
            if ~all(obj.frequency(:)==obj2.frequency(:))
+1 −0
Original line number Diff line number Diff line
@@ -450,6 +450,7 @@ classdef SnirfClass < AcqDataClass & FileLoadSaveClass
            
            % Save aux
            obj.SaveAux(fileobj);            

        end
       
        
+10 −9
Original line number Diff line number Diff line
@@ -68,8 +68,8 @@ class ProbeClass(ErrorClass):

        self.wavelengths          = np.array(fid.get(location + '/wavelengths'))
        self.wavelengthsEmission  = fid.get(location + '/wavelengthsEmission')
        self.sourcePos  = np.array(fid.get(location + '/sourcePos'))
        self.detectorPos  = np.array(fid.get(location + '/detectorPos'))
        self.sourcePos2D  = np.array(fid.get(location + '/sourcePos2D'))
        self.detectorPos2D  = np.array(fid.get(location + '/detectorPos2D'))
        self.frequency  = np.array(fid.get(location + '/frequency'))
        self.timeDelay  = 0
        self.timeDelayWidth  = 0
@@ -86,12 +86,12 @@ class ProbeClass(ErrorClass):
    def Print(self):
        sys.stdout.write('  wavelengths = %s\n'% self.wavelengths)
        sys.stdout.write('  wavelengthsEmission = %s\n'% self.wavelengthsEmission)
        sys.stdout.write('  sourcePos:\n')
        for ii in range(0, self.sourcePos.shape[0]):
            sys.stdout.write('      %s\n'% self.sourcePos[ii])
        sys.stdout.write('  detectorPos:\n')
        for ii in range(0, self.detectorPos.shape[0]):
            sys.stdout.write('      %s\n'% self.detectorPos[ii])
        sys.stdout.write('  sourcePos2D:\n')
        for ii in range(0, self.sourcePos2D.shape[0]):
            sys.stdout.write('      %s\n'% self.sourcePos2D[ii])
        sys.stdout.write('  detectorPos2D:\n')
        for ii in range(0, self.detectorPos2D.shape[0]):
            sys.stdout.write('      %s\n'% self.detectorPos2D[ii])
        sys.stdout.write('  frequency = %s\n'% self.frequency)
        sys.stdout.write('  timeDelay = %s\n'% self.timeDelay)
        sys.stdout.write('  timeDelayWidth = %s\n'% self.timeDelayWidth)
@@ -218,7 +218,8 @@ if __name__ == "__main__":
    if len(sys.argv) > 1:
        filenames[0] =  sys.argv[1]
    else:
        filenames = glob.glob('./Examples/*.snirf')
        filenames = glob.glob('../../../../snirf-samples/basic/*.snirf')
        # filenames = glob.glob('./Examples/*.snirf')

    for ii in range(0, len(filenames)):
        sys.stdout.write('======================================================================\n')
Loading