Skip to content

Commit 72e3a8d

Browse files
committed
v1.80.0
-- Redo Export Snirf feature for Exporting derived data to SNIRF file. -- Add SnirfClass functionality to plot derived data. -- Fix Spline SG MakeFilter.m with Teresa Girolamo Group dataset. The message for her data set keeps displaying the warning "Filter parameters exceed Nyquist frequency" during processing that ties up user clicking OK to message box messages for each channel of data time series. Fix by instead displaying a message dialog once for each file or option to quit processing and throw error exception. -- Fix issue with menu threowing exception error Error using matlab.ui.Figure/set Error setting property 'Position' of class 'Figure': Width and height must be greater than or equal to 0 because we change parent units for screen to 'normalized'. Fix is to make sure to always set the monitor units back to 'pixels'.
1 parent f162f70 commit 72e3a8d

File tree

16 files changed

+553
-68
lines changed

16 files changed

+553
-68
lines changed

DataTree/AcquiredData/AcqDataClass.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
% ---------------------------------------------------------
5050
s = GetStims(obj, t)
5151

52+
% ---------------------------------------------------------
53+
s = GetStim(obj)
54+
5255
% ---------------------------------------------------------
5356
CondNames = GetConditions(obj)
5457

DataTree/AcquiredData/Nirs/NirsClass.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,12 @@ function SetStims_MatInput(obj, s, ~, ~)
770770
end
771771

772772

773+
% ---------------------------------------------------------
774+
function s = GetStim(obj)
775+
s = obj.s;
776+
end
777+
778+
773779
% ----------------------------------------------------------------------------------
774780
function SetConditions(obj, CondNames)
775781
if nargin==1

DataTree/AcquiredData/Snirf/SnirfClass.m

Lines changed: 266 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
nirsdatanum
1717
nirs_tb
1818
stim0
19+
hFig
1920
end
2021

2122
methods
@@ -78,6 +79,8 @@
7879
obj.SetFileFormat('hdf5');
7980
obj.location = '/nirs';
8081
obj.nirsdatanum = 1;
82+
obj.hFig = [-1; -1];
83+
8184

8285
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8386
% Between 1 and 4 arguments covers the following syntax variants
@@ -1005,8 +1008,17 @@ function SetData(obj, val)
10051008
end
10061009

10071010
% ---------------------------------------------------------
1008-
function val = GetData(obj)
1009-
val = obj.data;
1011+
function [val, t] = GetData(obj, iBlk)
1012+
val = [];
1013+
t = [];
1014+
if ~exist('iBlk','var') || isempty(iBlk)
1015+
iBlk = 1;
1016+
end
1017+
if isempty(obj) || isempty(obj.data)
1018+
return;
1019+
end
1020+
val = obj.data(iBlk);
1021+
t = obj.data(iBlk).time;
10101022
end
10111023

