-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_spatial_rainfall.py
192 lines (124 loc) · 6 KB
/
plot_spatial_rainfall.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
import reading_gpm_data as gpm
import agreement as agr
import matplotlib.pyplot as plt
#from mpl_toolkits.basemap import Basemap, shiftgrid,interp
import netCDF4 as nc
import numpy as np
import reading_model_data as mod
import plot_agreement as plot
import cartopy.crs as ccrs
import cartopy
import matplotlib
matplotlib.rcParams.update({'font.size': 18})
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import matplotlib.dates as mdates
def plot_rainfall_acc_scale_obs(date,start_time,end_time,latmin,latmax,lonmin,lonmax):
filenameobs='C:/Users/carlo/Documents/Summer_School_evaluation/Data/gpm_imerg_production_V06B_'+str(date)+'.nc'
d=nc.Dataset(filenameobs)
latobs=d.variables['latitude']
lonobs=d.variables['longitude']
indexlatobs,indexlonobs=gpm.domain_specification_obs(date,latmin,latmax,lonmin,lonmax)
latobs=latobs[indexlatobs]
lonobs=lonobs[indexlonobs]
latcpa=indexlatobs[0]
latcpb=indexlatobs[len(indexlatobs)-1]+1
loncpa=indexlonobs[0]
loncpb=indexlonobs[len(indexlonobs)-1]+1
title='GPM-IMERG accumulation on '+str(date)
levels=np.linspace(0.1,50,10)
obs=gpm.obs_precip_accumulation_over_a_time_period(date,start_time,end_time,latmin,latmax,lonmin,lonmax)
fig=plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree())
# Contours and colour bar
cp=plt.contourf(lonobs, latobs,obs ,transform=ccrs.PlateCarree(), cmap = 'YlGnBu', levels =levels,extend='max' )
cbar = plt.colorbar(cp)
cbar_label=np.linspace(0,50,10)
cbar.set_label(cbar_label)
# Map features
ax.add_feature(cartopy.feature.COASTLINE)
ax.add_feature(cartopy.feature.BORDERS)
#ax.add_feature(cartopy.feature.OCEAN, facecolor='white')
# Grid lines
gl = ax.gridlines(crs=cartopy.crs.PlateCarree(), draw_labels=True,linewidth=1, color='black', alpha=0.5, linestyle='--')
gl.xlabels_top = False
gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
# Extent and title
ax.set_extent((lonmin,lonmax,latmin,latmax), crs=cartopy.crs.PlateCarree())
plt.title(title)
plt.show()
return
def plot_spatial_rainfall_acc_cp_model(date,valid_date,init_time,start_time,end_time,latmin,latmax,lonmin,lonmax):
filenameobs='C:/Users/carlo/Documents/Summer_School_evaluation/Data/gpm_imerg_production_V06B_'+str(valid_date)+'.nc'
d=nc.Dataset(filenameobs)
latobs=d.variables['latitude']
lonobs=d.variables['longitude']
indexlatobs,indexlonobs=gpm.domain_specification_obs(valid_date,latmin,latmax,lonmin,lonmax)
latobs=latobs[indexlatobs]
lonobs=lonobs[indexlonobs]
latcpa=indexlatobs[0]
latcpb=indexlatobs[len(indexlatobs)-1]+1
loncpa=indexlonobs[0]
loncpb=indexlonobs[len(indexlonobs)-1]+1
cp_precip=mod.cp_model_accumulation_regridded(date,init_time,start_time,end_time)[latcpa:latcpb,loncpa:loncpb]
title='CP deterministic accumulation_init_date'+str(date)+'times_T+'+str(start_time)+'-'+str(end_time)
fig=plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree())
# Contours and colour bar
levels=np.linspace(0.1,50,10)
cp=plt.contourf(lonobs, latobs,cp_precip,transform=ccrs.PlateCarree(), cmap = 'YlGnBu', levels =levels,extend='max' )
cbar = plt.colorbar(cp)
cbar_label=np.linspace(0,50,10)
cbar.set_label(cbar_label)
# Map features
ax.add_feature(cartopy.feature.COASTLINE)
ax.add_feature(cartopy.feature.BORDERS)
#ax.add_feature(cartopy.feature.OCEAN, facecolor='white')
# Grid lines
gl = ax.gridlines(crs=cartopy.crs.PlateCarree(), draw_labels=True,linewidth=1, color='black', alpha=0.5, linestyle='--')
gl.xlabels_top = False
gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
# Extent and title
ax.set_extent((lonmin,lonmax,latmin,latmax), crs=cartopy.crs.PlateCarree())
plt.title(title)
plt.show()
return
def plot_rainfall_acc_global_model(date,valid_date,init_time,start_time,end_time,latmin,latmax,lonmin,lonmax):
filenameobs='C:/Users/carlo/Documents/Summer_School_evaluation/Data/gpm_imerg_production_V06B_'+str(valid_date)+'.nc'
d=nc.Dataset(filenameobs)
latobs=d.variables['latitude']
lonobs=d.variables['longitude']
indexlatobs,indexlonobs=gpm.domain_specification_obs(valid_date,latmin,latmax,lonmin,lonmax)
latobs=latobs[indexlatobs]
lonobs=lonobs[indexlonobs]
latcpa=indexlatobs[0]
latcpb=indexlatobs[len(indexlatobs)-1]+1
loncpa=indexlonobs[0]
loncpb=indexlonobs[len(indexlonobs)-1]+1
x,y,m=plot.mapProjection(lonobs,latobs,latmin,latmax,lonmin,lonmax,res='i')
glob_precip=mod.global_model_accumulation_regridded(date,init_time,start_time,end_time)[latcpa:latcpb,loncpa:loncpb]
fig=plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree())
# Contours and colour bar
levels=np.linspace(0.1,50,10)
cp=plt.contourf(lonobs, latobs,glob_precip,transform=ccrs.PlateCarree(), cmap = 'YlGnBu', levels =levels,extend='max' )
cbar = plt.colorbar(cp)
cbar_label=np.linspace(0,50,10)
cbar.set_label(cbar_label)
# Map features
ax.add_feature(cartopy.feature.COASTLINE)
ax.add_feature(cartopy.feature.BORDERS)
#ax.add_feature(cartopy.feature.OCEAN, facecolor='white')
# Grid lines
gl = ax.gridlines(crs=cartopy.crs.PlateCarree(), draw_labels=True,linewidth=1, color='black', alpha=0.5, linestyle='--')
gl.xlabels_top = False
gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
# Extent and title
ax.set_extent((lonmin,lonmax,latmin,latmax), crs=cartopy.crs.PlateCarree())
plt.title(title)
return