-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsots_ncp_3_extractor.m
693 lines (383 loc) · 23.4 KB
/
sots_ncp_3_extractor.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
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
% Extracts the data from the relevant netcdf files
% Long term, could all the sots data be compiled into one netcdf file, and
% then selected by a deployment flag? In the meantime, use a cruder
% solution
function [mooring_data] = sots_ncp_extractor(deployment)
if deployment == 'pulse7'
% Opens the relevant netcdf file
ncid = netcdf.open('IMOS_DWM-SOTS_REFOBKGTPCS_20100817_Pulse_FV02_Pulse-7-2010-Gridded-Data_END-20110708_C-20190522.nc');
% In order to access a summary of the information contained in the netcdf
% file, you can use the following command
% ncdisp('IMOS_DWM-SOTS_REFOBKGTPCS_20100817_Pulse_FV02_Pulse-7-2010-Gridded-Data_END-20110708_C-20190522.nc')
% We create a cell object containing the names of each of the variables
% stored in the netcdf. Note that variables in a NetCDF file are indexed
% from 0.
varnames = cell(size(netcdf.inqVarIDs(ncid)));
for i=0:(length(netcdf.inqVarIDs(ncid))-1)
varnames{i+1} = netcdf.inqVar(ncid,i);
end
% We create and populate a Matalb structure named "pulse7", containing
% fields named for each of the variables of the NetCDF file, and subfields
% containing the instrument name and deployment depth, where relevant.
%
% For example, pulse7.DOX2.Aanderaa_Optode3975C_38_5m
for i=0:length(varnames)-1
try
depths_dummy = netcdf.getAtt(ncid,i,'sensor_depth');
depths_dummy = split(depths_dummy,';');
depths_dummy = strtrim(depths_dummy);
depths_dummy = strcat(depths_dummy,'m');
sensor_dummy = netcdf.getAtt(ncid,i,'sensor_name');
sensor_dummy = split(sensor_dummy,';');
sensor_dummy = strtrim(sensor_dummy);
serial_dummy = netcdf.getAtt(ncid,i,'sensor_serial_number');
serial_dummy = split(serial_dummy,';');
serial_dummy = strtrim(serial_dummy);
names_dummy = matlab.lang.makeValidName(strcat(sensor_dummy,'_',serial_dummy,'_',depths_dummy));
dummy_variable = netcdf.getVar(ncid,i);
for j=1:length(names_dummy)
pulse7.(varnames{i+1}).(names_dummy{j}) = dummy_variable(:,j);
end
catch
pulse7.(varnames{i+1}) = netcdf.getVar(ncid,i);
end
end
% We transpose the time vector, as it has a different format.
pulse7.TIME = pulse7.TIME;
% Here we set a time offset, as MATLAB's serial date number format is based
% on time since year 0, while the netcdf data's serial date number is from
% 01/01/1950 00:00:00 UTC
time_offset = datenum(1950,1,1,0,0,0);
% We apply this time offset to the TIME variable of the structure, so that
% data is now correctly timestamped in Matlab.
pulse7.TIME = pulse7.TIME + time_offset.*ones(size(pulse7.TIME));
% We close the netcdf file
netcdf.close(ncid);
% We now assign the relevant data from the extraction to the outputs of
% the function
mooring_data.time = pulse7.TIME;
mooring_data.temp_C = pulse7.TEMP.Sea_BirdElectronics_SBE16plusV2_6331_31_1m;
mooring_data.temp_C_qc = pulse7.TEMP_quality_control(:,1);
mooring_data.psal_PSU = pulse7.PSAL.Sea_BirdElectronics_SBE16plusV2_6331_31_1m;
mooring_data.psal_PSU_qc = pulse7.PSAL_quality_control(:,1);
mooring_data.density_kgm3 = pulse7.DENSITY.Sea_BirdElectronics_SBE16plusV2_6331_31_1m;
mooring_data.density_kgm3_qc = pulse7.DENSITY_quality_control(:,1);
% DOX2.Aanderaa_Optode3975_1161_31_1m or Sea_BirdElectronics_SBE43_431635_31_1m
mooring_data.dox2_umolkg = pulse7.DOX2.Aanderaa_Optode3975_1161_31_1m;
mooring_data.dox2_umolkg_qc = pulse7.DOX2_quality_control(:,1);
mooring_data.dox2_sol_umolkg = pulse7.OXSOL.Sea_BirdElectronics_SBE16plusV2_6331_31_1m;
mooring_data.dox2_sol_umolkg_qc = pulse7.OXSOL_quality_control(:,1);
mooring_data.gastension_Pa = pulse7.TOTAL_GAS_PRESSURE.ProOceanus_GTD_29_102_15_31_1m*100; % Record is in hPa
mooring_data.gastension_Pa_qc = pulse7.TOTAL_GAS_PRESSURE_quality_control;
mooring_data.mld_m = pulse7.MLD;
mooring_data.mld_m_qc = pulse7.MLD_quality_control;
% Use Eric's simulated wind speeds (Eric Schulz BOM 10m winds)
load('Pulse_7_Eric_wind_sim.mat','wind_sim_total');
mooring_data.windspeed_ms = wind_sim_total;
elseif deployment == 'pulse9'
% Here the NetCDF file containing the Pulse 9 data is imported into
% Matlab. This file must be in Matlab's current folder.
ncid = netcdf.open('IMOS_ABOS-SOTS_RWBKGOTPCS_20120619_Pulse_FV02_Pulse-9-2012-Gridded-Data_END-20130510_C-20210131.nc');
% In order to access a summary of the information contained in the netcdf
% file, you can use the following command
% ncdisp('IMOS_ABOS-SOTS_RWBKGOTPCS_20120619_Pulse_FV02_Pulse-9-2012-Gridded-Data_END-20130510_C-20190910.nc')
% We create a cell object containing the names of each of the variables
% stored in the netcdf. Note that variables in a NetCDF file are indexed
% from 0.
varnames = cell(size(netcdf.inqVarIDs(ncid)));
for i=0:(length(netcdf.inqVarIDs(ncid))-1)
varnames{i+1} = netcdf.inqVar(ncid,i);
end
% We create and populate a Matalb structure named "pulse9", containing
% fields named for each of the variables of the NetCDF file, and subfields
% containing the instrument name and deployment depth, where relevant.
%
% For example, pulse9.DOX2.Aanderaa_Optode3975C_38_5m
for i=0:length(varnames)-1
try
depths_dummy = netcdf.getAtt(ncid,i,'sensor_depth');
depths_dummy = split(depths_dummy,';');
depths_dummy = strtrim(depths_dummy);
depths_dummy = strcat(depths_dummy,'m');
sensor_dummy = netcdf.getAtt(ncid,i,'sensor_name');
sensor_dummy = split(sensor_dummy,';');
sensor_dummy = strtrim(sensor_dummy);
names_dummy = matlab.lang.makeValidName(strcat(sensor_dummy,'_',depths_dummy));
dummy_variable = netcdf.getVar(ncid,i);
for j=1:length(names_dummy)
pulse9.(varnames{i+1}).(names_dummy{j}) = dummy_variable(:,j);
end
catch
dummy_variable = netcdf.getVar(ncid,i);
if length(dummy_variable) > 100
pulse9.(varnames{i+1}) = dummy_variable;
else
pulse9.(varnames{i+1}) = netcdf.getVar(ncid,i);
end
end
end
% We transpose the time vector, as it has a different format.
pulse9.TIME = pulse9.TIME;
% Here we set a time offset, as MATLAB's serial date number format is based
% on time since year 0, while the netcdf data's serial date number is from
% 01/01/1950 00:00:00 UTC
time_offset = datenum(1950,1,1,0,0,0);
% We apply this time offset to the TIME variable of the structure, so that
% data is now correctly timestamped in Matlab.
pulse9.TIME = pulse9.TIME + time_offset.*ones(size(pulse9.TIME));
% We adjust the VEMCO temperature sensors from 45-85m in order for them to
% read in agreement with the two Seabird sensors they sit between, by
% applying linear offsets.
vemco_offsets = [0.025 0.025 0.015 0.045 0.015 -0.02 0.03 0];
fields_dummy=fieldnames(pulse9.TEMP);
for i=1:length(vemco_offsets)
pulse9.TEMP.(fields_dummy{i+1}) = pulse9.TEMP.(fields_dummy{i+1}) + vemco_offsets(i);
end
% We close the netcdf file
netcdf.close(ncid);
% We import the matching sofs3 surface data into Matlab, to access
% windspeed data.
ncid2 = netcdf.open('IMOS_DWM-ASFS_CFMST_20120714T080000Z_SOFS_FV02_SOFS-3-2012_END-20130102T000000Z_C-20180716T064518Z.nc');
% We perform the same routine as with the Pulse 9 data, to extract the
% data and place it in a structure named "sofs3".
varnames2 = cell(size(netcdf.inqVarIDs(ncid2)));
for i=0:(length(netcdf.inqVarIDs(ncid2))-1)
varnames2{i+1} = netcdf.inqVar(ncid2,i);
end
for i=0:length(varnames2)-1
try
depths_dummy = netcdf.getAtt(ncid2,i,'sensor_depth');
depths_dummy = split(depths_dummy,';');
depths_dummy = strtrim(depths_dummy);
depths_dummy = strcat(depths_dummy,'m');
sensor_dummy = netcdf.getAtt(ncid2,i,'sensor_name');
sensor_dummy = split(sensor_dummy,';');
sensor_dummy = strtrim(sensor_dummy);
names_dummy = matlab.lang.makeValidName(strcat(sensor_dummy,'_',depths_dummy));
dummy_variable = netcdf.getVar(ncid2,i);
for j=1:length(names_dummy)
sofs3.(varnames2{i+1}).(names_dummy{j}) = dummy_variable(:,j);
end
catch
sofs3.(varnames2{i+1}) = netcdf.getVar(ncid2,i);
end
end
sofs3.TIME = sofs3.TIME + time_offset.*ones(size(sofs3.TIME));
% As sofs3 surface data has been recorded in minute intervals, from a
% different starting date to Pulse 10, here we create a time index to
% subsample the sofs3 data to align it with Pulse 9 sampling.
% This results in the following being true:
% sofs3.TIME(sofs3timeindex) = pulse9.TIME
sofs3timeindex = zeros(size(pulse9.TIME));
for i = 1:length(pulse9.TIME)
try
sofs3timeindex(i) = find(sofs3.TIME == pulse9.TIME(i),1);
catch
sofs3timeindex(i) = 1;
end
end
% We close the netcdf
netcdf.close(ncid2);
% We now assign the relevant data from the extraction to the outputs of
% the function
mooring_data.time = pulse9.TIME;
mooring_data.temp_C = pulse9.TEMP.Sea_BirdElectronics_SBE16plusV2_28_5m;
mooring_data.temp_C_qc = pulse9.TEMP_quality_control(:,1);
mooring_data.psal_PSU = pulse9.PSAL.Sea_BirdElectronics_SBE16plusV2_28_5m;
mooring_data.psal_PSU_qc = pulse9.PSAL_quality_control(:,1);
mooring_data.density_kgm3 = pulse9.DENSITY.Sea_BirdElectronics_SBE16plusV2_28_5m;
mooring_data.density_kgm3_qc = pulse9.DENSITY_quality_control(:,1);
% Aanderaa_Optode3975C_38_5m or Sea_BirdElectronics_SBE43_38_5m
mooring_data.dox2_umolkg = pulse9.DOX2.Aanderaa_Optode3975C_28_5m;
mooring_data.dox2_umolkg_qc = pulse9.DOX2_quality_control(:,1);
mooring_data.dox2_sol_umolkg = pulse9.OXSOL.Sea_BirdElectronics_SBE16plusV2_28_5m;
mooring_data.dox2_sol_umolkg_qc = pulse9.OXSOL_quality_control(:,1);
mooring_data.gastension_Pa = pulse9.TOTAL_GAS_PRESSURE.ProOceanus_GTD_28_5m/(1E3); % Record is in millibars in netcdf
mooring_data.gastension_Pa_qc = pulse9.TOTAL_GAS_PRESSURE_quality_control;
mooring_data.mld_m = pulse9.MLD;
mooring_data.mld_m_qc = pulse9.MLD_quality_control;
mooring_data.windspeed_ms = sofs3.WSPD10M(sofs3timeindex);
% No atmospheric pressure available
elseif deployment == 'sofs75'
% addpath('C:\xx\xx\data_folder\composite1.dat')
%
% addpath('C:\xx\xx\data_folder\composite1.dat')
% Here the NetCDF file containing the SOFS-7.5 data is imported into
% Matlab. This file must be in Matlab's current folder.
ncid = netcdf.open('IMOS_ABOS-SOTS_FRVMWEBUOSTCGP_20180628_SOFS_FV02_SOFS-7.5-2018-Gridded-Data_END-20190423_C-20190916.nc');
% In order to access a summary of the information contained in the netcdf
% file, you can use the following command
% ncdisp('IMOS_ABOS-SOTS_FRVMWEBUOSTCGP_20180628_SOFS_FV02_SOFS-7.5-2018-Gridded-Data_END-20190423_C-20190916.nc')
% We create a cell object containing the names of each of the variables
% stored in the netcdf. Note that variables in a NetCDF file are indexed
% from 0.
varnames = cell(size(netcdf.inqVarIDs(ncid)));
for i=0:(length(netcdf.inqVarIDs(ncid))-1)
varnames{i+1} = netcdf.inqVar(ncid,i);
end
% We create and populate a Matalb structure named "sofs75", containing
% fields named for each of the variables of the NetCDF file, and subfields
% containing the instrument name and deployment depth, where relevant.
%
% For example, sofs75.DOX2.Aanderaa_Optode3975C_38_5m
for i=0:length(varnames)-1
try
depths_dummy = netcdf.getAtt(ncid,i,'sensor_depth');
depths_dummy = split(depths_dummy,';');
depths_dummy = strtrim(depths_dummy);
depths_dummy = strcat(depths_dummy,'m');
sensor_dummy = netcdf.getAtt(ncid,i,'sensor_name');
sensor_dummy = split(sensor_dummy,';');
sensor_dummy = strtrim(sensor_dummy);
serial_dummy = netcdf.getAtt(ncid,i,'sensor_serial_number');
serial_dummy = split(serial_dummy,';');
serial_dummy = strtrim(serial_dummy);
names_dummy = matlab.lang.makeValidName(strcat(sensor_dummy,'_',serial_dummy,'_',depths_dummy));
dummy_variable = netcdf.getVar(ncid,i);
for j=1:length(names_dummy)
sofs75.(varnames{i+1}).(names_dummy{j}) = dummy_variable(:,j);
end
catch
sofs75.(varnames{i+1}) = netcdf.getVar(ncid,i);
end
end
% We extract the global attributes from the netcdf file and insert them
% into the structure
% We transpose the time vector, as it has a different format.
sofs75.TIME = sofs75.TIME;
% Here we set a time offset, as MATLAB's serial date number format is based
% on time since year 0, while the netcdf data's serial date number is from
% 01/01/1950 00:00:00 UTC
time_offset = datenum(1950,1,1,0,0,0);
% We apply this time offset to the TIME variable of the structure, so that
% data is now correctly timestamped in Matlab.
sofs75.TIME = sofs75.TIME + time_offset.*ones(size(sofs75.TIME));
% We close the netcdf file
netcdf.close(ncid);
% We now assign the relevant data from the extraction to the outputs of
% the function
mooring_data.time = sofs75.TIME;
mooring_data.temp_C = sofs75.TEMP.Sea_BirdElectronics_SBE37SMP_ODO_15696_30_0m;
mooring_data.temp_C_qc = sofs75.TEMP_quality_control(:,6);
mooring_data.psal_PSU = sofs75.PSAL.Sea_BirdElectronics_SBE37SMP_ODO_15696_30_0m;
mooring_data.psal_PSU_qc = sofs75.PSAL_quality_control(:,4);
% Need to manually calculate density!
SP = mooring_data.psal_PSU;
t = mooring_data.temp_C;
p = sofs75.PRES.Sea_BirdElectronics_SBE37SMP_ODO_15696_30_0m;
long = sofs75.LONGITUDE;
lat = sofs75.LATITUDE;
SA = gsw_SA_from_SP(SP,p,long,lat);
CT = gsw_CT_from_t(SA,t,p);
mooring_data.density_kgm3 = gsw_rho(SA,CT,p);
mooring_data.density_kgm3_qc = max([mooring_data.psal_PSU_qc,mooring_data.temp_C_qc,sofs75.PRES_quality_control(:,1)],[],2);
mooring_data.dox2_umolkg = sofs75.DOX2.Sea_BirdElectronics_SBE37SMP_ODO_15696_30_0m;
mooring_data.dox2_umolkg_qc = sofs75.DOX2_quality_control(:,2);
mooring_data.dox2_sol_umolkg = sofs75.OXSOL.Sea_BirdElectronics_SBE37SMP_ODO_15696_30_0m;
mooring_data.dox2_sol_umolkg_qc = sofs75.OXSOL_quality_control(:,2);
mooring_data.sub_mld_dox2_umolkg = sofs75.DOX2.Sea_BirdElectronics_SBE37SMP_ODO_15972_480_0m;
mooring_data.sub_mld_dox2_umolkg_qc = sofs75.DOX2_quality_control(:,end);
mooring_data.gastension_Pa = sofs75.TOTAL_GAS_PRESSURE.ProOceanus_TGTD_37_468_33_30_0m*100; % Record is in hPa in netcdf
mooring_data.gastension_Pa_qc = sofs75.TOTAL_GAS_PRESSURE_quality_control(:,2);
% Build mld from FV02 file
build_mld = true;
% Calculate sensor offsets from FV02 file
manual_offset = true;
if build_mld
if manual_offset
% If temperature offsets haven't been applied in the FV02 file
% already
sofs75.TEMParray = struct2array(sofs75.TEMP);
% We select the profiles where all instruments record QC values of 1
sofs75.valid_record_start = find(all(sofs75.TEMP_quality_control==1,2),1);
sofs75.valid_record_end = find(all(sofs75.TEMP_quality_control==1,2),1,'last');
sofs75.TEMParray_qc1_profiles = sofs75.TEMParray(sofs75.valid_record_start:sofs75.valid_record_end,:);
sofs75.TIME_qc1_profiles = sofs75.TIME(sofs75.valid_record_start:sofs75.valid_record_end);
% We create an array of Nan the same size as 'sofs75.TEMParray_qc1_profiles', to
% store the excursions of the Starmon sensor values from the Seabird sensor
% values.
sofs75.TEMPexcursions = NaN(size(sofs75.TEMParray_qc1_profiles));
% We set a temperature threshold of 0.004°C, based on the accuracy of
% +-0.002°C of the SBE 37-SMP-ODO, as in a body of water of one temperature,
% two SBE 37s could read 0.004°C out from each other.
temp_thresh = 0.004;
% We give the indices of the trusted temperature sources (generally SBEs)
sofs75.trusted_temps = [1 6 14 18 25];
% We loop through all the selected temperature profiles
for i = 1:length(sofs75.TEMPexcursions)
% We create multiple if conditions. Each condition checks for the current
% time stamp if the pairs of Seabird sensors closest to each other
% agree to within the temp_thresh. If they do, the excursions of
% the Starmon sensors in between the two Seabirds are recorded in
% the array 'sofs75.TEMPexcursions' for the relevant time stamp.
for j=1:(length(sofs75.trusted_temps)-1)
if abs(sofs75.TEMParray_qc1_profiles(i,sofs75.trusted_temps(j))-sofs75.TEMParray_qc1_profiles(i,sofs75.trusted_temps(j+1)))<=temp_thresh
sofs75.TEMPexcursions(i,(sofs75.trusted_temps(j)+1):(sofs75.trusted_temps(j+1)-1)) = mean([sofs75.TEMParray_qc1_profiles(i,sofs75.trusted_temps(j)) sofs75.TEMParray_qc1_profiles(i,sofs75.trusted_temps(j+1))]) - sofs75.TEMParray_qc1_profiles(i,(sofs75.trusted_temps(j)+1):(sofs75.trusted_temps(j+1)-1));
end
end
end
% We calculate the median value of the offsets for each temperature sensor,
% ignoring any NaN values generated by the Seabird sensors.
sofs75.TEMPoffsets = median(sofs75.TEMPexcursions,'omitnan');
% We set the NaN results from the Seabirds to 0.
sofs75.TEMPoffsets(isnan(sofs75.TEMPoffsets))=0;
% We adjust the selected temperature readings in sofs75.TEMParray_qc1_profiles
% and sofs75.TEMParray by the calculated offsets.
sofs75.TEMParray_qc1_profiles = sofs75.TEMParray_qc1_profiles + sofs75.TEMPoffsets;
sofs75.TEMParray = sofs75.TEMParray + sofs75.TEMPoffsets;
else
sofs75.TEMParray = struct2array(sofs75.TEMP);
end
% *********************************************************************** %
% ----------------------------------------------------------------------- %
% Calculation of Mixed layer depth %
% ----------------------------------------------------------------------- %
% *********************************************************************** %
% We calculate the mixed layer depth using a threshold method.
% First a temperature threshold is set.
MLDP_temp_thresh = 0.2;
% We create a new field in the sofs75 structure to store the MLDP data.
sofs75.MLDP.thresh02 = max(sofs75.DEPTH_TEMP).*ones(length(sofs75.TEMParray),1);
% For each timestamp, the MLDP is set at the depth of the first sensor whose
% absolute difference from the shallowest sensor exceeds the threshold. If
% no sensor exceeds this threshold, then the MLDP is set as the deepest
% sensor depth.
for i = 1:length(sofs75.MLDP.thresh02)
if any(abs(sofs75.TEMParray(i,1)-sofs75.TEMParray(i,:))>=MLDP_temp_thresh)
sofs75.MLDP.thresh02(i) = sofs75.DEPTH_TEMP(find(abs(sofs75.TEMParray(i,1)-sofs75.TEMParray(i,:))>=MLDP_temp_thresh,1));
end
end
% Here we use a linear interpolation method, as suggested in Huang et al (2018)
% as the most accurate method for temperature data, spare in depth resolution.
sofs75.MLDP.interp02 = nan.*ones(length(sofs75.TEMParray),1);
MLDP_temp_interp02 = 0.2;
for i = 1:length(sofs75.MLDP.interp02)
if sum(isnan(sofs75.TEMParray(i,:)))==0 && ~any(abs(sofs75.TEMParray(i,1)-sofs75.TEMParray(i,:))>=MLDP_temp_interp02)
sofs75.MLDP.interp02(i) = max(sofs75.DEPTH_TEMP);
elseif sum(isnan(sofs75.TEMParray(i,:)))==0
idx_below = find(abs(sofs75.TEMParray(i,1)-sofs75.TEMParray(i,:))>=MLDP_temp_interp02,1);
idx_above = idx_below-1;
sofs75.MLDP.interp02(i) = interp1(sofs75.TEMParray(i,idx_above:idx_below),sofs75.DEPTH_TEMP(idx_above:idx_below),sofs75.TEMParray(i,1)-MLDP_temp_interp02);
end
end
end
mooring_data.mld_m = sofs75.MLDP.interp02;
mooring_data.mld_m_qc = max(sofs75.TEMP_quality_control,[],2);
% Windspeed measured at 2.61m, scale using the power law from
% Justus and Mikhail (1976)
for w_idx=1:length(sofs75.WSPD(:,1))
wind_alpha(w_idx) = (0.37-0.088*log(sofs75.WSPD(w_idx,1)))/(1-0.088*log(2.61/10));
windspeed_10m(w_idx) = sofs75.WSPD(w_idx,1) * (10/2.61)^wind_alpha(w_idx);
end
% % Currently using linearly interpolated 10m windspeeds from the 2
% % hour realtime SOTS files, downloaded from the AODN as of
% % 14/05/20, will progress to using the 10m windspeeds from FV02
% % file once available
% load('sofs75_wspd10_interp.mat','WSPD10M_interp')
%
% mooring_data.windspeed_ms = WSPD10M_interp;
mooring_data.windspeed_ms = sofs75.WSPD(:,1);
mooring_data.windspeed_ms_qc = sofs75.WSPD_quality_control(:,1);
mooring_data.atmosphericpress_Pa = sofs75.CAPH(:,1)*100; % Record is in hPa
end
end