-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tag.m
183 lines (153 loc) · 7.5 KB
/
run_tag.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
%clear all;
%close all;
addpath(genpath('../'));
%addpath(genpath('../../preprocess/'));
%addpath('/opt/matlab/googleearth');
global fvcom_tidaldb % path to fvcom tidal database
fvcom_tidaldb = '../../preprocess/gen_tidal_db/fvcomdb_gom3_v2.mat';
global bottom_temperature % path to fvcom bottom temperature
bottom_temperature = '../../bottom_temperature/gom3_btemp_davged_2003_2013.nc';
ptags = [12,22,24,55,56];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% tag-specific paremeters %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global std_temp_offset tag_depth_range tag_depth_accu tag_temp_accu
std_temp_offset=2.0; %higher value is more inclusive
tag_depth_range = 250; % in meters
tag_depth_accu = 0.008; % fraction of depth renge
tag_temp_accu = 0.1; % in degree C
%ptags = [12,22,24,55,56];
ptags = 11;
tag_num_range = ptags;
global tideLV
% tideLV = [RMSE upper bound, R^2 lower bound, AMPLITUDE lower, AMPLITUDE upper]
tideLV = [0.42 0.85 0.2 2.0];
% main loop over tags
for tag_num=tag_num_range
clear tag;
clear mpt;
recap = 'yes'; %yes/no, use/do not use the recapture info
%if the uncertainty < 0 , this will automatically be disabled
z_off_bottom = 20.0; %max off-bottom extent in meters
%set to -99.0 to use original Petersen likelihood estimator
%do_parts = 6;
do_parts(1) = 1; %1 generate a new tidaldb, =0 use tidaldb.mat
do_parts(2) = 1; %2 strip
do_parts(3) = 1; %3 behavior
do_parts(4) = 1; %4 likelihood
do_parts(5) = 1; %5 cliu likelihood & tidal constraint
do_parts(6) = 1; %6 geolocate
do_parts(7) = 1; %7 most probable track
do_parts(8) = 0; %8 make a movie
fast_likelihood = 1; %=1 use fast scheme, =0 use more accurate scheme
tagname = [num2str(tag_num) '_raw'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% generate the tidal database %%%
%%% only run the command if the raw tidal database (harmonics) %%%
%%% have been changed or you wish to change the lon/lat bounds %%%
%%% or resolution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(do_parts(1)==1);
% gen_tidaldb(-71,-70,42,43,.02,{'M2','S2','N2','K1','O1'}); %for fixed tags
%gen_tidaldb(-71,-66,40,45,.015,{'M2','N2','S2','O1','K1','K2','P1','Q1'}); %all GOM
%gen_tidaldb(-71,-66,40,45,.05,{'M2','N2','S2','O1','K1','K2','P1','Q1'}); %all GOM
%readdb
%finddbvars
gen_tidaldb_draft(-71,-66,40,45,.01);
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Read in the raw data file from an SMAST-format tag %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
path_to_tags = '~/Dropbox/Geolocation/projects/cod_zemeckis/tag_data/' ;
fprintf('loading %s\n',[path_to_tags tagname]);
if(exist([path_to_tags tagname '.mat']))
load([path_to_tags tagname]);
tagid = [num2str(tag_num) '_' tag.tag_id];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Subsample the tag data and shift to hmm time %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(do_parts(2)==1)
smast_datastrip(tag)
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Extract tidal and behaviour information from rawXXXX.mat %%%
%%% tagdataxxxx.mat is created %%%
% tidebehavextr(tagno,tideFL,tideLV,behavFL,behavLV,DBname)
%
% inputs:
% tidFL is the length of the fitting interval in hours (def=10)
% tideLV - goodness of fit thresholds for detecting tide
% [RMSE, R^2, AMPLITUDE]: def = [0.42 0.85 0.6]
% fit is found if criteria are met:
% rmse_computed < RMSE
% r^2_computed > R^2
% amp_computed > AMPLITUDE
% behavFL lenght of fitting interval for behaviour - 16
% behavLV - goodness of fit thresholds for detecting behavior
% [RMSE, R^2, AMPLITUDE]: def = [0.42 0.85 0.6]
% dbname - alternate tidal base: def = tidaldb.mat
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(do_parts(3)==1)
tidebehavextr(tagid,10,tideLV,16,tideLV); %default
end;
%tidebehavextr(tagid);
% make strict criteria so no tide is found
%tidebehavextr(tagid,10,[0.1 0.99 0.2],16,[0.1 0.99 0.2]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Calculate the datalikelihood using the tidal database %%%
%%% datalikelihoodxxxx.mat is created %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(do_parts(4)==1)
% manually override a recap='on' if there is no recap [lon/lat]
if (tag.recap_uncertainty_km<0)
recap='no';
fprintf('============setting recap to NO\n');
end;
if(fast_likelihood)
datalikelihood(tagid,'fast', 'on',recap,z_off_bottom);
else
datalikelihood(tagid,'full', 'on',recap,z_off_bottom);
end;
end;
if(do_parts(5)==1)
likelihood_cliu(tag_num,path_to_tags,tagname)
tidal_rmse_cliu(tag_num,path_to_tags,tagname)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Geolocate the tag %%%
%%% resultxxxx.mat is created %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(do_parts(6)==1)
%hmmgeolocate(tagid,2,'on',[],true)
%hmmgeolocate(tagid,2,'on',[10. 100.]);
hmmgeolocate(tagid,2,'on',[1.,10.]);
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Find the most probable track of the fish %%%
%%% mptxxxx.mat is created %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(do_parts(7)==1)
mpt=mptrack(tagid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Plot the most probable track %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all
plottrack(mpt);
%write_ge_track(mpt);
write_ge_track_UD(tagid)
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Create an avi file that shows how the probability distribution %%%
%%% evolves in time %%%
%%% geolocationxxxx.avi is created %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(do_parts(8)==1)
%write_ge_track_UD(tagid)
pause on;close all;
avimaker(tagid)
end
else
error('tag file does not exist, stopping...');
end;
end;
%return