Skip to content

Commit

Permalink
UI bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Liddell committed Mar 8, 2019
1 parent 63b8147 commit 50f3461
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 64 deletions.
6 changes: 4 additions & 2 deletions +jrclust/+curate/@CurateController/endSession.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
function res = endSession(obj)
%ENDSESSION Finish curating and return results
if obj.isWorking
jrclust.utils.qMsgBox('An operation is in progress.');
return;
dlgAns = questdlg('An operation is in progress. Really quit?', 'Operation in progress', 'No');
if ~strcmp(dlgAns, 'Yes')
return;
end
end

obj.isEnding = 1;
Expand Down
59 changes: 1 addition & 58 deletions +jrclust/+curate/@CurateController/updateFigRD.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,5 @@ function updateFigRD(obj)
return;
end

plotFigRD(obj.hFigs('FigRD'), obj.hClust, obj.hCfg);
end

%% LOCAL FUNCTIONS
function hFigRD = plotFigRD(hFigRD, hClust, hCfg)
%DOPLOTFIGRD Display rho-delta data
hFigRD.clf();

% if isfield(hClust, 'cS_clu_shank')
% cellfun(@(hc) doPlotFigRD(hc, P), hClust.cS_clu_shank);
% return;
% end

if strcmp(hCfg.RDDetrendMode, 'global')
[centers, x, y] = jrclust.sort.detrendRhoDelta(hClust, hClust.spikesBySite, 0, hCfg);
y = jrclust.utils.nanlog10(y);
fDetrend = 1;
elseif strcmp(hCfg.RDDetrendMode, 'local')
[centers, x, y] = jrclust.sort.detrendRhoDelta(hClust, hClust.spikesBySite, 1, hCfg);
y = jrclust.utils.nanlog10(y);
fDetrend = 1;
else
centers = find(hClust.spikeRho(:) > 10^(hCfg.log10RhoCut) & hClust.spikeDelta(:) > 10^(hCfg.log10DeltaCut));
x = jrclust.utils.nanlog10(hClust.spikeRho(:));
y = jrclust.utils.nanlog10(hClust.spikeDelta(:));
fDetrend = 0;
end

hFigRD.addPlot('allSpikes', x, y, '.');
hFigRD.axApply('default', @hold, 'on');

hFigRD.axApply('default', @axis, 'tight');
hFigRD.axApply('default', @axis, [-4 -.5 -1 2]);
hFigRD.axApply('default', @set, 'XScale', 'linear', 'YScale', 'linear');

% show rho/delta cutoff lines
hFigRD.addPlot('RDCuts', hCfg.log10RhoCut * [1 1], hFigRD.axApply('default', @get, 'YLim'), 'r--', ...
hFigRD.axApply('default', @get, 'XLim'), hCfg.log10DeltaCut*[1, 1], 'r--');
hFigRD.axApply('default', @grid, 'on');

% label cluster centers
if ~isempty(hClust.clusterCenters)
centers = hClust.clusterCenters; % do not overwrite
end
centersX = double(x(centers));
centersY = double(y(centers));
hFigRD.addPlot('centers', centersX, centersY, 'r.');

% set labels
hFigRD.axApply('default', @xlabel, 'log10 rho');
if fDetrend
hFigRD.axApply('default', @ylabel, 'log10 delta (detrended)');
else
hFigRD.axApply('default', @ylabel, 'log10 delta');
end
hFigRD.axApply('default', @title, sprintf('rho-cut: %f, delta-cut: %f', hCfg.log10RhoCut, hCfg.log10DeltaCut));

drawnow;
jrclust.views.plotFigRD(obj.hFigs('FigRD'), obj.hClust, obj.hCfg);
end
14 changes: 14 additions & 0 deletions +jrclust/+interfaces/@Clustering/editSeek.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function editSeek(obj, seekTo)

% restore initial state and fast forward
spikeClusters_ = obj.initialClustering;

if isfield(obj.sRes, 'clusterCenters')
obj.clusterCenters = obj.sRes.clusterCenters;
else
Expand All @@ -18,6 +19,9 @@ function editSeek(obj, seekTo)
deleted = op{3};
nClustersOld = max(spikeClusters_);
spikeClusters_(ismember(spikeClusters_, deleted)) = 0;
if ~isempty(obj.clusterCenters)
obj.clusterCenters(deleted) = [];
end

% shift clusters larger than deleted down by 1
if numel(deleted) == 1
Expand Down Expand Up @@ -69,6 +73,16 @@ function editSeek(obj, seekTo)
end
obj.spikeClusters = spikeClusters_;

% reassign cluster centers
newCenters = zeros(obj.nClusters, 1);
for iCluster = 1:obj.nClusters
iSpikes = find(obj.spikeClusters == iCluster);
[~, iBest] = max(obj.spikeRho(iSpikes));
newCenters(iCluster) = iSpikes(iBest);
end

obj.clusterCenters = newCenters;

