Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor fixes to SNIRF import code #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions DataFiles/FileLoadSaveClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


% ---------------------------------------------------------
function Load(obj, filename, format)
function varargout=Load(obj, filename, format)
if ~exist('filename','var')
filename = obj.filename;
end
Expand All @@ -41,9 +41,28 @@ function Load(obj, filename, format)
end
case obj.supportedFomats.hdf5
if ismethod(obj, 'LoadHdf5')
obj.LoadHdf5(filename);

flds=ListHDF5fields(filename);
cnt=1; parent={};
for i=1:length(flds)
f=strsplit(flds{i},'/');
if(length(f)>1 && ~isempty(strfind(f{2},'nirs')))
parent{cnt}=['/' f{2}];
cnt=cnt+1;
end
end
parent=unique(parent);
for i=1:length(parent)
obj(i)=obj(1);
obj(i).LoadHdf5(filename,parent{i});
end
end
end
if(nargout>0)
varargout={obj};
elseif(length(parent)>1)
warning(['multiple /nirs entries found; use snirf=snirf.load(''' filename ''');']);
end
end


Expand Down
33 changes: 33 additions & 0 deletions DataFiles/Hdf5/hd5read_safeStrArray.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function valout2 = hd5read_safeStrArray(fname, name, val)

valout2 = {};
try
try
valout2 = h5read(fname, name);
catch
cnt=1;
valout={};
while(1)
try
valout{cnt}= h5read(fname, [name num2str(cnt)]);
cnt=cnt+1;
catch
break;
end
end


for ii=1:length(valout)
valout2{ii,1} = convertH5StrToStr(valout{ii});
end
end
catch
switch(class(val))
case 'char'
valout2 = '';
case 'cell'
valout2 = {};
otherwise
valout2 = [];
end
end
6 changes: 3 additions & 3 deletions Snirf/DataClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@
obj.time = h5read(fname, [parent, '/time']);
ii=1;
while 1
if ii > length(obj.measurementList)
obj.measurementList(ii) = MeasListClass;
end
if ii > length(obj.measurementList)
obj.measurementList(ii) = MeasListClass;
end
if obj.measurementList(ii).LoadHdf5(fname, [parent, '/measurementList', num2str(ii)]) < 0
obj.measurementList(ii).delete();
obj.measurementList(ii) = [];
Expand Down
56 changes: 56 additions & 0 deletions Snirf/ListHDF5fields.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function [names,val] = ListHDF5fields(filename);

% Ted Added 4/8/2020
info=hdf5info(filename);

names={};
for i=1:length(info.GroupHierarchy)
for j=1:length(info.GroupHierarchy.Groups)
n=getgroups(info.GroupHierarchy.Groups(j));
names={names{:} n{:}};
end
for j=1:length(info.GroupHierarchy.Datasets)
n=getdatasets(info.GroupHierarchy.Datasets(j));
names={names{:} n{:}};
end
end

names=unique(names)';



if(nargout>1)
for i=1:length(names)
val{i}=hdf5read(filename,names{i});
end
varargout{1}=val;
end

function names= getgroups(in)

names={};
if(~isempty(in))
% names={names{:} in.Name};
for j=1:length(in.Groups)
n=getgroups(in.Groups(j));
names={names{:} n{:}};
end
for j=1:length(in.Datasets)
n=getdatasets(in.Datasets(j));
names={names{:} n{:}};
end
end


function names= getdatasets(in)

names={};
if(~isempty(in))
names={names{:} in.Name};
% for j=1:length(in.Groups)
% names={names{:} getgroups(in.Groups(j))};
% end
% for j=1:length(in.Datasets)
% names={names{:} getdatasets(in.Datasets(j))};
% end
end
2 changes: 1 addition & 1 deletion Snirf/MeasListClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
obj.detectorIndex = hdf5read(fname, [parent, '/detectorIndex']);
obj.wavelengthIndex = hdf5read(fname, [parent, '/wavelengthIndex']);
obj.dataType = hdf5read(fname, [parent, '/dataType']);
obj.dataTypeLabel = convertH5StrToStr(hdf5read_safe(fname, [parent, '/dataTypeLabel'], obj.dataTypeLabel));
obj.dataTypeLabel = convertH5StrToStr(h5read_safe(fname, [parent, '/dataTypeLabel'], obj.dataTypeLabel));
obj.dataTypeIndex = hdf5read(fname, [parent, '/dataTypeIndex']);
obj.sourcePower = hdf5read_safe(fname, [parent, '/sourcePower'], obj.sourcePower);
obj.detectorGain = hdf5read_safe(fname, [parent, '/detectorGain'], obj.detectorGain);
Expand Down
12 changes: 4 additions & 8 deletions Snirf/ProbeClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,10 @@
obj.momentOrder = hdf5read_safe(fname, [parent, '/momentOrder'], obj.momentOrder);
obj.correlationTimeDelay = hdf5read_safe(fname, [parent, '/correlationTimeDelay'], obj.correlationTimeDelay);
obj.correlationTimeDelayWidth = hdf5read_safe(fname, [parent, '/correlationTimeDelayWidth'], obj.correlationTimeDelayWidth);
obj.sourceLabels = h5read_safe(fname, [parent, '/sourceLabels'], obj.sourceLabels);
for ii=1:length(obj.sourceLabels)
obj.sourceLabels{ii} = convertH5StrToStr(obj.sourceLabels{ii});
end
obj.detectorLabels = h5read_safe(fname, [parent, '/detectorLabels'], obj.detectorLabels);
for ii=1:length(obj.detectorLabels)
obj.detectorLabels{ii} = convertH5StrToStr(obj.detectorLabels{ii});
end
obj.sourceLabels = hd5read_safeStrArray(fname, [parent, '/sourceLabels'], obj.sourceLabels);

obj.detectorLabels = hd5read_safeStrArray(fname, [parent, '/detectorLabels'], obj.detectorLabels);

catch
err=-1;
return;
Expand Down