Skip to content

examples_example.mesoscaleInfluence.SWiFTsiteLubbock.11Nov2013Diurnal_tendency.py problem.(Tkany you for helping) #102

@wineallergy

Description

@wineallergy

Hello.All. I know the tendency.py file is in example_example.mesoscaleInfluence.SWiFTsiteLubbock.11Nov2013Diurnal.When I run tendency.py in my wrfout file,
image
image
I looked up the official WRF Users' Guide and it doesn't have some of the variables in the code.So the error occcured:
image
I verified that none of these variables were in the file:'Uadv','Vadv','Thadv','Ug','Vg','Utend','Vtend','Ucor','Vcor','Uphys','Vphys'
Where did I make the mistake?
May I ask someone how to solve this problem? Forgive me if my question is too stupid, but I'm really confused by it.Thank you very much.

Cp = 1005.0
R = 286.9
p0 = 100000.0
kappa = 2.0/7.0
nHrs = 0.5 
nPerHr = 6
nLevels = 41

fileName="/home/lihao/PycharmProjects/wrf-python/wrfout_d03_2018-09-16_00:00:00"
#fileName = '../tendency_ncfiles/SWIFT_all_w0_L19000.nc'
#fileName = '../tendency_ncfiles/SWIFT_all_w60_L0.nc'
#fileName = '../tendency_ncfiles/SWIFT_all_w60_L19000.nc'
#fileName = '../tendency_ncfiles/SWIFT_all_neutral_FNL_notdivbyfc_tend_L4000'
#fileName = '.\TendencyForcing/tendency_ncfiles\SWIFT_all_neutral_FNL_notdivbyfc_1gp_tend_L0'

fieldVarName = ['U','V','T','Uadv','Vadv','Thadv','Ug','Vg','Utend','Vtend','Ucor','Vcor','Uphys','Vphys']
# Th to T /

multiplyByfc = [0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
timeAvgWindowSize = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];

surfaceVarName = ['HFX','LH','TSK','T2','PSFC']

writeFields = True
writeForcings = True
writeSurfaceValues = True
writeProbes = True
probeX = [2500.0, 2500.0, 2500.0, 2500.0, 2500.0]
probeY = [ 500.0, 1500.0, 2500.0, 3500.0, 4500.0]
probeMinZ = 5.0
probeMaxZ = 1995.0
probedZ = 10.0
writeInitialValues = True
initialTime = 12.0

plotFields = False
plotSurface = True



# Declare some variables
U = []
V = []
T = []
Uadv = []
Vadv = []
Thadv = []
Ug = []
Vg = []
Utend = []
Vtend = []
Ucor = []
Vcor = []
Uphys = []
Vphys = []
Qs = []
Ts = []
T2m = []


# zzy changed variables z-ZNW fc-F  time-XTIME Psfc-PSFC 
nc_fid = Dataset(fileName,'r')

z = nc_fid.variables['ZNW'][:]
# print('z',z)
# #
fc = nc_fid.variables['F'][:]
# print('fc',fc)
#
# zzy np.array: remove mask
time1 =  np.array(nc_fid.variables['Times'][:]) # zzy *24:day to hour
#
# # zzy from bytes to string
time2 = time1.astype('U1') #.reshape(time.size,-1)
time2 = np.array(time2)
#
# # zzy concatenate strings in every rows
time3=["" for x in range(len(time2))]
for i in range(len(time2)):
   time3[i]="".join(time2[i,:])
time=np.reshape(time3,(len(time2),1))
#
# print('time',time)
# print('time.shape',time.shape)
#
# # zzy np.array string to datetime type
timestamp=["" for x in range(len(time))]
#
for i in range(len(time)):
   timestamp[i]=[pd.to_datetime(time[i],errors='coerce',format='%Y-%m-%d_%H:%M:%S')]
#
# # zzy datetime force to array
time4=np.asarray(timestamp)
#
# print('time4',time4)
# print('time4[1]',time4[1])
# #
# # zzy array 3D to 2D / 2D to 1D
time_2d=np.reshape(np.transpose(time4,(2,0,1)),(-1,1))
time_1d=np.ravel(time_2d)
#
# print('time_1d',time_1d)
# print('time_1d[1]',time_1d[0])
#
# # zzy datetime string to float
# # zzy define conversion function
def datetime2matlabdn(dt):
    ord = datetime.date.toordinal(dt)
    mdn = dt + timedelta(days = 366)
    frac = (dt-datetime.datetime(dt.year,dt.month,dt.day,0,0,0)).seconds / (24.0 * 60.0 * 60.0)
    return datetime.date.toordinal(mdn) + frac
#
# # zzy test defined function
# print('1')
#
# zzy apply the definde fuction
time=[]
for i in range(len(timestamp)):
   time.append(datetime2matlabdn(pd.to_datetime(time_1d[i])))
time=np.asarray(time)*24	# zzy *24:day to hour

#print('time',time)
#print('timediff',time-time[0])

############

t0 = time[0]
#print('t0',t0)

t = time - t0
#print('t.shape',t.shape)

nt = len(t)
nz = len(z)
# print(nt)
# print(nz)
#nz = 87 # zzy len(z)
#
#
# # Loop through the field variables.
for m in range(len(fieldVarName)):

   print('m_count',m)

   var = np.zeros([nz,nt])
   ncVar = nc_fid.variables[fieldVarName[m]][:]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions