1
+ %%
2
+ % This script requires:
3
+ % Timeline data uploaded to master server
4
+ %
5
+ % This script does:
6
+ %
7
+ % apply SVD
8
+ % visualize SVD results (inspectSVDresult.m)
9
+ % check if #frames are identical that recorded in TL (in saveSVD.m)
10
+ % split V into each experiment (in saveSVD.m)
11
+ % save U and V to the market server (in saveSVD.m)
12
+
13
+ % things to do before running this script:
14
+ % 1, upload raw data to Market
15
+ % 2, download the raw data under E:\Subjects
16
+
17
+ clear all
18
+ setPath_analysisImaging ;
19
+
20
+ % cd('\\ad.monash.edu\home\User006\dshi0006\Documents\MATLAB\master\Analysis\wfAnalysis\daily_pipeline');
21
+ cd(' C:\Users\dshi0006\git\analysisImaging\wfAnalysis\daily_pipeline' );
22
+ load(' amberOps.mat' );
23
+ % For blue/purple alternate
24
+ % load('bluePurpleOps.mat');
25
+ % For purple only
26
+ % load('C:\Users\Experiment\Documents\MATLAB\purpleOps.mat')
27
+ mouseName = ' susanoo' ;
28
+ thisDate = ' 2024-11-22' ; % [datestr(now,'yyyy-mm-dd')];
29
+ thisSeries = 1 ;
30
+ expNums = 5 ;% [1:4];
31
+ hwbinning = 1 ; % automatically retrieve this from thorcam header??
32
+ magnification = .5 ;
33
+ makeROI = false ; % if false, use already saved ROI from the save subject (thisROI.mat)
34
+ doRegistration = 1 ; % 15/10/20
35
+
36
+
37
+ % where vidXraw.dat and vidXreg.dat are created (subsequently moved to the data server)
38
+ % rootDrive = 'C:\svdinput'; %NG ... too small
39
+ rootDrive = ' E:\svdinput' ;
40
+ % will be used in;
41
+ % ops.localSavePath
42
+
43
+ % where raw data is temporally downloaded must be under
44
+ % rawDataDir/(animal)/(session)/(expNum)
45
+ % rawDataDir = '\\vault-v2.erc.monash.edu.au\MNHS-dshi0006\Subjects';%if the raw data is already uploaded to the server
46
+ % rawDataDir = 'X:\Subjects'; %market server ... too slow to load
47
+ rawDataDir = ' E:\Subjects' ; % local temporary storage
48
+
49
+
50
+ % where SVD and summary data is saved
51
+ % dat.expFilePath(ops.mouseName, thisDate, thisSeries, expNums, 'widefield','master')
52
+
53
+ % where the raw and processed data is saved
54
+ % dat.expFilePath(ops.mouseName, thisDate, thisSeries, expNums, 'widefield_raw','master')
55
+
56
+
57
+ %% modify ops for this experiment
58
+ % hack for 9/6/20 phpL
59
+ % ops.vids(1).frameMod = [2 0];
60
+ % ops.vids(2).frameMod = [2 1];
61
+ % ops.vids = ops.vids(1);%3/7/20
62
+
63
+ thisDateSeries = [thisDate , ' _' num2str(thisSeries )];
64
+ if ~makeROI
65
+ if exist(fullfile(rawDataDir , mouseName ,' thisROI.mat' ),' file' )
66
+ load(fullfile(rawDataDir , mouseName ,' thisROI.mat' ),' thisROI' );
67
+ ops.roi = thisROI ;
68
+ else
69
+ ops.roi = [];
70
+ end
71
+ end
72
+
73
+ ops.mouseName = mouseName ;
74
+ ops.thisDate = thisDateSeries ;
75
+ % if using inclExpList, specify ops.fileBase
76
+ ops.inclExpList = expNums ;
77
+ ops.fileBase = fullfile(rawDataDir , mouseName , thisDateSeries );
78
+ ops.statusDestination = fopen(' test.txt' ,' w' );
79
+ ops.userName = ' Daisuke' ;
80
+ ops = rmfield(ops ,' emailAddress' );
81
+ ops.rigName = ' alloptrig' ;% 'wfrig'; %used in determineTimelineAlignments
82
+ ops.doRegistration = doRegistration ;
83
+ ops.useGPU = 1 ; % used only for registration?
84
+ ops.objectiveType = num2str(magnification ); % 0.5 / 0.8
85
+ ops.pixelSizeUM = 5 / str2num(ops .objectiveType )*hwbinning ; % added 15/5/20
86
+ ops.hasASCIIstamp = 0 ; % 18/5/20
87
+
88
+
89
+ for e = 1 : length(expNums )
90
+ expRefs{e } = dat .constructExpRef(mouseName , thisDate , thisSeries , expNums(e ));
91
+ end
92
+ ops.expRefs = expRefs ;
93
+
94
+ % retrieve camera sampling rate and exposure duration from Timeline
95
+ timelinePath = dat .expFilePath(expRefs{1 }, ' timeline' , ' master' );
96
+ load(timelinePath );
97
+ [strobeOnTimes , ~ , strobeDurs ] = getStrobeTimes(Timeline , ops .rigName );
98
+ exposureDur = median(strobeDurs ); % [s]
99
+ FsPerColor = 1 / median(diff(strobeOnTimes ))/length(ops .vids );
100
+ ops.Fs = FsPerColor ;% 16/10/20
101
+ clear Timeline
102
+
103
+
104
+ for i = 1 : length(ops .vids )
105
+ % where video data is stored
106
+ ops .vids(i ).fileBase = fullfile(rawDataDir , mouseName , thisDateSeries );
107
+ ops .vids(i ).exposureDur = exposureDur ;
108
+ ops .vids(i ).Fs = FsPerColor ;
109
+ end
110
+ %% for single color imaging
111
+ % ops.vids = ops.vids(1);
112
+ % ops.vids.frameMod = [1 0];
113
+
114
+
115
+ % create ROI
116
+ if makeROI
117
+ theseFiles = generateFileList(ops , 1 );
118
+
119
+ imageForROI = mean(loadTiffStack(theseFiles{1 }, ' tiffobj' ,0 ),3 ); % make purple and blue image separately??
120
+ imagesc(imageForROI );
121
+ axis equal tight ;
122
+ colormap(gray );
123
+ caxis(prctile(imageForROI(: ),[1 99 ]));
124
+ % colormouse;%change the colormap range interactively using the mouse
125
+ title(' left click to put anchor points., double click to finish' );
126
+ roiAhand = images .roi .AssistedFreehand ;
127
+ draw(roiAhand );
128
+ ops.roi = createMask(roiAhand );
129
+ close ;
130
+
131
+ % 22/7/20 for use later
132
+ thisROI= ops .roi ;
133
+ save(fullfile(rawDataDir , mouseName ,' thisROI.mat' ),' thisROI' );
134
+ else % reuse ROI created previously.
135
+ load(fullfile(rawDataDir , mouseName ,' thisROI.mat' ));
136
+ ops.roi = thisROI ;
137
+ end
138
+
139
+
140
+ % where SVD data is saved
141
+ ops.localSavePath = fullfile(rootDrive , ' data' , mouseName , thisDate );
142
+
143
+ if ~exist(ops .localSavePath ,' dir' )
144
+ mkdir(ops .localSavePath ); % 7/5/20
145
+ end
146
+ cd(ops .localSavePath )
147
+ save ops.mat ops
148
+
149
+
150
+ %% run SVD, save results to server, erase original data
151
+ pipelineHereKT();
152
+
153
+
154
+
155
+
156
+ %%
157
+ % mouseName = 'Erlanger';
158
+ % thisDate = datestr(now, 'yyyy-mm-dd');
159
+ % expNums = [2 3];
160
+ %
161
+ %
162
+ % addpath(genpath('C:\Users\Experiment\Documents\GitHub\widefield'))
163
+ % addpath(genpath('\\zserver.cortexlab.net\Code\Rigging\main'));
164
+ % addpath(genpath('\\zserver.cortexlab.net\Code\Rigging\cb-tools'));
165
+ %
166
+ % s = svdVid.listen;
167
+ %
168
+ % s.ops.mouseName = mouseName;
169
+ % s.ops.thisDate = thisDate;
170
+ %
171
+ % s.wizard
172
+ %
173
+ % s.ops.vids(1).fileBase = fullfile('J:\data', mouseName, thisDate);
174
+ % s.ops.vids(2).fileBase = fullfile('J:\data', mouseName, thisDate);
175
+ % s.ops.vids(1).rigName = 'kilotrode';
176
+ % s.ops.vids(2).rigName = 'kilotrode';
177
+ % s.ops.useGPU = true;
178
+ %
179
+ % for e = 1:length(expNums)
180
+ % clear ed
181
+ % ed.expRef = dat.constructExpRef(mouseName, thisDate, expNums(e));
182
+ % s.addExpDat(ed)
183
+ % end
184
+ %
185
+ % s.ops.localSavePath = fullfile('J:\data', mouseName, thisDate);
186
+ %
187
+ % cd(fullfile('J:\data', mouseName, thisDate))
188
+ % ops = s.ops;
189
+ % save ops.mat ops
190
+ % pipelineHereKT
0 commit comments