obj.refresh(0, []);
if ~isempty(obj.meanWfGlobal) % only compute mean waveforms if we already had them
obj.updateWaveforms();
Expand Down
15 changes: 13 additions & 2 deletions +jrclust/+sort/@DensityPeakClustering/inconsistentFields.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
inconsistencies = inconsistentFields@jrclust.interfaces.Clustering(obj);

% also check all clusterCenters are unique
if numel(obj.clusterCenters) ~= numel(unique(obj.clusterCenters))
inconsistencies{end+1} = 'clusterCenters';
if ~ismember('clusterCenters', inconsistencies)
% find all putative centers which don't actually belong to their
% assigned cluster and reassign them
dupes = find(obj.spikeClusters(obj.clusterCenters) ~= (1:obj.nClusters)');
newCenters = zeros(numel(dupes), 1);
for i = 1:numel(dupes)
iDupe = dupes(i);
iSpikes = find(obj.spikeClusters == iDupe);
[~, iBest] = max(obj.spikeRho(iSpikes));
newCenters(i) = iSpikes(iBest);
end

obj.clusterCenters(dupes) = newCenters;
end
end
1 change: 1 addition & 0 deletions +jrclust/+utils/mToStruct.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
S.(varnames{j}) = a;
end
catch ME
warning('Failed to parse %s: %s', filename, ME.message);
end
end

Expand Down
1 change: 1 addition & 0 deletions +jrclust/+views/@Figure/Figure.m
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ function hidePlot(obj, plotKey)

function vals = plotApply(obj, plotKey, hFun, varargin)
%PLOTAPPLY Apply hFun to the plot given by plotKey
vals = [];
if ~obj.hasPlot(plotKey)
return;
end
Expand Down
57 changes: 57 additions & 0 deletions +jrclust/+views/plotFigRD.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function hFigRD = plotFigRD(hFigRD, hClust, hCfg)
%DOPLOTFIGRD Display rho-delta data
hFigRD.clf();

% if isfield(hClust, 'cS_clu_shank')
% cellfun(@(hc) doPlotFigRD(hc, P), hClust.cS_clu_shank);
% return;
% end

if strcmp(hCfg.RDDetrendMode, 'global')
[centers, x, y] = jrclust.sort.detrendRhoDelta(hClust, hClust.spikesBySite, 0, hCfg);
y = jrclust.utils.nanlog10(y);
fDetrend = 1;
elseif strcmp(hCfg.RDDetrendMode, 'local')
[centers, x, y] = jrclust.sort.detrendRhoDelta(hClust, hClust.spikesBySite, 1, hCfg);
y = jrclust.utils.nanlog10(y);
fDetrend = 1;
else
centers = find(hClust.spikeRho(:) > 10^(hCfg.log10RhoCut) & hClust.spikeDelta(:) > 10^(hCfg.log10DeltaCut));
x = jrclust.utils.nanlog10(hClust.spikeRho(:));
y = jrclust.utils.nanlog10(hClust.spikeDelta(:));
fDetrend = 0;
end

indices = randsample(numel(x), min(numel(x), 50000), 0);

% label cluster centers
if ~isempty(hClust.clusterCenters)
centers = hClust.clusterCenters; % do not overwrite
end
centersX = double(x(centers));
centersY = double(y(centers));

hFigRD.addPlot('allSpikes', x(indices), y(indices), '.');
hFigRD.addPlot('centers', centersX, centersY, 'r.');
hFigRD.axApply('default', @hold, 'on');

hFigRD.axApply('default', @axis, 'tight');
hFigRD.axApply('default', @axis, [-4 -.5 -1 2]);
hFigRD.axApply('default', @set, 'XScale', 'linear', 'YScale', 'linear');

% show rho/delta cutoff lines
hFigRD.addPlot('RDCuts', hCfg.log10RhoCut * [1 1], hFigRD.axApply('default', @get, 'YLim'), 'r--', ...
hFigRD.axApply('default', @get, 'XLim'), hCfg.log10DeltaCut*[1, 1], 'r--');
hFigRD.axApply('default', @grid, 'on');

% set labels
hFigRD.axApply('default', @xlabel, 'log10 rho');
if fDetrend
hFigRD.axApply('default', @ylabel, 'log10 delta (detrended)');
else
hFigRD.axApply('default', @ylabel, 'log10 delta');
end
hFigRD.axApply('default', @title, sprintf('rho-cut: %f, delta-cut: %f', hCfg.log10RhoCut, hCfg.log10DeltaCut));

drawnow;
end
4 changes: 2 additions & 2 deletions json/jrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"major": 4,
"minor": 0,
"release": 0,
"tag": "alpha-patch5",
"tag": "alpha-patch6",
"codename": "Edward"
},
"changeDate": "26 Feb 2019",
"changeDate": "8 March 2019",
"authors": [
"James Jun"
],
Expand Down

0 comments on commit 50f3461

Please sign in to comment.