Пример #1
0
"""

from netCDF4 import Dataset
import numpy as np
import mapping_functions as f
#from mpl_toolkits.basemap import interp
from scipy import interpolate

root = Dataset('wrf_2011_07_01', 'r')
vars = root.variables
grd = vars['HGT'][0, :, :]
hgt = (vars['PH'][0, :, :, :] + vars['PHB'][0, :, :, :]) / 9.81
#hgt = f.unstagger(hgt,axis=0)
lat = vars['XLAT'][0, :, :]
lon = vars['XLONG'][0, :, :]
u = f.unstagger(vars['U'][:], axis=3)
v = f.unstagger(vars['V'][:], axis=2)
w = f.unstagger(vars['W'][:], axis=1)
root.close()
hgt = hgt - grd
heightmax = hgt.max(axis=(1, 2))
heightmin = hgt.min(axis=(1, 2))
heightmean = hgt.mean(axis=(1, 2))

dx = 12000
dy = 12000
dz = np.diff(heightmean)
xx = np.linspace(0, dx * (hgt.shape[2] - 1), hgt.shape[2])
yy = np.linspace(0, dy * (hgt.shape[1] - 1), hgt.shape[1])
[yy, zz, xx] = np.meshgrid(yy, heightmean, xx)
t = 0
height_level = 3  #roughly 80 m above ground level
grid_spacing = 12 * 1000  #km 2 m

#xdim = 405
#ydim = 325
time_step = 21  #2100hrs

figwidth = 6
FigSize = (figwidth, ydim / xdim * figwidth)

tstart = calendar.timegm(
    time.strptime('Jun 1, 2017 @ 00:00:00 UTC', '%b %d, %Y @ %H:%M:%S UTC'))
ncfile = "wrf_2011_07_01"  #"ftle_80m.nc"
root = Dataset(ncfile, 'r')
vars = root.variables
u = mf.unstagger(vars['U'][:, height_level, :, :], axis=2)
v = mf.unstagger(vars['V'][:, height_level, :, :], axis=1)
lat = vars['XLAT'][0, :, :]
lon = vars['XLONG'][0, :, :]
root.close()
[tdim, ydim, xdim] = u.shape

#u=u[time_step,:,:]
#v=v[time_step,:,:]

#lon = lon[-1,:,:]
#lat = lat[-1,:,:]
#latin = lat[:25,:,:]
#longin = lon[:25,:,:]
dt = 3600  #sec
#x = np.linspace(-grid_spacing*(xdim-1)/2,grid_spacing*(xdim-1)/2,xdim)
#u = mf.unstagger(vars['U'][:,height_level,:,:],axis=2)
#v = mf.unstagger(vars['V'][:,height_level,:,:],axis=1)
u = vars['U'][:, height_level, :, :]
v = vars['V'][:, height_level, :, :]
lat = vars['XLAT'][0, :, :]
lon = vars['XLONG'][0, :, :]
root.close()

ncfile = "wrf_2011_07_02"  #"ftle_80m.nc"
root = Dataset(ncfile, 'r')
vars = root.variables
u = np.concatenate((u, vars['U'][:, height_level, :, :]))
v = np.concatenate((v, vars['V'][:, height_level, :, :]))
root.close()

u = 24 * 3.6 * mf.unstagger(u, axis=2)
v = 24 * 3.6 * mf.unstagger(v, axis=1)

[tdim, ydim, xdim] = u.shape

dt = 1 / 24  #1 day to hr 3600 #1 hrs 2 sec
x = np.linspace(0, grid_spacing * (xdim - 1), xdim)
dx = x[1] - x[0]
y = np.linspace(0, grid_spacing * (ydim - 1), ydim)
dy = y[1] - y[0]
x, y = np.meshgrid(x, y)

dudy, dudx = np.gradient(u, dy, dx, axis=(1, 2))
dvdy, dvdx = np.gradient(v, dy, dx, axis=(1, 2))

dudydt = np.gradient(dudy, dt, axis=0)
Пример #4
0
ref_lon = getattr(root,'STAND_LON')
vars = root.variables
u = vars['U'][:,height_level,:,:]
v = vars['V'][:,height_level,:,:]
lat_vel = vars['XLAT'][0,:,:]
lon_vel = vars['XLONG'][0,:,:]
root.close()

checklon, checklat = mf.lonlat2km(ref_lon,ref_lat,lon_vel,lat_vel,true_lat1,true_lat2) 

root = Dataset('wrf_2011_07_02','r')
vars = root.variables
u = np.concatenate((u,vars['U'][:,height_level,:,:]))
v = np.concatenate((v,vars['V'][:,height_level,:,:]))
root.close()
u = mf.unstagger(u[:tdim,:,:],2)
v = mf.unstagger(v[:tdim,:,:],1)
dx = grid_spacing
dy = grid_spacing
time_in = np.linspace(0,24,25)
time_want = np.linspace(0,24,145)

u_out = np.empty([145,82,102])
v_out = np.empty([145,82,102])
for i in range(ydim):
    for j in range(xdim):
        fu = interp1d(time_in,u[:,i,j],kind='cubic')
        u_out[:,i,j] = fu(time_want)
        fv = interp1d(time_in,v[:,i,j],kind='cubic')
        v_out[:,i,j] = fv(time_want)
Пример #5
0
grid_spacing = 12 #km

tdim = 25
xdim = 102
ydim = 82

root = Dataset('wrf_2011_07_01','r')
cen_lat = getattr(root,'CEN_LAT')
cen_lon = getattr(root,'CEN_LON')
true_lat1 = getattr(root,'TRUELAT1')
true_lat2 = getattr(root,'TRUELAT2')
ref_lat = getattr(root,'MOAD_CEN_LAT')
ref_lon = getattr(root,'STAND_LON')
vars = root.variables
#Wind Velocity
u = mf.unstagger(vars['U'][:],axis=3)
v = mf.unstagger(vars['V'][:],axis=2)
w = mf.unstagger(vars['W'][:],axis=1)
grd = vars['HGT'][0,:,:]
hgt = mf.unstagger((vars['PH'][0,:,:,:] + vars['PHB'][0,:,:,:])/9.81,axis=0)-grd
#Water Vapor Flux, Vertically Integrated
lat_in = vars['XLAT'][0,:,:]
lon_in = vars['XLONG'][0,:,:]
#root.close()

xin = np.linspace(0,12000*101,102)
yin = np.linspace(0,12000*81,82)
hin = hgt.mean(axis=(1,2))
time = np.linspace(0,3600*23,24)
u = u.data
v = v.data
#v = vars['VQ_Q'][:,:,:]
lat = vars['XLAT'][0,:,:]
lon = vars['XLONG'][0,:,:]
root.close()
checklon, checklat = mf.lonlat2km(ref_lon,ref_lat,lon,lat,true_lat1,true_lat2) 

root = Dataset('wrf_2011_07_02','r')
vars = root.variables
#Wind Velocity
u = np.concatenate((u,vars['U'][:,height_level,:,:]))
v = np.concatenate((v,vars['V'][:,height_level,:,:]))
#Water Vapor Flux, Vertically Integrated
#u = np.concatenate((u,vars['UQ_Q'][:,:,:]))
#v = np.concatenate((v,vars['VQ_Q'][:,:,:]))
root.close()
u = mf.unstagger(u[:25,:,:],2)
v = mf.unstagger(v[:25,:,:],1)

u=u[-1,:,:]
v=v[-1,:,:]
#lon = lon[-1,:,:]
#lat = lat[-1,:,:]
#latin = lat[:25,:,:]
#longin = lon[:25,:,:]

#x = np.linspace(-grid_spacing*(xdim-1)/2,grid_spacing*(xdim-1)/2,xdim)
x = np.linspace(0,grid_spacing*(xdim-1),xdim)
dx = x[1]-x[0]
#y = np.linspace(-grid_spacing*(ydim-1)/2,grid_spacing*(ydim-1)/2,ydim)
y = np.linspace(0,grid_spacing*(ydim-1),ydim)
dy = y[1]-y[0]
Пример #7
0
#v = vars['VQ_Q'][:,:,:]
lat_in = vars['XLAT'][0,:,:]
lon_in = vars['XLONG'][0,:,:]
root.close()

root = Dataset('wrf_2011_07_02','r')
vars = root.variables
#Wind Velocity
u = np.concatenate((u,vars['U'][:,height_level,:,:]))
v = np.concatenate((v,vars['V'][:,height_level,:,:]))
#Water Vapor Flux, Vertically Integrated
#u = np.concatenate((u,vars['UQ'][:,:,:]))
#v = np.concatenate((v,vars['VQ'][:,:,:]))
root.close()
#FLUX DOES NOT NEED UNSTAGGERING
u = mf.unstagger(np.double(u[:25,:,:]),2)
v = mf.unstagger(np.double(v[:25,:,:]),1)
#u = mf.unstagger(u[:25,:,:],2)
#v = mf.unstagger(v[:25,:,:],1)
#u = u[:25,:,:]
#v = v[:25,:,:]
u = np.moveaxis(u,0,-1)
v = np.moveaxis(v,0,-1)
x = np.linspace(0,(xdim-1)*grid_spacing,xdim)
y = np.linspace(0,(ydim-1)*grid_spacing,ydim)
t = np.linspace(0,24,25)
t=t*3600
[x,y,t] = np.meshgrid(x,y,t)
u = u.data
v = v.data
savemat('wrf_vel_data.mat',{'u':u,'v':v,'x':x,'y':y,'time':t},format='7.3')
Пример #8
0
    y = p0 - p * np.cos(th)
    return x, y


height_level = 17  #0.81 eta level
grid_spacing = 12  #km

tdim = 25
xdim = 102
ydim = 82

#root = Dataset('subset_wrfout_d01_2011-07-01_00_00_00','r')
root = Dataset('wrf_2011_07_01', 'r')
vars = root.variables
grd = vars['HGT'][0, :, :]
hgt = mf.unstagger((vars['PH'][0, :, :, :] + vars['PHB'][0, :, :, :]) / 9.81)
lat = vars['XLAT'][0, :, :]
lon = vars['XLONG'][0, :, :]
root.close()
hgt = hgt - grd
heightmax = hgt.max(axis=(1, 2))
heightmin = hgt.min(axis=(1, 2))
heightmean = hgt.mean(axis=(1, 2))
diff = heightmax - heightmin

import matplotlib.pyplot as plt
plt.plot(heightmean, 'b*-')
plt.plot(heightmin, 'c*-')
plt.plot(heightmax, 'r*-')
'''
data = hgt[0,:,:]
Пример #9
0
tdim = 24
xdim = 102
ydim = 82

root = Dataset('wrf_2011_07_01', 'r')
cen_lat = getattr(root, 'CEN_LAT')
cen_lon = getattr(root, 'CEN_LON')
true_lat1 = getattr(root, 'TRUELAT1')
true_lat2 = getattr(root, 'TRUELAT2')
ref_lat = getattr(root, 'MOAD_CEN_LAT')
ref_lon = getattr(root, 'STAND_LON')
vars = root.variables

if True:
    mf.unstagger('a')

#Wind Velocity
uu = mf.unstagger(vars['U'][:, :, :, :], axis=3)
vv = mf.unstagger(vars['V'][:, :, :, :], axis=2)
#Water Vapor Flux, Vertically Integrated
lat_in = vars['XLAT'][0, :, :]
lon_in = vars['XLONG'][0, :, :]
root.close()

xin, yin = mf.lonlat2km(ref_lon, ref_lat, lon_in, lat_in, true_lat1, true_lat2)

lat2file = np.linspace(np.min(lat_in), np.max(lat_in), (ydim - 1) * 4 + 1)
lon2file = np.linspace(np.min(lon_in), np.max(lon_in), (xdim - 1) * 4 + 1)
xodim = lon2file.shape[0]
yodim = lat2file.shape[0]