|
16 | 16 | nirsdatanum
|
17 | 17 | nirs_tb
|
18 | 18 | stim0
|
| 19 | + hFig |
19 | 20 | end
|
20 | 21 |
|
21 | 22 | methods
|
|
78 | 79 | obj.SetFileFormat('hdf5');
|
79 | 80 | obj.location = '/nirs';
|
80 | 81 | obj.nirsdatanum = 1;
|
| 82 | + obj.hFig = [-1; -1]; |
| 83 | + |
81 | 84 |
|
82 | 85 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
83 | 86 | % Between 1 and 4 arguments covers the following syntax variants
|
@@ -1005,8 +1008,17 @@ function SetData(obj, val)
|
1005 | 1008 | end
|
1006 | 1009 |
|
1007 | 1010 | % ---------------------------------------------------------
|
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; |
1010 | 1022 | end
|
1011 | 1023 |
|
1012 | 1024 | % ---------------------------------------------------------
|
@@ -1886,9 +1898,261 @@ function Info(obj)
|
1886 | 1898 | MenuBox(msg);
|
1887 | 1899 | end
|
1888 | 1900 | 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 | + |
1889 | 1917 |
|
| 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 |
1890 | 1998 |
|
1891 | 1999 |
|
| 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 | + |
1892 | 2156 | end
|
1893 | 2157 |
|
1894 | 2158 |
|
|
0 commit comments