altitude: A script for deriving pressure/temperature/altitude

```
usage: altitude [-h] [--height HEIGHT] [--temperature TEMPERATURE]
[--pressure PRESSURE]

optional arguments:
  -h, --help            show this help message and exit
  --height HEIGHT       Height above sea level in metres
  --temperature TEMPERATURE
                        Temperature in Celcius
  --pressure PRESSURE   Atmospheric pressure in Pascals
```

Example:

```
$ ./altitude --pressure 98708 --temperature 13.03
Temperature
        Height at 13.03C: 303.08m
        Pressure at 303.08m: 97748.79Pa

Pressure
        Height at 98708.00Pa: 220.71m
        Temperature at 220.71m: 13.57C
```

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Idc320c8d620fcd6f672d48e2f780af549e4f314e
diff --git a/amboar/obmc-scripts/altitude/altitude b/amboar/obmc-scripts/altitude/altitude
new file mode 100755
index 0000000..5500ea0
--- /dev/null
+++ b/amboar/obmc-scripts/altitude/altitude
@@ -0,0 +1,73 @@
+#!/usr/bin/python3
+
+# SPDX-License-Identifier: Apache-2.0
+# Copyright 2020 IBM Corp.
+
+# https://en.wikipedia.org/wiki/Barometric_formula
+
+from math import exp, log
+import sys
+import argparse
+
+Pb = 101325.00
+Tb = 288.15
+Lb = -0.0065
+hb = 0
+Rstar = 8.3144598
+g0 = 9.80665
+M = 0.0289644
+C0 = 273.15
+
+def P(h):
+    return Pb * exp((-g0 * M * (h - hb)) / (Rstar * Tb))
+
+def T(h):
+    return (h - hb) * Lb + Tb
+
+def Hp(p):
+    return (log(p / Pb) * (Rstar * Tb)) / (-g0 * M) + hb
+
+def Ht(t):
+    return ((t - Tb) / Lb) + hb
+
+def K(c):
+    return C0 + c
+
+def C(k):
+    return k - C0
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--height", type=float, default=None, help="Height above sea level in metres")
+    parser.add_argument("--temperature", type=float, default=None, help="Temperature in Celcius")
+    parser.add_argument("--pressure", type=float, default=None, help="Atmospheric pressure in Pascals")
+    args = parser.parse_args()
+    out = []
+    if args.height is not None:
+        local = []
+        local.append("Height")
+        p = P(args.height)
+        local.append("Pressure at {:.2f}m: {:.2f}Pa".format(args.height, p))
+        c = C(T(args.height))
+        local.append("Temperature at {:.2f}m: {:.2f}C".format(args.height, c))
+        out.append("\n\t".join(local))
+    if args.temperature is not None:
+        local = []
+        local.append("Temperature")
+        ht = Ht(K(args.temperature))
+        local.append("Height at {:.2f}C: {:.2f}m".format(args.temperature, ht))
+        p = P(ht)
+        local.append("Pressure at {:.2f}m: {:.2f}Pa".format(ht, p))
+        out.append("\n\t".join(local))
+    if args.pressure is not None:
+        local = []
+        local.append("Pressure")
+        hp = Hp(args.pressure)
+        local.append("Height at {:.2f}Pa: {:.2f}m".format(args.pressure, hp))
+        t = C(T(hp))
+        local.append("Temperature at {:.2f}m: {:.2f}C".format(hp, t))
+        out.append("\n\t".join(local))
+    print("\n\n".join(out))
+
+if __name__ == "__main__":
+    main()