I use wrf-python to extract the variable wind u = wrf.getvar(nc,"ua") and vertically interpolate it to pressure levels. I now wish to compute the horizontal gradients of ua. The horizontal grid spacing configured in my namelist is 27 km.
Is it valid to use dx and dy to perform centered differencing for this calculation?
Yes, centered differencing is valid, but I would use the grid information already written to the WRF output rather than hard-coding 27 km.
Since
ua = wrf.getvar(nc, "ua")
returns U destaggered to the mass grid, you can use RDX, RDY, MAPFAC_MX, and MAPFAC_MY, assuming those variables are available in your WRF output.
∂u/∂x ≈ 0.5 × RDX × MAPFAC_MX × (u[i+1,j] - u[i-1,j])
∂u/∂y ≈ 0.5 × RDY × MAPFAC_MY × (u[i,j+1] - u[i,j-1])
where
RDX = (Δx)^-1<br>RDY = (Δy)^-1
For a 27 km grid:
RDX = RDY = (27,000 m)^-1
You could also write this as:
∂u/∂x ≈ MAPFAC_MX × (u[i+1,j] - u[i-1,j]) / 54,000 m
∂u/∂y ≈ MAPFAC_MY × (u[i,j+1] - u[i,j-1]) / 54,000 m
One caveat is that this assumes RDX, RDY, MAPFAC_MX, and MAPFAC_MY are present in the WRFOUT file. You can check the file header first with NetCDF commands such as:
Bash:
ncdump -h wrfout_d01_YYYY-MM-DD_HH:MM:SS | grep -E "RDX|RDY|MAPFAC_MX|MAPFAC_MY"
or simply:
Bash:
ncdump -h wrfout_d01_YYYY-MM-DD_HH:MM:SS
WRF does not appear to output DUDX or DUDY directly, but if these grid-metric variables are available, they provide what you need to calculate the gradients.
Hope this helps.