-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpscr_processdidsondata.m
executable file
·115 lines (97 loc) · 4.21 KB
/
cpscr_processdidsondata.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
% Example script for the CollPen PIV analysis toolbox
%
% (c) Lars Helge Stien/Nils Olav Handegard
%% Create raw PIV
%d=dir('/Volumes/Datos/collpen/predator/test/*.avi');
d=dir('\\callisto\collpen\AustevollExp\data\didson_stationary\data\*.avi');
for i=1:length(d)
par(i).showmsg = 20;
% This defines the snrs weights. w =.5*(1+erf(snrs-msnrs)/sqrt(2*snrss^2)
par(i).msnrs = 1.3;
par(i).ssnrs = .2;
filedir{i} = '\\callisto\collpen\AustevollExp\data\didson_stationary\data';
file{i} = d(i).name;
end
%%
for i=1:length(d)
disp([datestr(now),' Running on file: ' num2str(i) ', ' file{i} '.']);
parstrpiv64 = struct('showmsg',1,'winsize',16,'olap',0.5,'write',1,'useold',0);
% Establish background image
parstrbgimage = struct('showmsg',1,'Nframes',500,'perc',30,'write',1,'useold',1);
[bgimage, filepathbg] = PIV_createBGImage(filedir{i}, file{i}, parstrbgimage); % alternativ par(i) hvor vi angir spesifikt for hver fil
disp([datestr(now),' BGImage saved as: ' filepathbg]);
tic
% Estimate flow fields
% [datapath rawpivel] = PIV_getRawPIVvectors(filedir{i}, file{i}, parstrpiv64);
toc
end
%% Filter, weigh and calculate metrics
clear
d=dir('\\callisto\collpen\AustevollExp\data\didson_stationary\data\*.avi');
for i=1:length(d)
filedir{i} = '\\callisto\collpen\AustevollExp\data\didson_stationary\data';
file{i} = d(i).name;
par(i).templag = 20;
par(i).x0= [186 330];% The centre of the school for the rotational order parameter
par(i).w = struct('msnrs',1.3,'ssnrs',0.5,'mthr',10,'sthr',7);
end
for i=1:length(d)
tic
disp(['File ',num2str(i),' of ',num2str(length(d))])
% Load rawpivel data
datafile = fullfile(filedir{i},'PIVdata',[file{i}(1:end-4),'_PIV.mat']);
bgimage = fullfile(filedir{i},'PIVdata',[file{i}(1:end-4),'_BG.bmp']);
load(datafile)
rawpivel = pivdatas.rawpivel;
% Parse file string
datapoint_1 = regexp(file{i}(1:end-4),'_','split');
datapoint_1{4}=sscanf(datapoint_1{4},'block%d');
datapoint_1{5}=sscanf(datapoint_1{5},'sub%d');
if datapoint_1{4}>36
datapoint_1{6}='NA';
else
datapoint_1{6}=sscanf(datapoint_1{6},'treat%d');
end
% Filter flow field
parstrfilt = struct('showmsg',1,'global',4,'timeaverage',5,'localmedian',[3 3],'backgroundimage',bgimage);
[xs ys us vs snrs pkhs is] = PIV_filterPIVvectors(rawpivel.xs, rawpivel.ys, rawpivel.us, rawpivel.vs, rawpivel.snrs, rawpivel.pkhs, rawpivel.is, parstrfilt);
% Weigths
w=PIV_weights(snrs,pkhs,is,par(i).w);
% Calculate school metrics
[speed,dalpha,dcav,cav,RotOrd]=PIV_schoolstructure(xs,ys,us,vs,w,par(i));
% The primary sampling unit
PSU = [datapoint_1 {speed,cav,RotOrd}];
% Data point from this video for analysis (NEED TO PARSE THE FILENAMES)
%{speed,cav}
% Store the filtered school data, weoghts and metrics to file
save(fullfile(filedir{i},[file{i}(1:end-4),'_school.mat']),'PSU','speed','dalpha','dcav','cav','RotOrd','xs','ys','us','vs','snrs','pkhs','is','w','par')
toc
end
%% Create AVI
clear
d=dir('\\callisto\collpen\AustevollExp\data\didson_stationary\data\*.avi');
for i=1:length(d)
filedir{i} = '/Volumes/Datos/collpen/predator/';
file{i} = d(i).name;
end
for i=1:length(d)
tic
load(fullfile(filedir{i},[file{i}(1:end-4),'_school.mat']))
% Create AVIs
dparstravi = struct('showmsg',1,'id','');
avipath = PIV_createAVIfigure(filedir{i}, file{i}, xs, ys, us, vs, w, pkhs, is, dparstravi);
disp(['Avi showing results stored in: ' avipath]);
toc
end
%% Compile data set for analysis in R
clear
d=dir('\\callisto\collpen\AustevollExp\data\didson_stationary\data\*_school.mat');
PSUcombined = {'Type','NT','dummy','Block','Subblock','Treatment','Speed','CAV','RotOrd'};
for i=1:length(d)
filedir{i} = '\\callisto\collpen\AustevollExp\data\didson_stationary\data';
file{i} = d(i).name;
load(fullfile(filedir{i},file{i}))
PSUcombined = [PSUcombined ;PSU];
end
% Link with par variable...
xlswrite('\\callisto\collpen\AustevollExp\data\didson_stationary\didson_stationary.xls',PSUcombined)