-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalignToALF.m
More file actions
65 lines (43 loc) · 1.88 KB
/
alignToALF.m
File metadata and controls
65 lines (43 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
%% script to align a dataset in ALF format
mn = 'Robbins';
td = '2017-06-13';
en = 1;
[tags, hasEphys] = getEphysTags(mn, td);
masterAlign = tags{1};
rootE = dat.expPath(mn, td, 1, 'main', 'master');
root = fileparts(rootE);
alignDir = fullfile(root, 'alignments');
%% eye alignment
eyeFolder = fileparts(dat.expFilePath(mn, td, en, 'eyetracking', 'master'));
load(fullfile(eyeFolder, 'eye_timeStamps.mat'))
alignFile = dir(fullfile(alignDir, sprintf('correct_timeline*ephys_%s.npy', masterAlign)));
b = readNPY(fullfile(alignDir, alignFile.name));
tAligned = applyCorrection(tVid, b); % will be a column after this
nFr = numel(tVid);
writeNPY([[0:nFr-1]' tVid(:)], fullfile(eyeFolder, 'eye.timestamps_Timeline.npy'));
writeNPY([[0:nFr-1]' tAligned(:)], fullfile(eyeFolder, 'eye.timestamps.npy'));
%% for timeline
alignFile = dir(fullfile(alignDir, sprintf('correct_timeline*ephys_%s.npy', masterAlign)));
b = readNPY(fullfile(alignDir, alignFile.name));
tlFile = dat.expFilePath(mn, td, en, 'Timeline', 'master');
load(tlFile);
kilotrodeTimelineToAFF(Timeline, b, fileparts(tlFile))
%% for electrophysiology
for t = 1:length(tags)
ksd = getKSdir(mn, td, tags{t});
spikeStruct = loadParamsPy(fullfile(ksd, 'params.py'));
ss = readNPY(fullfile(ksd, 'spike_times.npy'));
st = double(ss)/spikeStruct.sample_rate;
if t>1
alignFN = sprintf('correct_ephys_%s_to_ephys_%s.npy', tags{t}, masterAlign);
b = readNPY(fullfile(alignDir, alignFN));
st = applyCorrection(st, b);
end
writeNPY(st, fullfile(ksd, 'spikes.times.npy'));
cluFile = fullfile(ksd, 'spike_clusters.npy');
if exist(cluFile, 'file')
copyfile(fullfile(ksd, 'spike_clusters.npy'), fullfile(ksd, 'spikes.clusters.npy'));
else
copyfile(fullfile(ksd, 'spike_templates.npy'), fullfile(ksd, 'spikes.clusters.npy'));
end
end