forked from ilkkavir/EFISR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integrationLimitsTime.m
91 lines (75 loc) · 2.21 KB
/
integrationLimitsTime.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
function [ indTime , nTime ] = integrationLimitsTime( ts, te , tres , ...
startTime)
%
%
% calculate indices for integration periods. This is very simple
% now, I may implement other optionsn in future
%
%
% INPUT:
% ts integration start times
% te integration end times
% tres time resolution [s], OR a vector of unixtimes, OR
% number of slices to integrate as a negative integer
% startTime beginning of first time slice
%
% OUTPUT:
% indTime time slice indices for each data point
% nTime number of time slices
%
% IV 2017
%
% start from beginning of data, if starttime is not specified
if startTime < 0
% startTime = round(te(1));
startTime = round(min(te));
end
if tres(1)>0
% create the time-slice limits
if length(tres==1)
tlims = startTime:tres:(max(te)+tres);
else
tlims = tres;
end
% number of slices
nTime = length(tlims) - 1;
% number of data points
nd = length(te);
% allocate the index vector, use -1 for points outside the
% integration limits
indTime = -ones(nd,1);
% the indices
for iT=1:nTime
indTime( te >= tlims(iT) & te < tlims(iT+1) ) = iT;
end
elseif tres(1)<0
% arrange the integration periods with start time
tse = [ts(:)';te(:)']';
[~,its] = sort(tse(:,1));
tse = tse(its,:);
% number of data points
nd = length(te);
% initialize the index vector
indTime = -ones(nd,1);
% find the period indices for the sorted data
iT = 1;
ii = 1;
while iT <= nd
% a 1 ms tolerance because the EISCAT timestamps are
% slightly inaccurate
iMask = tse(:,1) >= tse(iT,1) & tse(:,1) < (tse(iT,2)-1e-3);%& tse(:,1) < tse(iT,2);
indTime(iMask) = ii;
ii = ii+1;
iT = iT + sum(iMask);
end
% put the indices in the correct order
indTime(its) = indTime;
% the indices are ordered with increasing time, the time
% integration reduces to rounding
indTime = ceil(indTime/abs(tres(1)));
% number of time slices
nTime = length(unique(indTime));
else
error(['Invalide tres ',num2str(tres)])
end
end