Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
96 lines (73 sloc) 2.55 KB
function spikeStruct = loadKSdir(ksDir, varargin)
if ~isempty(varargin)
params = varargin{1};
else
params = [];
end
if ~isfield(params, 'excludeNoise')
params.excludeNoise = true;
end
if ~isfield(params, 'loadPCs')
params.loadPCs = false;
end
% load spike data
spikeStruct = loadParamsPy(fullfile(ksDir, 'params.py'));
ss = readNPY(fullfile(ksDir, 'spike_times.npy'));
st = double(ss)/spikeStruct.sample_rate;
spikeTemplates = readNPY(fullfile(ksDir, 'spike_templates.npy')); % note: zero-indexed
if exist(fullfile(ksDir, 'spike_clusters.npy'))
clu = readNPY(fullfile(ksDir, 'spike_clusters.npy'));
else
clu = spikeTemplates;
end
tempScalingAmps = readNPY(fullfile(ksDir, 'amplitudes.npy'));
if params.loadPCs
pcFeat = readNPY(fullfile(ksDir,'pc_features.npy')); % nSpikes x nFeatures x nLocalChannels
pcFeatInd = readNPY(fullfile(ksDir,'pc_feature_ind.npy')); % nTemplates x nLocalChannels
else
pcFeat = [];
pcFeatInd = [];
end
cgsFile = '';
if exist(fullfile(ksDir, 'cluster_groups.csv'))
cgsFile = fullfile(ksDir, 'cluster_groups.csv');
end
if exist(fullfile(ksDir, 'cluster_group.tsv'))
cgsFile = fullfile(ksDir, 'cluster_group.tsv');
end
if ~isempty(cgsFile)
[cids, cgs] = readClusterGroupsCSV(cgsFile);
if params.excludeNoise
noiseClusters = cids(cgs==0);
st = st(~ismember(clu, noiseClusters));
spikeTemplates = spikeTemplates(~ismember(clu, noiseClusters));
tempScalingAmps = tempScalingAmps(~ismember(clu, noiseClusters));
if params.loadPCs
pcFeat = pcFeat(~ismember(clu, noiseClusters), :,:);
%pcFeatInd = pcFeatInd(~ismember(cids, noiseClusters),:);
end
clu = clu(~ismember(clu, noiseClusters));
cgs = cgs(~ismember(cids, noiseClusters));
cids = cids(~ismember(cids, noiseClusters));
end
else
clu = spikeTemplates;
cids = unique(spikeTemplates);
cgs = 3*ones(size(cids));
end
coords = readNPY(fullfile(ksDir, 'channel_positions.npy'));
ycoords = coords(:,2); xcoords = coords(:,1);
temps = readNPY(fullfile(ksDir, 'templates.npy'));
winv = readNPY(fullfile(ksDir, 'whitening_mat_inv.npy'));
spikeStruct.st = st;
spikeStruct.spikeTemplates = spikeTemplates;
spikeStruct.clu = clu;
spikeStruct.tempScalingAmps = tempScalingAmps;
spikeStruct.cgs = cgs;
spikeStruct.cids = cids;
spikeStruct.xcoords = xcoords;
spikeStruct.ycoords = ycoords;
spikeStruct.temps = temps;
spikeStruct.winv = winv;
spikeStruct.pcFeat = pcFeat;
spikeStruct.pcFeatInd = pcFeatInd;
You can’t perform that action at this time.