-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanels_variables.py
More file actions
170 lines (154 loc) · 6.61 KB
/
panels_variables.py
File metadata and controls
170 lines (154 loc) · 6.61 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 4 14:13:39 2021
@author: danilocoutodsouza
"""
import SLP_maps as smaps
import numpy as np
import pylab as pl
import cmocean.cm as cmo
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib.ticker as mticker
from matplotlib import colors
from matplotlib.colors import LinearSegmentedColormap
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import maps
# ---------------
def plot_var(ax,WT,proj,var):
# cmap for rain and wind
col_hcl = [
[0.9921568627450981, 0.6588235294117647, 0.7058823529411765],
[0.9294117647058824, 0.4392156862745098, 0.6627450980392157],
[0.8, 0.16470588235294117, 0.6470588235294118],
[0.5294117647058824, 0.058823529411764705, 0.5254901960784314],
[0.36470588235294116,0.1568627450980392, 0.39215686274509803],
[0.3215686274509804, 0.2549019607843137, 0.4549019607843137],
[0.1843137254901961, 0.4627450980392157, 0.5725490196078431],
[0.0, 0.5843137254901961, 0.6862745098039216],
[0.09411764705882353, 0.7411764705882353, 0.6901960784313725],
[0.9450980392156862, 0.9450980392156862, 0.9450980392156862]
]
col_hcl.reverse()
cmap = LinearSegmentedColormap.from_list(
'MyMap', col_hcl, N=20)
cmap.set_under('white')
#
lims = [-54, -44.05, -34, -25.05]
data = smaps.get_OLAM_data(WT)
if var in ['slp','wind']:
time = data.time[5]
else:
time = data.time[-1]
data = data.sel(lon=slice(lims[0],lims[1]),
lat=slice(lims[2],lims[3]),
time=time)
slp = data.sslp/100
prec = data.pt
u = data.uwnd
v = data.vwnd
lat = slp.lat
lon = slp.lon
ws = np.sqrt(u**2 + v**2)
if var == 'slp':
# set limits for plotting
cmap = cmo.balance
levels = np.arange(995,1036,2)
norm = maps.MidpointNormalize(vmin=995, vcenter=1014, vmax=1036)
cf1 = ax.contourf(lon, lat, slp, levels=levels, cmap=cmap,
norm=norm)
ax.contour(lon, lat, slp, cf1.levels,colors='grey', linewidths=1)
qv = ax.quiver(lon[::20],lat[::20],u[::20,::20],
v[::20,::20],color= 'k')
ax.quiverkey(qv,-0.3, 1.07, 10, r'$10 \frac{m}{s}$', labelpos = 'E',
coordinates='axes', labelsep = 0.05,
fontproperties={'size': 12, 'weight': 'bold'})
if var == 'prec':
# set limits for plotting
levels = np.arange(0,301,25)
norm = plt.Normalize(0, 300)
cf1 = ax.contourf(lon, lat, prec, levels=levels, cmap=cmap,
norm=norm)
if var == 'wind':
# set limits for plotting
levels = np.arange(0,23,2)
norm = plt.Normalize(0, 22)
cf1 = ax.contourf(lon, lat, ws, levels=levels, cmap=cmap, norm=norm)
ax.contour(lon, lat, ws, cf1.levels,colors='grey', linewidths=1)
qv = ax.quiver(lon[::20],lat[::20],u[::20,::20],
v[::20,::20],color= 'k')
ax.quiverkey(qv,-0.3, 1.07, 10, r'$10 \frac{m}{s}$', labelpos = 'E',
coordinates='axes', labelsep = 0.05,
fontproperties={'size': 12, 'weight': 'bold'})
return cf1
# ------------------
def grid_labels_params(ax):
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
linewidth=1, color='gray', alpha=0.5,linestyle='--')
gl.top_labels = False
gl.right_labels = False
gl.ylocator = mticker.FixedLocator(range(-35,-25,2))
gl.xlocator = mticker.FixedLocator(range(-51,-45,2))
gl.xlabel_style = {'size': 10, 'color': 'gray'}
gl.ylabel_style = {'size': 10, 'color': 'gray', 'rotation' : None}
ax.outline_patch.set_edgecolor('gray')
gl.xformatter = LongitudeFormatter(number_format='.0f',
degree_symbol='')
gl.yformatter = LatitudeFormatter(number_format='.0f',
degree_symbol='')
return ax
# ---------------
def main():
for var in ['slp','prec','wind']:
proj = ccrs.PlateCarree()
lims = [-54, -44.05, -34, -25.05]
fig = pl.figure(constrained_layout=False,figsize=(10,8))
gs = gridspec.GridSpec(ncols=6, nrows=6, figure=fig,
left= 0.05,right= 0.9, top = 0.95, bottom = 0.05,
wspace=0.3, hspace=0.15)
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
wt = 1
for col in range(6):
for row in range(6):
ax = (fig.add_subplot(gs[row, col], projection=proj))
ax.set_extent(lims)
# Plot variable
cf1 = plot_var(ax,wt,proj,var)
# Cosmedics
grid_labels_params(ax)
maps.map_features(ax)
maps.Brazil_states(ax)
ax.text(0.05,0.8,str(wt), transform=ax.transAxes, fontsize=12,bbox=props)
wt += 1
# colorbar
pos = ax.get_position()
cbar_ax = fig.add_axes([pos.x1+0.01, pos.y0*4.4, 0.02, pos.height*4])
if var == 'slp':
norm = maps.MidpointNormalize(vmin=995, vcenter=1014, vmax=1036)
cbar = plt.colorbar(cf1, cax=cbar_ax, orientation='vertical',
norm=norm)
cbar.ax.tick_params(labelsize=12)
cbar.mappable.set_clim(995,1035)
cbar.ax.set_title('(hPa)', rotation=0, fontsize= 12)
elif var == 'prec':
norm = plt.Normalize(0, 300)
cbar = plt.colorbar(cf1, cax=cbar_ax,
orientation='vertical', extend='max',
norm=norm)
cbar.ax.tick_params(labelsize=12)
cbar.ax.set_title('(mm)', rotation=0, fontsize= 12)
elif var == 'wind':
norm = plt.Normalize(0, 22)
cbar = plt.colorbar(cf1, cax=cbar_ax,
orientation='vertical', norm=norm,
extend='max')
cbar.ax.tick_params(labelsize=12)
cbar.ax.set_title('(m/s)', rotation=0, fontsize= 12)
pl.savefig('../Figures/panels/'+var+'.png', format='png')
pl.savefig('../Figures/panels/'+var+'.tiff', format='tiff', dpi=600)
# ------------------
if __name__ == "__main__":
main()