forked from MouseLand/Kilosort
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement channel map creation and saving
- Loading branch information
Showing
7 changed files
with
203 additions
and
33 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
|
||
function cm = createValidChanMap(q, varargin) | ||
cm = []; | ||
if isfield(q, 'chanMap') && ... | ||
isfield(q, 'xcoords') && ... | ||
isfield(q, 'ycoords') && ... | ||
numel(q.chanMap)==numel(q.xcoords) &&... | ||
numel(q.chanMap)==numel(q.ycoords) | ||
|
||
if min(q.chanMap)==0 | ||
q.chanMap = q.chanMap+1; | ||
end | ||
|
||
% has required fields - we accept it | ||
|
||
cm.chanMap = q.chanMap(:); | ||
cm.xcoords = q.xcoords(:); | ||
cm.ycoords = q.ycoords(:); | ||
cm.chanMap0ind = q.chanMap(:)-1; | ||
|
||
if isfield(q, 'connected') | ||
if numel(q.connected)==numel(cm.chanMap) | ||
cm.connected = q.connected(:); | ||
else | ||
warning('Invalid chanMap variable ''connected'': must be the same size as chanMap. Using default.'); | ||
end | ||
|
||
else | ||
cm.connected = true(size(cm.chanMap)); | ||
end | ||
|
||
cm.kcoords = ones(size(cm.chanMap)); | ||
if isfield(q, 'kcoords') | ||
if numel(q.kcoords)==numel(cm.chanMap) | ||
cm.kcoords = q.kcoords(:); | ||
else | ||
warning('Invalid chanMap variable ''kcoords'': must be the same size as chanMap. Using default.'); | ||
end | ||
elseif isfield(q, 'shankInd') | ||
if numel(q.shankInd)==numel(cm.chanMap) | ||
cm.kcoords = q.shankInd(:); | ||
else | ||
warning('Invalid chanMap variable ''shankInd'': must be the same size as chanMap. Using default.'); | ||
end | ||
end | ||
|
||
if isfield(q, 'name') | ||
cm.name = q.name; | ||
else | ||
if nargin>1 | ||
filename = varargin{1}; | ||
x = strfind(filename, 'kilosortChanMap'); | ||
if ~isempty(x) | ||
cm.name = filename(1:x-2); | ||
else | ||
cm.name = filename; | ||
end | ||
else | ||
cm.name = 'unknown'; | ||
end | ||
end | ||
|
||
if isfield(q, 'siteSize') | ||
cm.siteSize = siteSize; | ||
end | ||
|
||
else | ||
warning('Invalid channel map: A valid channel map must have chanMap, xcoords, and ycoords, and they must all be the same size.') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
|
||
function chanMaps = loadChanMaps() | ||
|
||
|
||
ksroot = fileparts(fileparts(mfilename('fullpath'))); | ||
chanMapFiles = dir(fullfile(ksroot, 'configFiles', '*.mat')); | ||
|
||
idx = 1; | ||
chanMaps = []; | ||
for c = 1:numel(chanMapFiles) | ||
|
||
q = load(fullfile(ksroot, 'configFiles', chanMapFiles(c).name)); | ||
|
||
cm = createValidChanMap(q, chanMapFiles(c).name); | ||
if ~isempty(cm) | ||
if idx==1; chanMaps = cm; else; chanMaps(idx) = cm; end; | ||
idx = idx+1; | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
|
||
function saveNewChanMap(cm, obj) | ||
|
||
newName = cm.name; | ||
if strcmp(cm.name, 'unknown') | ||
answer = inputdlg('Name for this channel map:'); | ||
if ~isempty(answer) && ~isempty(answer{1}) | ||
newName = answer{1}; | ||
else | ||
newName = ''; | ||
end | ||
end | ||
if ~isempty(newName) | ||
ksRoot = fileparts(fileparts(mfilename('fullpath'))); | ||
newFn = [answer{1} '_kilosortChanMap.mat']; | ||
save(fullfile(ksRoot, 'configFiles', newFn), '-struct', 'cm'); | ||
obj.log(['Saved new channel map: ' fullfile(ksRoot, 'configFiles', newFn)]); | ||
else | ||
obj.log('Could not save new channel map without a name'); | ||
end |