3

相対渦度、つまり dV/dX - dU/dY を計算しようとしていますが、現在 numpy で勾配関数を使用しています。以下は私のコードです。dU/dY を実行したいときに配列を再形成しようとする代わりに、これを行うためのより良い方法があるかどうかを知りたいです。U と Y のみを示す数字の 2 つの行列を指定して微分を行うより良い方法はありますか? U と Y を微分したいと思います。

import numpy as np
import netCDF4
import matplotlib.pyplot as plt
from numpy import *
import decimal
from netCDF4 import Dataset

ncfile= Dataset('test.nc','r')

#--------------------Reading in Variables---------------------------------#

lon      = ncfile.variables['lon'][:]
lat      = ncfile.variables['lat'][:]
UWind850 = ncfile.variables['U'][:,22,:,:] (time, level,lat,lon)
VWind850 = ncfile.variables['V'][:,22,:,:] (time, level,lat,lon)
time     = ncfile.variables['time'][:] 
MSLP     = ncfile.variables['PSL'][:]

# Variable[time,Longitude,Latitude]
#These values are equivalent to I,J and L in the netCDF file

t = 30  #time
x = 300 #longitude 
y = 240 #latitude


#-----------------------Calculating Vorticity-----------------------------#

dX = np.gradient(lon) #shape 300
dY = np.gradient(lat) #shape 240

#VWind850.shape (30,240,300)
#UWind850.shape (30,240,300)

dV = (np.gradient(VWind850))

#dV.shape(3,30,240,300) --The extra "3" dimension is caused by the gradient because 
#Its creating a Matrix for gradients by (time,latitude,longitude)

Vgradient =  dV[2]/dX



UWindTemp = np.reshape(UWind850,(30,300,240)) # I am reshaping so I can divide by dY



dU = (np.gradient(UWindTemp))
Ugradient =  dU[2]/dY
Ugradient = np.reshape(Ugradient,(30,240,300)) # Taking it back to normal


VORT= Vgradient - Ugradient 

# VORT.shape(time, latitude, longitude)
#-------------------------------------------------------------------------#
4

0 に答える 0