-
Notifications
You must be signed in to change notification settings - Fork 0
/
Creategif.m
90 lines (82 loc) · 2.9 KB
/
Creategif.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
% Clear workspace and command window
clear all;clc;close all;
% Load data
load('USALQ19smallrange_withCH4.mat')
load('USALQ2020_smallrange_withCH4.mat')
%% ALQ 2019
Table = USALQ19smallrange_withCH4;
for i= 2:width(Table)
Table.(i)(Table.(i)==-9999) = NaN;
end
Table2 = USALQ2020_smallrange_withCH4;
for i= 3:width(Table2)
Table2.(i)(Table2.(i)==-9999) = NaN;
end
%% Make the Scatter Wind Roses for LOST CREEK
% Eliminate unrealistic data
WS = [Table.WS;Table2.WS];
WD = [Table.WD;Table2.WD];
WS(WS<0) = NaN;
WD(WD<0) = NaN;
timestamp = [Table.TIMESTAMP_END;Table2.TIMESTAMP_END];
CH4 = [Table.FCH4_RF_filled;Table2.FCH4_RF_filled];
%% Set limits and variable names
limU = [min(WS),max(WS)];
name_U = 'U (m/s)'; % #4 name of variable U
name_IU = 'CH4 (nmol/m2/s)'; % #4 name of variable IU
%% Plot
starting = 0;
% Plot the first frame:
ScatterWindRose(WD((1+(starting*144)):(144*(1+starting))),WS((1+(starting*144)):(144*(1+starting))),'Ylim',limU,'labelY',name_U,'labelZ',name_IU,'Z',CH4((1+(starting*144)):(144*(1+starting))));
title([datestr(timestamp(starting+1),'mmm dd yyyy')])
%% Split up data into even numbers of 3-day sets
remainder = mod(size(WS,1),144);
ending = size(WS,1)-remainder;
repetitions = ending/144;
%% Plot all figures
for starting = 1:(repetitions-1)
newCH4 = CH4((1+(starting*144)):(144*(1+starting)));
newWD = WD((1+(starting*144)):(144*(1+starting)));
newWS = WS((1+(starting*144)):(144*(1+starting)));
if (sum(isnan(newWD))>130)||(sum(isnan(newWS))>130)
continue
end
fig = figure;
ScatterWindRose(newWD,newWS,'Ylim',limU,'labelY',name_U,'labelZ',name_IU,'Z',newCH4);
title([datestr(timestamp(starting*144+1),'mmm dd yyyy')])
drawnow
frame = getframe(fig);
im{starting} = frame2im(frame);
end
close;
%%
filename = 'testAnimated.gif'; % Specify the output file name
% for starting = 1:(repetitions-1)
% newCH4 = CH4((1+(starting*144)):(144*(1+starting)));
% newWD = WD((1+(starting*144)):(144*(1+starting)));
% newWS = WS((1+(starting*144)):(144*(1+starting)));
% if (sum(isnan(newWD))>130)||(sum(isnan(newWS))>130)
% continue
% end
% [A,map] = rgb2ind(im{starting},256);
% if starting == 1
% if (sum(isnan(newWD))>130)||(sum(isnan(newWS))>130)
% continue
% end
% imwrite(A,map,filename,'gif','LoopCount',Inf,'DelayTime',0.2);
% else
% if (sum(isnan(newWD))>130)||(sum(isnan(newWS))>130)
% continue
% end
% imwrite(A,map,filename,'gif','WriteMode','append','DelayTime',0.2);
% end
% end
series = find(~cellfun(@isempty,im));
for i = series
[A,map] = rgb2ind(im{i},256);
if i == series(1)
imwrite(A,map,filename,'gif','LoopCount',Inf,'DelayTime',0.2);
else
imwrite(A,map,filename,'gif','WriteMode','append','DelayTime',0.2);
end
end