-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkorea.py
82 lines (65 loc) · 2.15 KB
/
korea.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
import matplotlib.pyplot as plt
import netCDF4 as nc
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import os
datadir = '/work/noaa/da/weiwli/c768/restart/'
griddir = '/work/noaa/da/weiwli/c768/oro/'
# one tile for now
tile=1
fname = os.path.join(datadir, f"20210801.000000.sfc_data.tile{tile}.nc")
oroname = os.path.join(griddir, f"C768_oro_data.tile{tile}.nc")
# read data and grid
ncdf = nc.Dataset(fname)
ncgf = nc.Dataset(oroname)
lat = ncgf.variables['geolat'][:]
lon = ncgf.variables['geolon'][:]
lon[np.where(lon>180)] = lon[np.where(lon>180)]-360
t127 = ncdf.variables['t2m'][0,:,:]
# set up map
#ax = plt.axes(projection=ccrs.PlateCarree())
# define grid
#gnomonic = ccrs.Gnomonic(central_latitude=lat[384,384], central_longitude=lon[384,384])
# plot data
#ax.pcolormesh(lon, lat, t127)
##ax.pcolormesh(lon, lat, t127, transform=gnomonic)
#ax.coastlines(zorder=10)
#ax.set_global()
#plt.show()
# loop and try all six and get the min/max values
arr3d=np.empty((6,768,768))
lat3d=np.empty((6,768,768))
lon3d=np.empty((6,768,768))
tilenum = [4,5,6]
for tile in tilenum:
#for tile in range(1,7,2):
print(tile)
fname = os.path.join(datadir, f"20210801.000000.sfc_data.tile{tile}.nc")
oroname = os.path.join(griddir, f"C768_oro_data.tile{tile}.nc")
# read data and grid
ncdf = nc.Dataset(fname)
ncgf = nc.Dataset(oroname)
lat = ncgf.variables['geolat'][:]
lon = ncgf.variables['geolon'][:]
lon[np.where(lon>180)] = lon[np.where(lon>180)]-360
t2m = ncdf.variables['t2m'][0,:,:]
# put these 2D arrays in the 3D arrays
arr3d[tile-1,...] = t2m
lat3d[tile-1,...] = lat
lon3d[tile-1,...] = lon
# get min/max for plotting
minval = np.nanmin(arr3d)
maxval = np.nanmax(arr3d)
# set up map
ax = plt.axes(projection=ccrs.PlateCarree())
# loop and plot data
cmaps=['jet', 'brg', 'terrain', 'gnuplot', 'coolwarm', 'RdGy']
#itilenum = [1,2,3]
itile = 4
#for itile in itilenum:
print(itile)
ax.pcolormesh(lon3d[itile], lat3d[itile], arr3d[itile], vmin=minval, vmax=maxval)
#ax.pcolormesh(lon3d[itile], lat3d[itile], arr3d[itile], vmin=minval, vmax=maxval, cmap=cmaps[itile])
ax.coastlines()
plt.show()