-
Notifications
You must be signed in to change notification settings - Fork 1
/
trajectories_AMSEAS_realtime.m
167 lines (115 loc) · 4.65 KB
/
trajectories_AMSEAS_realtime.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
%% Script to generate particle trajectories of Sargassum seaweed near Puerto Rico.
% Written by Joseph Anarumo on 3/19/2019
%% Clear workspace
close all
clear all
clc
compType=computer;
if ~isempty(strmatch('MACI64',compType))
root='/Volumes';
else
root='/home';
end
%% Add directories to MATLAB path for following functions.
% addpath([root '/jpa104/matlab/m_map'])
% addpath([root '/codaradm/HFR_Progs-2_1_3beta/matlab/general']);
% addpath([root '/codaradm/HFR_Progs-2_1_3beta/matlab/trajectories']);
% addpath([root '/codaradm/HFR_Progs-2_1_3beta/matlab/totals']);
%add_subdirectories_to_path([root '/codaradm/HFR_Progs-2_1_3beta/matlab/'],{'CVS','private','@'});
%% Load NOAA data
f = 'https://ecowatch.ncddc.noaa.gov/thredds/dodsC/ncom_amseas_agg/AmSeas_Apr_05_2013_to_Current_best.ncd';
%% Set date & time variables.
dnow= ((round(now*24))/24);
dtime = dnow-1:1/24:dnow;
%% Set Latitude & Longitude for figure window limits.
conf.HourPlot.axisLims=[-68 -64 16 20];
conf.HourPlot.DomainName='Puerto Rico';
conf.HourPlot.Print=false;
conf.HourPlot.grid=1;
%conf.Totals.DomainName
conf.Totals.grid_lims=[(conf.HourPlot.axisLims(1)+360) (conf.HourPlot.axisLims(2)+360) ...
conf.HourPlot.axisLims(3) conf.HourPlot.axisLims(4)];
[TUVcat] = convert_AmSeas_NC_to_TUVstruct(f,dtime,conf);
%% Grid the total data onto a rectangular grid
[TUVcat,dim]=gridTotals(TUVcat,0,0);
X=TUVcat.LonLat(:,1);
Y=TUVcat.LonLat(:,2);
U=TUVcat.U;
V=TUVcat.V;
tt=TUVcat.TimeStamp;
tspan=TUVcat.TimeStamp(1):1/24:TUVcat.TimeStamp(end);
wp1=[17+0/60+0/3600 -67-0/60-0/3600];
%wp1=[35.25 -75];
resolution=40;
range=450;
[wp]=release_point_generation_matrix(wp1,resolution,range);
drifter=[wp(:,2) wp(:,1)];
[X1,Y1]=meshgrid(unique(X),unique(Y));
[r,c]=size(X1);
U1=reshape(U,r,c,length(TUVcat.TimeStamp)-1);
V1=reshape(V,r,c,length(TUVcat.TimeStamp)-1);
%% generate the particle trajectories
[x,y,ts]=particle_track_ode_grid_LonLat(X1,Y1,U1,V1,tt,tspan,drifter);
[r1,c1]=size(x);
%% determine which position estimates are Nans to use in the coloring of the
%% particles
color_flag=~isnan(x);
%% When the drifter leaves the domain the position turns into nans
%% replace the nans with the last known position
xx=x;
for ii=1:c1
tf=find(isnan(x(:,ii)),1,'first');
x(tf:end,ii)=x(tf-1,ii);
y(tf:end,ii)=y(tf-1,ii);
end
%% plot the results
%WHERE THE PNG FILES ARE BEING SAVED TO
% conf.Plot.BaseDir='C:\Users\Joe Anarumo\Documents\Puerto_Rico\Sargassum\Test_trajectories\Realtime_AMSEAS\';
dir_sav=datestr(dnow,'yyyymmdd');
conf.Plot.BaseDir=['/Users/roarty/COOL/01_CODAR/02_Collaborations/Puerto_Rico/20190530_AMSEAS_Drifter_Plots/' dir_sav '/'];
f1=[root '/jpa104/caricoos/etopo1_Puerto_Rico.nc'];
[LON,LAT,Z] = read_in_etopo_bathy(f1);
% bathy=load ('/Users/roarty/Documents/GitHub/HJR_Scripts/data/bathymetry/puerto_rico/puerto_rico_6second_grid.mat');
% ind2= bathy.depthi==99999;
% bathy.depthi(ind2)=NaN;
bathylines=[ -50 -100 -500 -1000 -2000 -3000 -4000 -5000];
close all
for ii=1:r1
hold on
m_proj('albers equal-area','lat',conf.HourPlot.axisLims(3:4),'long',conf.HourPlot.axisLims(1:2),'rect','on');
m_gshhs_f('patch',[240,230,140]./255);
m_grid('box','fancy','tickdir','in','xaxisloc','bottom','yaxisloc','left');
%% plot bathymetry
[cs, h1] = m_contour(LON,LAT, Z,bathylines);
clabel(cs,h1,'fontsize',8,'Color',[0.8 0.8 0.8]);
set(h1,'LineColor',[0.8 0.8 0.8])
%% plot entire track in gray
if ii>=2
m_plot(x(1:ii,:),y(1:ii,:),'-','Color',[0.5 0.5 0.5]);
end
%% plot last 6 hours in black
if ii>6
m_plot(x(ii-6:ii,:),y(ii-6:ii,:),'-','Color','k','LineWidth',2);
elseif ii>1
m_plot(x(1:ii,:),y(1:ii,:),'-','Color','k','LineWidth',2);
end
%% plot last location of drifter in red
m_plot(x(ii,:),y(ii,:),'ro','MarkerFaceColor','r');
if ~isempty(find(isnan(xx(ii,:)), 1))
m_plot(x(ii,find(isnan(xx(ii,:)))),y(ii,find(isnan(xx(ii,:)))),'bo','MarkerFaceColor','b');
end
%% add zeros before the number string
N=append_zero(ii);
%%-------------------------------------------------
%% Add title string
conf.HourPlot.TitleString = [' Particle Trajectories: ', ...
datestr(tspan(ii),'mm/dd/yyyy HH:MM'),' ',TUVcat.TimeZone(1:3)];
hdls.title = title( conf.HourPlot.TitleString, 'fontsize', 12,'color',[0 0 0] );
timestamp(1,'trajectories_AMSEAS.m')
if ~exist(conf.Plot.BaseDir, 'dir')
mkdir(conf.Plot.BaseDir)
end
print(1,'-dpng','-r100',[ conf.Plot.BaseDir conf.HourPlot.DomainName '_' datestr(tspan(ii),'yyyy_mm_dd_HHMM') '.png'])
close all
clear conf.HourPlot.TitleString
end