generated from ICESAT-2HackWeek/sample_project_repository
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess_floats_draft.m
128 lines (98 loc) · 3.55 KB
/
process_floats_draft.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
%% Import ARGO synthetic floats
% Step 0: download full catalog of synthetic floats via:
% wget -r -A Sprof.nc -nH --cut-dirs=4 ftp://ftp.ifremer.fr/ifremer/argo/dac/ -A Sprof.nc
% note that this is ~50Gb of data.
% ---> kelsey bisson, dec 17, 2019
% ////////////////////////////////////////////////////////
% Step 1: Grab names of each file in the server with Sprof in name.
% (stuff into a cell)
pipe='/data1/bisson/argo_coriolis_synth/Summer19/*/*/*Sprof*'
[e,r]=unix(['ls -1 ',pipe]);
% Step 1. Get nc files into workspace within cell structure
if (~e)
r(end)=[]; % kill new line at end
cellLs=eval([abs([123,39]),strrep(r,char(10),char([39,59,39])), ...
abs([39,125])]);
else
warning(r)
cellLs={};
end
% Step 2. Index where bbp700 is available (because we don't want to
% extract profiles where there isn't bbp).
% preallocate idxx
idxx = NaN(length(cellLs), 1);
for i = 1: length(cellLs)
try
ncid = netcdf.open(cellLs{i},'NOWRITE')
varid = netcdf.inqVarID(ncid,'BBP700');
idxx(i) = i;
catch
warning('No bbp in file, moving on...')
idxx(i) = NaN;
end
end
idxx(isnan(idxx))=[];
% Step 3. Loop over all cells and extract float profiles
for i = 1:length(idxx)
ncid = netcdf.open(cellLs{idxx(i)},'NOWRITE')
% Read in Pressure
% note bad data is flagged with 99999
varid = netcdf.inqVarID(ncid,'PRES');
pres = netcdf.getVar(ncid, varid,'double');
pres(pres==99999)=NaN;
% Read in Temp
varid = netcdf.inqVarID(ncid,'TEMP');
temp = netcdf.getVar(ncid, varid,'double');
temp(temp==99999)=NaN;
% Read in Chl
varid = netcdf.inqVarID(ncid,'CHLA');
chl = netcdf.getVar(ncid, varid,'double');
chl(chl==99999)=NaN;
% BBP
varid = netcdf.inqVarID(ncid,'BBP700');
bbp = netcdf.getVar(ncid, varid,'double');
bbp(bbp==99999)=NaN;
% Read in practical salinity
varid = netcdf.inqVarID(ncid,'PSAL');
sal = netcdf.getVar(ncid, varid,'double');
sal(sal==99999)=NaN;
% Lat and Lon
varid = netcdf.inqVarID(ncid,'LATITUDE');
lat = netcdf.getVar(ncid, varid,'double');
varid = netcdf.inqVarID(ncid,'LONGITUDE');
lon = netcdf.getVar(ncid, varid,'double');
% read in JULian day
% days since 1950-01-01 00:00:00 UTC
varid = netcdf.inqVarID(ncid,'JULD');
juld = netcdf.getVar(ncid, varid,'double');
% make lat lon juld day same size
newsz = size(bbp,1) * size(bbp,2);
LAT = reshape(repmat(lat',[size(bbp,1) 1]),[newsz 1]);
LON = reshape(repmat(lon',[size(bbp,1) 1]),[newsz 1]);
JUD = reshape(repmat(juld',[size(bbp,1) 1]),[newsz 1]);
Pres = reshape(pres,[newsz 1]);
BBP = reshape(bbp,[newsz 1]);
CHL = reshape(chl,[newsz 1]);
TEMP = reshape(temp,[newsz 1]);
SAL = reshape(sal,[newsz 1]);
ID = ones([newsz 1]);
% adjust days so theyre standalone and not w.r.t ref
time=datenum(JUD+datenum('01-Jan-1950'));
date = datevec(time);
data = [LAT LON date(:,1:5) Pres BBP TEMP SAL CHL];
% throw out deep values and NaN pressure values
data(data(:,9)==99999,:)=NaN;
data(isnan(data(:,1)),:)=[];
data(isnan(data(:,9)),:)=[];
netcdf.close(ncid)
% stuff data into structure
alldata(i,1).floats = data;
clearvars -except alldata cellLs idxx
% keep track of progress
i
end
% collapse structure into 2d matrix with values
synth=cat(1, alldata.floats);
header= {'Lat','Lon','YYYY','MM','DD','HH','MM','sec','Pressure','BBP700(m^-1)',...
'TEMP','SALINITY','CHL(ug/L)'};
save('/home/bissonk/floats/ARGO_synthetic_floats/BGCfloats_dec17.mat','synth','-v7.3');