# altitude derivations

1. altitude from geopotential height

   symbol | description | unit | variable name
   --- | --- | --- | ---
   \(g\) | normal gravity at sea level | \(\frac{m}{s^2}\) |
   \(g_{0}\) | mean earth gravity | \(\frac{m}{s^2}\) |
   \(R\) | local earth curvature radius | \(m\) |
   \(z\) | altitude | \(m\) | altitude {:}
   \(z_{g}\) | geopotential height | \(m\) | geopotential_height {:}
   \(\phi\) | latitude | \(degN\) | latitude {:}

   The pattern : for the dimensions can represent {vertical}, {time}, {time,vertical}, or no dimensions at all.

   \begin{eqnarray} g & = & 9.7803253359 \frac{1 + 0.00193185265241{\sin}^2(\frac{\pi}{180}\phi)} {\sqrt{1 - 0.00669437999013{\sin}^2(\frac{\pi}{180}\phi)}} \\ R & = & \frac{1}{\sqrt{\left(\frac{\cos(\frac{\pi}{180}\phi)}{6356752.0}\right)^2 + \left(\frac{\sin(\frac{\pi}{180}\phi)}{6378137.0}\right)^2}} \\ z & = & \frac{g_{0}Rz_{g}}{gR - g_{0}z_{g}} \end{eqnarray}

2. altitude from bounds

   symbol | description | unit | variable name
   --- | --- | --- | ---
   \(z\) | altitude | \(m\) | altitude {:}
   \(z^{B}(l)\) | altitude boundaries (\(l \in \{1,2\}\)) | \(m\) | altitude_bounds {:,2}

   The pattern : for the dimensions can represent {vertical}, or {time,vertical}.

   \[z = \frac{z^{B}(2) + z^{B}(1)}{2}\]

3. altitude from sensor altitude

   symbol | description | unit | variable name
   --- | --- | --- | ---
   \(z\) | altitude | \(m\) | altitude {:}
   \(z_{instr}\) | altitude of the sensor | \(m\) | sensor_altitude {:}

   The pattern : for the dimensions can represent {time}, or no dimensions at all.

   \[z = z_{instr}\]

4. altitude from pressure

   symbol | description | unit | variable name
   --- | --- | --- | ---
   \(a\) | WGS84 semi-major axis | \(m\) |
   \(b\) | WGS84 semi-minor axis | \(m\) |
   \(f\) | WGS84 flattening | \(m\) |
   \(g\) | normal gravity at sea level | \(\frac{m}{s^2}\) |
   \(g_{0}\) | mean earth gravity | \(\frac{m}{s^2}\) |
   \(g_{h}\) | gravity at specific height | \(\frac{m}{s^2}\) |
   \(GM\) | WGS84 earth’s gravitational constant | \(\frac{m^3}{s^2}\) |
   \(M_{air}(i)\) | molar mass of total air | \(\frac{g}{mol}\) | molar_mass {:,vertical}
   \(p(i)\) | pressure | \(Pa\) | pressure {:,vertical}
   \(p_{surf}\) | surface pressure | \(Pa\) | surface_pressure {:}
   \(R\) | universal gas constant | \(\frac{kg m^2}{K mol s^2}\) |
   \(T(i)\) | temperature | \(K\) | temperature {:,vertical}
   \(z(i)\) | altitude | \(m\) | altitude {:,vertical}
   \(z_{surf}\) | surface height | \(m\) | surface_altitude {:}
   \(\phi\) | latitude | \(degN\) | latitude {:}
   \(\omega\) | WGS84 earth angular velocity | \(rad/s\) |

   The pattern : for the dimensions can represent {latitude,longitude}, {time}, {time,latitude,longitude}, or no dimensions at all.

   The surface pressure \(p_{surf}\) and surface height \(z_{surf}\) need to use the same definition of ‘surface’.

   The pressures \(p(i)\) are expected to be at higher levels than the surface pressure (i.e. lower values). This should normally be the case since even for pressure grids that start at the surface, \(p_{surf}\) should equal the lower pressure boundary \(p^{B}(1,1)\), whereas \(p(1)\) should then be between \(p^{B}(1,1)\) and \(p^{B}(1,2)\) (which is generally not equal to \(p^{B}(1,1)\)).

   \begin{eqnarray} g & = & 9.7803253359 \frac{1 + 0.00193185265241{\sin}^2(\frac{\pi}{180}\phi)} {\sqrt{1 - 0.00669437999013 {\sin}^2(\frac{\pi}{180}\phi)}} \\ m & = & \frac{\omega^2a^2b}{GM} \\ g_{h}(1) & = & g \left(1 - \frac{2}{a}\left(1+f+m-2f{\sin}^2(\frac{\pi}{180}\phi)\right)z_{surf} + \frac{3}{a^2}z_{surf}^2\right) \\ g_{h}(i) & = & g \left(1 - \frac{2}{a}\left(1+f+m-2f{\sin}^2(\frac{\pi}{180}\phi)\right)z(i-1) + \frac{3}{a^2}z(i-1)^2\right), 1 < i \leq N \\ z(1) & = & z_{surf} + 10^{3}\frac{T(1)}{M_{air}(1)}\frac{R}{g_{h}(1)}\ln\left(\frac{p_{surf}}{p(i)}\right) \\ z(i) & = & z(i-1) + 10^{3}\frac{T(i-1)+T(i)}{M_{air}(i-1)+M_{air}(i)}\frac{R}{g_{h}(i)}\ln\left(\frac{p(i-1)}{p(i)}\right), 1 < i \leq N \end{eqnarray}

