-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNrControllerTest.m
149 lines (119 loc) · 5.13 KB
/
NrControllerTest.m
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
classdef NrControllerTest < matlab.unittest.TestCase
% Tests the TrialModel class
properties
dirs
movieStructList
myexp
mycon
end
methods(TestClassSetup)
function createData(testCase)
tmpDir = 'tmp';
if ~exist(tmpDir, 'dir')
mkdir(tmpDir)
end
resultDir = fullfile(tmpDir, 'results');
if ~exist(resultDir, 'dir')
mkdir(resultDir)
end
stack = testUtils.createStack();
rawFileList = testUtils.saveTestMovies(tmpDir, stack.movieStructList);
expInfo.name = 'test_exp';
expInfo.frameRate = 10;
expInfo.nPlane = 1;
myexp = NrModel('rawDataDir', tmpDir,...
'rawFileList', rawFileList,...
'resultDir', resultDir,...
'expInfo', expInfo);
mycon = NrController(myexp);
templateMask = stack.movieStructList{1}.templateMask;
maskDir = myexp.getDefaultDir('mask');
if ~exist(maskDir, 'dir')
mkdir(maskDir)
end
templateMaskFile = fullfile(maskDir, 'template_mask.tif');
movieFunc.saveTiff(uint16(templateMask), templateMaskFile);
% Convert template mask to RoiArray
roiDir = myexp.getDefaultDir('roi');
roiFile = fullfile(roiDir, iopath.modifyFileName(rawFileList{1}, '', '_RoiArray', 'mat'));
roiArr = roiFunc.RoiArray('maskImg', templateMask);
roiDir = myexp.getDefaultDir('roi');
if ~exist(roiDir, 'dir')
mkdir(roiDir)
end
save(roiFile, 'roiArr')
myexp.processRawData();
testDirs.tmpDir = tmpDir;
testDirs.resultDir = resultDir;
testCase.dirs = testDirs;
testCase.movieStructList = stack.movieStructList;
testCase.myexp = myexp;
testCase.mycon = mycon;
% testCase.addTeardown(@rmdir, tmpDir, 's')
end
end
methods(Test)
function testBunwarpj(testCase)
myexp = testCase.myexp;
mycon = testCase.mycon;
src.Value = 1;
mycon.BUnwarpJReferencetrial_Callback(src);
src = struct('Value', true);
mycon.BUnwarpJUseSIFT_Callback(src);
src = struct('Value', false);
mycon.BUnwarpJUseSIFT_Callback(src);
evnt.NewValue.Tag = 'Norm_HistoEqu_radiobutton';
mycon.BUnwarpJNormTypeGroup_Callback(1, evnt) % 1 is placeholder for src
evnt.NewValue.Tag = 'Norm_CLAHE_radiobutton';
mycon.BUnwarpJNormTypeGroup_Callback(1, evnt)
% TODO make normalize image work
evnt.NewValue.Tag = 'Norm_none_radiobutton';
mycon.BUnwarpJNormTypeGroup_Callback(1, evnt)
src = struct('String', 'transf1');
mycon.BUnwarpJTransformationName_Callback(src);
% button.Tag = 'Norm_CLAHE_radiobutton';
% evnt.NewValue = button;
% TODO also test hist eq
% mycon.BUnwarpJNormTypeGroup_Callback(1, evnt)
% mycon.BUnwarpJCalculateButton_Callback();
% myexp.applyBunwarpj();
myexp.calculatedTransformationsList = {'transf1'};
myexp.calculatedTransformationsIdx = 1;
myexp.BUnwarpJCalculated = true;
mycon.BUnwarpJInspectTrialsButton_Callback();
stackCtrl = mycon.stackCtrl;
stackCtrl.view.setTrialNumberSlider(2);
stackCtrl.TrialNumberSlider_Callback();
% Add two ROIs
import java.awt.Robot;
import java.awt.event.*;
mouse = Robot;
roi1p = [556, 1537];
pause(0.1);
stackCtrl.addRoiByDrawing([73, 25; 84, 25; 84, 36; 73, 36]);
stackCtrl.addRoiByDrawing([93, 85; 104, 85; 104, 96; 93, 96]);
% Add the two ROIs in the stack
mouse.mouseMove(roi1p(1)+187, roi1p(2)-8);
mouse.keyPress(KeyEvent.VK_CONTROL);
mouse.mousePress(InputEvent.BUTTON1_MASK); % actual left click press
pause(0.1);
mouse.mouseRelease(InputEvent.BUTTON1_MASK);
pause(0.1);
mouse.keyRelease(KeyEvent.VK_CONTROL);
stackCtrl.model.roiGroupName = 'default';
stackCtrl.addRoisInStack();
end
% TODO test for multiplane data
end
end
function movieStructList = createTestMovies()
movieStructList = {};
movieStructList{1} = createMovie();
affineMat2 = [1 0 0; 0 1 0; -5 8 1];
movieStructList{2}= createMovie('ampList', [45, 60, 100, 40], 'affineMat', affineMat2);
affineMat3 = [1.2 0 0; 0.1 1 0; -20 8 1];
movieStructList{3}= createMovie('ampList', [60, 50, 80, 50], 'affineMat', affineMat3);
end
% loadTrials
% arrangeTrialTable
% batchExtractTimeTrace