-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHycomTracker.m
119 lines (106 loc) · 3.96 KB
/
HycomTracker.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
function R=HycomTracker(V,G,IC,varargin)
% Demonstration MATLAB code for particle tracking with HYCOM model output
% posted to THREDDS Data Servers (TDS). The default url is:
% http://tds.hycom.org/thredds/dodsC/GLBa0.08/expt_91.1/2015.
%
% This code uses nctoolbox to access and extract variables from urls.
% You can get nctoolbox from https://github.com/nctoolbox/nctoolbox.
% Either download as a zip file or clone in Desktop. Then, add the path
% to MATLAB and run the setup code, something like:
% addpath('<path_to_nctoolbox>/nctoolbox')
% setup_nctoolbox;
%
% There are 3 main codes:
% + HycomTrackerPrep - Builds velocity arrays and fake HYCOM grid.
% Default subregion is Caribbean and Gulf of Mexico, surface velocities.
% The default HYCOM URL is http://tds.hycom.org/thredds/dodsC/GLBa0.08/expt_91.1/2015
% + HycomTrackerIC - Generates initial particle locations.
% Default is a square patch off the TX/MEX border. User can edit/enhance as needed.
% + HycomTracker - This converts lon/lat coords to cartesian, calls drog2ddt,
% and inverts the projected particle locations back to lon/lat.
%
% There are other supporting codes that handle grid structures and coordinate projections.
%
% Run in MATLAB.
% First step: generate the velocity arrays from HYCOM and fake HYCOM/finite element grid.
% [V,G]=HycomTrackerPrep;
% Then, build initial condition/locations:
% IC=HycomTrackerIC;
% Then, pass to drog2ddt, through HycomTracker handler:
% R=HycomTracker(V,G,IC);
%
% options
drawp=true;
verbose=true;
lag=1;
integrator='rk2';
dt=(V(2).time-V(1).time)*24; % use nc units attribute!!!
level=1;
stride=1;
tstart=V(1).time;
tend=V(end).time;
% Strip off propertyname/value pairs in varargin not related to
% "line" object properties.
k=1;
while k<length(varargin)
switch lower(varargin{k})
case 'drawp'
drawp=varargin{k+1};
varargin([k k+1])=[];
case 'level'
level=varargin{k+1};
varargin([k k+1])=[];
case 'verbose'
verbose=varargin{k+1};
varargin([k k+1])=[];
case 'stride'
stride=varargin{k+1};
varargin([k k+1])=[];
case 'tstart'
tstart=varargin{k+1};
varargin([k k+1])=[];
case 'tend'
tend=varargin{k+1};
varargin([k k+1])=[];
case 'dt'
dt=varargin{k+1};
varargin([k k+1])=[];
otherwise
k=k+2;
end
end
% project lon/lat to xy since u,v are in m/s
[IC.x,IC.y]=convll2m(IC.lon,IC.lat,G.lo0,G.la0);
figure
%line(IC.x-360,IC.y,'Marker','.','Color','k','LineStyle','none')
line(IC.x,IC.y,'Marker','.','Color','k','LineStyle','none')
axis([min(G.x) max(G.x) min(G.y) max(G.y)])
options.draw=drawp;
[R.xx,R.yy,R.tt,R.uu,R.vv]=drog2ddt(G,tstart,tend,dt,stride,IC.x,IC.y,V,options);
line(R.xx',R.yy')
% invert the forward projection for drogue locations
[R.lon,R.lat]=convm2ll(R.xx,R.yy,G.lo0,G.la0);
%%% Then, make plots of R.lon and R.lat, etc...
figure
% plot the trajectories
% Subtract 360 from longitude to get it in the range -180->180; note the transpose.
%plot(R.lon'-360,R.lat')
plot(R.lon',R.lat')
axis('equal')
% plot the initial positions
%line(R.lon(:,1)-360,R.lat(:,1),'Marker','.','Color','k','LineStyle','none')
%line(R.lon(:,end)-360,R.lat(:,end),'Marker','.','Color','r','LineStyle','none','MarkerSize',14)
line(R.lon(:,1),R.lat(:,1),'Marker','.','Color','k','LineStyle','none')
line(R.lon(:,end),R.lat(:,end),'Marker','.','Color','r','LineStyle','none','MarkerSize',14)
% plot some coastline data, if you have it. If you have the mapping toolbox, then:
if exist('coast.mat','file')
c=load('coast');
% note that this data is already in the range -180->180
line(c.long,c.lat,'Color','k')
end
%axis([min(G.lon)-360 max(G.lon)-360 min(G.lat) max(G.lat)])
axis([min(G.lon) max(G.lon) min(G.lat) max(G.lat)])
title({'Trajectories in HYCOM Surface Velocity',...
V(1).url,...
[datestr(V(1).time,2) ' thru ' datestr(V(end).time,2) ]},...
'Interpreter','none')