10121024
% ---------------------------------------------------------
@@ -1886,9 +1898,261 @@ function Info(obj)
18861898
MenuBox(msg);
18871899
end
18881900
end
1901+
1902+
1903+
1904+
% ----------------------------------------------------------------------------------
1905+
function hAxes = GenerateStandaloneAxes(obj, datatype, iChs)
1906+
k = find(obj.hFig(1,:)==-1);
1907+
obj.hFig(1,k(1)) = figure;
1908+
hAxes = gca;
1909+
plotname = sprintf('"%s"; %s data ; channels idxs: [%s]', obj.GetFilename(), datatype, num2str(iChs'));
1910+
namesize = uint32(length(plotname)/3);
1911+
set(obj.hFig(1,k(1)), 'units','characters');
1912+
p1 = get(obj.hFig(1,k(1)), 'position');
1913+
set(obj.hFig(1,k(1)), 'name',plotname, 'menubar','none', 'NumberTitle','off', 'position',[p1(1)/2, p1(2), p1(3)+namesize, p1(4)]);
1914+
obj.hFig(:,k(1)+1) = -1;
1915+
end
1916+
18891917

1918+
1919+
% ----------------------------------------------------------------------------------
1920+
function Plot(obj, sdPairs, iBlk)
1921+
%
1922+
% SYNTAX:
1923+
% TreeNodeClass.Plot(iChs, iBlk)
1924+
%
1925+
%
1926+
% DESCRIPTION:
1927+
% Plot data from channels specified by 2d array where each row spoecifying a single channel
1928+
% contains indices [source, detector, condition, wavelength]. In addtion to the data, this method
1929+
% plots any existing stims, and the probe associated with the SNIRF object from which the data
1930+
% was taken. NOTE: the args iBlk and hAxes can be ommitted and will default to 1 and current
1931+
% axes respectively.
1932+
%
1933+
%
1934+
% INPUT:
1935+
% sdPairs - 2d array of channel indices where each row represents a channel consisting of the indices
1936+
% [source, detector, condition, datatype]
1937+
%
1938+
% iBlk - Optional argument (defaults = 1). In theory SNIRF data field is an array of data blocks. This argunment selects the
1939+
% data block from which the plot data is taken.
1940+
%
1941+
% hAxes - Optional argument (default is current axes or gca()), specifying the axes handle of the axes in which to plot the data.
1942+
%
1943+
%
1944+
1945+
% Parse input args
1946+
if ~exist('sdPairs','var')
1947+
sdPairs = [1,1,0,1];
1948+
end
1949+
if ~exist('iBlk','var') || isempty(iBlk)
1950+
iBlk = 1;
1951+
end
1952+
1953+
1954+
% Convert channels in the form of a list of sd pairs to a column vector of indices into the measurement list
1955+
iChs = obj.SdPairIdxs2vectorIdxs(sdPairs, iBlk);
1956+
1957+
1958+
% Extract SNIRF parameters for plotting: probe, data, time, measuremntList and stim
1959+
d = obj.data(1).dataTimeSeries;
1960+
t = obj.data(1).time;
1961+
ml = obj.data(1).GetMeasurementList('matrix');
1962+
1963+
% If there's no data to plot then exit
1964+
if isempty(d)
1965+
fprintf('No data to plot\n');
1966+
return;
1967+
end
1968+
1969+
1970+
% Set up standalone figure with axes for plotting data, if axes handle was not passed down from caller
1971+
% in the last arg. There will be a separate figure displaying the probe associated with this data plot.
1972+
% a few lines down in DisplayProbe.
1973+
hAxes = obj.GenerateStandaloneAxes('HRF', iChs);
1974+
1975+
% Plot data
1976+
hold on
1977+
chSelect = [];
1978+
for ii = 1:length(iChs)
1979+
hdata(ii) = plot(hAxes, t, d(:,iChs(ii)), 'linewidth',2);
1980+
chSelect(ii,:) = [ml(iChs(ii),1), ml(iChs(ii),2), ml(iChs(ii),3), ml(iChs(ii),4), get(hdata(ii), 'color')];
1981+
end
1982+
set(hAxes, 'xlim', [t(1), t(end)]);
1983+
1984+
% Display probe in separate figure
1985+
if isempty(chSelect)
1986+
fprintf('ERROR: no valid channels were selelcted\n');
1987+
obj.DisplayProbe();
1988+
else
1989+
obj.DisplayProbe(chSelect(:,1:2), chSelect(:,5:7));
1990+
end
1991+
1992+
1993+
% Wrap up before exiting
1994+
drawnow;
1995+
pause(.1);
1996+
hold off
1997+
end
18901998

18911999

2000+
% ----------------------------------------------------------------------------------
2001+
function iChs = SdPairIdxs2vectorIdxs(obj, sdPairs, iBlk)
2002+
iChs = [];
2003+
if ~exist('sdPairs','var')
2004+
sdPairs = [1,1,0,1];
2005+
end
2006+
if ~exist('iBlk','var') || isempty(iBlk)
2007+
iBlk = 1;
2008+
end
2009+
2010+
% Error Checking
2011+
if size(sdPairs, 2)>1 && size(sdPairs, 2)~=4
2012+
fprintf('ERROR: invalid sdPair. sdPair has to be a Nx4 2D array\n');
2013+
return;
2014+
end
2015+
2016+
2017+
% If sdPairs argument is a column vector then we are done because channels are
2018+
% already specified in the output format i.e., as single number indices.
2019+
if size(sdPairs, 2)==1
2020+
iChs = sdPairs;
2021+
return;
2022+
end
2023+
2024+
ml = obj.data(1).GetMeasurementList('matrix', iBlk);
2025+
2026+
% Error checking
2027+
if isempty(ml)
2028+
return
2029+
end
2030+
2031+
for ii = 1:size(sdPairs,1)
2032+
k = find(ml(:,1)==sdPairs(ii,1) & ml(:,2)==sdPairs(ii,2) & ml(:,3)==sdPairs(ii,3) & ml(:,4)==sdPairs(ii,4));
2033+
if isempty(k)
2034+
continue;
2035+
end
2036+
iChs(ii,1) = k;
2037+
end
2038+
end
2039+
2040+
2041+
2042+
% ----------------------------------------------------------------------------------
2043+
function sdPairs = VectorIdxs2SdPairIdxs(obj, iChs, iBlk)
2044+
if ~exist('iChs','var')
2045+
iChs = 1;
2046+
end
2047+
if ~exist('iBlk','var') || isempty(iBlk)
2048+
iBlk = 1;
2049+
end
2050+
2051+
% If sdPairs argument is not a column vector then we are done; because the
2052+
% channels are already specified in the output format i.e., as a 2d array.
2053+
if size(iChs, 2)>1
2054+
sdPairs = iChs;
2055+
return;
2056+
end
2057+
2058+
ml = obj.data(1).GetMeasurementList('matrix', iBlk);
2059+
2060+
% Remove any invalid indices
2061+
iChs(iChs==0) = [];
2062+
iChs(iChs>size(ml,1)) = [];
2063+
2064+
sdPairs = ml(iChs,:);
2065+
end
2066+
2067+
2068+
2069+
% ----------------------------------------------------------------------------------
2070+
function hAxes = DisplayProbe(obj, chSelect, chSelectColors, hAxes)
2071+
% Parse args
2072+
if ~exist('chSelect','var')
2073+
chSelect = [];
2074+
end
2075+
if ~exist('chSelectColors','var')
2076+
chSelectColors = repmat([1.0, 0.5, 0.2], size(chSelect,1),1);
2077+
end
2078+
if ~exist('hAxes','var')
2079+
hAxes = [];
2080+
end
2081+
2082+
% If chSelect is in the form of a column vector rather than sd pairs
2083+
% then convert to sd pairs
2084+
chSelect = obj.VectorIdxs2SdPairIdxs(chSelect);
2085+
2086+
freememoryflag = false;
2087+
if ~isempty(obj) && obj.IsEmpty()
2088+
obj.acquired.Load();
2089+
freememoryflag = true;
2090+
end
2091+
2092+
% Set up the axes
2093+
bbox = obj.GetSdgBbox();
2094+
if isempty(hAxes)
2095+
k = find(obj.hFig(2,:)==-1);
2096+
2097+
% See if there's a data plot associated with this probe display
2098+
% If there is get its name and use it to name this figure
2099+
plotname = '';
2100+
if ishandle(obj.hFig(1,k(1)))
2101+
plotname = get(obj.hFig(1,k(1)), 'name');
2102+
end
2103+
obj.hFig(2,k(1)) = figure('menubar','none', 'NumberTitle','off', 'name',plotname);
2104+
hAxes = gca;
2105+
end
2106+
2107+
axis(hAxes, [bbox(1), bbox(2), bbox(3), bbox(4)]);
2108+
gridsize = get(hAxes, {'xlim', 'ylim', 'zlim'});
2109+
if ismac() || islinux()
2110+
fs = 18;
2111+
else
2112+
fs = 11;
2113+
end
2114+
2115+
% Get probe paramaters
2116+
probe = obj.GetProbe();
2117+
srcpos = probe.sourcePos2D;
2118+
detpos = probe.detectorPos2D;
2119+
ml = obj.GetMeasurementList('matrix');
2120+
lstSDPairs = find(ml(:,4)==1);
2121+
2122+
% Draw all channels
2123+
for ii = 1:length(lstSDPairs)
2124+
hCh(ii) = line2(srcpos(ml(lstSDPairs(ii),1),:), detpos(ml(lstSDPairs(ii),2),:), [], gridsize, hAxes);
2125+
col = [1.00 1.00 1.00] * 0.85;
2126+
if ~isempty(chSelect)
2127+
k = find(chSelect(:,1)==ml(lstSDPairs(ii),1) & chSelect(:,2)==ml(lstSDPairs(ii),2));
2128+
if ~isempty(k)
2129+
col = chSelectColors(k(1),:);
2130+
end
2131+
end
2132+
set(hCh(ii), 'color',col, 'linewidth',2, 'linestyle','-', 'userdata',ml(lstSDPairs(ii),1:2));
2133+
end
2134+
2135+
% ADD SOURCE AND DETECTOR LABELS
2136+
for iSrc = 1:size(srcpos,1)
2137+
if ~isempty(find(ml(:,1)==iSrc)) %#ok<*EFIND>
2138+
hSD(iSrc) = text( srcpos(iSrc,1), srcpos(iSrc,2), sprintf('%d', iSrc), 'fontsize',fs, 'fontweight','bold', 'color','r' );
2139+
set(hSD(iSrc), 'horizontalalignment','center', 'edgecolor','none', 'Clipping', 'on');
2140+
end
2141+
end
2142+
for iDet = 1:size(detpos,1)
2143+
if ~isempty(find(ml(:,2)==iDet))
2144+
hSD(iDet+iSrc) = text( detpos(iDet,1), detpos(iDet,2), sprintf('%d', iDet), 'fontsize',fs, 'fontweight','bold', 'color','b' );
2145+
set(hSD(iDet+iSrc), 'horizontalalignment','center', 'edgecolor','none', 'Clipping', 'on');
2146+
end
2147+
end
2148+
2149+
if freememoryflag
2150+
obj.FreeMemory();
2151+
end
2152+
end
2153+
2154+
2155+
18922156
end
18932157

18942158

DataTree/GroupClass.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,15 @@ function Save(obj, hwait)
709709
obj.logger.Write(ME.message);
710710
end
711711
obj.initsaveflag = true;
712+
713+
% Clean up folder of .error files
714+
if exist([pwd, '/.error'],'file')
715+
try
716+
delete([pwd, '/.error'])
717+
catch
718+
end
719+
end
720+
712721
end
713722

714723

DataTree/ProcStream/ProcInputClass.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ function SaveAcquiredData(obj)
198198
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199199
methods
200200

201+
% ----------------------------------------------------------------------------------
202+
function stim = GetStim(obj)
203+
stim = obj.acquired.GetStim();
204+
end
205+
206+
201207
% ----------------------------------------------------------------------------------
202208
function vals = GetStimValSettings(obj)
203209
vals = obj.stimValSettings;

DataTree/ProcStream/ProcResultClass.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,26 @@ function SetNtrials(obj, val)
660660
end
661661

662662

663+
% ----------------------------------------------------------------------------------
664+
function s = GetData(obj, datatype)
665+
if nargin==1
666+
t = [];
667+
end
668+
s = obj.GetVar('s');
669+
if isempty(s)
670+
if isempty(obj.dod) || ~isa(obj.dod, 'DataClass')
671+
return;
672+
end
673+
stim = obj.GetVar('stim');
674+
if isempty(stim)
675+
return;
676+
end
677+
snirf = SnirfClass(obj.dod, stim);
678+
s = snirf.GetStims(t);
679+
end
680+
end
681+
682+
663683
% ----------------------------------------------------------------------------------
664684
function val = GetTincAuto(obj, iBlk)
665685
val = {};

0 commit comments

Comments
 (0)