I'm trying to calculate the 3D divergence field on a layer of the atmosphere (500mb) for wind. The data I have is the U, V and W wind vectors from a grib file, as follows:
DataA = source.select(name='U component of wind',typeOfLevel='isobaricInhPa',level=250)[0]
DataA = DataA.values
DataB = source.select(name='V component of wind',typeOfLevel='isobaricInhPa',level=250)[0]
DataB = DataB.values
DataC = source.select(name='Vertical velocity',typeOfLevel='isobaricInhPa',level=250)[0]
DataC = DataC.values
What I am wondering is how to combine this into one array so that I can calculate the divergence (presumably from np.grad). E.g. I tried:
Data = np.zeros((3,721,1440))
Data[0:,:] = DataA
Data[1:,:] = DataB
Data[2:,:] = DataC
Plot = np.gradient(Data,axis=0)
But this produces a (3,1,1440) array (which is wrong as the output should be the same dimension as the input data, i.e. a 721 (lat) by 1440 (lon) grid..