<p>I have calculated the <span class="math-container">$∂θ_\varepsilon/∂z$</span> with 'Height', 'Latitude', 'Longitude' dimensions.</p>
<pre><code>import numpy as np
import xarray as xr
from wrf import (getvar)

eth = np.array(getvar(ncfile, &quot;eth&quot;, timeidx=time))
z = np.array(getvar(ncfile, &quot;z&quot;, timeidx=time, units=&quot;km&quot;)) 

deth = np.gradient(eth, axis=0)
dz = np.gradient(z, axis=0)
deth_dz = deth/dz

dthdz = xr.DataArray(data=deth_dz, dims=['Height', 'Latitude', 'Longitude'])
</code></pre>
<p>I would like to plot the horizontal depth or thickness (in km) of the <code>dthdz</code>.
It is a bit similar to <a href="https://stackoverflow.com/questions/69009774/calculating-total-depth-of-a-variable">this</a> question. But when I do <code>dthdz.sum(dim='Height')</code>, I get very low depth values. I just want to know where I'm doing it wrong. Thank you!</p>

CC BY-SA 4.0
2021-09-14T08:36:13.677Z
thanks @gansub! this uses conventional wrfout data. i tried the thickness_hydrostatic but it outputs in 1D. i was hoping to make a horizontal plot of the depth
Kas
<meteorology><wrf><python><netcdf>
Calculating layer thickness in python
Kas
# Calculating layer thickness in python

(Asked by: username_0 on 2021-09-14)

I have calculated the $∂θ_\varepsilon/∂z$ with 'Height', 'Latitude', 'Longitude' dimensions.
import numpy as np
import xarray as xr
from wrf import (getvar)

eth = np.array(getvar(ncfile, "eth", timeidx=time))
z = np.array(getvar(ncfile, "z", timeidx=time, units="km")) 

deth = np.gradient(eth, axis=0)
dz = np.gradient(z, axis=0)
deth_dz = deth/dz

dthdz = xr.DataArray(data=deth_dz, dims=['Height', 'Latitude', 'Longitude'])

I would like to plot the horizontal depth or thickness (in km) of the dthdz.
It is a bit similar to this question. But when I do dthdz.sum(dim='Height'), I get very low depth values. I just want to know where I'm doing it wrong. Thank you!

**Tags:** meteorology, wrf, python, netcdf

> **Comments:**
> **username_0**: thanks @gansub! this uses conventional wrfout data. i tried the thickness_hydrostatic but it outputs in 1D. i was hoping to make a horizontal plot of the depth  

---

## 0 answers

