-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlackSea.py
121 lines (51 loc) · 2.04 KB
/
BlackSea.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
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'
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('../*.png',dpi=200) #change to your directory