-
Notifications
You must be signed in to change notification settings - Fork 2
/
process_tsv_planktoscope.m
228 lines (154 loc) · 7.91 KB
/
process_tsv_planktoscope.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
function [base_Zooscan,m,zoo_groups,Idlistshort]=process_tsv_planktoscope
A=dir('*.tsv');
filenames={A.name};
[n,m]=size(filenames);
%filenames(31:33)=[]; % sample from easter island are in double
% sampleheaders=readtable('allsampleheaders.xlsx');
% scanheaders=readtable('allscanheaders.xls');
base_Zooscan=[];
Idlist=[];
Idlistshort=[];
h = waitbar(0,'Please wait...');
for i=1:m
i
% if i==60
% continue
% end
S=readtable(char(filenames(i)),'Filetype','text','ReadVariableNames',1);
%sample=unique(S.sample_id);
sample=unique(S.object_date);
%return
%% cleaning empty cells
[no_use,n]=size(S);
varnames=S.Properties.VariableNames;
for j=16:n
eval(['var_j=S.' char(varnames(j)) ';']);
if iscellstr(var_j)
index = (cellfun(@isempty, var_j) ==1);
if sum(index)>0
var_j(index)={'NaN'};
var_j=(cellfun(@str2num, var_j));
%var_j=cell2mat(var_j);
eval(['S.' char(varnames(j)) '=var_j;']);
end
end
end
%% cleaning anotation hierarchy
[n,no_use]=size(S);
for j=1:n
f=find(S.object_annotation_hierarchy{j,:}=='-');
S.object_annotation_hierarchy{j,1}(f)='_';
f=find(S.object_annotation_hierarchy{j,:}=='>');
S.object_annotation_hierarchy{j,1}(f)='_';
end
% I=strfind(sampleheaders.sampleid,sample);
% index = (cellfun(@isempty, I) ==0);
% sample_header = sampleheaders(index,:);
%
% I=strfind(scanheaders.sampleid,sample);
% index = (cellfun(@isempty, I) ==0);
% scan_header = scanheaders(index,:);
%% if samples contains µ
% f=find(char(sample)=='µ');
% sample=char(sample);
% sample(f:f+1)='mu';
% sample=cellstr(sample);
%% getting relevant info
base_Zooscan(i).SampleID=sample;
% i
% sample
%
%base_Zooscan(i).Scanop=unique(S.sample_scan_operator);
%base_Zooscan(i).Idstatus=
base_Zooscan(i).Ship=unique(S.sample_ship);
%base_Zooscan(i).Scientificprog=unique(S.sample_program);
%base_Zooscan(i).StationId=str2num(cell2mat(unique(S.sample_stationid)));
base_Zooscan(i).Date=unique(S.object_date);
base_Zooscan(i).time=unique(S.object_time);
%base_Zooscan(i).Datenum=
base_Zooscan(i).Latitude=unique(S.object_lat);
base_Zooscan(i).Longitude=unique(S.object_lon);
%base_Zooscan(i).Depth=str2num(cell2mat(unique(S.sample_bottomdepth)));
%base_Zooscan(i).CTDref=unique(S.sample_ctdrosettefilename);
%base_Zooscan(i).Otherref=unique(S.sample_other_ref);
%base_Zooscan(i).Townb=str2num(cell2mat(unique(S.sample_tow_nb)));
%base_Zooscan(i).Towtype=str2num(cell2mat(unique(S.sample_tow_type)));
%base_Zooscan(i).Nettype=unique(S.sample_net_type);
%base_Zooscan(i).Netmesh=str2num(cell2mat(unique(S.sample_net_mesh)));
%base_Zooscan(i).Netsurf=str2num(cell2mat(unique(S.sample_net_surf)));
base_Zooscan(i).Zmax=unique(S.object_depth_min);
base_Zooscan(i).Zmin=unique(S.object_depth_min);
base_Zooscan(i).Volconc=1/(10^6); %1L en m3
base_Zooscan(i).Volpump=1;
%%
% test=unique(S.sample_comment_or_volume);
% if length(test)==1
% base_Zooscan(i).comment_or_volume=str2num(cell2mat(unique(S.sample_comment_or_volume)))/1000000;
% else
% base_Zooscan(i).comment_or_volume=str2num(cell2mat(unique(S.sample_comment)))/1000000;
% end
% if isempty(base_Zooscan(i).comment_or_volume)==1
base_Zooscan(i).comment_or_volume=1;
% end
temp=unique(S.acq_fluid_volume_imaged);
%if length(test)==1
f=strfind(temp,'_'); %supressing the _ml
temp=char(temp);
temp2=temp(1:cell2mat(f)-1);
base_Zooscan(i).fluidimaged=str2num(temp2)/1000000;
% else
% char(filenames(i))
% %% correcting for inomogeneous notations of metadata in TPac part 1 (to supress when corrected)
% base_Zooscan(i).fluidimaged=0.1863*base_Zooscan(i).Volpump;
% end
%% getting pixel size in micrometer and converting in mm
%unique(process_particle_pixel_size__m)
pixelsize=str2num((cell2mat(unique(S.process_pixel))))/1000; % in mm/pixel
base_Zooscan(i).pixelsize=pixelsize;
%%
base_Zooscan(i).FracIds=unique(S.acq_id);
[nfrac, no_use]=size(base_Zooscan(i).FracIds);
for fracnb=1:nfrac
I=strcmp(S.acq_id,base_Zooscan(i).FracIds(fracnb));
%return
% eval(['base_Zooscan(i).d' num2str(fracnb) '.Fracmin=unique(S.acq_min_esd);']);
% eval(['base_Zooscan(i).d' num2str(fracnb) '.Fracsup=unique(S.acq_max_esd);']);
%base_Zooscan(i).tot.Fracnb= unique(S.acq_sub_part);
%base_Zooscan(i).tot.Scanned_Objects=
%base_Zooscan(i).tot.Resolution=unique(S.process_img_resolution);
eval(['base_Zooscan(i).d' num2str(fracnb) '.object_annotation_hierarchy=unique(S.object_annotation_hierarchy(I));']);
%%
eval(['base_Zooscan(i).d' num2str(fracnb) '.anotStatus=S.object_annotation_status(I);']);
[Idlist, ia, ic]=unique([Idlist; S.object_annotation_hierarchy(I)]);
Idlistshort=[Idlistshort; S.object_annotation_category(I)];
Idlistshort=Idlistshort(ia);
%base_Zooscan(i).tot.Comments=
I2=strfind(S.object_annotation_status(I),'validated');
index = (cellfun(@isempty, I2) ==0);
eval(['base_Zooscan(i).d' num2str(fracnb) '.percentValidated=100*sum(index)/length(index);']);
eval(['base_Zooscan(i).d' num2str(fracnb) '.object_annotation_hierarchy=S.object_annotation_hierarchy(I);']);
%cellfun(@str2num,S.object_major)*pixelsize;
if iscell(S.object_major)==0
eval(['base_Zooscan(i).d' num2str(fracnb) '.major=S.object_major(I)*pixelsize;']); %object_perimmajor
eval(['base_Zooscan(i).d' num2str(fracnb) '.minor=S.object_minor(I)*pixelsize;']);
eval(['base_Zooscan(i).d' num2str(fracnb) '.area_exc=S.object_area_exc(I)*(pixelsize^2);']);
eval(['base_Zooscan(i).d' num2str(fracnb) '.area=S.object_area(I)*(pixelsize^2);']); %object__area
eval(['base_Zooscan(i).d' num2str(fracnb) '.area_origin=S.object_area(I);']); %object__area
eval(['base_Zooscan(i).d' num2str(fracnb) '.ESD=2*(((S.object_area(I))*(pixelsize^2)/pi).^0.5);']);
%eval(['base_Zooscan(i).d' num2str(fracnb) '.perimferet=S.object_feret(I)*pixelsize;']); % object_perimferet %object_feretareaexc
else
eval(['base_Zooscan(i).d' num2str(fracnb) '.major=cellfun(@str2num,S.object_major(I))*pixelsize;']); %object_perimmajor
eval(['base_Zooscan(i).d' num2str(fracnb) '.minor=cellfun(@str2num,S.object_minor(I))*pixelsize;']);
eval(['base_Zooscan(i).d' num2str(fracnb) '.area_exc=cellfun(@str2num,S.object_area_exc(I))*(pixelsize^2);']);
eval(['base_Zooscan(i).d' num2str(fracnb) '.ESD=2*((cellfun(@str2num,S.object_area(I))*(pixelsize^2)/pi).^0.5);']);
eval(['base_Zooscan(i).d' num2str(fracnb) '.area=cellfun(@str2num,S.object_area(I))*(pixelsize^2);']); %object__area
eval(['base_Zooscan(i).d' num2str(fracnb) '.area_origin=cellfun(@str2num,S.object_area(I));']); %object__area
%eval(['base_Zooscan(i).d' num2str(fracnb) '.perimferet=cellfun(@str2num,S.object_feret(I))*pixelsize;']); % object_perimferet %object_feretareaexc
end
eval(['base_Zooscan(i).d' num2str(fracnb) '.conver= base_Zooscan(i).Volconc./(base_Zooscan(i).fluidimaged.*base_Zooscan(i).comment_or_volume);']); %ind per cubic meter
end
waitbar(i/m)
end
close(h)
[n,m]=size(base_Zooscan);
zoo_groups=Idlist;