from netCDF4 import Dataset
import numpy as np
from mpl_toolkits.basemap import Basemap, cm
import matplotlib.pyplot as plt
import numpy as np
#import h5py as h5py
#nc_file = './3B-DAY-L.MS.MRG.3IMERG.20181112-S000000-E235959.V05.nc4.nc'
nc_file= '3B-DAY-L.MS.MRG.3IMERG.20181113-S000000-E235959.V05.nc4.nc'
dataset = Dataset(nc_file, mode='r')
precip1 = dataset.variables['precipitationCal'][:]
precip1 = np.transpose(precip1)
precip = precip1
theLats= dataset['lat'][:]
theLons = dataset['lon'][:]
# Plot the figure, define the geographic bounds
fig = plt.figure(dpi=300)
latcorners = ([38,46])
loncorners = ([34,45])
m = Basemap(projection='cyl',llcrnrlat=latcorners[0],urcrnrlat=latcorners[1],llcrnrlon=loncorners[0],urcrnrlon=loncorners[1],resolution="h")
# Draw coastlines, state and country boundaries, edge of map.
m.drawcoastlines(linewidth=1.2, linestyle='solid', color='k', antialiased=3, ax=None, zorder=None)
m.drawcountries(linewidth=0.8, linestyle='solid', color='k', antialiased=3, ax=None, zorder=None)
m.bluemarble(scale=3)
#m.shadedrelief(scale=2)
#m.etopo(scale=3)
#m.drawstates()
#m.drawcountries()
# Draw filled contours.
clevs = np.arange(0,60,5)
#color scale changing
#clevs = [2,5,10,20,30,40,50,60,70,100]
# Define the latitude and longitude data
x, y = np.float32(np.meshgrid(theLons, theLats))
# Mask the values less than 0 because there is no data to plot.
masked_array = np.ma.masked_where(precip < 0,precip)
# Plot every masked value as white
#cmap = cm.GMT_drywet
cmap = cm.GMT_drywet
cmap.set_bad('w',1.)
# Plot the data
cs = m.contourf(x,y,precip,clevs,cmap=cmap,latlon=True)
parallels = np.arange(-60.,61,20.)
m.drawparallels(parallels,labels=[True,False,True,False])
meridians = np.arange(-180.,180.,60.)
m.drawmeridians(meridians,labels=[False,False,False,True])
# Set the title and fonts
plt.title('Black Sea Total Rain Rate')
font = {'weight' : 'bold', 'size' : 6}
plt.rc('font', **font)
# Add colorbar
cbar = m.colorbar(cs,location='right',pad="5%")
cbar.set_label('mm/h')
plt.savefig('a.png',dpi=200) #change to your directory
GPM卫星降水绘图
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1: Inference and train with existing models and standard ...
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 1) 注...