I want to calculate moisture flux divergence (MFD) over southern Africa. I use u and v wind components at 850 hPa and specific humidity at 850 hPa, for a specific day. I have followed the steps described here: Calculating wind divergence of u and v using Python, np.gradient and here: https://earthscience.stackexchange.com/questions/8418/how-to-calculate-water-vapor-flux-divergence-from-temperature-relative-humidity
The code I am using is the following:
from matplotlib.cm import get_cmap
from __future__ import print_function
from netCDF4 import Dataset,num2date,date2num
from matplotlib.colors import from_levels_and_colors
from cartopy import crs
from cartopy.feature import NaturalEarthFeature, COLORS
#
import metpy.calc as mpcalc
import xarray as xr
import cartopy.crs as ccrs
import matplotlib
import cartopy.feature as cfe
import numpy as np
import matplotlib.pyplot as plt
import datetime
#
#############################################################################################################
####################################### Calculate Moisture Divergence #######################################
#############################################################################################################
#
root_dir = '/users/pr007/mkaryp/'
nc = Dataset(root_dir+'merge_SAF.nc')
#
v = np.array(nc.variables['va850'][0,:,:])
u = np.array(nc.variables['ua850'][0,:,:])
q = np.array(nc.variables['hus850'][0,:,:])
#
lon=nc.variables['lon'][:]
lat=nc.variables['lat'][:]
#
qu = q*u
qv = q*v
#
# Compute dx and dy spacing for use in divergence calculation
dx, dy = mpcalc.lat_lon_grid_deltas(lon, lat)
# Calculate horizontal moisture flux divergence using https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.divergence.html
HMC = (np.array(mpcalc.divergence(qu, qv, dx=dx, dy=dy)))
#
The output is shown below:Moisture Flux Divergence for a specific day
Div = (np.array(mpcalc.divergence(u, v, dx=dx, dy=dy)))
However, when I use u and v (instead of qu and qv) in the divergence function (mpcalc.divergence), the output is spatially identical (shown here:Wind divergence for the same day (as in previous plot)). '''
I am wondering whether there is a more meaningful way to calculate moisture flux divergence in python.
Thank you!