This repository was archived by the owner on Jun 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOutputManager.m
More file actions
595 lines (528 loc) · 23 KB
/
OutputManager.m
File metadata and controls
595 lines (528 loc) · 23 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
%% OutputManager - SCRIPT which takes processed data, saved as an
% ProcessedData object called "pd" and outputs SeaBASS data files and plots
%
%
% Requires: the .mat file saved in ProcessingManager, if not in memory
%
% Outputs: SeaBASS txt files
%
% Other m-files required: readIngestParameters, ProcessedData,
% Subfunctions: checkTimestamps
% MAT-files required: "acsPROC_(YEAR)_(DAY)" saved by PreProcessingManager,
% "acsPREPROC_(YEAR)_(DAY)" saved by PreProcessingManager
%
% See also: readIngestParameters, ProcessedData, checkTimestamps
%
% Author: Wendy Neary
% MISCLab, University of Maine
% email address: wendy.neary@maine.edu
% Website: http://misclab.umeoce.maine.edu/index.php
% May 2015; Last revision: 4-Mar-16
% June 2016 - added bin_count and units to output files.
% July 2016 - changed to use new data
% Aug 2016 - removed bin_count wavelength-specific columns.
%----------------------------- BEGIN CODE ---------------------------------
%%Load data file from disk if necessary
if params.RUN.LOAD_OUTPUT_DATA_FROM_DISK
matFileName = fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, ...
strcat('acsPROC', '_', num2str(params.INGEST.YEAR), '_', num2str(params.INGEST.YEAR_DAY)));
load(matFileName);
clear matFileName;
matFileName = fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, ...
strcat('acsPREPROC', '_', num2str(params.INGEST.YEAR), '_', num2str(params.INGEST.YEAR_DAY)));
load(matFileName);
clear matFileName;
end;
%% -----------------------------------------------------------------------
% SECTION 1: OUTPUT SEABASS FILES
% -----------------------------------------------------------------------
% VARIABLES TO GO IN PARAMS:
% ----------------------------------------------------------------------
% PART 1: GET DATA READY
% ----------------------------------------------------------------------
% get variables needed for output:
% ap, cp, ap_std, cp_std
% get timestamps - % this should be coming from L9 now.
ap_timestamps = pd.getVar('name', 'ap', 'data', 'timestamps');
cp_timestamps = pd.getVar('name', 'cp', 'data', 'timestamps');
% get ap - for each correction - more than one correction is possible
% this should be coming from L9 now.
if params.PROCESS.SCATTERING_CORR_SLADE
ap_data_slade = pd.getVar('name', 'ap', 'data', 'data_slade'); %, 'level', 'corrected');
end;
if params.PROCESS.SCATTERING_CORR_ROTTGERS
ap_data_rottgers = pd.getVar('name', 'ap', 'data', 'data_rottgers'); %, 'level', 'corrected');
end;
if params.PROCESS.SCATTERING_CORR_FLAT
ap_data_flat = pd.getVar('name', 'ap', 'data', 'data_flat'); %, 'level', 'corrected');
end;
% get cp - this should be coming from L9 now.
cp_data = pd.getVar('name', 'cp', 'data', 'cp_data'); %, 'level', 'corrected');
% get ap uncertainty
% there can be more than one correction calculated - but we can only report
% one to seabass
% July2016 - Not using this anymore for SeaBASS
% if params.PROCESS.AP_UNCERTAINTY_BETWEEN_CORRECTIONS
% ap_uncertainty = pd.getVar('name', 'ap', 'data', 'uncertainty_between_corrections', 'level', 'corrected');
% else
% ap_uncertainty = pd.getVar('name', 'ap', 'data', 'uncertainty', 'level', 'corrected');
% end;
% get cp uncertainty
% July2016 - Not using this anymore for SeaBASS
% cp_uncertainty = pd.getVar('name', 'cp', 'data', 'uncertainty');
% added 3/3
% get std
cp_std_to_print = pd.getVar('name', 'cp', 'data', 'cp_std');
ap_std_to_print = pd.getVar('name', 'ap', 'data', 'ap_std');
% added 4/5/16
% JULY 16 - THIS NEEDS TO BE DESPIKED DATA BIN COUNT
cp_bin_count = pd.getVar('name', 'cp', 'data', 'cp_bin_count');
cp_bin_count = cp_bin_count(:,1);
ap_bin_count = pd.getVar('name', 'ap', 'data', 'ap_bin_count');
ap_bin_count = ap_bin_count(:,1);
% GET ANCILLARY DATA: Temperature, Salinity, GPS
temp_data = allData.TemperatureData.var.L3.BinnedLabTempData;
temp_timestamps = allData.TemperatureData.var.L3.BinnedTimestamps;
sal_timestamps = allData.SalinityData.var.L3.BinnedTimestamps;
sal_data = allData.SalinityData.var.L3.BinnedData;
lat_data = allData.GPSData.var.L3.BinnedLatData;
lon_data = allData.GPSData.var.L3.BinnedLonData;
gps_timestamps = allData.GPSData.var.L3.BinnedTimestamps;
% should all be the same
wavelengths = pd.var.ap.L7.wavelengths_slade;
%%
% check timestamps are all the same
% CHANGED 10/22
if checkTimestamps(ap_timestamps, cp_timestamps)
L.debug('OutputManager', 'a and c timestamps same')
else
L.error('OutputManager', 'a and c timestamps diff')
end;
if checkTimestamps(ap_timestamps, temp_timestamps)
L.debug('OutputManager', 'a and temp timestamps same')
else
L.error('OutputManager', 'a and temp timestamps diff')
end;
if checkTimestamps(ap_timestamps, gps_timestamps)
L.debug('OutputManager', 'a and gps timestamps same')
else
L.error('OutputManager', 'a and gps timestamps diff')
end;
if checkTimestamps(ap_timestamps, sal_timestamps)
L.debug('OutputManager', 'a and sal timestamps same')
else
L.error('OutputManager', 'a and sal timestamps diff')
end;
%%
goodrows = logical(isfinite(ap_data_slade(:,20)) .* isfinite(lat_data) .* ...
isfinite(cp_data(:,20)));
%%
% Replace values below 0.005 with -9999
replaceWith999Index = cp_data < -0.005;
numReplaced = sum(replaceWith999Index);
totalNumReplaced = sum(numReplaced);
L.info('OutputManager', sprintf('Replaced %u values in cp_data with -9999', totalNumReplaced));
cp_data(replaceWith999Index) = -9999;
cp_uncertainty(replaceWith999Index) = -9999;
cp_std_to_print(replaceWith999Index) = -9999;
if params.PROCESS.SCATTERING_CORR_SLADE
replaceWith999Index = ap_data_slade < -0.005;
numReplaced = sum(replaceWith999Index);
totalNumReplaced = sum(numReplaced);
L.info('OutputManager', sprintf('Replaced %u values in ap_data_slade with -9999', totalNumReplaced));
ap_data_slade(replaceWith999Index) = -9999;
end
if params.PROCESS.SCATTERING_CORR_ROTTGERS
replaceWith999Index = ap_data_rottgers < -0.005;
numReplaced = sum(replaceWith999Index);
totalNumReplaced = sum(numReplaced);
L.info('OutputManager', sprintf('Replaced %u values in ap_data_rottgers with -9999', totalNumReplaced));
ap_data_rottgers(replaceWith999Index) = -9999;
end
if params.PROCESS.SCATTERING_CORR_FLAT
replaceWith999Index = ap_data_flat < -0.005;
numReplaced = sum(replaceWith999Index);
totalNumReplaced = sum(numReplaced);
L.info('OutputManager', sprintf('Replaced %u values in ap_data_flat with -9999', totalNumReplaced));
ap_data_flat(replaceWith999Index) = -9999;
end
ap_uncertainty(replaceWith999Index) = -9999;
ap_std_to_print(replaceWith999Index) = -9999;
% bin_tempc(isnan(bin_tempc)) = -9999;
replaceWith999Index = isnan(temp_data);
numReplaced = sum(replaceWith999Index);
totalNumReplaced = sum(numReplaced);
L.info('OutputManager', sprintf('Replaced %u values in temp_data with -9999', totalNumReplaced));
temp_data(replaceWith999Index) = -9999;
replaceWith999Index = isnan(sal_data);
numReplaced = sum(replaceWith999Index);
totalNumReplaced = sum(numReplaced);
L.info('OutputManager', sprintf('Replaced %u values in sal_data with -9999', totalNumReplaced));
sal_data(replaceWith999Index) = -9999;
% get start and end dates and times
% same for all files for this yearday
timestamps = cellstr(datestr(ap_timestamps));
temp_date = datestr(datenum(timestamps),'yyyymmdd');
temp_time = datestr(datenum(timestamps),'HH:MM:SS');
timestamps_date_to_print = cellstr(temp_date(goodrows,:));
timestamps_time_to_print = cellstr(temp_time(goodrows,:));
% same for all files for this yearday - NEEDS TO BE DONE AFTER BADROWS
% FILTERED OUT
start_date = timestamps_date_to_print{1,1};
end_date = timestamps_date_to_print{end,1};
start_time = timestamps_time_to_print{1,1};
end_time = timestamps_time_to_print{end,1};
% ----------------------------------------------------------------------
% PART 2: PRODUCE HEADER
% ----------------------------------------------------------------------
% ----------------------------------------------------------------------
% Step 1: Set up variables
% ----------------------------------------------------------------------
sb_fname_xls = [params.OUTPUT.SEABASS_FILE_PREFIX ...
num2str(params.INGEST.YEAR) '_' num2str(params.INGEST.YEAR_DAY) '.xls'];
sb_fname_ascii = [params.OUTPUT.SEABASS_FILE_PREFIX ...
num2str(params.INGEST.YEAR) '_' num2str(params.INGEST.YEAR_DAY)];
cruise = strrep(params.INGEST.CRUISE_LEG, ' ', '');
if params.OUTPUT.USE_SLADE
data_type = {ap_data_slade, cp_data};
elseif params.OUTPUT.USE_ROTTGERS
data_type = {ap_data_rottgers, cp_data};
elseif params.OUTPUT.USE_FLAT
data_type = {ap_data_flat, cp_data};
else
L.error('OutputManager','No ap data chosen for output');
end;
std_type = {ap_std_to_print, cp_std_to_print};
binCount_type = {ap_bin_count, cp_bin_count};
dataFiles = {'ap', 'cp'};
wlPrefix = {'ap', 'cp'};
if ~exist(params.INGEST.DATA_OUTPUT_DIRECTORY, 'dir')
mkdir(params.INGEST.DATA_OUTPUT_DIRECTORY)
L.info('OutputManager','made new direcotry for output');
end;
%%
for iData = 1:length(data_type)
% ----------------------------------------------------------------------
% Step 2: Create Header
% ----------------------------------------------------------------------
thisData = data_type{iData}; %ap_data_slade;
thisSTD = std_type{iData};
thisBinCount = binCount_type{iData};
thisFileName = dataFiles{iData}; %;
thisPrefix = wlPrefix{iData}; %;
data_to_print = [lat_data lon_data temp_data sal_data thisData thisSTD thisBinCount];
data_to_print = data_to_print(goodrows,:);
data_size(:,:) = size(data_to_print);
if data_size(1) == 0
L.error('OutputManager', 'ERROR - NO DATA TO OUTPUT FOR SEABASS FILES');
continue;
end;
northLat = max(data_to_print(:,1));
southLat = min(data_to_print(:,1));
eastLon = max(data_to_print(:,2));
westLon = min(data_to_print(:,2));
% create list of units, get rid of last ','
apcp_units = char(repmat(uint8(strcat(params.INGEST.AC_UNITS, ',')),...
1, 2*(length(wavelengths))));
% create units for bin_count
units_to_print = strcat(apcp_units, 'none');
% build the extension name from the dataFile
extension = strcat(thisFileName, '.txt');
seabassFileName = fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, strcat(sb_fname_ascii, extension));
sb_hdr = {'date', 'time', 'lat', 'lon', 'Wt', 'sal'};
% put all these fields into a matrix
sb_hdr = [sb_hdr strcat(thisPrefix, cellstr(num2str(wavelengths)))' ...
strcat(thisPrefix, cellstr(num2str(wavelengths)), '_sd')' 'bincount'];
% remove whitespace
sb_hdr = strrep(sb_hdr, ' ', '');
% name file
fid = fopen(seabassFileName, 'w', 'n', 'US-ASCII');
if fid ~= -1
fprintf(fid,'/begin_header\n');
fprintf(fid,'/investigators=%s\n', params.OUTPUT.INVESTIGATOR );
fprintf(fid,'/affiliations=%s\n', params.OUTPUT.AFFILIATION );
fprintf(fid,'/contact=%s\n', params.OUTPUT.CONTACT);
fprintf(fid,'/experiment=%s\n', params.OUTPUT.EXPERIMENT);
fprintf(fid,'/cruise=');
fprintf(fid,cruise);
fprintf(fid,'\n');
fprintf(fid,'/station=NA\n');
fprintf(fid,'/data_file_name=');
fprintf(fid,strcat(sb_fname_ascii,extension));
fprintf(fid,'\n');
fprintf(fid,'/documents=%s\n', params.OUTPUT.DOCUMENTATION);
fprintf(fid,'/calibration_files=%s\n', params.OUTPUT.CALIBRATION_FILES);
fprintf(fid,'/data_type=%s\n', params.OUTPUT.DATA_TYPE);
fprintf(fid,'/data_status=%s\n', params.OUTPUT.DATA_STATUS);
fprintf(fid, '/start_date=%s\n', start_date);
fprintf(fid, '/end_date=%s\n', end_date);
fprintf(fid,'/start_time=%s[GMT]\n', start_time);
fprintf(fid,'/end_time=%s[GMT]\n', end_time);
fprintf(fid,'/north_latitude=%5.3f[DEG]\n', northLat);
fprintf(fid,'/south_latitude=%5.3f[DEG]\n', southLat);
fprintf(fid,'/east_longitude=%5.3f[DEG]\n', eastLon);
fprintf(fid,'/west_longitude=%5.3f[DEG]\n', westLon);
fprintf(fid,'/water_depth=NA\n');
fprintf(fid,'/measurement_depth=%s\n', params.OUTPUT.MEASUREMENT_DEPTH); % not allowed if depth is in the data
fprintf(fid,'/secchi_depth=NA\n');
fprintf(fid,'/cloud_percent=NA\n');
fprintf(fid,'/wind_speed=NA\n');
fprintf(fid,'/wave_height=NA\n');
fprintf(fid,'/missing=-9999\n');
fprintf(fid,'/delimiter=space\n');
% new 9/8/16
fprintf(fid, '!\n');
fprintf(fid, '! COMMENTS\n');
fprintf(fid, '!\n');
fprintf(fid, '! Filters used for designating bins as SUSPECT:\n');
comment_1 = 'abs(TSW_bin_median - TSW_bin_mean))./(TSW_bin_median-FSW_interp_median) > max(';
comment_2 = ', ';
comment_3 = ' ./(TSW_bin_median-FSW_interp_median))';
fprintf(fid, '! mean/median filter:');
fprintf(fid, '%s %5.3f %s %5.3f %s\n', comment_1, ...
params.PROCESS.MEAN_MEDIAN_FILTER_1, ...
comment_2, params.PROCESS.MEAN_MEDIAN_FILTER_2, ...
comment_3);
fprintf(fid, '! std filter: std_fail_index = TSW_bin_std > stdThreshold\n');
fprintf(fid, '! where stdThreshold = %5.3f for a and %5.3f for c\n', ...
params.PROCESS.a_STD_THRESH, params.PROCESS.c_STD_THRESH);
fprintf(fid, '!\n');
fprintf(fid,'/fields=');
for j=1:length(sb_hdr)
if j < length(sb_hdr)
fprintf(fid, '%s,',cell2mat(sb_hdr(j)));
else
fprintf(fid, '%s',cell2mat(sb_hdr(j)));
end;
end
fprintf(fid,'\n');
fprintf(fid,['/units=yyyymmdd,hh:mm:ss,degrees,degrees,degreesC,PSU,' units_to_print '\n']);
fprintf(fid,'/end_header\n');
% ----------------------------------------------------------------------
% Step 3: Create Data
% ----------------------------------------------------------------------
[nRows, ~]=size(data_to_print);
for thisRow = 1:nRows
fprintf(fid, '%8s ', cell2mat( timestamps_date_to_print( thisRow,1 )));
fprintf(fid, '%8s ', cell2mat( timestamps_time_to_print( thisRow,1 )));
% print all columns except last with a space after
fprintf(fid,'%6.4f ', data_to_print(thisRow,1:end-1));
% print last column without a space
fprintf(fid,'%6.4f', data_to_print(thisRow,end));
fprintf(fid,'\n');
end
fclose(fid);
clear seabassFileName;
else
L.error('Outputmanager', sprintf('Failed to open file: %s', seabassFileName));
end;
end % for loop for data
%% ----------------------------------------------------------------------
% SECTION 2: CREATE FINAL PLOTS
% -----------------------------------------------------------------------
%%
fignum = 41;
wavelengthToPlot = 20;
figure(fignum);
ax1 = subplot(2,1,1);
hold on;
grid on;
plot(pd.var.c.L1.timestamps, pd.var.c.L1.data(:, wavelengthToPlot), 'b');
scatter(pd.var.cFSW.L3.binnedTime, pd.var.cFSW.L3.median(:,20), 5, 'o', 'fill', 'MarkerFaceColor', 'green', 'MarkerEdgeColor','green');
xlabel('Timestamps');
ylabel('c Data');
dynamicDateTicks;
xlim([ datenum(params.INGEST.YEAR, params.INGEST.MONTH, params.INGEST.DAY, 0, 0, 0) ,...
datenum(params.INGEST.YEAR, params.INGEST.MONTH, params.INGEST.DAY + 1, 0, 0, 0) ] );
% ylim([-0.1, .5])
legend('Synchronized c data', 'FSW Bins');
title_text = sprintf('Filtered c Data - using median\n Cruise: %s Leg: %s \n%u-%s-%u (Yearday: %u)', ...
params.INGEST.CRUISE, params.INGEST.CRUISE_LEG, params.INGEST.DAY, ...
params.INGEST.MONTH_TEXT, params.INGEST.YEAR, params.INGEST.YEAR_DAY);
title(title_text,'fontsize',12);
ax2 = subplot(2,1,2);
hold on;
grid on;
plot(pd.var.a.L1.timestamps, pd.var.a.L1.data(:, wavelengthToPlot), 'b');
scatter(pd.var.aFSW.L3.binnedTime, pd.var.aFSW.L3.median(:,20), 5, 'o', 'fill', 'MarkerFaceColor', 'green', 'MarkerEdgeColor','green');
xlabel('Timestamps');
ylabel('a Data');
dynamicDateTicks;
xlim([ datenum(params.INGEST.YEAR, params.INGEST.MONTH, params.INGEST.DAY, 0, 0, 0) ,...
datenum(params.INGEST.YEAR, params.INGEST.MONTH, params.INGEST.DAY + 1, 0, 0, 0) ] );
% ylim([ -0.05, 0.15])
legend('Synchronized a data', 'FSW Bins');
title_text = sprintf('Filtered a Data - using median\n Cruise: %s Leg: %s \n%u-%s-%u (Yearday: %u)', ...
params.INGEST.CRUISE, params.INGEST.CRUISE_LEG, params.INGEST.DAY, ...
params.INGEST.MONTH_TEXT, params.INGEST.YEAR, params.INGEST.YEAR_DAY);
title(title_text,'fontsize',12);
linkaxes([ax1, ax2], 'x')
saveas(gcf, fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, strcat(num2str(params.INGEST.YEAR), ...
'_', num2str(params.INGEST.YEAR_DAY), '_filtered')));
saveas(gcf, fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, strcat(num2str(params.INGEST.YEAR), ...
'_', num2str(params.INGEST.YEAR_DAY), '_filtered.jpg')));
%% FIGURE 2: "PEACHY"
fignum = 42;
figure(fignum);
ax1 = subplot(2,1,1);
hold on;
grid on;
plot(pd.var.c.L1.timestamps, pd.var.c.L1.data(:, wavelengthToPlot), 'k');
scatter(pd.var.cTSW.L3.binnedTime, pd.var.cTSW.L3.median(:,20), 5, 'o', 'MarkerFaceColor', 'green', 'MarkerEdgeColor','green');
scatter(pd.var.cFSW.L4.binnedTime, pd.var.cFSW.L4.interpolatedData(:,20),10,'o','fill','MarkerEdgeColor','blue');
xlabel('Timestamps');
ylabel('c Data');
dynamicDateTicks;
xlim([ datenum(params.INGEST.YEAR, params.INGEST.MONTH, params.INGEST.DAY, 0, 0, 0) ,...
datenum(params.INGEST.YEAR, params.INGEST.MONTH, params.INGEST.DAY + 1, 0, 0, 0) ] );
% ylim([ -0.05, 0.5])
legend('Synchronized c data', 'TSW Bins', 'Interpolated data');
title_text = sprintf('Interpolated Filtered c Data - using median\n Cruise: %s Leg: %s \n%u-%s-%u (Yearday: %u)', ...
params.INGEST.CRUISE, params.INGEST.CRUISE_LEG, params.INGEST.DAY, ...
params.INGEST.MONTH_TEXT, params.INGEST.YEAR, params.INGEST.YEAR_DAY);
title(title_text,'fontsize',12);
% dynamicDateTicks;
ax2 = subplot(2,1,2);
hold on;
grid on;
plot(pd.var.a.L1.timestamps, pd.var.a.L1.data(:, wavelengthToPlot), 'k');
scatter(pd.var.aTSW.L3.binnedTime, pd.var.aTSW.L3.median(:,20), 5, 'o', 'fill', 'MarkerFaceColor', 'green', 'MarkerEdgeColor','green');
scatter(pd.var.aFSW.L4.binnedTime, pd.var.aFSW.L4.interpolatedData(:,20), 5, 'fill', 'MarkerEdgeColor', 'blue');
xlabel('Timestamps');
ylabel('a Data');
dynamicDateTicks;
xlim([ datenum(params.INGEST.YEAR, params.INGEST.MONTH, params.INGEST.DAY, 0, 0, 0) ,...
datenum(params.INGEST.YEAR, params.INGEST.MONTH, params.INGEST.DAY + 1, 0, 0, 0) ] );
% ylim([ -0.03, 0.5])
legend('Synchronized a data', 'TSW Bins', 'Interpolated data');
title_text = sprintf('Interpolated Filtered a Data - using median\n Cruise: %s Leg: %s \n%u-%s-%u (Yearday: %u)', ...
params.INGEST.CRUISE, params.INGEST.CRUISE_LEG, params.INGEST.DAY, ...
params.INGEST.MONTH_TEXT, params.INGEST.YEAR, params.INGEST.YEAR_DAY);
title(title_text,'fontsize',12);
%
linkaxes([ax1, ax2], 'x')
saveas(gcf, fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, ...
strcat(num2str(params.INGEST.YEAR), '_', num2str(params.INGEST.YEAR_DAY), '_interp')));
saveas(gcf, fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, ...
strcat(num2str(params.INGEST.YEAR), '_',num2str(params.INGEST.YEAR_DAY), '_interp.jpg')));
%% FIGURE 3: wlap
fignum=43;
figure(fignum)
hold on;
grid on;
plot(pd.var.ap.L7.wavelengths_slade, pd.var.ap.L9.data_slade);
xlabel('Wavelength')
ylabel('ap - corrected using Slade')
title_text = sprintf('Corrected ap vs. Wavelength\n Cruise: %s Leg: %s \n%u-%s-%u (Yearday: %u)', ...
params.INGEST.CRUISE, params.INGEST.CRUISE_LEG, params.INGEST.DAY, ...
params.INGEST.MONTH_TEXT, params.INGEST.YEAR, params.INGEST.YEAR_DAY);
title(title_text, 'fontsize', 12);
saveas(gcf, fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, ...
strcat(num2str(params.INGEST.YEAR), '_', num2str(params.INGEST.YEAR_DAY), '_wlap')));
saveas(gcf, fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, ...
strcat(num2str(params.INGEST.YEAR), '_', num2str(params.INGEST.YEAR_DAY), '_wlap.jpg')));
%% FIGURE 4: wlap
fignum=44;
figure(fignum)
hold on;
grid on;
plot(pd.var.ap.L7.wavelengths_rottgers, pd.var.ap.L9.data_rottgers);
xlabel('Wavelength')
ylabel('ap - corrected using Rottgers')
title_text = sprintf('Corrected ap vs. Wavelength\n Cruise: %s Leg: %s \n%u-%s-%u (Yearday: %u)', ...
params.INGEST.CRUISE, params.INGEST.CRUISE_LEG, params.INGEST.DAY, ...
params.INGEST.MONTH_TEXT, params.INGEST.YEAR, params.INGEST.YEAR_DAY);
title(title_text, 'fontsize', 12);
saveas(gcf, fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, ...
strcat(num2str(params.INGEST.YEAR), '_', num2str(params.INGEST.YEAR_DAY), '_wlap_rottgers')));
saveas(gcf, fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, ...
strcat(num2str(params.INGEST.YEAR), '_', num2str(params.INGEST.YEAR_DAY), '_wlap_rottgers.jpg')));
%% FIGURE 5: wlcp
fignum=45;
figure(fignum)
hold on;
grid on;
plot(pd.var.cp.L7.wavelengths, pd.var.cp.L9.cp_data);
xlabel('Wavelength')
ylabel('cp - corrected')
title_text = sprintf('Corrected cp vs. Wavelength\n Cruise: %s Leg: %s \n%u-%s-%u (Yearday: %u)', ...
params.INGEST.CRUISE, params.INGEST.CRUISE_LEG, params.INGEST.DAY, ...
params.INGEST.MONTH_TEXT, params.INGEST.YEAR, params.INGEST.YEAR_DAY);
title(title_text, 'fontsize', 12);
saveas(gcf, fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, ...
strcat(num2str(params.INGEST.YEAR), '_', num2str(params.INGEST.YEAR_DAY), '_wlcp')));
saveas(gcf, fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, ...
strcat(num2str(params.INGEST.YEAR), '_', num2str(params.INGEST.YEAR_DAY), '_wlcp.jpg')));
%% write params to .ini file
struct2ini( fullfile(params.INGEST.DATA_OUTPUT_DIRECTORY, ...
strcat(num2str(params.INGEST.YEAR), '_',num2str(params.INGEST.YEAR_DAY), '.ini')), params );
%% close variables
if params.INGEST.CLEAR_VARS
clear ans;
clear ap_bin_count;
clear ap_std_to_print;
clear ap_data_rottgers;
clear ap_data_slade;
clear ap_timestamps;
clear ap_uncertainty;
clear apcp_units;
clear ax1;
clear ax2;
clear binCount_type;
clear cp_bin_count;
clear cp_std_to_print;
clear cp_data;
clear cp_timestamps;
clear cp_uncertainty;
clear cruise;
clear data;
clear data_size;
clear data_type;
clear data_to_print;
clear dataFiles;
clear eastLon;
clear end_date;
clear end_time;
clear extension;
clear fid;
clear fignum;
clear goodrows;
clear gps_timestamps;
clear iData;
clear j;
clear lat_data;
clear lon_data;
clear northLat;
clear nRows;
clear numReplaced;
clear replaceWith999Index;
clear sal_data;
clear sal_timestamps;
clear sb_fname_ascii;
clear sb_fname_xls;
clear sb_hdr;
clear seabassFileName;
clear southLat;
clear start_date;
clear start_time;
clear std_type;
clear temp_data;
clear temp_date;
clear temp_time;
clear temp_timestamps;
clear thisBinCount;
clear thisSTD;
clear thisData;
clear thisFileName;
clear thisPrefix;
clear thisRow;
clear timestamps;
clear timestamps_date_to_print;
clear timestamps_time_to_print;
clear title_text;
clear totalNumReplaced;
clear wavelengths;
clear wavelengthToPlot;
clear westLon;
clear wlPrefix;
end;