-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmoothingAfterBackgroundTask.java
More file actions
222 lines (151 loc) · 8.19 KB
/
Copy pathSmoothingAfterBackgroundTask.java
File metadata and controls
222 lines (151 loc) · 8.19 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package wf.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javafx.concurrent.Task;
public class SmoothingAfterBackgroundTask extends Task<Object> {
private static DataHistoHandler dataHistoHandler = DataHistoHandler.getInstance();
private static final SmoothingAfterBackgroundTask INSTANCE = new SmoothingAfterBackgroundTask();
private int progressCounter;
private int numberOfSeries;
private int pointsOfSereis;
private double sumYValue;
private double sumYValueWeighted;
private final int sm_div1 = 3; // divider constant for 3 points smoothing
private final int sm_div2 = 9; // divider constant for 5 points smoothing
private final int sm_div3 = 27; // divider constant for 7 points smoothing
private final List<Integer> sm_k2 = new ArrayList<Integer>(Arrays.asList(1,2,3,2,1));
private final List<Integer> sm_k3 = new ArrayList<Integer>(Arrays.asList(1,3,6,7,6,3,1));
private List<Double> temp_data = new ArrayList<Double>();
private int sm_kIndex; //index used to loop through the coefficients
public static SmoothingAfterBackgroundTask getInstance() {
return INSTANCE;
}
@Override
public Object call() throws Exception {
return null;
}
//points refers to the number of points in the smoothing window
//if twoSteps is true it means that processed data has to be used for smoothing
public Task<Void> performSmoothingAfterBackground(int points, int seriesTotalNumber) {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
progressCounter = 0;
for(int channel = 0; channel < 4; channel++) {
//System.out.println("Channel: " + channel);
if(dataHistoHandler.getSeriesValuesProc().get(channel).size() > 0) {
// number of series per channel
numberOfSeries = dataHistoHandler.getSeriesValuesProc().get(channel).size();
//loop through all the series of a channel
for(int series = 0; series < numberOfSeries; series++) {
temp_data.clear();
//loop through the series for background subtraction
pointsOfSereis = dataHistoHandler.getSeriesValuesProc()
.get(channel).get(series).getData().size();
if(points == 3) {
//the first and last point are set to zero
temp_data.add(0.0);
//calculate weighted temporary values
for(int i = 1; i < pointsOfSereis-1; i++) {
sumYValue = 0;
sumYValueWeighted = 0;
//evaluate weighted point from raw data
for(int j = i-1; j < i+2; j++) {
sumYValue = sumYValue + (double)
dataHistoHandler
.getSeriesValuesProc().get(channel).get(series)
.getData().get(j).getYValue();
}
sumYValueWeighted = sumYValue / (double) sm_div1;
temp_data.add(sumYValueWeighted);
}
//add last point to be zero
temp_data.add(0.0);
//copy temp_data to histo processed data
for(int data = 0; data < pointsOfSereis; data++) {
dataHistoHandler.getSeriesValuesProc().get(channel)
.get(series).getData().get(data).setXValue(data);
dataHistoHandler.getSeriesValuesProc().get(channel)
.get(series).getData().get(data).setYValue(temp_data.get(data));
}
} //end if 3 points
if(points == 5) {
//the two first and last point are set to zero
temp_data.add(0.0);
temp_data.add(0.0);
//calculate weighted temporary values
for(int i = 2; i < pointsOfSereis-2; i++) {
sm_kIndex = 0; //index to loop through the coefficients
sumYValue = 0;
sumYValueWeighted = 0;
//evaluate weighted point from raw data
for(int j = i-2; j < i+3; j++) {
sumYValue = sumYValue + ((double)
dataHistoHandler
.getSeriesValuesProc().get(channel).get(series)
.getData().get(j).getYValue() * (double) sm_k2.get(sm_kIndex));
sm_kIndex++;
}
sumYValueWeighted = sumYValue / (double) sm_div2;
temp_data.add(sumYValueWeighted);
}
//add last two points to be zero
temp_data.add(0.0);
temp_data.add(0.0);
//copy temp_data to histo processed data
for(int data = 0; data < pointsOfSereis; data++) {
dataHistoHandler.getSeriesValuesProc().get(channel)
.get(series).getData().get(data).setXValue(data);
dataHistoHandler.getSeriesValuesProc().get(channel)
.get(series).getData().get(data).setYValue(temp_data.get(data));
}
} //end if 5 points
if(points == 7) {
//the three first and last point are set to zero
temp_data.add(0.0);
temp_data.add(0.0);
temp_data.add(0.0);
//calculate weighted temporary values
for(int i = 3; i < pointsOfSereis-3; i++) {
sm_kIndex = 0; //index to loop through the coefficients
sumYValue = 0;
sumYValueWeighted = 0;
//evaluate weighted point from raw data
for(int j = i-3; j < i+4; j++) {
sumYValue = sumYValue + ((double)
dataHistoHandler
.getSeriesValuesProc().get(channel).get(series)
.getData().get(j).getYValue() * (double) sm_k3.get(sm_kIndex));
sm_kIndex++;
}
sumYValueWeighted = sumYValue / (double) sm_div3;
temp_data.add(sumYValueWeighted);
}
//add last three points to be zero
temp_data.add(0.0);
temp_data.add(0.0);
temp_data.add(0.0);
//copy temp_data to histo processed data
for(int data = 0; data < pointsOfSereis; data++) {
dataHistoHandler.getSeriesValuesProc().get(channel)
.get(series).getData().get(data).setXValue(data);
dataHistoHandler.getSeriesValuesProc().get(channel)
.get(series).getData().get(data).setYValue(temp_data.get(data));
}
} //end if 7 points
update(++progressCounter, seriesTotalNumber);
}
}
//Progress is related to the channels processed
//this.updateProgress(channel+1, 4);
}
return null;
}
};
}
private void update(int value1, int value2) {
this.updateProgress(value1, value2);
//System.out.println("Value " + value);
}
}