-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathespessura_gfs.py
215 lines (174 loc) · 6.58 KB
/
espessura_gfs.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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 24 18:20:34 2022
@author: coqueiro
"""
#importando bibliotecas
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import matplotlib.colors
import metpy.calc as mpcalc
from metpy.units import units
import numpy as np
import xarray as xr
import cartopy.io.shapereader as shpreader # Import shapefiles
from datetime import datetime, timedelta # basicas datas e tipos de tempo
import cmocean
#dataset
file_1 = xr.open_dataset(
'/home/ladsin/Downloads/GFS_analise_11_13.nc4'
).metpy.parse_cf()
file_1 = file_1.assign_coords(dict(
longitude = (((file_1.longitude.values + 180) % 360) - 180))
).sortby('longitude')
#extent
lon_0 = -120.
lon_1 = -20.
lat_0 = 10.
lat_1 = -55.
lon_slice = slice(lon_0, lon_1)
lat_slice = slice(lat_0, lat_1)
#pega as lat/lon
lats = file_1.latitude.sel(latitude=lat_slice).values
lons = file_1.longitude.sel(longitude=lon_slice).values
#seta as variaveis
level_1 = 1000 * units('hPa')
level_2 = 500 * units('hPa')
for i in range(len(file_1.variables['time'])):
geopotencial_1000 = file_1.Geopotential_height_isobaric.metpy.sel(
time = file_1.time[i],
vertical=level_1,
latitude=lat_slice,
longitude=lon_slice
).metpy.unit_array.squeeze()
geopotencial_500 = file_1.Geopotential_height_isobaric.metpy.sel(
time = file_1.time[i],
vertical=level_2,
latitude=lat_slice,
longitude=lon_slice
).metpy.unit_array.squeeze()
pnmm = file_1.Pressure_reduced_to_MSL_msl.metpy.sel(
time = file_1.time[i],
latitude=lat_slice,
longitude=lon_slice
).metpy.unit_array.squeeze()*0.01*units.hPa/units.Pa
#data
vtime = file_1.time.data[i].astype('datetime64[ms]').astype('O')
dx, dy = mpcalc.lat_lon_grid_deltas(lons, lats)
espessura = geopotencial_500 - geopotencial_1000
# escolha o tamanho do plot em polegadas (largura x altura)
plt.figure(figsize=(25,25))
# usando a projeção da coordenada cilindrica equidistante
ax = plt.axes(projection=ccrs.PlateCarree())
gl = ax.gridlines(crs=ccrs.PlateCarree(),
color='gray',
alpha=1.0,
linestyle='--',
linewidth=0.5,
xlocs=np.arange(-180, 180, 10),
ylocs=np.arange(-90, 90, 10),
draw_labels=True
)
gl.top_labels = False
gl.right_labels = False
gl.xlabel_style = {'size': 29, 'color': 'black'}
gl.ylabel_style = {'size': 29, 'color': 'black'}
# cria uma escala de cores:
colors = ["#2d001c", "#5b0351", "#780777", "#480a5e", "#1e1552",
"#1f337d", "#214c9f", "#2776c6", "#2fa5f1", "#1bad1d",
"#8ad900", "#ffec00", "#ffab00", "#f46300", "#de3b00",
"#ab1900", "#6b0200", '#3c0000']
cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", colors)
cmap.set_over('#3c0000')
cmap.set_under('#28000a')
# intevalos da espessura
intervalo_min2 = 5000
intervalo_max2 = 5825
interval_2 = 25 # de quanto em quanto voce quer que varie
levels_2 = np.arange(intervalo_min2, intervalo_max2, interval_2)
# intevalos da pnmm
intervalo_min1 = np.amin(np.array(pnmm))
intervalo_max1 = np.amax(np.array(pnmm))
interval_1 = 2 # de quanto em quanto voce quer que varie
levels_1 = np.arange(intervalo_min1, intervalo_max1, interval_1)
# plota a imagem espessura
sombreado = ax.contourf(lons,
lats,
espessura,
cmap=cmap,
levels = levels_2,
extend = 'neither'
)
# plota a imagem pressao
contorno_1 = ax.contour(lons,
lats,
pnmm,
colors='black',
linewidths=2,
levels=levels_1
)
ax.clabel(contorno_1,
inline = 1,
inline_spacing = 1,
fontsize=20,
fmt = '%3.0f',
colors= 'black'
)
#adicionando shapefile
shapefile = list(
shpreader.Reader(
'/work/archive/Everson/Coqueiro/script_gfs/GFS-analysis_and_forecast-main/shapefiles/BR_UF_2021/BR_UF_2021.shp'
).geometries()
)
ax.add_geometries(
shapefile, ccrs.PlateCarree(),
edgecolor = 'black',
facecolor='none',
linewidth=0.5
)
# adiciona mascara de terra
ax.add_feature(cfeature.LAND)
# adiciona continente e bordas
ax.coastlines(resolution='10m', color='black', linewidth=3)
ax.add_feature(cfeature.BORDERS, edgecolor='black', linewidth=3)
# # inset axes....
# axins = ax.inset_axes([0.58, 0.58, 0.4, 0.4])
# axins.contourf(sombreado, cmap=cmap, origin="image")
# contorno_2 = axins.contour(contorno_1, colors='black', origin="image")
# axins.clabel(contorno_2,
# inline = 1,
# inline_spacing = 1,
# fontsize=15,
# fmt = '%3.0f',
# colors= 'black'
# )
# # sub region of the original image
# x1, x2, y1, y2 = -55, -40, -35 , -15
# axins.set_xlim(x1, x2)
# axins.set_ylim(y1, y2)
# axins.set_xticklabels([])
# axins.set_yticklabels([])
# ax.indicate_inset_zoom(axins, edgecolor="black")
# adiciona legenda
barra_de_cores = plt.colorbar(sombreado,
orientation = 'horizontal',
pad=0.04,
fraction=0.04
)
font_size = 20 # Adjust as appropriate.
barra_de_cores.ax.tick_params(labelsize=font_size)
# Add a title
plt.title('Espessura (500-1000)hPa',
fontweight='bold',
fontsize=35,
loc='left'
)
#previsao
#plt.title('Valid time: {}'.format(vtime), fontsize=35, loc='right')
#analise
plt.title('Análise: {}'.format(vtime), fontsize=35, loc='right')
#--------------------------------------------------------------------------
# Salva imagem
plt.savefig(f'/work/archive/Everson/Coqueiro/Estagio/plots/espessura/espessura_{vtime}.png', bbox_inches='tight')