diff --git a/UVPread_persample.m b/UVPread_persample.m index 13c74de..6c27649 100644 --- a/UVPread_persample.m +++ b/UVPread_persample.m @@ -1,5 +1,6 @@ %% Construct a matlab base structured in size for a given depth strata (UVP) % by Fabien Lombard 2016-2018 +% adapted for multiple depth bin by Guillaume Bourdin January 2020 % clear all % close all @@ -12,32 +13,45 @@ offset_depth=1.2; %% - %for i = 1:width(t), if iscell(t.(i)), t.(i) = cell2mat(t.(i)); end, end -prompt = {'Enter max depth'};% -dlg_title = 'Input'; -num_lines = 1; -defaultans = {'200'}; -maxdepth = inputdlg(prompt,dlg_title,num_lines,defaultans); -maxdepth=str2num(maxdepth{1}); - - A=dir('*tsv'); filenames={A.name}; -[n,m]=size(filenames); -f = msgbox('select the particle base') +% f = msgbox('select the particle base') +fprintf('Select the particle base\n') [file,path] = uigetfile('*.mat') load(file) % load tha particles data base in which volume per depth intervals are storred samplebase={base(:).profile}; + +% prompt = {'Enter max depth'};% +% dlg_title = 'Input'; +% num_lines = 1; +% defaultans = {'200'}; +% maxdepth = inputdlg(prompt,dlg_title,num_lines,defaultans); +% maxdepth=str2num(maxdepth{1}); +prompt = {'Enter depth bin size above MLD (m)', 'Input MLD (enter "no" to use default = 150 m)', 'Enter depth bin size below MLD (m)'};% +dlg_title = 'Input'; +num_lines = 1; +defaultans = {'50', 'Yes', '300'}; +sz_depthbin = inputdlg(prompt,dlg_title,num_lines,defaultans); +up_sz_depthbin = str2double(sz_depthbin{1}); +down_sz_depthbin = str2double(sz_depthbin{3}); +if contains(sz_depthbin{2}, {'yes', 'Yes', 'YES', 'true', 'True', 'TRUE'}) + [MLDfile,~] = uigetfile('*.csv'); + MLD = readtable(MLDfile); +else + MLD = table(fullfile({base.profile}'), repmat(150, size(base,1), 1), 'VariableNames', {'profile', 'mld'}); + fprintf('Default MLD used: 150 m') +end + %samplebase=samplebase'; %% caution this assumes that the same UVP was used for an entire project (not anymore= corrected ) expo=[base(:).exp]; aa=[base(:).aa]; %pixelsize=aa.^(expo); % pixelsize=[base(:).PixelSize]; %in mm -pixelsize=pixelsize.^0.5; % in mm2 +% pixelsize=pixelsize.^0.5; % in mm2 % sampleheaders=readtable('allsampleheaders.xlsx'); @@ -51,11 +65,10 @@ %filenames([425 466])=[]; -[n,m]=size(filenames); +[~,m]=size(filenames); %return for i=1:m - % if i==430 % continue % end @@ -68,48 +81,45 @@ S=readtable(char(filenames(i)),'Filetype','text','ReadVariableNames',1); sample=unique(S.sample_id); + fprintf('Sorting %s ... ', cell2mat(sample)) %for i = 1:width(S), if iscell(t.(i)), t.(i) = cell2mat(t.(i)); 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 - +% [n,no_use]=size(S); + S.object_annotation_hierarchy = strrep(S.object_annotation_hierarchy,'-','_'); + S.object_annotation_hierarchy = strrep(S.object_annotation_hierarchy,'>','_'); + +% 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 %% cleaning for messy (text) entrance of files - if iscell(S.object_depth_max)==1 - S.object_depth_max=cellfun(@str2num,S.object_depth_max); + S.object_depth_max=cellfun(@str2num,S.object_depth_max); end if iscell(S.object_major)==1 - S.object_major=cellfun(@str2num,S.object_major); + S.object_major=cellfun(@str2num,S.object_major); end if iscell(S.object_minor)==1 - S.object_minor=cellfun(@str2num,S.object_minor); + S.object_minor=cellfun(@str2num,S.object_minor); end if iscell(S.object_area_exc)==1 - S.object_area_exc=cellfun(@str2num,S.object_area_exc); + S.object_area_exc=cellfun(@str2num,S.object_area_exc); end if iscell(S.object_area)==1 - S.object_area=cellfun(@str2num,S.object_area); + S.object_area=cellfun(@str2num,S.object_area); end - if iscell(S.object_feret)==1 - S.object_feret=cellfun(@str2num,S.object_feret); + S.object_feret=cellfun(@str2num,S.object_feret); end - - base_Zooscan(i).SampleID=sample; base_Zooscan(i).DN=unique(S.sample_dn); @@ -119,7 +129,7 @@ base_Zooscan(i).StationId=sample; temp=cell2mat(sample); %base_Zooscan(i).StationIdnum=num2str(temp(6:8)); % to extract number in tara - base_Zooscan(i).StationIdnum=(temp); + base_Zooscan(i).StationIdnum=(temp); base_Zooscan(i).Date=unique(S.object_date); base_Zooscan(i).time=unique(S.object_time); %base_Zooscan(i).Datenum= @@ -145,65 +155,80 @@ %base_Zooscan(i).pixelsize=pixelsize; %pixelsize=0.174^(0.5); %% - test=strfind(samplebase,temp); -index = (cellfun(@isempty, test)==0); -I=find(index==1); -if length(I)>1 - I=I(1); -end - volumes=base(I).histnb.data.SampledVolume_L_; %basetot(1,I).hisnb(:,3).*basetot(1,I).volimg0; - depthUVP=base(I).histnb.data.Depth_m_; %basetot(1,I).hisnb(:,1); -% if isempty(basetot(I).zoopuvp5)==0; -% -% pixelsize=basetot(I).zoopuvp5.pixel; -% -% end - base_Zooscan(i).pixelsize=pixelsize(I); - - I=depthUVP<(maxdepth+2.5); %because layer of UVP particles counts are centered: eg 200 = 197.5-202.5 - - %return - - base_Zooscan(i).tot.vol=(volumes(I)/1000); %in m3 - base_Zooscan(i).tot.conver=1./(volumes(I)/1000); - base_Zooscan(i).tot.depthstrata=depthUVP; %in m3 - -base_Zooscan(i).tot.totvol=nansum(volumes(I)/1000); %in m3 -base_Zooscan(i).tot.totconver=1/nansum(volumes(I)/1000); -%return - - %base_Zooscan(i).tot.Scanfilename= -% base_Zooscan(i).FracIds=unique(S.acq_id); -% [nfrac, no_use]=size(base_Zooscan(i).FracIds); - - S.object_depth_max=S.object_depth_max+offset_depth; - - I=S.object_depth_max<(maxdepth+2.5); %because layer of UVP particles counts are centered: eg 200 = 197.5-202.5 - %base_Zooscan(i).tot.Fracmin=unique(S.acq_min_mesh(I)); - %base_Zooscan(i).tot.Fracsup=unique(S.acq_max_mesh(I)); - %base_Zooscan(i).tot.Fracnb= unique(S.acq_sub_part(I)); - %base_Zooscan(i).tot.Scanned_Objects= - %base_Zooscan(i).tot.Resolution=unique(S.process_img_resolution(I)); - - base_Zooscan(i).tot.object_annotation_hierarchy=unique(S.object_annotation_hierarchy(I)); - Idlist=unique([Idlist; S.object_annotation_hierarchy(I)]); - base_Zooscan(i).tot.object_annotation_hierarchy=S.object_annotation_hierarchy(I); - base_Zooscan(i).tot.depth=S.object_depth_max(I);%,S.object_depth_max - %base_Zooscan(i).tot.object_annotation_hierarchy=S.object_annotation_hierarchy; - base_Zooscan(i).tot.major=S.object_major(I)*base_Zooscan(i).pixelsize; %object_perimmajor - base_Zooscan(i).tot.minor=S.object_minor(I)*base_Zooscan(i).pixelsize; - base_Zooscan(i).tot.area_exc=S.object_area_exc(I)*(base_Zooscan(i).pixelsize^2); - base_Zooscan(i).tot.area=S.object_area(I)*(base_Zooscan(i).pixelsize^2); %object__area - base_Zooscan(i).tot.perimferet=S.object_feret(I)*base_Zooscan(i).pixelsize; % object_perimferet %object_feretareaexc - %base_Zooscan(i).tot.conver= str2num(cell2mat(base_Zooscan(i).d.Fracnb))./base_Zooscan(i).Vol; %per cubic meter - - - - - - - -waitbar(i/m) + I = find(contains(samplebase,temp)); + volumes = base(I(1)).histnb.data.SampledVolume_L_; %basetot(1,I).hisnb(:,3).*basetot(1,I).volimg0; + depthUVP = base(I(1)).histnb.data.Depth_m_; %basetot(1,I).hisnb(:,1); +% if isempty(basetot(I).zoopuvp5)==0; +% pixelsize = basetot(I).zoopuvp5.pixel; +% end + base_Zooscan(i).pixelsize = pixelsize(I(1)); + base_Zooscan(i).tot = table(NaN(ceil(max(depthUVP)/up_sz_depthbin),1),... + NaN(ceil(max(depthUVP)/up_sz_depthbin),1), cell(ceil(max(depthUVP)/up_sz_depthbin),1),... + cell(ceil(max(depthUVP)/up_sz_depthbin),1), cell(ceil(max(depthUVP)/up_sz_depthbin),1),... + NaN(ceil(max(depthUVP)/up_sz_depthbin),1), NaN(ceil(max(depthUVP)/up_sz_depthbin),1),... + cell(ceil(max(depthUVP)/up_sz_depthbin),1), cell(ceil(max(depthUVP)/up_sz_depthbin),1),... + cell(ceil(max(depthUVP)/up_sz_depthbin),1), cell(ceil(max(depthUVP)/up_sz_depthbin),1),... + cell(ceil(max(depthUVP)/up_sz_depthbin),1), cell(ceil(max(depthUVP)/up_sz_depthbin),1),... + cell(ceil(max(depthUVP)/up_sz_depthbin),1), 'VariableNames',{'higher_bin_depth','lower_bin_depth','vol','conver',... + 'depthstrata','totvol','totconver','object_annotation_hierarchy',... + 'depth','major','minor','area_exc','area','perimferet'}); + % bin total depth + bin_higher_depth = 0; + if up_sz_depthbin <= MLD.mld(i) + bin_lower_depth = up_sz_depthbin + 2.5; + else + bin_lower_depth = down_sz_depthbin + 2.5; + end + pp = 1; + while bin_higher_depth < max(depthUVP) + I = depthUVP > bin_higher_depth & depthUVP <= bin_lower_depth; +% return + base_Zooscan(i).tot.higher_bin_depth(pp) = bin_higher_depth; + base_Zooscan(i).tot.lower_bin_depth(pp) = max(depthUVP(I)); + base_Zooscan(i).tot.vol{pp} = volumes(I)/1000; %in m3 + base_Zooscan(i).tot.conver{pp} = 1./(volumes(I)/1000); + base_Zooscan(i).tot.depthstrata{pp} = depthUVP; %in m3 + + base_Zooscan(i).tot.totvol(pp) = nansum(volumes(I)/1000); %in m3 + base_Zooscan(i).tot.totconver(pp) = 1/nansum(volumes(I)/1000); +% return +% base_Zooscan(i).tot.Scanfilename= +% base_Zooscan(i).FracIds=unique(S.acq_id); +% [nfrac, no_use]=size(base_Zooscan(i).FracIds); + S.object_depth_max = S.object_depth_max+offset_depth; + I = S.object_depth_max > bin_higher_depth & S.object_depth_max <= bin_lower_depth; + %base_Zooscan(i).tot.Fracmin{pp} = unique(S.acq_min_mesh(I)); + %base_Zooscan(i).tot.Fracsup{pp} = unique(S.acq_max_mesh(I)); + %base_Zooscan(i).tot.Fracnb{pp} = unique(S.acq_sub_part(I)); + %base_Zooscan(i).tot.Scanned_Objects{pp} = + %base_Zooscan(i).tot.Resolution{pp} = unique(S.process_img_resolution(I)); + +% base_Zooscan(i).tot.object_annotation_hierarchy = unique(S.object_annotation_hierarchy(I)); + Idlist = unique([Idlist; S.object_annotation_hierarchy(I)]); + base_Zooscan(i).tot.object_annotation_hierarchy{pp} = S.object_annotation_hierarchy(I); + base_Zooscan(i).tot.depth{pp} = S.object_depth_max(I); %,S.object_depth_max + %base_Zooscan(i).tot.object_annotation_hierarchy{pp} = S.object_annotation_hierarchy; + base_Zooscan(i).tot.major{pp} = S.object_major(I)*base_Zooscan(i).pixelsize; %object_perimmajor + base_Zooscan(i).tot.minor{pp} = S.object_minor(I)*base_Zooscan(i).pixelsize; + base_Zooscan(i).tot.area_exc{pp} = S.object_area_exc(I)*(base_Zooscan(i).pixelsize^2); + base_Zooscan(i).tot.area{pp} = S.object_area(I)*(base_Zooscan(i).pixelsize^2); %object__area + base_Zooscan(i).tot.perimferet{pp} = S.object_feret(I)*base_Zooscan(i).pixelsize; % object_perimferet %object_feretareaexc + %base_Zooscan(i).tot.conver{pp} = str2num(cell2mat(base_Zooscan(i).d.Fracnb))./base_Zooscan(i).Vol; %per cubic meter + if bin_higher_depth <= MLD.mld(i) + bin_lower_depth = bin_lower_depth + up_sz_depthbin; + else + bin_lower_depth = bin_lower_depth + down_sz_depthbin; + end + if bin_higher_depth <= MLD.mld(i) + bin_higher_depth = bin_lower_depth - up_sz_depthbin; + else + bin_higher_depth = bin_lower_depth - down_sz_depthbin; + end + pp = pp + 1; + end + base_Zooscan(i).tot(isnan(base_Zooscan(i).tot.higher_bin_depth),:) = []; + fprintf('done\n') + waitbar(i/m) end close(h) @@ -213,50 +238,49 @@ %% now working on spectra %% -------------- setting for calculus of the size spectra ------------------------------ % Area, Minor and Major are in mm in base_zooscan -smin=0.000000000001; %set the lower limit of the biovolume spectra that will be calculated -smax=10000; %set the upper limit of the biovolume spectra that will be calculated -k=2^(1/4); %set logarithmic base used to calculate bins of the size spectra +smin = 0.000000000001; %set the lower limit of the biovolume spectra that will be calculated +smax = 10000; %set the upper limit of the biovolume spectra that will be calculated +k = 2^(1/4); %set logarithmic base used to calculate bins of the size spectra %according to platt & denman's theory (1978). scaling %exponent set to 0.25. -uu=1; % change here the first size class for the regression (and put option = 1 for performing on the spectra from uu to end) +uu = 1; % change here the first size class for the regression (and put option = 1 for performing on the spectra from uu to end) %zoo_groups = sort(unique(zoo_groups)); %% starting to process the base -[n,m]=size(base_Zooscan); -zoo_groups=Idlist; +[~,m] = size(base_Zooscan); +zoo_groups = Idlist; %return +nsamp = 0; for i=1:m - %[nfrac, no_use]=size(base_Zooscan(i).FracIds); - subset=base_Zooscan(i).tot; - fracnb=1; - conver1=subset.conver; - depth=subset.depth; - depthstrata=subset.depthstrata; - - [ndepth,no_use]=size(conver1); - depthstrata=depthstrata(1:ndepth); - [nobject,no_use]=size(depth); - conver2=NaN*zeros(nobject,1); + fprintf('Processing base %s ... ', cell2mat(base_Zooscan(i).SampleID)) + for j = 1:size(base_Zooscan(i).tot,1) + nsamp = nsamp + 1; + %[nfrac, no_use]=size(base_Zooscan(i).FracIds); + fracnb = 1; + conver1 = base_Zooscan(i).tot.conver{j}; + depth = base_Zooscan(i).tot.depth{j}; + depthstrata = base_Zooscan(i).tot.depthstrata{j}; + + depthstrata = depthstrata(1:size(conver1,1)); +% conver2=NaN(size(depth,1),1); %% caution only works with 5m depth intervals - toto=0.5+depthstrata/5; - toto2=ceil(depth/5); - I=find(toto2>ndepth);% for the few cases where depth observations sligthly overpass max depth (by max 2.5m...) - toto2(I)=ndepth; - conver2=conver1(toto2); - base_Zooscan(i).tot.conver=conver2; - base_Zooscan(i).tot.converorig=conver1; - subset.conver=conver2; - %% - - [base_Zooscan SStot] = process_abundances_spectres_multiples_UVP(subset,base_Zooscan,smin,smax,k,uu,zoo_groups,i,fracnb); - - - - +% toto = 0.5+depthstrata/5; + toto2 = ceil(depth/5); + I = toto2 > base_Zooscan(i).tot.lower_bin_depth(j)/5;% for the few cases where depth observations sligthly overpass max depth (by max 2.5m...) + toto2(I) = floor(base_Zooscan(i).tot.lower_bin_depth(j)/5); + toto2 = toto2 - (min(toto2)-1); +% toto2 = toto2 - sz_depthbin/5*(j-1); + conver2 = conver1(toto2); + base_Zooscan(i).tot.conver{j} = conver2; + base_Zooscan(i).tot.converorig{j} = conver1; + base_Zooscan(i).tot.conver{j} = conver2; + end + [base_Zooscan, SStot] = process_abundances_spectres_multiples_UVP(base_Zooscan(i).tot,... + base_Zooscan, smin, smax, k, uu, zoo_groups, i, fracnb); + fprintf('done\n') end - - %save base_temporary base_Zooscan - %load base_temporary +%save base_temporary base_Zooscan +%load base_temporary %return @@ -264,21 +288,20 @@ % thus abundances/biovolumes needs to be divided by the number of depth % strata accumulated for i=1:m - [ndepth,no_use]=size(base_Zooscan(i).tot.converorig); - base_Zooscan(i).tot.Ab=base_Zooscan(i).tot.Ab/ndepth; - base_Zooscan(i).tot.Yab=base_Zooscan(i).tot.Yab/ndepth; - base_Zooscan(i).tot.Ybv_Plain_Area_BV_spectra=base_Zooscan(i).tot.Ybv_Plain_Area_BV_spectra/ndepth; - base_Zooscan(i).tot.Ybv_Riddled_Area_BV_spectra=base_Zooscan(i).tot.Ybv_Riddled_Area_BV_spectra/ndepth; - base_Zooscan(i).tot.Bv=base_Zooscan(i).tot.Bv/ndepth; - base_Zooscan(i).tot.Ybv_Ellipsoid_BV_spectra=base_Zooscan(i).tot.Ybv_Ellipsoid_BV_spectra/ndepth; - + for j = 1:size(base_Zooscan(i).tot,1) + ndepth = size(base_Zooscan(i).tot.depthstrata{j},1); + base_Zooscan(i).tot.Ab{j} = base_Zooscan(i).tot.Ab{j}/ndepth; + base_Zooscan(i).tot.Yab{j} = base_Zooscan(i).tot.Yab{j}/ndepth; + base_Zooscan(i).tot.Ybv_Plain_Area_BV_spectra{j} = base_Zooscan(i).tot.Ybv_Plain_Area_BV_spectra{j}/ndepth; + base_Zooscan(i).tot.Ybv_Riddled_Area_BV_spectra{j} = base_Zooscan(i).tot.Ybv_Riddled_Area_BV_spectra{j}/ndepth; + base_Zooscan(i).tot.Bv{j} = base_Zooscan(i).tot.Bv{j}/ndepth; + base_Zooscan(i).tot.Ybv_Ellipsoid_BV_spectra{j} = base_Zooscan(i).tot.Ybv_Ellipsoid_BV_spectra{j}/ndepth; + end end - - %% plus producing regrouped groups - table_groupage=readtable('zooregroup_zooscan.xlsx','ReadVariableNames',false); %all copoda as omnivorous - table_groupage=table2cell(table_groupage); - +%% plus producing regrouped groups +table_groupage=readtable('zooregroup_zooscan.xlsx','ReadVariableNames',false); %all copoda as omnivorous +table_groupage=table2cell(table_groupage); %% if needing to add new functional/trophic finction, mofify and add your desired within the excell file % currently trophic groups includes @@ -294,119 +317,103 @@ % "placement" is still subject to debate) %% now working on regrouping taxa per functional/trophic groups -% Zoo_groups=table_groupage(:,1); -[n,p]=size(zoo_groups); +% [n,p]=size(zoo_groups); %return %% finding if temporary groups are used istemporary=0; -k = strfind(zoo_groups,'temporary_'); -test=sum(cell2mat(k)); -test2=cellfun(@isempty,k); -test2=test2==0; +test = contains(zoo_groups,'temporary_'); -if test>0 +if sum(test)>0 answer = questdlg('Your files includes one or several temporary "t00X" categories. Do you have any "functional/trophic" mapping existing for those', ... 'temporary categories mapping', ... 'Yes please load them','No please create them','No please ignore them (not recommended)','Yes please load them'); - switch answer - case 'No please ignore them (not recommended)' - zoo_groups(test2)=[]; - [n,p]=size(zoo_groups); - %% updating to remove temporary groups - for i=1:m - base_Zooscan(i).tot.Zoo_groups(test2)=[]; - base_Zooscan(i).tot.Ab(test2)=[]; % abundance per fraction rapportée au volume (#/m3) - base_Zooscan(i).tot.Bv(test2)=[]; % abundance per fraction rapportée au volume (#/m3) - - base_Zooscan(i).tot.Yab(:,test2)=[]; - base_Zooscan(i).tot.Ybv_Plain_Area_BV_spectra (:,test2)=[]; - base_Zooscan(i).tot.Ybv_Riddled_Area_BV_spectra(:,test2)=[]; - base_Zooscan(i).tot.Ybv_Ellipsoid_BV_spectra(:,test2)=[]; - end - case 'Yes please load them' - [file,path] = uigetfile('*.xlsx') - addontemp=readtable([path file],'ReadVariableNames',false); %all copoda as herbivorous - addontemp=table2cell(addontemp); - Zoo_groups=[Zoo_groups; addontemp(:,1)]; - istemporary=1; - case 'No please create them' - - groups=table_groupage(:,2:end); - [n,p]=size(groups); - - group1=unique(groups(:,1)); - group2=unique(groups(:,2)); - group3=unique(cellstr(num2str(cell2mat(groups(:,3))))); - - %return - I=cellfun(@isempty,k); - I=I==0; - new_taxa=zoo_groups(I); - [p]=length(new_taxa); - newfunctional=[]; - - for i=1:p - - settings = settingsdlg('Description', ['A new temporary taxonomic group have been found ' char(new_taxa(i))],... - 'title' , 'New taxa functional mapping',... - 'Alive' , group1 ,... - 'functional group' , group2 , ... - 'trophic group' , group3 ,... - 'WindowWidth' , 800) - newfunctional=[newfunctional settings]; + case 'No please ignore them (not recommended)' + zoo_groups(test)=[]; +% [n,p]=size(zoo_groups); + %% updating to remove temporary groups + for i=1:m + for j = 1:size(base_Zooscan(i).tot,1) + base_Zooscan(i).tot.Zoo_groups{j}(test)=[]; + base_Zooscan(i).tot.Ab{j}(test)=[]; % abundance per fraction rapportée au volume (#/m3) + base_Zooscan(i).tot.Bv{j}(test)=[]; % abundance per fraction rapportée au volume (#/m3) + + base_Zooscan(i).tot.Yab{j}(:,test)=[]; + base_Zooscan(i).tot.Ybv_Plain_Area_BV_spectra{j}(:,test)=[]; + base_Zooscan(i).tot.Ybv_Riddled_Area_BV_spectra{j}(:,test)=[]; + base_Zooscan(i).tot.Ybv_Ellipsoid_BV_spectra{j}(:,test)=[]; end - newfunctional=struct2table(newfunctional) - newfunctional(:,4)=[]; - %% updating the xls reference list - % - addontemp=[new_taxa table2cell(newfunctional)]; - tosave=array2table(addontemp); - [file,path] = uiputfile('temporarymapping_instrument_net_location.xlsx'); - filename = fullfile(path,file); - writetable(tosave,filename,'WriteVariableNames',0); - Zoo_groups=[Zoo_groups; addontemp(:,1)]; - istemporary=1; - + end + case 'Yes please load them' + [file,path] = uigetfile('*.xlsx') + addontemp = readtable([path file],'ReadVariableNames',false); %all copoda as herbivorous + addontemp = table2cell(addontemp); + Zoo_groups = [Zoo_groups; addontemp(:,1)]; + istemporary = 1; + case 'No please create them' + + groups=table_groupage(:,2:end); +% [n,p]=size(groups); + + group1=unique(groups(:,1)); + group2=unique(groups(:,2)); + group3=unique(cellstr(num2str(cell2mat(groups(:,3))))); + + %return + new_taxa = zoo_groups(test); + p = length(new_taxa); + newfunctional = []; + + for i=1:p + settings = settingsdlg('Description', ['A new temporary taxonomic group have been found ' char(new_taxa(i))],... + 'title' , 'New taxa functional mapping',... + 'Alive' , group1 ,... + 'functional group' , group2 , ... + 'trophic group' , group3 ,... + 'WindowWidth' , 800) + newfunctional = [newfunctional settings]; + end + newfunctional=struct2table(newfunctional); + newfunctional(:,4)=[]; + %% updating the xls reference list + addontemp=[new_taxa table2cell(newfunctional)]; + tosave=array2table(addontemp); + [file,path] = uiputfile('temporarymapping_instrument_net_location.xlsx'); + filename = fullfile(path,file); + writetable(tosave,filename,'WriteVariableNames',0); + Zoo_groups=[Zoo_groups; addontemp(:,1)]; + istemporary=1; end - end %% checking if no "new" groups are present -% -[n,p]=size(zoo_groups); +[n,~]=size(zoo_groups); new_taxa={};p=0; for i=1:n %J=strcmp(char(zoo_groups(i)),Zoo_groups(1:I-1,:)); J=strcmp(char(zoo_groups(i)),Zoo_groups); if sum(J)==0 - p=p+1; new_taxa(p,1)=zoo_groups(i); end end clear Zoo_group - - %% proposing a mapping for the new groups -% - -groups=table_groupage(:,2:end); -[n,p]=size(groups); +groups = table_groupage(:,2:end); +[n,~] = size(groups); group1=unique(groups(:,1)); group2=unique(groups(:,2)); group3=unique(cellstr(num2str(cell2mat(groups(:,3))))); %return -[p]=length(new_taxa); +p = length(new_taxa); newfunctional=[]; for i=1:p - settings = settingsdlg('Description', ['A new taxonomic group have been found ' char(new_taxa(i))],... 'title' , 'New taxa functional mapping',... 'Alive' , group1 ,... @@ -416,7 +423,7 @@ newfunctional=[newfunctional settings]; end if p>0 -newfunctional=struct2table(newfunctional) +newfunctional=struct2table(newfunctional); newfunctional(:,4)=[]; %% updating the xls reference list % @@ -424,7 +431,6 @@ table_groupage=[table_groupage; addon]; - tosave=array2table(table_groupage); cd(directoryoftoolbox); writetable(tosave,'zooregroup_zooscan.xlsx','WriteVariableNames',0); @@ -434,33 +440,29 @@ table_groupage=[table_groupage; addontemp]; end - - %% producing the regrouped groups +for i=1:m + base_regroup = f_regroup_all(table_groupage,base_Zooscan(i).tot); + base_Zooscan(i).regroupped = base_regroup; +end - for i=1:m - - [base_regroup] = f_regroup_all(table_groupage,base_Zooscan(i).tot); - base_Zooscan(i).regroupped=base_regroup; - end - - - %% preparing resume files on abundance / BV per taxa per sample - - Ab_resume=[]; - Bv_resume=[]; - samplelist=[]; - - for i=1:m - - Ab_resume=[Ab_resume;base_Zooscan(i).regroupped.Ab]; - Bv_resume=[Bv_resume;base_Zooscan(i).regroupped.Bv]; - samplelist=[samplelist;base_Zooscan(i).SampleID]; - Zoo_groups=base_Zooscan(i).regroupped.Zoo_groups; +%% preparing resume files on abundance / BV per taxa per sample +Zoo_groups = base_Zooscan(i).regroupped.Zoo_groups{1}; +Ab_resume = NaN(nsamp,size(Zoo_groups,1)); +Bv_resume = NaN(nsamp,size(Zoo_groups,1)); +samplelist = cell(nsamp,1); +depthslice = cell(nsamp,1); +nsa = 0; +for i=1:m + for j = 1:size(base_Zooscan(i).tot,1) + nsa = nsa + 1; + Ab_resume(nsa,:) = base_Zooscan(i).regroupped.Ab{j}; + Bv_resume(nsa,:) = base_Zooscan(i).regroupped.Bv{j}; + samplelist(nsa) = base_Zooscan(i).SampleID; + depthslice{nsa} = num2str(j); end - - - +end + %% saving the final bases and resume files instrument=char(list2(indx2)); @@ -471,14 +473,15 @@ definput = {instrument,'pointB_Regent_1995_2019'}; answer = inputdlg(prompt,title,dims,definput) - save(['base_instrument_' char(answer(1)) '_' char(answer(2))],'base_Zooscan','-v7.3') %save base_spectre_zooscan_regent_point_B base_Zooscan %save base_spectre_flowcam_168b20 base_spectres +colname = strcat(samplelist, cellfun(@(c)['_depthslice_' c], depthslice, 'uni',false)); + %Abtable=table(Ab_resume,'VariableNames',Zoo_groups,'RowNames',samplelist); % do not work because the name of taxa are TOO LONG -Abtable=array2table(Ab_resume','VariableNames',samplelist,'rownames',Zoo_groups); -Bvtable=array2table(Bv_resume','VariableNames',samplelist,'rownames',Zoo_groups); +Abtable=array2table(Ab_resume','VariableNames', colname, 'rownames', Zoo_groups); +Bvtable=array2table(Bv_resume','VariableNames', colname, 'rownames',Zoo_groups); writetable(Abtable,'Abundance_resume.csv','WriteRowNames',true) writetable(Bvtable,'Biovolume_resume.csv','WriteRowNames',true) diff --git a/f_regroup_all.m b/f_regroup_all.m index 71bb431..4e91820 100644 --- a/f_regroup_all.m +++ b/f_regroup_all.m @@ -20,164 +20,175 @@ tab=table_groupage; %tab_orig=id; -tab_orig=base.Zoo_groups; -id=tab_orig; - -g_pft2=tab(:,3); -%g_trophic=tab(:,4); +base_regroup = table(base.higher_bin_depth, base.lower_bin_depth, cell(size(base,1),1),... + cell(size(base,1),1), cell(size(base,1),1), cell(size(base,1),1),... + cell(size(base,1),1), cell(size(base,1),1), cell(size(base,1),1),... + NaN(size(base,1),1), NaN(size(base,1),1), NaN(size(base,1),1),... + cell(size(base,1),1), cell(size(base,1),1),... + 'VariableNames',{'higher_bin_depth','lower_bin_depth','Ab','Ybv_Plain_Area_BV_spectra',... + 'Ybv_Riddled_Area_BV_spectra','Bv','Ybv_Ellipsoid_BV_spectra','Zoo_groups',... + 'originalplace','allplace','livingplace','notlivingplace','pftplace','trophicplace'}); + +for dep = 1:size(base,1) + tab_orig=base.Zoo_groups{dep}; + + g_pft2=table_groupage(:,3); + + to_keep = zeros(size(tab,1),1); + for i=1:size(tab_orig,1) + a=strcmp(tab_orig(i),tab(:,1)); + if sum(a)>1 + warning(['warning' tab_orig(i) 'is in double, please check reference excel file before going further']); + end + to_keep = to_keep + double(a); + end -% not_to_keep = strfind(id,'not_living'); -% to_keep = (cellfun(@isempty,not_to_keep)==1); + if max(to_keep)>1 + warning('warning there is a double in zoo_groups, please check reference excel file before going further'); + end -to_keep=[]; -for i=1:size(id,1) - a=strmatch(id(i),tab(:,1),'exact'); - if isempty(a)==0 - if length(a)>1 - warning(['warning' id(i) 'is in double, please check reference excell file before going further']); - end - to_keep=[to_keep;a]; + tab=tab(logical(to_keep),:); + + g_orig=tab(:,1); + g_living=tab(:,2);% idée: recherche des strings "living" et "not-living" + g_pft=tab(:,3); + g_trophic=tab(:,4); + + %données de spectres de taille + % Ab + % Yab + % Ybv_Plain_Area_BV_spectra + % Ybv_Riddled_Area_BV_spectra + % Bv + % Ybv_Ellipsoid_BV_spectra + + Ab=base.Ab{dep}; + %Yab=base.Yab; + Ybv_Plain_Area_BV_spectra=base.Ybv_Plain_Area_BV_spectra{dep}; + Ybv_Riddled_Area_BV_spectra=base.Ybv_Riddled_Area_BV_spectra{dep}; + Bv=base.Bv{dep}; + ss=base.Ybv_Ellipsoid_BV_spectra{dep}; + + clear SA + %% regroupement total = 'all' + Ab_t=sum(Ab); + %Yab_t=sum(Yab,2); + Ybv_Plain_Area_BV_spectra_t=sum(Ybv_Plain_Area_BV_spectra,2); + Ybv_Riddled_Area_BV_spectra_t=sum(Ybv_Riddled_Area_BV_spectra,2); + Bv_t=sum(Bv); + + sst=sum(ss,2); + + %% regroupement living vs non living + new_groups = unique(g_living); + Ab_n1 = NaN(1, size(new_groups,1)); + Ybv_Plain_Area_BV_spectra_n1 = NaN(size(Ybv_Plain_Area_BV_spectra,1), size(new_groups,1)); + Ybv_Riddled_Area_BV_spectra_n1 = NaN(size(Ybv_Riddled_Area_BV_spectra,1), size(new_groups,1)); + Bv_n1 = NaN(1,size(new_groups,1)); + ssn1 = NaN(size(ss,1),size(new_groups,1)); + for i=1:size(new_groups,1) + ng = new_groups(i); + f_ng = strcmp(g_living, ng); + + % spectres bv + ss_r = ss(:,f_ng); + Ab_r = Ab(f_ng); + %Yab_r=Yab(:,f_ng); + Ybv_Plain_Area_BV_spectra_r = Ybv_Plain_Area_BV_spectra(:,f_ng); + Ybv_Riddled_Area_BV_spectra_r = Ybv_Riddled_Area_BV_spectra(:,f_ng); + Bv_r=Bv(f_ng); + + Ab_n1(i) = sum(Ab_r); + %Yab_n1(:,i)=sum(Yab_r,2); + Ybv_Plain_Area_BV_spectra_n1(:,i) = sum(Ybv_Plain_Area_BV_spectra_r,2); + Ybv_Riddled_Area_BV_spectra_n1(:,i) = sum(Ybv_Riddled_Area_BV_spectra_r,2); + Bv_n1(i) = sum(Bv_r); + ssn1(:,i) = sum( ss_r,2); + + clear SSJ ssj ss_r f_ng ng Bv_r Ybv_Riddled_Area_BV_spectra_r Ybv_Plain_Area_BV_spectra_r Ab_r end -end -tab=tab(to_keep,:); - -g_orig=tab(:,1); -g_living=tab(:,2);% idée: recherche des strings "living" et "not-living" -g_pft=tab(:,3); -g_trophic=tab(:,4); - - -%données de spectres de taille -% Ab -% Yab -% Ybv_Plain_Area_BV_spectra -% Ybv_Riddled_Area_BV_spectra -% Bv -% Ybv_Ellipsoid_BV_spectra - -Ab=base.Ab; -%Yab=base.Yab; -Ybv_Plain_Area_BV_spectra=base.Ybv_Plain_Area_BV_spectra; -Ybv_Riddled_Area_BV_spectra=base.Ybv_Riddled_Area_BV_spectra; -Bv=base.Bv; -ss=base.Ybv_Ellipsoid_BV_spectra; - - -clear SA -%% regroupement total = 'all' - -Ab_t=sum(Ab); -%Yab_t=sum(Yab,2); -Ybv_Plain_Area_BV_spectra_t=sum(Ybv_Plain_Area_BV_spectra,2); -Ybv_Riddled_Area_BV_spectra_t=sum(Ybv_Riddled_Area_BV_spectra,2); -Bv_t=sum(Bv); - -sst=sum(ss,2); - - - -%% regroupement living vs non living -new_groups=unique(g_living); -for i=1:size(new_groups,1) - ng=new_groups(i); - f_ng=strmatch(ng,g_living); - - - % spectres bv - ss_r=ss(:,f_ng); - Ab_r=Ab(f_ng); - %Yab_r=Yab(:,f_ng); - Ybv_Plain_Area_BV_spectra_r=Ybv_Plain_Area_BV_spectra(:,f_ng); - Ybv_Riddled_Area_BV_spectra_r=Ybv_Riddled_Area_BV_spectra(:,f_ng); - Bv_r=Bv(f_ng); - - Ab_n1(i)=sum(Ab_r); - %Yab_n1(:,i)=sum(Yab_r,2); - Ybv_Plain_Area_BV_spectra_n1(:,i)=sum(Ybv_Plain_Area_BV_spectra_r,2); - Ybv_Riddled_Area_BV_spectra_n1(:,i)=sum(Ybv_Riddled_Area_BV_spectra_r,2); - Bv_n1(i)=sum(Bv_r); - ssn1(:,i)=sum( ss_r,2); - - - clear SSJ ssj ss_r f_ng ng Bv_r Ybv_Riddled_Area_BV_spectra_r Ybv_Plain_Area_BV_spectra_r Ab_r -end + %% regroupement pft + new_groups=unique(g_pft2); + Ab_n2 = NaN(1,size(new_groups,1)); + Ybv_Plain_Area_BV_spectra_n2 = NaN(size(Ybv_Plain_Area_BV_spectra,1), size(new_groups,1)); + Ybv_Riddled_Area_BV_spectra_n2 = NaN(size(Ybv_Riddled_Area_BV_spectra,1), size(new_groups,1)); + Bv_n2 = NaN(1,size(new_groups,1)); + ssn2 = NaN(size(ss,1),size(new_groups,1)); + for i=1:size(new_groups,1) + ng = new_groups(i); + f_ng = strcmp(g_pft, ng); + + %spectres bv + ss_r = ss(:,f_ng); + Ab_r = Ab(f_ng); + %Yab_r=Yab(:,f_ng); + Ybv_Plain_Area_BV_spectra_r = Ybv_Plain_Area_BV_spectra(:,f_ng); + Ybv_Riddled_Area_BV_spectra_r = Ybv_Riddled_Area_BV_spectra(:,f_ng); + Bv_r = Bv(f_ng); + + Ab_n2(i) = sum(Ab_r); + %Yab_n2(:,i)=sum(Yab_r,2); + Ybv_Plain_Area_BV_spectra_n2(:,i) = sum(Ybv_Plain_Area_BV_spectra_r,2); + Ybv_Riddled_Area_BV_spectra_n2(:,i) = sum(Ybv_Riddled_Area_BV_spectra_r,2); + Bv_n2(i) = sum(Bv_r); + ssn2(:,i) = sum( ss_r,2) ; + + clear SSJ ssj ss_r f_ng ng Bv_r Ybv_Riddled_Area_BV_spectra_r Ybv_Plain_Area_BV_spectra_r Ab_r + end -%% regroupement pft -new_groups=unique(g_pft2); -for i=1:size(new_groups,1) - ng=new_groups(i); - f_ng=strmatch(ng,g_pft); - - - %spectres bv - ss_r=ss(:,f_ng); - Ab_r=Ab(f_ng); - %Yab_r=Yab(:,f_ng); - Ybv_Plain_Area_BV_spectra_r=Ybv_Plain_Area_BV_spectra(:,f_ng); - Ybv_Riddled_Area_BV_spectra_r=Ybv_Riddled_Area_BV_spectra(:,f_ng); - Bv_r=Bv(f_ng); - - Ab_n2(i)=sum(Ab_r); - %Yab_n2(:,i)=sum(Yab_r,2); - Ybv_Plain_Area_BV_spectra_n2(:,i)=sum(Ybv_Plain_Area_BV_spectra_r,2); - Ybv_Riddled_Area_BV_spectra_n2(:,i)=sum(Ybv_Riddled_Area_BV_spectra_r,2); - Bv_n2(i)=sum(Bv_r); - ssn2(:,i)=sum( ss_r,2) ; - - clear SSJ ssj ss_r f_ng ng Bv_r Ybv_Riddled_Area_BV_spectra_r Ybv_Plain_Area_BV_spectra_r Ab_r -end - %% regroupement trophic -new_groups=unique(cell2mat(g_trophic)); -for i=1:size(new_groups,1) - ng=new_groups(i); - f_ng=ng==cell2mat(g_trophic); - - - %spectres bv - ss_r=ss(:,f_ng); - Ab_r=Ab(f_ng); - %Yab_r=Yab(:,f_ng); - Ybv_Plain_Area_BV_spectra_r=Ybv_Plain_Area_BV_spectra(:,f_ng); - Ybv_Riddled_Area_BV_spectra_r=Ybv_Riddled_Area_BV_spectra(:,f_ng); - Bv_r=Bv(f_ng); - + new_groups=unique(cell2mat(g_trophic)); + Ab_n3 = NaN(1,size(new_groups,1)); + Ybv_Plain_Area_BV_spectra_n3 = NaN(size(Ybv_Plain_Area_BV_spectra,1), size(new_groups,1)); + Ybv_Riddled_Area_BV_spectra_n3 = NaN(size(Ybv_Riddled_Area_BV_spectra,1), size(new_groups,1)); + Bv_n3 = NaN(1,size(new_groups,1)); + ssn3 = NaN(size(ss,1),size(new_groups,1)); + for i=1:size(new_groups,1) + ng = new_groups(i); + f_ng = ng==cell2mat(g_trophic); + %spectres bv + ss_r = ss(:,f_ng); + Ab_r = Ab(f_ng); + %Yab_r=Yab(:,f_ng); + Ybv_Plain_Area_BV_spectra_r = Ybv_Plain_Area_BV_spectra(:,f_ng); + Ybv_Riddled_Area_BV_spectra_r = Ybv_Riddled_Area_BV_spectra(:,f_ng); + Bv_r=Bv(f_ng); + Ab_n3(i)=sum(Ab_r); - %Yab_n3(:,i)=sum(Yab_r,2); - Ybv_Plain_Area_BV_spectra_n3(:,i)=sum(Ybv_Plain_Area_BV_spectra_r,2); - Ybv_Riddled_Area_BV_spectra_n3(:,i)=sum(Ybv_Riddled_Area_BV_spectra_r,2); - Bv_n3(i)=sum(Bv_r); - ssn3(:,i)=sum( ss_r,2); - - - clear SSJ ssj ss_r f_ng ng Bv_r Ybv_Riddled_Area_BV_spectra_r Ybv_Plain_Area_BV_spectra_r Ab_r + %Yab_n3(:,i)=sum(Yab_r,2); + Ybv_Plain_Area_BV_spectra_n3(:,i)=sum(Ybv_Plain_Area_BV_spectra_r,2); + Ybv_Riddled_Area_BV_spectra_n3(:,i)=sum(Ybv_Riddled_Area_BV_spectra_r,2); + Bv_n3(i)=sum(Bv_r); + ssn3(:,i)=sum( ss_r,2); + + clear SSJ ssj ss_r f_ng ng Bv_r Ybv_Riddled_Area_BV_spectra_r Ybv_Plain_Area_BV_spectra_r Ab_r + end + %% + %Spec_regroup=[ss sst ssn1 ssn2 ssn3]; + + Ab_regroup=[Ab' Ab_t Ab_n1 Ab_n2 Ab_n3]; + %Yab_regroup=[Yab Yab_t Yab_n1 Yab_n2 Yab_n3]; + Ybv_Plain_Area_BV_spectra_regroup=[Ybv_Plain_Area_BV_spectra Ybv_Plain_Area_BV_spectra_t Ybv_Plain_Area_BV_spectra_n1 Ybv_Plain_Area_BV_spectra_n2 Ybv_Plain_Area_BV_spectra_n3]; + Ybv_Riddled_Area_BV_spectra_regroup=[Ybv_Riddled_Area_BV_spectra Ybv_Riddled_Area_BV_spectra_t Ybv_Riddled_Area_BV_spectra_n1 Ybv_Riddled_Area_BV_spectra_n2 Ybv_Riddled_Area_BV_spectra_n3]; + Bv_regroup=[Bv' Bv_t Bv_n1 Bv_n2 Bv_n3]; + Ybv_Ellipsoid_BV_spectra_regroup=[ss sst ssn1 ssn2 ssn3]; + + %base_regroup.Abtot=base.Abtot; % ne sert a rien + base_regroup.Ab{dep} = Ab_regroup; + %base_regroup.Yab=Yab_regroup; + base_regroup.Ybv_Plain_Area_BV_spectra{dep} = Ybv_Plain_Area_BV_spectra_regroup; + base_regroup.Ybv_Riddled_Area_BV_spectra{dep} = Ybv_Riddled_Area_BV_spectra_regroup; + base_regroup.Bv{dep} = Bv_regroup; + %base_regroup.Bvtot=base.Bvtot; % ne sert a rien + base_regroup.Ybv_Ellipsoid_BV_spectra{dep} = Ybv_Ellipsoid_BV_spectra_regroup; + + base_regroup.Zoo_groups{dep} = [g_orig;{'all'};unique(g_living);unique(g_pft2);cellstr(num2str(unique(cell2mat(g_trophic))))]; + base_regroup.originalplace{dep} = [1 length(g_orig)]; + base_regroup.allplace(dep) = length(g_orig)+1; + base_regroup.livingplace(dep) = length(g_orig)+2; + base_regroup.notlivingplace(dep) = length(g_orig)+3; + base_regroup.pftplace{dep} = [length(g_orig)+4 length(g_orig)+3+length(unique(g_pft2))]; + base_regroup.trophicplace{dep} = [length(g_orig)+4+length(unique(g_pft2)) length(g_orig)+3+length(unique(g_pft2))+length(unique(cell2mat(g_trophic)))]; + % groups=[g_orig(:,1);{'all'};unique(g_living);unique(g_pft)]; end -%% - -%Spec_regroup=[ss sst ssn1 ssn2 ssn3]; - -Ab_regroup=[Ab' Ab_t Ab_n1 Ab_n2 Ab_n3]; -%Yab_regroup=[Yab Yab_t Yab_n1 Yab_n2 Yab_n3]; -Ybv_Plain_Area_BV_spectra_regroup=[Ybv_Plain_Area_BV_spectra Ybv_Plain_Area_BV_spectra_t Ybv_Plain_Area_BV_spectra_n1 Ybv_Plain_Area_BV_spectra_n2 Ybv_Plain_Area_BV_spectra_n3]; -Ybv_Riddled_Area_BV_spectra_regroup=[Ybv_Riddled_Area_BV_spectra Ybv_Riddled_Area_BV_spectra_t Ybv_Riddled_Area_BV_spectra_n1 Ybv_Riddled_Area_BV_spectra_n2 Ybv_Riddled_Area_BV_spectra_n3]; -Bv_regroup=[Bv' Bv_t Bv_n1 Bv_n2 Bv_n3]; -Ybv_Ellipsoid_BV_spectra_regroup=[ss sst ssn1 ssn2 ssn3]; -base_regroup=[]; -%base_regroup.Abtot=base.Abtot; % ne sert a rien -base_regroup.Ab=Ab_regroup; -%base_regroup.Yab=Yab_regroup; -base_regroup.Ybv_Plain_Area_BV_spectra=Ybv_Plain_Area_BV_spectra_regroup; -base_regroup.Ybv_Riddled_Area_BV_spectra=Ybv_Riddled_Area_BV_spectra_regroup; -base_regroup.Bv=Bv_regroup; -%base_regroup.Bvtot=base.Bvtot; % ne sert a rien -base_regroup.Ybv_Ellipsoid_BV_spectra=Ybv_Ellipsoid_BV_spectra_regroup; - -base_regroup.Zoo_groups=[g_orig;{'all'};unique(g_living);unique(g_pft2);cellstr(num2str(unique(cell2mat(g_trophic))))]; -base_regroup.originalplace=[1 length(g_orig)]; -base_regroup.allplace=length(g_orig)+1; -base_regroup.livingplace=length(g_orig)+2; -base_regroup.notlivingplace=length(g_orig)+3; -base_regroup.pftplace=[length(g_orig)+4 length(g_orig)+3+length(unique(g_pft2))]; -base_regroup.trophicplace=[length(g_orig)+4+length(unique(g_pft2)) length(g_orig)+3+length(unique(g_pft2))+length(unique(cell2mat(g_trophic)))]; -% groups=[g_orig(:,1);{'all'};unique(g_living);unique(g_pft)]; diff --git a/process_abundances_spectres_multiples_UVP.m b/process_abundances_spectres_multiples_UVP.m index 149500f..e8de916 100644 --- a/process_abundances_spectres_multiples_UVP.m +++ b/process_abundances_spectres_multiples_UVP.m @@ -8,8 +8,9 @@ % modified and commented by jean-baptiste romagnan on january 2010 % adapted by Marc Picheral January 2013 % adapted by Fabien Lombard 2016-2018 +% adapted for multiple depth bins by Guillaume Bourdin january 2020 -function [base_spectres SStot] = process_abundances_spectres_multiples_UVP(subset,base_spectres,smin,smax,k,uu,zoo_groups,i,fracnb); +function [base_spectres, SStot] = process_abundances_spectres_multiples_UVP(subset,base_spectres,smin,smax,k,uu,zoo_groups,i,fracnb); %base_spectres=base_Zooscan; %global ID aaa pred @@ -17,14 +18,10 @@ SStot = []; warning off % ----------- name of the groups (identifications of objects) ----------- -zoo_groups = zoo_groups; %zoo_groups = idnames; m=length(zoo_groups); disp([num2str(m),' groups']); -for j=1:m -f=find(zoo_groups{j,:}=='-'); -zoo_groups{j,1}(f)='_'; -end +zoo_groups = strrep(zoo_groups,'-','_'); % ------------ WAIT BAR ------------------------- %h=waitbar(0,'Computing SPECTRA ...');%create and display a bar that show progess of the analysis @@ -47,285 +44,288 @@ x=log(x); X=(x(1:end-1,1)+x(2:end,1))./2; % choix de la classe milieu X1=x1; % taille des classes -nb_int = length(X); %% method_list = {'Plain_Area_BV_spectra' 'Riddled_Area_BV_spectra' 'Ellipsoid_BV_spectra'}; - -for meth = 1:3 - clear mj mn sss vol pred ar aarea esd R3 area_int aareaexc fferet % clear variables that will be reused later - %% exctracting data 'area' 'major' 'minor' 'perimferet' 'area_exc' - mj = subset.major; % (mm) - mn = subset.minor; % (mm) eval(['mn(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Minor;']);% (mm�) - aareaexc = subset.area_exc; % (mm2) eval(['aareaexc(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Area_exc;']); % (mm�) - aarea = subset.area; % (mm2) eval(['aarea(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Area;']);% (mm�) - fferet = subset.perimferet; % (mm) eval(['fferet(:,1) - %% calculating volumes - if meth == 3; - % ---------- calculation of area of best fitting ellipse ----------- - ar=pi.*(mj./2).*(mn./2); - sss=(4/3)*pi.*(mj./2).*(mn./2).*(mn./2); % calculation of biovolume (mm3/m3) - elseif meth == 2; - area_int=aareaexc./pi; - esd=2*(sqrt(area_int)); - R3=(esd./2).^3; - sss=(4/3)*pi.*R3; - else - area_int=aarea./pi; - esd=2*(sqrt(area_int)); - R3=(esd./2).^3; - sss=(4/3)*pi.*R3; - end - vol=double(sss); % vol=biovolume - sss=double(log(sss)); % log of biovolume - pred=subset.object_annotation_hierarchy; - - for j=1:m % m = # de gpes de zoo - id(:,j)=strcmp(zoo_groups{j,1},pred); % id matrix for initially identified groups - id=double(id); - end - ID = id; % matrice des indices d'identification de chaque objets l = size(pred,1) et c = # de gpes: on a un seul 1 par ligne!!! - - conver = subset.conver; %per cubic meter - eval(['base_spectres(i).tot.conver=conver;']) - for j=1:m - % -------- conversion factor to have all in cubic meter --- - % eval(['conver = base_spectres(t).',char(fraction_names(nbr)),'.Fracnb/(base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Vol * base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Townb);']); - - - Ab(j)=sum(ID(:,j).*conver); % abundance per fraction rapport�e au volume - eval(['base_spectres(i).tot.Ab(j,1)=Ab(j);']) % abundance per fraction rapport�e au volume (#/m3) - Abtot(j)=sum(ID(:,j)); % abondance totale sur toute la profondeur echantillonn�e (= # d'organismes EN TOUT, pas rapport� au volume filtr�) - eval(['base_spectres(i).tot.Abtot(j,1)=Abtot(j);']) % # d'organismes EN TOUT pour la fraction scann�e, pas rapport� au volume filtr� - +for dep = 1:size(subset,1) + for meth = 1:3 + clear mj mn sss vol pred ar aarea esd R3 area_int aareaexc fferet % clear variables that will be reused later + %% exctracting data 'area' 'major' 'minor' 'perimferet' 'area_exc' + mj = subset.major{dep}; % (mm) + mn = subset.minor{dep}; % (mm) eval(['mn(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Minor;']);% (mm�) + aareaexc = subset.area_exc{dep}; % (mm2) eval(['aareaexc(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Area_exc;']); % (mm�) + aarea = subset.area{dep}; % (mm2) eval(['aarea(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Area;']);% (mm�) +% fferet = subset.perimferet{dep}; % (mm) eval(['fferet(:,1) + %% calculating volumes if meth == 3 - Bv(j)=sum(ID(:,j).*vol.*conver) ;% biovolume per fraction rapport�e au volume - eval(['base_spectres(i).tot.Bv(j,1)=Bv(j);']) % abundance per fraction rapport�e au volume (#/m3) - Bvtot(j)=sum(ID(:,j).*vol); % biovolume total sur toute la profondeur echantillonn�e (= # d'organismes EN TOUT, pas rapport� au volume filtr�) - eval(['base_spectres(i).tot.Bvtot(j,1)=Bvtot(j);']) % # d'organismes EN TOUT pour la fraction scann�e, pas rapport� au volume filtr� + % ---------- calculation of area of best fitting ellipse ----------- +% ar=pi.*(mj./2).*(mn./2); + sss=(4/3)*pi.*(mj./2).*(mn./2).*(mn./2); % calculation of biovolume (mm3/m3) + elseif meth == 2 + area_int=aareaexc./pi; + esd=2*(sqrt(area_int)); + R3=(esd./2).^3; + sss=(4/3)*pi.*R3; + else + area_int=aarea./pi; + esd=2*(sqrt(area_int)); + R3=(esd./2).^3; + sss=(4/3)*pi.*R3; end - - aaa=find(ID(:,j)==1); - f=find(zoo_groups{j,1}=='-'); - zoo_groups{j,1}(f)='_'; - % ----------- spectra per fraction ------------- - % ----------- Presence d'organismes de cette categorie pour cette fraction ------------- - if isempty(aaa) == 0; - - % ---------- Abundances --------------------- - eval(['[X,Yab_zoo_groups_',num2str(j),',Z,X1]=f_ZOO_spectrumUVP(sss(aaa,1),vol(aaa,1),smin,smax,k,1,conver(aaa));']);% clear aaa - eval(['Yab_zoo_groups_',num2str(j),'=Yab_zoo_groups_',num2str(j),';']) %'Ygroup'= size distribution for a group for a fraction - - % ---------- Biovolume --------------------- - eval(['[X,Ybv_zoo_groups_',num2str(j),',Z,X1]=f_ZOO_spectrumUVP(sss(aaa,1),vol(aaa,1),smin,smax,k,2,conver(aaa));']);% clear aaa - eval(['Ybv_zoo_groups_',num2str(j),'=Ybv_zoo_groups_',num2str(j),';']) %'Ygroup'= size distribution for a group for a fraction - - % ----------- Pas d'organismes de cette categorie pour cette fraction --------- - elseif isempty(aaa) == 1; - eval(['Yab_zoo_groups_',num2str(j),'=zeros(size(X,1),1);']); - eval(['Ybv_zoo_groups_',num2str(j),'=zeros(size(X,1),1);']); + vol = double(sss); % vol=biovolume + sss=double(log(sss)); % log of biovolume + pred = subset.object_annotation_hierarchy{dep}; + id = NaN(size(mj,1),m); + for j=1:m % m = # de gpes de zoo + id(:,j) = strcmp(zoo_groups{j,1},pred); % id matrix for initially identified groups end - % ----------- On charge les donn�es pour les fractions dans la base --------- - eval(['base_spectres(i).tot.Yab(:,j) = Yab_zoo_groups_',num2str(j),';']); - eval(['base_spectres(i).tot.Ybv_',char(method_list(meth)),'(:,j) = Ybv_zoo_groups_',num2str(j),';']); + id = logical(id); % matrice des indices d'identification de chaque objets l = size(pred,1) et c = # de gpes: on a un seul 1 par ligne!!! + + conver = subset.conver{dep}; %per cubic meter + base_spectres(i).tot.conver{dep}=conver; +% % eval(['base_spectres(i).tot.conver{dep}=conver;']) + base_spectres(i).tot.Ab{dep} = NaN(m,1); + base_spectres(i).tot.Abtot{dep} = NaN(m,1); + base_spectres(i).tot.Bv{dep} = NaN(m,1); + base_spectres(i).tot.Bvtot{dep} = NaN(m,1); + base_spectres(i).tot.Yab{dep} = NaN(size(X,1), m); + eval(['base_spectres(i).tot.Ybv_',char(method_list(meth)),'{dep} = NaN(size(X,1), m);']); - end -end + for j=1:m + % -------- conversion factor to have all in cubic meter --- + % eval(['conver = base_spectres(t).',char(fraction_names(nbr)),'.Fracnb/(base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Vol * base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Townb);']); +% % Ab(j) = sum(ID(:,j).*conver); % abundance per fraction rapport�e au volume + base_spectres(i).tot.Ab{dep}(j,1) = sum(id(:,j).*conver); +% % eval(['base_spectres(i).tot.Ab(j,1)=Ab(j);']) % abundance per fraction rapport�e au volume (#/m3) +% % Abtot(j) = sum(ID(:,j)); % abondance totale sur toute la profondeur echantillonn�e (= # d'organismes EN TOUT, pas rapport� au volume filtr�) + base_spectres(i).tot.Abtot{dep}(j,1) = sum(id(:,j)); +% % eval(['base_spectres(i).tot.Abtot(j,1)=Abtot(j);']) % # d'organismes EN TOUT pour la fraction scann�e, pas rapport� au volume filtr� + if meth == 3 +% % Bv(j) = sum(ID(:,j).*vol.*conver) ;% biovolume per fraction rapport�e au volume + base_spectres(i).tot.Bv{dep}(j,1) = sum(id(:,j).*vol.*conver); +% % eval(['base_spectres(i).tot.Bv(j,1)=Bv(j);']) % abundance per fraction rapport�e au volume (#/m3) +% % Bvtot(j) = sum(ID(:,j).*vol); % biovolume total sur toute la profondeur echantillonn�e (= # d'organismes EN TOUT, pas rapport� au volume filtr�) + base_spectres(i).tot.Bvtot{dep}(j,1) = sum(id(:,j).*vol); +% % eval(['base_spectres(i).tot.Bvtot(j,1)=Bvtot(j);']) % # d'organismes EN TOUT pour la fraction scann�e, pas rapport� au volume filtr� + end + % ----------- spectra per fraction ------------- + % ----------- Presence d'organismes de cette categorie pour cette fraction ------------- +% if ~isempty(aaa) + if any(id(:,j)) + % ---------- Abundances --------------------- + eval(['[X,Yab_zoo_groups_',num2str(j),',Z,X1]=f_ZOO_spectrumUVP(sss(id(:,j),1),vol(id(:,j),1),smin,smax,k,1,conver(id(:,j)));']);% clear aaa + eval(['Yab_zoo_groups_',num2str(j),'=Yab_zoo_groups_',num2str(j),';']) %'Ygroup'= size distribution for a group for a fraction + % ---------- Biovolume --------------------- + eval(['[X,Ybv_zoo_groups_',num2str(j),',Z,X1]=f_ZOO_spectrumUVP(sss(id(:,j),1),vol(id(:,j),1),smin,smax,k,2,conver(id(:,j)));']);% clear aaa + eval(['Ybv_zoo_groups_',num2str(j),'=Ybv_zoo_groups_',num2str(j),';']) %'Ygroup'= size distribution for a group for a fraction -eval(['base_spectres(i).tot.X = X;']); -eval(['base_spectres(i).tot.X1 = X1;']); -eval(['base_spectres(i).tot.Zoo_groups = zoo_groups;']); - - -return -for t=1:n; % boucle sur les �chantillons - - waitbar(t / n) - disp([num2str(t),' / ',num2str(n),' : ',char(base_spectres(t).SampleId)]); - %strcmp(base_zooscan(2).ids.tag_nb_objs,'ok') - - % --------------- Boucle sur les 3 methodes de calcul du BV ------- - for meth = 1:3 - % ---------- Boucle sur les fractions pour 1 �chantillon ------ - for nbr=1:NBR - clear mj mn sss vol pred ar aarea esd R3 area_int aareaexc fferet % clear variables that will be reused later - % ---------------------- Test existence de donn�es pour la fraction --------------- - eval(['testpred = isempty(base_spectres(t).',char(fraction_names(nbr)),');']); - if testpred == 0; - compteur_frac=compteur_frac+1; - % ----------- Fraction contains data ------------------------- - eval(['mj(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Major;']); % (mm) - eval(['mn(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Minor;']);% (mm�) - eval(['aareaexc(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Area_exc;']); % (mm�) - eval(['aarea(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Area;']);% (mm�) - eval(['fferet(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Feret;']);% (mm�) - if meth == 3; - % ---------- calculation of area of best fitting ellipse ----------- - ar=pi.*(mj./2).*(mn./2); - sss=(4/3)*pi.*(mj./2).*(mn./2).*(mn./2); % calculation of biovolume (mm3/m3) - elseif meth == 2; - area_int=aareaexc./pi; - esd=2*(sqrt(area_int)); - R3=(esd./2).^3; - sss=(4/3)*pi.*R3; - else - area_int=aarea./pi; - esd=2*(sqrt(area_int)); - R3=(esd./2).^3; - sss=(4/3)*pi.*R3; - end - vol=double(sss); % vol=biovolume - sss=double(log(sss)); % log of biovolume - % ----------------- definition of 'pred' variable corresponding to the identifications - eval(['pred = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Pred;']); - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Ids=pred;']); - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Major=double(mj);']); - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Minor=double(mn);']); - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Area_exc=double(aareaexc);']); - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Area=double(aarea);']); - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Feret=double(fferet);']); - - % -------------- Boucle sur les groupes -------------------- - - for j=1:m % m = # de gpes de zoo - id(:,j)=strcmp(zoo_groups{j,1},pred); % id matrix for initially identified groups - id=double(id); - end - - clear j - ID = id; % matrice des indices d'identification de chaque objets l = size(pred,1) et c = # de gpes: on a un seul 1 par ligne!!! - if isequal(size(vol,1),size(ID,1))==1 - % -------------- Boucle sur les groupes -------------------- - for j=1:m - % -------- conversion factor to have all in cubic meter --- - % eval(['conver = base_spectres(t).',char(fraction_names(nbr)),'.Fracnb/(base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Vol * base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Townb);']); - eval(['conver = base_spectres(t).',char(fraction_names(nbr)),'.Fracnb/(base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Vol);']); - - eval(['base_spectres(t).',char(fraction_names(nbr)),'.conver=conver;']); - Ab(nbr,j)=sum(ID(:,j)).*conver; % abundance per fraction rapport�e au volume - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Ab(j,1)=Ab(nbr,j);']); % abundance per fraction rapport�e au volume (#/m3) - Abtot(nbr,j)=sum(ID(:,j)); % abondance totale sur toute la profondeur echantillonn�e (= # d'organismes EN TOUT, pas rapport� au volume filtr�) - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Abtot(j,1)=Abtot(nbr,j);']); % # d'organismes EN TOUT pour la fraction scann�e, pas rapport� au volume filtr� - - if meth == 3 - Bv(nbr,j)=sum(ID(:,j).*vol).*conver ;% biovolume per fraction rapport�e au volume - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Bv(j,1)=Bv(nbr,j);']); % abundance per fraction rapport�e au volume (#/m3) - Bvtot(nbr,j)=sum(ID(:,j).*vol); % biovolume total sur toute la profondeur echantillonn�e (= # d'organismes EN TOUT, pas rapport� au volume filtr�) - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Bvtot(j,1)=Bvtot(nbr,j);']); % # d'organismes EN TOUT pour la fraction scann�e, pas rapport� au volume filtr� - end - - aaa=find(ID(:,j)==1); - f=find(zoo_groups{j,1}=='-'); - zoo_groups{j,1}(f)='_'; - % ----------- spectra per fraction ------------- - % ----------- Presence d'organismes de cette categorie pour cette fraction ------------- - if isempty(aaa) == 0; - - % ---------- Abundances --------------------- - eval(['[X,Yab_zoo_groups_',num2str(j),'(:,nbr),Z,X1]=f_ZOO_spectrum(sss(aaa,1),vol(aaa,1),smin,smax,k,1);']);% clear aaa - eval(['Yab_zoo_groups_',num2str(j),'(:,nbr)=Yab_zoo_groups_',num2str(j),'(:,nbr).*conver;']) %'Ygroup'= size distribution for a group for a fraction - - % ---------- Biovolume --------------------- - eval(['[X,Ybv_zoo_groups_',num2str(j),'(:,nbr),Z,X1]=f_ZOO_spectrum(sss(aaa,1),vol(aaa,1),smin,smax,k,2);']);% clear aaa - eval(['Ybv_zoo_groups_',num2str(j),'(:,nbr)=Ybv_zoo_groups_',num2str(j),'(:,nbr).*conver;']) %'Ygroup'= size distribution for a group for a fraction - - % ----------- Pas d'organismes de cette categorie pour cette fraction --------- - elseif isempty(aaa) == 1; - eval(['Yab_zoo_groups_',num2str(j),'(:,nbr)=zeros(size(X,1),1);']); - eval(['Ybv_zoo_groups_',num2str(j),'(:,nbr)=zeros(size(X,1),1);']); - end - % ----------- On charge les donn�es pour les fractions dans la base --------- - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Yab(:,j) = Yab_zoo_groups_',num2str(j),'(:,nbr);']); - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Ybv_',char(method_list(meth)),'(:,j) = Ybv_zoo_groups_',num2str(j),'(:,nbr);']); - - end - - clear id aaa pred f% clean variables that will be reused later - - else - for j=1:m - eval(['conver = base_spectres(t).',char(fraction_names(nbr)),'.Fracnb/(base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Vol);']); - eval(['base_spectres(t).',char(fraction_names(nbr)),'.conver=conver;']); - - % abondances - Ab(nbr,j)=nan; - Abtot(nbr,j)=nan; - - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Ab(j,1)=Ab(nbr,j);']); % abundance per fraction rapport�e au volume (#/m3) - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Abtot(j,1)=Abtot(nbr,j);']); % # d'or - - % biovolumes - Bv(nbr,j)=nan; - Bvtot(nbr,j)=nan; - - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Bv(j,1)=Bv(nbr,j);']); % abundance per fraction rapport�e au volume (#/m3) - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Bvtot(j,1)=Bvtot(nbr,j);']); % # d'organismes EN TOUT pour la fraction scann�e, pas rapport� au volume filtr� - - % spectres - eval(['Yab_zoo_groups_',num2str(j),'(:,nbr)=nan(size(X,1),1);']); - eval(['Ybv_zoo_groups_',num2str(j),'(:,nbr)=nan(size(X,1),1);']); - - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Yab(:,j) = Yab_zoo_groups_',num2str(j),'(:,nbr);']); - eval(['base_spectres(t).',char(fraction_names(nbr)),'.Ybv_',char(method_list(meth)),'(:,j) = Ybv_zoo_groups_',num2str(j),'(:,nbr);']); - end - end + % ----------- Pas d'organismes de cette categorie pour cette fraction --------- + elseif all(~id(:,j)) + eval(['Yab_zoo_groups_',num2str(j),'=zeros(size(X,1),1);']); + eval(['Ybv_zoo_groups_',num2str(j),'=zeros(size(X,1),1);']); end + % ----------- On charge les donnees pour les fractions dans la base --------- + eval(['base_spectres(i).tot.Yab{dep}(:,j) = Yab_zoo_groups_',num2str(j),';']); + eval(['base_spectres(i).tot.Ybv_',char(method_list(meth)),'{dep}(:,j) = Ybv_zoo_groups_',num2str(j),';']); + end - - Ab1=nan_sum(Ab,1)'; - Abtot1=nan_sum(Abtot,1)'; - if meth == 3 - Bv1=nan_sum(Bv,1)'; - Bvtot1=nan_sum(Bvtot,1); - end - % ----------- On travaille maintenant a rassembler les fractions --------- - for j=1:m - - eval(['Yab_zoo_groups_',num2str(j),'= nan_sum(Yab_zoo_groups_',num2str(j),',2);']) % sum of the several fractions spectra for a sample - eval(['Yab_' ,char(method_list(meth)),'(:,j)=Yab_zoo_groups_',num2str(j),';']); - eval(['Ybv_zoo_groups_',num2str(j),'= nan_sum(Ybv_zoo_groups_',num2str(j),',2);']) % sum of the several fractions spectra for a sample - eval(['Ybv_' ,char(method_list(meth)),'(:,j)=Ybv_zoo_groups_',num2str(j),';']); - end - - %clear id - clear Ab Abtot Bv Bvtot - end - - base_spectres(t).combined_frac.smin = smin; - base_spectres(t).combined_frac.smax = smax; - base_spectres(t).combined_frac.k = k; - base_spectres(t).combined_frac.uu = uu; - base_spectres(t).combined_frac.X = X; - base_spectres(t).combined_frac.X1 = X1; - base_spectres(t).combined_frac.Zoo_groups = zoo_groups; - base_spectres(t).combined_frac.Ab = Ab1; % abundance of groups for a station, all fractions combined - base_spectres(t).combined_frac.Abtot = Abtot1;% - base_spectres(t).combined_frac.Bv = Bv1; % biovolume of groups for a station, all fractions combined - base_spectres(t).combined_frac.Bvtot = Bvtot1;% - eval(['base_spectres(t).combined_frac.Abundance_spectra=Yab_',char(method_list(meth)),';']);% - for j=1:size(method_list,2) - eval(['base_spectres(t).combined_frac.',char(method_list(j)),' = Ybv_',char(method_list(j)),';']); % Somme des distributions de taille - end - eval(['SStot(:,:,t)=base_spectres(t).combined_frac.',char(method_list(3)),';']); - for i=1:size(method_list) - a=method_list(i); - eval(['clear Ybv_',cell2mat(a)]) - end - for i=1:m - eval(['clear Ybv',zoo_groups{i,1}]) - eval(['clear Yab',zoo_groups{i,1}]) end + base_spectres(i).tot.X{dep} = X; + % % eval(['base_spectres(i).tot.X = X;']); + base_spectres(i).tot.X1{dep} = X1; + % % eval(['base_spectres(i).tot.X1 = X1;']); + base_spectres(i).tot.Zoo_groups{dep} = zoo_groups; + % % eval(['base_spectres(i).tot.Zoo_groups = zoo_groups;']); end -SStot=permute(SStot,[1 3 2]); -for i=1:size(SStot,3) - Sz=SStot(:,:,i); - S(i,1)={Sz}; -end - -SStot=S; - -% -------- Fermeture ------------ -close(h) +% for t=1:n % boucle sur les �chantillons +% +% waitbar(t / n) +% disp([num2str(t),' / ',num2str(n),' : ',char(base_spectres(t).SampleId)]); +% %strcmp(base_zooscan(2).ids.tag_nb_objs,'ok') +% +% % --------------- Boucle sur les 3 methodes de calcul du BV ------- +% for meth = 1:3 +% % ---------- Boucle sur les fractions pour 1 �chantillon ------ +% for nbr=1:NBR +% clear mj mn sss vol pred ar aarea esd R3 area_int aareaexc fferet % clear variables that will be reused later +% % ---------------------- Test existence de donn�es pour la fraction --------------- +% eval(['testpred = isempty(base_spectres(t).',char(fraction_names(nbr)),');']); +% if testpred == 0 +% compteur_frac=compteur_frac+1; +% % ----------- Fraction contains data ------------------------- +% eval(['mj(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Major;']); % (mm) +% eval(['mn(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Minor;']);% (mm�) +% eval(['aareaexc(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Area_exc;']); % (mm�) +% eval(['aarea(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Area;']);% (mm�) +% eval(['fferet(:,1) = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Feret;']);% (mm�) +% if meth == 3 +% % ---------- calculation of area of best fitting ellipse ----------- +% ar=pi.*(mj./2).*(mn./2); +% sss=(4/3)*pi.*(mj./2).*(mn./2).*(mn./2); % calculation of biovolume (mm3/m3) +% elseif meth == 2 +% area_int=aareaexc./pi; +% esd=2*(sqrt(area_int)); +% R3=(esd./2).^3; +% sss=(4/3)*pi.*R3; +% else +% area_int=aarea./pi; +% esd=2*(sqrt(area_int)); +% R3=(esd./2).^3; +% sss=(4/3)*pi.*R3; +% end +% vol=double(sss); % vol=biovolume +% sss=double(log(sss)); % log of biovolume +% % ----------------- definition of 'pred' variable corresponding to the identifications +% eval(['pred = base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).ids.Pred;']); +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Ids=pred;']); +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Major=double(mj);']); +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Minor=double(mn);']); +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Area_exc=double(aareaexc);']); +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Area=double(aarea);']); +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Raw_Feret=double(fferet);']); +% +% % -------------- Boucle sur les groupes -------------------- +% +% for j=1:m % m = # de gpes de zoo +% id(:,j)=strcmp(zoo_groups{j,1},pred); % id matrix for initially identified groups +% id=double(id); +% end +% +% clear j +% ID = id; % matrice des indices d'identification de chaque objets l = size(pred,1) et c = # de gpes: on a un seul 1 par ligne!!! +% if size(vol,1) == size(ID,1) +% % -------------- Boucle sur les groupes -------------------- +% for j=1:m +% % -------- conversion factor to have all in cubic meter --- +% % eval(['conver = base_spectres(t).',char(fraction_names(nbr)),'.Fracnb/(base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Vol * base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Townb);']); +% eval(['conver = base_spectres(t).',char(fraction_names(nbr)),'.Fracnb/(base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Vol);']); +% +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.conver=conver;']); +% Ab(nbr,j)=sum(ID(:,j)).*conver; % abundance per fraction rapport�e au volume +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Ab(j,1)=Ab(nbr,j);']); % abundance per fraction rapport�e au volume (#/m3) +% Abtot(nbr,j)=sum(ID(:,j)); % abondance totale sur toute la profondeur echantillonn�e (= # d'organismes EN TOUT, pas rapport� au volume filtr�) +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Abtot(j,1)=Abtot(nbr,j);']); % # d'organismes EN TOUT pour la fraction scann�e, pas rapport� au volume filtr� +% +% if meth == 3 +% Bv(nbr,j)=sum(ID(:,j).*vol).*conver ;% biovolume per fraction rapport�e au volume +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Bv(j,1)=Bv(nbr,j);']); % abundance per fraction rapport�e au volume (#/m3) +% Bvtot(nbr,j)=sum(ID(:,j).*vol); % biovolume total sur toute la profondeur echantillonn�e (= # d'organismes EN TOUT, pas rapport� au volume filtr�) +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Bvtot(j,1)=Bvtot(nbr,j);']); % # d'organismes EN TOUT pour la fraction scann�e, pas rapport� au volume filtr� +% end +% +% aaa=find(ID(:,j)==1); +% f=find(zoo_groups{j,1}=='-'); +% zoo_groups{j,1}(f)='_'; +% % ----------- spectra per fraction ------------- +% % ----------- Presence d'organismes de cette categorie pour cette fraction ------------- +% if isempty(aaa) == 0 +% +% % ---------- Abundances --------------------- +% eval(['[X,Yab_zoo_groups_',num2str(j),'(:,nbr),Z,X1]=f_ZOO_spectrum(sss(aaa,1),vol(aaa,1),smin,smax,k,1);']);% clear aaa +% eval(['Yab_zoo_groups_',num2str(j),'(:,nbr)=Yab_zoo_groups_',num2str(j),'(:,nbr).*conver;']) %'Ygroup'= size distribution for a group for a fraction +% +% % ---------- Biovolume --------------------- +% eval(['[X,Ybv_zoo_groups_',num2str(j),'(:,nbr),Z,X1]=f_ZOO_spectrum(sss(aaa,1),vol(aaa,1),smin,smax,k,2);']);% clear aaa +% eval(['Ybv_zoo_groups_',num2str(j),'(:,nbr)=Ybv_zoo_groups_',num2str(j),'(:,nbr).*conver;']) %'Ygroup'= size distribution for a group for a fraction +% +% % ----------- Pas d'organismes de cette categorie pour cette fraction --------- +% elseif isempty(aaa) == 1 +% eval(['Yab_zoo_groups_',num2str(j),'(:,nbr)=zeros(size(X,1),1);']); +% eval(['Ybv_zoo_groups_',num2str(j),'(:,nbr)=zeros(size(X,1),1);']); +% end +% % ----------- On charge les donn�es pour les fractions dans la base --------- +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Yab(:,j) = Yab_zoo_groups_',num2str(j),'(:,nbr);']); +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Ybv_',char(method_list(meth)),'(:,j) = Ybv_zoo_groups_',num2str(j),'(:,nbr);']); +% +% end +% +% clear id aaa pred f% clean variables that will be reused later +% +% else +% for j=1:m +% eval(['conver = base_spectres(t).',char(fraction_names(nbr)),'.Fracnb/(base_zooscan(base_spectres(t).',char(fraction_names(nbr)),'.base_zooscan_index).Vol);']); +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.conver=conver;']); +% +% % abondances +% Ab(nbr,j)=nan; +% Abtot(nbr,j)=nan; +% +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Ab(j,1)=Ab(nbr,j);']); % abundance per fraction rapport�e au volume (#/m3) +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Abtot(j,1)=Abtot(nbr,j);']); % # d'or +% +% % biovolumes +% Bv(nbr,j)=nan; +% Bvtot(nbr,j)=nan; +% +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Bv(j,1)=Bv(nbr,j);']); % abundance per fraction rapport�e au volume (#/m3) +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Bvtot(j,1)=Bvtot(nbr,j);']); % # d'organismes EN TOUT pour la fraction scann�e, pas rapport� au volume filtr� +% +% % spectres +% eval(['Yab_zoo_groups_',num2str(j),'(:,nbr)=nan(size(X,1),1);']); +% eval(['Ybv_zoo_groups_',num2str(j),'(:,nbr)=nan(size(X,1),1);']); +% +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Yab(:,j) = Yab_zoo_groups_',num2str(j),'(:,nbr);']); +% eval(['base_spectres(t).',char(fraction_names(nbr)),'.Ybv_',char(method_list(meth)),'(:,j) = Ybv_zoo_groups_',num2str(j),'(:,nbr);']); +% end +% end +% end +% end +% +% Ab1=nan_sum(Ab,1)'; +% Abtot1=nan_sum(Abtot,1)'; +% if meth == 3 +% Bv1=nan_sum(Bv,1)'; +% Bvtot1=nan_sum(Bvtot,1); +% end +% % ----------- On travaille maintenant a rassembler les fractions --------- +% for j=1:m +% +% eval(['Yab_zoo_groups_',num2str(j),'= nan_sum(Yab_zoo_groups_',num2str(j),',2);']) % sum of the several fractions spectra for a sample +% eval(['Yab_' ,char(method_list(meth)),'(:,j)=Yab_zoo_groups_',num2str(j),';']); +% eval(['Ybv_zoo_groups_',num2str(j),'= nan_sum(Ybv_zoo_groups_',num2str(j),',2);']) % sum of the several fractions spectra for a sample +% eval(['Ybv_' ,char(method_list(meth)),'(:,j)=Ybv_zoo_groups_',num2str(j),';']); +% end +% +% %clear id +% clear Ab Abtot Bv Bvtot +% end +% +% base_spectres(t).combined_frac.smin = smin; +% base_spectres(t).combined_frac.smax = smax; +% base_spectres(t).combined_frac.k = k; +% base_spectres(t).combined_frac.uu = uu; +% base_spectres(t).combined_frac.X = X; +% base_spectres(t).combined_frac.X1 = X1; +% base_spectres(t).combined_frac.Zoo_groups = zoo_groups; +% base_spectres(t).combined_frac.Ab = Ab1; % abundance of groups for a station, all fractions combined +% base_spectres(t).combined_frac.Abtot = Abtot1;% +% base_spectres(t).combined_frac.Bv = Bv1; % biovolume of groups for a station, all fractions combined +% base_spectres(t).combined_frac.Bvtot = Bvtot1;% +% eval(['base_spectres(t).combined_frac.Abundance_spectra=Yab_',char(method_list(meth)),';']);% +% for j=1:size(method_list,2) +% eval(['base_spectres(t).combined_frac.',char(method_list(j)),' = Ybv_',char(method_list(j)),';']); % Somme des distributions de taille +% end +% eval(['SStot(:,:,t)=base_spectres(t).combined_frac.',char(method_list(3)),';']); +% for i=1:size(method_list) +% a=method_list(i); +% eval(['clear Ybv_',cell2mat(a)]) +% end +% for i=1:m +% eval(['clear Ybv',zoo_groups{i,1}]) +% eval(['clear Yab',zoo_groups{i,1}]) +% end +% end +% +% SStot=permute(SStot,[1 3 2]); +% for i=1:size(SStot,3) +% Sz=SStot(:,:,i); +% S(i,1)={Sz}; +% end +% +% SStot=S; +% +% % -------- Fermeture ------------ +% close(h)