5. surface altitude from surface geopotential height

   symbol | description | unit | variable name
   --- | --- | --- | ---
   \(g\) | nominal gravity at sea level | \(\frac{m}{s^2}\) |
   \(g_{0}\) | mean earth gravity | \(\frac{m}{s^2}\) |
   \(R\) | local earth curvature radius | \(m\) |
   \(z_{surf}\) | surface altitude | \(m\) | surface_altitude {:}
   \(z_{g,surf}\) | surface geopotential height | \(m\) | surface_geopotential_height {:}
   \(\phi\) | latitude | \(degN\) | latitude {:}

   The pattern : for the dimensions can represent {latitude,longitude}, {time}, {time,latitude,longitude}, or no dimensions at all.

   \begin{eqnarray} g & = & 9.7803253359 \frac{1 + 0.00193185265241{\sin}^2(\frac{\pi}{180}\phi)} {\sqrt{1 - 0.00669437999013{\sin}^2(\frac{\pi}{180}\phi)}} \\ R & = & \frac{1}{\sqrt{\left(\frac{\cos(\frac{\pi}{180}\phi)}{6356752.0}\right)^2 + \left(\frac{\sin(\frac{\pi}{180}\phi)}{6378137.0}\right)^2}} \\ z_{surf} & = & \frac{g_{0}Rz_{g,surf}}{gR - g_{0}z_{g,surf}} \end{eqnarray}

6. tropopause altitude from temperature and altitude/pressure

   symbol | description | unit | variable name
   --- | --- | --- | ---
   \(p(i)\) | pressure | \(Pa\) | pressure {:,vertical}
   \(T(i)\) | temperature | \(K\) | temperature {:,vertical}
   \(z(i)\) | altitude | \(m\) | altitude {:,vertical}
   \(z_{TP}\) | tropopause altitude | \(m\) | tropopause_altitude {:}

   The pattern : for the dimensions can represent {latitude,longitude}, {time}, {time,latitude,longitude}, or no dimensions at all.

   The tropopause altitude \(z_{TP}\) equals the altitude \(z(i)\) where \(i\) is the minimum level that satisfies:

   \begin{eqnarray} & 1 < i < N & \wedge \\ & 5000 <= p(i) <= 50000 & \wedge \\ & \frac{T(i-1)-T(i)}{z(i)-z(i-1)} > 0.002 \wedge \frac{T(i)-T(i+1)}{z(i+1)-z(i)} <= 0.002 & \wedge \\ & \frac{\sum_{j, i < j < N \wedge z(j+1)-z(i) <= 2000} \frac{T(j)-T(j+1)}{z(j+1)-z(j)}}{\sum_{j, i < j < N \wedge z(j+1)-z(i) <= 2000}{1}} <= 0.002 & \end{eqnarray}

   If no such \(i\) can be found then \(z_{TP}\) is set to NaN.