-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotData.m
More file actions
145 lines (129 loc) · 4.21 KB
/
plotData.m
File metadata and controls
145 lines (129 loc) · 4.21 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
% plotData.m
%
% uses
% Data - 2-D array of data for all channels
% metaData - a structure that contains location
% return full data set (no decimation);scale into
% physical units (but no other filter corrections applied)
decFac = 1;
scale = 1; %if scale == 1 data are returned with units of nT and mV
% note: not divided by dipole length!
% tUnits = time units for labeling time series plots
% other choices are 'Seconds','Minutes','Days'
tUnits = 'Hours';
% Number of Hours (more generally, tUnits) to plot on one pag3e
nTunits = 24;
% Assumed sampling rate (used to calculate number of points in
% the plotting window only ... should recompute after reading file)
% *******************************************************************
% [y,SysTF,dt,t0,ch,sta,error] = readTSnims(FileNames,decFac,scale);
%
% The code below now replaces readTSnims
% these are now hard-coded for NIMS
nch = 5;
ch = ['Hx ';'Hy ';'Hz ';'Ex ';'Ey '];
freq = [8,1e-5];
dt = metaData.dt;
STA = metaData.runID;
DateStart = istime(metaData.startDate,metaData.startTime);
if isempty(DateStart)
disp('Unable to determine start time from the metaData');
end
DateZero = [DateStart(1) 1 1 0 0 0];
% compute relative starting scan number
dt = dt*decFac;
% here t0 is in samples, not seconds
t0 = round((datenum(DateStart)-datenum(DateZero))*24*3600/dt);
% convert t0 to seconds
t0 = t0*dt;
[SysTF] = setUnitSysTF(nch,freq);
% create a temporary copy of the Data !!!!!
y = Data;
if isfield(metaData,'gainApplied') && isfield(metaData,'gain_char')
if ~metaData.gainApplied
% gain H(igh) or L(ow) or E(X) high or E(Y) high
if strcmp(metaData.gain_char,'L')
disp('Applied software gain of 10 to low gain Ex and Ey data');
y(4,:) = 10 * y(4,:);
y(5,:) = 10 * y(5,:);
elseif strcmp(metaData.gain_char,'X') % E(X) high
disp('Applied software gain of 10 to low gain Ey data');
y(5,:) = 10 * y(5,:);
elseif strcmp(metaData.gain_char,'Y') % E(Y) high
disp('Applied software gain of 10 to low gain Ex data');
y(4,:) = 10 * y(4,:);
end
end
end
% insert the missing data flags
if isfield(metaData,'gapsFilled') && isfield(metaData,'gaps')
if ~metaData.gapsFilled && metaData.ngaps > 0
len = metaData.gaps.len;
ind = metaData.gaps.ind;
missingdataflag = NaN;
y = fillDataGaps(y,ind,len,missingdataflag);
end
end
if decFac > 1
% decimate
y = y(:,1:decFac:end);
end
if scale
if isfield(metaData,'scaling')
scaling = metaData.scaling;
for k = 1:nch
y(k,:) = y(k,:)*scaling(k);
end
else
% scale to nT, mV
gain=200;
Ecount=8.192*1e3/(256*256*256)/gain;
y(1:3,:) = y(1:3,:)/100;
y(4:5,:) = y(4:5,:)*Ecount;
end
end
clear sta
for ic = 1:nch
sta(ic,:) = char(STA);
end
% *******************************************************************
% initialize structure "plotStart" using dt obtained from metaData
[plotStart] = plotSetup(tUnits,nTunits,dt);
% reset nPw (# of points to plot initially on one page) now
% that dt has been read from data file (NOTE: dt returned
% by readTSnims accounts for subsampling by a factor of decFac)
nPw = round(plotStart.tFac*plotStart.nTunits/dt);
plotStart.nPw = min(nPw,size(y,2));
% Initialize cell arrays for data, time series metadata,
% window metadata, etc.
TSc = {};
TSp = {};
TSd = {};
TSw = {};
TSdata = {};
TSfigInd = zeros(100,1);
% set up TSd
TSd1 = setTSd(y,t0,dt,ch,sta,SysTF);
TSd1.sta = char(TSd1.sta);
TSdata0 = (TSd1.range(:,1)+TSd1.range(:,2))/2;
rng = (TSd1.range(:,2)-TSd1.range(:,1))/2;
rng = plotStart.rangeScale*rng;
TSd1.range(:,1:2) = [ TSdata0-rng TSdata0+rng];
% are these needed???
TSd1.DataDir = '';
TSd1.arrayID = '';
% copy into cell arrays
iA = 1;
TSdata{iA} = y;
TSd{iA} = TSd1;
[hTSw,TSw1] = plotTSwin(TSd{1},plotStart);
TSfigInd(hTSw.Number) = 1;
i0 = TSw1.i0; i1 = TSw1.i1; di = TSw1.di;
yFac = TSw1.yFac;
ddt = TSd{1}.dt/TSw1.tFac;
t0 = (TSd{1}.t0)*(1-TSw1.t0Eq0)/TSw1.tFac;
I = (i0:di:i1);
[TSw1] = plotPage(ddt*I+t0,...
yFac*TSdata{1}(:,I),...
TSw1,TSd{1},1);
TSw{1} = TSw1;