-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_paper_fig_8.py
164 lines (128 loc) · 6.16 KB
/
plot_paper_fig_8.py
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
"""
A first attempt at quickly plotting fields for the SWIFT paper, test 1
"""
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from netCDF4 import Dataset
import numpy as np
from tomplot import (set_tomplot_style, tomplot_contours, tomplot_cmap,
plot_contoured_field, add_colorbar_fig,
tomplot_field_title, extract_lfric_coords,
extract_lfric_field, plot_field_quivers,
regrid_horizontal_slice, extract_lfric_vertical_slice)
# ---------------------------------------------------------------------------- #
# Things that can be altered and parameters for the test case
# ---------------------------------------------------------------------------- #
# Directories for results and to plot to
branch = 'swift_revision'
results_dirname = f'/data/users/tbendall/results/{branch}'
plotdir = f'/data/users/tbendall/results/swift_revision'
mesh_dt = '64_2p5' # dt is 0p5, 1p25 or 2p5
# To alter test-by-test
fig_idx = 8
plot_stem = 'three_dimensional'
title = r'Three-dimensional Test, $c_{max}=4.8$'
# Options relating to the different fields to be plotted
field_names = ['rho', 'tracer_con', 'tracer_adv']
cbar_labels = [r"$\rho$ (kg m$^{-3}$)",
r"$m$ (kg kg$^{-1}$)",
r"$m^L$ (kg kg$^{-1}$)"]
colour_schemes = ['YlGn', 'BuPu', 'BuPu']
remove_contours = [None, 0.0, 0.0]
# Options for different configurations
test_configs = ['cosmic', 'swift']
config_titles = ['COSMIC', 'SWIFT']
slice_along = 'y'
slice_at = 0.00078125 # Nearest value to the center
# Options shared for all plots and subplots
time_factor = 25.0 # For some reason LFRic outputs the wrong time
xlabel = r'$x \ /$ km'
ylabel = r'$z \ /$ km'
contour_method = 'contour'
time_idxs = [1]
level = 0
xlims = [-0.5, 0.5]
ylims = [0, 1]
contour_dict = {'rho': np.linspace(0.5, 1.0, 11),
'tracer_adv': np.linspace(-0.2, 1.2, 15),
'tracer_con': np.linspace(-0.2, 1.2, 15)}
# This is declared BEFORE figure and ax are initialised
set_tomplot_style(16)
# ---------------------------------------------------------------------------- #
# Loop through the different time-points
# ---------------------------------------------------------------------------- #
for time_idx in time_idxs:
# Make figure
fig, axarray = plt.subplots(len(config_titles), len(field_names),
figsize=(12, 8), sharex='col', sharey='row')
all_cf = []
for i, (field_name, colour_scheme, remove_contour) in \
enumerate(zip(field_names, colour_schemes, remove_contours)):
# -------------------------------------------------------------------- #
# Loop through subplots
# -------------------------------------------------------------------- #
for j, (results_opt, config_title) in \
enumerate(zip(test_configs, config_titles)):
ax = axarray.flatten()[j*len(field_names)+i]
main_filename = f'{results_dirname}/{results_opt}_skam3d_{mesh_dt}_diag.nc'
data_file = Dataset(main_filename, 'r')
full_field_data = extract_lfric_field(data_file, field_name, time_idx)
# Extract coords
time = time_factor*data_file['time_instant'][time_idx]
field_data, coords_X, coords_Y, coords_Z = \
extract_lfric_vertical_slice(data_file, field_name, time_idx,
slice_along=slice_along, slice_at=slice_at)
# Scale coordinates
coords_X *= 10.
coords_Z *= 1./64.
# ---------------------------------------------------------------- #
# Plot data
# ---------------------------------------------------------------- #
# Contours based on data for whole row
contours = contour_dict[field_name]
cmap, lines = tomplot_cmap(contours, colour_scheme,
remove_contour=remove_contour,
cmap_rescale_type='top', cmap_rescaling=0.7)
cf, _ = plot_contoured_field(ax, coords_X, coords_Z, field_data,
contour_method, contours, line_contours=lines,
cmap=cmap, plot_contour_lines=True)
# Save cf for later
all_cf.append(cf)
data_file.close()
# ---------------------------------------------------------------- #
# Add labels
# ---------------------------------------------------------------- #
if i == 0:
ax.set_ylabel(ylabel, labelpad=-10)
ax.set_yticks(ylims)
ax.set_yticklabels(ylims)
ax.set_ylim(ylims)
if j == len(config_titles) - 1:
ax.set_xlabel(xlabel, labelpad=-12)
ax.set_xticks(xlims)
ax.set_xticklabels(xlims)
ax.set_xlim(xlims)
tomplot_field_title(ax, None, minmax=True, field_data=full_field_data,
minmax_format='.4f')
if i == len(field_names)-1:
ax2 = ax.twinx()
ax2.set_yticks([])
text = f'{config_title}, '+r'$t=$'+f' {time:0.0f} s'
ax2.set_ylabel(text, labelpad=10)
# -------------------------------------------------------------------- #
# Add colorbars and adjust figures
# -------------------------------------------------------------------- #
for i, cbar_label in enumerate(cbar_labels):
ij = (len(config_titles)-1)*len(field_names) + i
add_colorbar_fig(fig, all_cf[i*len(config_titles)+j], cbar_label,
ax_idxs=[ij], cbar_labelpad=-10,
location='bottom', cbar_thickness=0.025)
fig.subplots_adjust(hspace=0.2)
# -------------------------------------------------------------------- #
# Save figure
# -------------------------------------------------------------------- #
plt.suptitle(f'{title}')
plotname = f'{plotdir}/fig_{fig_idx}_{plot_stem}.jpg'
print(f'Saving figure to {plotname}')
fig.savefig(plotname, bbox_inches='tight', dpi=300)
plt.close()