-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathumidade-relativa-1000hpa.py
167 lines (134 loc) · 5.01 KB
/
umidade-relativa-1000hpa.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 16 15:17:49 2022
@author: beatrzzi
"""
#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
from datetime import datetime, timedelta
#dataset
file_1 = xr.open_dataset('/home/cliente/estagio2/dados/GFS_Global_0p25deg_20220916_1200.grib2.nc4').metpy.parse_cf()
file_1 = file_1.assign_coords(dict(
longitude = (((file_1.longitude.values + 180) % 360) - 180))
).sortby('longitude')
#extent
lon_slice = slice(-90., -10.)
lat_slice = slice(10., -70.)
#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')
for i in range(len(file_1.variables['time'])):
umi_rel_1000 = file_1.Relative_humidity_isobaric.metpy.sel(
time = file_1.time[i],
vertical=level_1,
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)
# 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())
# intevalos da pnmm
intervalo_min2 = np.amin(np.array(pnmm))
intervalo_max2 = np.amax(np.array(pnmm))
interval_2 = 2
levels_2 = np.arange(intervalo_min2, intervalo_max2, interval_2)
# intevalos da umidade relativa
#intervalo_min3 = np.amin(np.array(umi_rel_1000))
#intervalo_max3 = np.amax(np.array(umi_rel_1000))
intervalo_min3 = 1
intervalo_max3 = 100
interval_3 = 0.1
levels_3 = np.arange(intervalo_min3, intervalo_max3, interval_3)
# adiciona mascara de terra
ax.add_feature(cfeature.LAND)
# plota a umidade relativa
sombreado = ax.contourf(lons,
lats,
umi_rel_1000,
cmap='PRGn',
levels = levels_3,
extend = 'both'
)
# plota a imagem pressao
contorno = ax.contour(lons,
lats,
pnmm,
colors='black',
linewidths=0.8,
levels=levels_2
)
ax.clabel(contorno,
inline = 1,
inline_spacing = 1,
fontsize=20,
fmt = '%3.0f',
colors= 'black'
)
shapefile = list(
shpreader.Reader(
'/home/cliente/estagio2/shapefiles/BR_UF_2021.shp'
).geometries()
)
ax.add_geometries(
shapefile, ccrs.PlateCarree(),
edgecolor = 'black',
facecolor='none',
linewidth=0.5
)
# adiciona continente e bordas
ax.coastlines(resolution='50m', color='black', linewidth=2)
ax.add_feature(cfeature.BORDERS, edgecolor='black', linewidth=1)
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'}
# 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('Umidade relativa (%) em 1000 hPa',
fontweight='bold',
fontsize=30,
loc='left'
)
#previsao
#plt.title('Valid Time: {}'.format(vtime), fontsize=35, loc='right')
#analise
plt.title('Análise: {}'.format(vtime), fontsize=30, loc='right')
#--------------------------------------------------------------------------
# Salva imagem
plt.savefig(f'/home/cliente/estagio2/plots/umi-rel-1000/umi-rel_pnmm_{format(vtime)}.png', bbox_inches='tight')