-
Notifications
You must be signed in to change notification settings - Fork 2
/
plot_energy_map.m
326 lines (323 loc) · 9.89 KB
/
plot_energy_map.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
%% PLOT_ENERGY_MAP
% function used to plot map of energy dissipatoion
%% INPUT
%Energy_Spectra:
%Energy_Spectra.n: degrees with non-zero energy
%Energy_Spectra.m: orders with non-zero energy
%Energy_Spectra.n_v: degrees from 0 to Numerics.Nenergy
%Energy_Spectra.n_v: orders from 0 to Numerics.Nenergy
%Energy_Spectra.energy(radial_point,mode): radial profile of energy spectra
%Energy_Spectra.energy_integral(mode): radially integrated energy for all non-zero degrees an orders (n,m)
%Energy_Spectra.energy_integral_v(mode): radially integrated energy for all degrees an orders (n_v,m_v)
% optional variables
% 'type': 'total' or 'difference'
% 'save_plot': name of the file where plot is saved
% 'limits': specify the limits of the colorscale
% 'label': label of the colorbar
% 'projection': type of projection used for the plot, 'mollweide' is the default and accepts
% mollweide,
% flat
% cut: flat plus includes integral along longitude and latitude
%% OUTPUT
%%
function [varargout] = plot_energy_map(Energy_Spectra,varargin)
%% TOTAL TIDAL DISSIPATION
n_v=Energy_Spectra.n_v;
m_v=Energy_Spectra.m_v;
energy_s=Energy_Spectra.energy_integral_v;
limits=[];
cut=0;
projection='mollweide';
label_z=[];
no_colorbar=0;
no_grid=0;
type='total';
title_plot='';
save_plot=0;
for k = 1:length(varargin)
if strcmpi(varargin{k},'limits')
limits=varargin{k+1};
varargin{k+1}=[];
varargin{k}=[];
end
if strcmpi(varargin{k},'save_plot')
save_plot = 1;
save_name=varargin{k+1};
varargin{k}=[];
end
if strcmpi(varargin{k},'label')
label_z=varargin{k+1};
varargin{k+1}=[];
varargin{k}=[];
end
if strcmpi(varargin{k},'type')
type=varargin{k+1};
varargin{k+1}=[];
varargin{k}=[];
end
if strcmpi(varargin{k},'no_colorbar')
no_colorbar=1;
varargin{k}=[];
end
if strcmpi(varargin{k},'no_grid')
no_grid=1;
varargin{k}=[];
end
if strcmpi(varargin{k},'title')
title_plot=varargin{k+1};
varargin{k+1}=[];
varargin{k}=[];
end
if strcmpi(varargin{k},'projection')
projection=varargin{k+1};
varargin{k+1}=[];
varargin{k}=[];
end
end
%% Get Map
th = linspace(0,pi,500); % inclination
phi = linspace(-pi,pi,500); % azimuth
[th,phi] = meshgrid(th,phi);
EnergyV=zeros(size(th));
for i=1:length(n_v)
if abs(energy_s(i))>0
EnergyV=EnergyV+energy_s(i)*harmonicY(n_v(i),m_v(i),th,phi);
end
end
aux2=real(EnergyV);
% get colobar limits
if strcmpi(type,'total')
max_E=max(aux2(:));
min_E=min(aux2(:));
else
max_E=max(aux2(:));
min_E=min(aux2(:));
max_E2=max([abs(max_E), abs(min_E)]);
end
%% Integrate energy along longitude and latitude
th_cut=th(1,:);
phi_cut=phi(:,1);
Delta_th=th_cut(2)-th_cut(1);
Delta_phi=phi_cut(2)-phi_cut(1);
Energy_Lat=zeros(1,length(th_cut));
Energy_Lon=zeros(1,length(th_cut));
for i=1:length(th_cut)
% keep latitude constant, integrate longitude
Energy_Lat(i)=sum(real(EnergyV(:,i))*Delta_phi);
% keep longitude constant, integrate latitude
Energy_Lon(i)=sum(real(EnergyV(i,:)).*sin(th_cut)*Delta_th);
end
varargout{1}=Energy_Lat;
varargout{2}=Energy_Lon;
sum(Energy_Lat.*sin(th_cut)*Delta_th)/(4*pi);
sum(Energy_Lon*Delta_phi)/(4*pi);
%% Make plot
if strcmpi(projection,'mollweide')
fig=figure;
set(fig, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 0.6, 0.95]);
m_proj('mollweide','clongitude',0);
set(0,'defaulttextInterpreter','none')
obj=m_pcolor(phi*180/pi,90-th*180/pi,real(EnergyV));
set(0,'defaulttextInterpreter','latex')
shading interp;
if strcmpi(type,'total')
colormap(cmocean('solar',100))
else
colormap(cmocean('balance',100))
end
set(0,'defaulttextInterpreter','none')
if no_grid==0
m_grid('xaxislocation','middle','xtick',[-90:90:180],'ytick',[-90:90:90],'fontsize',20,'gridcolor',[0.8 0.8 0.8],'linewidth',3,'linestyle','--','gridcolor','k');
else
m_grid('xaxislocation','middle','xtick',[-90:90:180],'ytick',[-90:90:90],'gridcolor',[0.8 0.8 0.8],'linewidth',3,'linestyle','--','gridcolor','k','fontsize',1);
end
if no_colorbar==0
cb=colorbar('southoutside');
set(0,'defaulttextInterpreter','latex')
cb.Label.Interpreter = 'latex';
if isempty(label_z)==1
if strcmpi(type,'total')
cb.Label.String='$\dot{e}$ [-]';
else
cb.Label.String='$\Delta\dot{e}$ [-]';
end
else
cb.Label.String=label_z;
cb.FontSize=50;
end
cb.FontName = 'CMU Serif';
end
set(gca,'fontsize', 50);
set(gcf,'color','w');
if isempty(limits)==0
caxis([limits(1) limits(2)])
else
if strcmpi(type,'total')
caxis([0 max_E])
else
caxis([-max_E2 max_E2])
end
end
if isempty(title_plot)==0
title(title_plot,'interpreter','latex')
end
elseif strcmpi(projection,'flat')
fig=figure;
set(fig, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 0.6, 0.95]);
pcolor(phi*180/pi,90-th*180/pi,real(EnergyV));
shading interp;
set(0,'defaulttextInterpreter','latex')
shading interp;
if strcmpi(type,'total')
colormap(cmocean('solar',100))
else
colormap(cmocean('balance',100))
end
set(0,'defaulttextInterpreter','none')
if no_grid==0
m_grid('xaxislocation','middle','xtick',[-90:90:180],'ytick',[-90:90:90],'fontsize',20,'gridcolor',[0.8 0.8 0.8],'linewidth',3,'linestyle','--','gridcolor','k');
else
m_grid('xaxislocation','middle','xtick',[-90:90:180],'ytick',[-90:90:90],'gridcolor',[0.8 0.8 0.8],'linewidth',3,'linestyle','--','gridcolor','k','fontsize',1);
end
if no_colorbar==0
cb=colorbar('southoutside');
set(0,'defaulttextInterpreter','latex')
cb.Label.Interpreter = 'latex';
if isempty(label_z)==1
if strcmpi(type,'total')
cb.Label.String='$\dot{e}$ [-]';
else
cb.Label.String='$\Delta\dot{e}$ [-]';
end
else
cb.Label.String=label_z;
cb.FontSize=50;
end
cb.FontName = 'CMU Serif';
end
set(gca,'fontsize', 50);
set(gcf,'color','w');
if isempty(limits)==0
caxis([limits(1) limits(2)])
else
if strcmpi(type,'total')
caxis([0 max_E])
else
caxis([-max_E2 max_E2])
end
end
if isempty(title_plot)==0
title(title_plot,'interpreter','latex')
end
elseif strcmpi(projection,'cut')
fig=figure;
if strcmpi(type,'units')
set(fig, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 1]);
else
set(fig, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 0.75, 1]);
end
% MAP
if no_colorbar==1
pos1 = [0.1 0.15 0.7 0.53];
else
if strcmpi(type,'units')
pos1 = [0.1 0.13 0.8 0.85];
else
pos1 = [0.1 0.08 0.7 0.6];
end
end
pos2 = [0.8 0.15 0.15 0.53];
pos3=[0.1 0.68 0.7 0.2];
subplot('Position',pos1)
set(gca,'fontsize', 20);
pcolor(phi*180/pi,90-th*180/pi,real(EnergyV));
shading interp;
if strcmpi(type,'total')
colormap(cmocean('solar',100))
elseif strcmpi(type,'units')
colormap(cmocean('thermal',50))
else
colormap(cmocean('balance',100))
end
set(0,'defaulttextInterpreter','none')
if no_colorbar==0
cb=colorbar('southoutside');
set(0,'defaulttextInterpreter','latex')
if isempty(label_z)==1
cb.Label.String='$\Delta\dot{e}$' ;
else
cb.Label.String=label_z;
cb.FontSize=30;
end
cb.Label.Interpreter = 'latex';
cb.FontName = 'CMU Serif';
end
set(gcf,'color','w');
if isempty(limits)==0
caxis([limits(1) limits(2)])
else
if strcmpi(type,'total')
caxis([0 max_E])
else
caxis([-max_E2 max_E2])
end
end
xticks(-180:45:180)
xlim([-180 180])
yticks(-90:45:89)
ylim([-90 90])
if ~strcmpi(type,'units')
xticklabels('')
end
set(gca,'fontsize', 30);
set(gca,'TickLabelInterpreter','latex')
ylabel('Latitude [deg]','interpreter','latex' )
grid minor
set(gca, 'layer', 'top');
text(20,-75,title_plot,'Interpreter','latex','FontSize',40,'color',[0.5 0.5 0.5])
if ~strcmpi(type,'units')
% Latitude averaged
subplot('Position',pos2)
box on
plot(Energy_Lat/(2*pi),90-th_cut*180/pi,'LineWidth',3,'color','k');
set(gca,'TickLabelInterpreter','latex')
yticks(-90:45:90)
ylim([-90 90])
ax = gca;
ax.YAxis.FontSize =30;
ax.XAxis.FontSize =30;
xlabel('$\frac{1}{2\pi\dot{e}_0^u}\int\Delta\dot{e}d\phi$','interpreter','latex','FontSize',25)
yticklabels('')
grid minor
%Longitude averaged
subplot('Position',pos3)
box on
plot(phi_cut*180/pi,Energy_Lon/2,'LineWidth',3,'color','k');
xticks(-180:45:180)
xlim([-180 180])
ax = gca;
ax.YAxis.FontSize =30;
ax.XAxis.FontSize =30;
set(gca, 'XAxisLocation', 'top')
xlabel('Longitude [deg]','interpreter','latex','FontSize',30)
yyaxis right
ylabel('$\frac{1}{2\dot{e}_0^u}\int\Delta\dot{e}\sin\theta d\theta$','color','k','interpreter','latex','FontSize',25)
set(gca,'YTick',[])
set(gca,'ycolor','k')
grid minor
set(gca,'TickLabelInterpreter','latex')
set(gcf,'color','w');
else
xticks(-180:45:180)
xlabel('Longitude [deg]','interpreter','latex','FontSize',30)
end
else
error('Incorrect entry for projection')
end
set(gcf,'color','w');
%% Save Plot
if (save_plot)==1
%export_fig(fig,save_name,'-pdf','-opengl')
saveas(fig,save_name)%,'-png','-opengl','-r400')
end
end