Skip to content

Commit

Permalink
A few consistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Marilyth committed Jul 30, 2021
1 parent 8de2a0e commit e159e55
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mslib/_tests/test_thermolib.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


def test_flightlevel2pressure2flightlevel():
fs = np.arange(1, 71000, 1000.) / 30.48 * units.hft
fs = (np.arange(1, 71000, 1000.) * units.m).to(units.hft)
ps = tl.flightlevel2pressure(fs)
fs_p = tl.pressure2flightlevel(ps).magnitude
assert fs.magnitude == pytest.approx(fs_p)
Expand Down
4 changes: 2 additions & 2 deletions mslib/msui/mpl_qtwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,8 @@ def _determine_ticks_labels(self, typ):
ma_dist, mi_dist = 2, 0.5
major_heights = np.arange(0, top_km + 1, ma_dist)
minor_heights = np.arange(0, top_km + 1, mi_dist)
major_ticks = thermolib.flightlevel2pressure(major_heights * units.kilometer).magnitude
minor_ticks = thermolib.flightlevel2pressure(minor_heights * units.kilometer).magnitude
major_ticks = thermolib.flightlevel2pressure(major_heights * units.km).magnitude
minor_ticks = thermolib.flightlevel2pressure(minor_heights * units.km).magnitude
labels = major_heights
ylabel = "pressure altitude (km)"
elif typ == "flight level":
Expand Down
14 changes: 9 additions & 5 deletions mslib/thermolib.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def omega_to_w(omega, p, t):

# Values according to the 1976 U.S. Standard atmosphere [NOAA1976]_.
# List of tuples (height, temperature, pressure, temperature gradient)
standard_atmosphere = [
_STANDARD_ATMOSPHERE = [
(0 * units.km, 288.15 * units.K, 101325 * units.Pa, 0.0065 * units.K / units.m),
(11 * units.km, 216.65 * units.K, 22632.1 * units.Pa, 0 * units.K / units.m),
(20 * units.km, 216.65 * units.K, 5474.89 * units.Pa, -0.001 * units.K / units.m),
Expand All @@ -222,6 +222,7 @@ def omega_to_w(omega, p, t):
(51 * units.km, 270.65 * units.K, 66.9389 * units.Pa, 0.0028 * units.K / units.m),
(71 * units.km, 214.65 * units.K, 3.95642 * units.Pa, float("NaN") * units.K / units.m)
]
_HEIGHT, _TEMPERATURE, _PRESSURE, _TEMPERATURE_GRADIENT = 0, 1, 2, 3


@exporter.export
Expand Down Expand Up @@ -259,7 +260,8 @@ def flightlevel2pressure(height):
# Initialize the return array.
p = numpy.full_like(height, numpy.nan) * units.Pa

for i, ((z0, t0, p0, gamma), (z1, t1, p1, _)) in enumerate(zip(standard_atmosphere[:-1], standard_atmosphere[1:])):
for i, ((z0, t0, p0, gamma), (z1, t1, p1, _)) in enumerate(zip(_STANDARD_ATMOSPHERE[:-1],
_STANDARD_ATMOSPHERE[1:])):
indices = (height >= z0) & (height < z1)
if i == 0:
indices |= height < z0
Expand Down Expand Up @@ -310,8 +312,9 @@ def pressure2flightlevel(pressure):
# Initialize the return array.
z = numpy.full_like(pressure, numpy.nan) * units.hft

for i, ((z0, t0, p0, gamma), (z1, t1, p1, _)) in enumerate(zip(standard_atmosphere[:-1], standard_atmosphere[1:])):
p1 = standard_atmosphere[i + 1][-2]
for i, ((z0, t0, p0, gamma), (z1, t1, p1, _)) in enumerate(zip(_STANDARD_ATMOSPHERE[:-1],
_STANDARD_ATMOSPHERE[1:])):
p1 = _STANDARD_ATMOSPHERE[i + 1][_PRESSURE]
indices = (pressure > p1) & (pressure <= p0)
if i == 0:
indices |= (pressure >= p0)
Expand Down Expand Up @@ -343,7 +346,8 @@ def isa_temperature(height):
Returns:
temperature (K)
"""
for i, ((z0, t0, p0, gamma), (z1, t1, p1, _)) in enumerate(zip(standard_atmosphere[:-1], standard_atmosphere[1:])):
for i, ((z0, t0, p0, gamma), (z1, t1, p1, _)) in enumerate(zip(_STANDARD_ATMOSPHERE[:-1],
_STANDARD_ATMOSPHERE[1:])):
if ((i == 0) and (height < z0)) or (z0 <= height < z1):
return t0 - gamma * (height - z0)

Expand Down
2 changes: 1 addition & 1 deletion mslib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from mslib.thermolib import pressure2flightlevel
from PyQt5 import QtCore, QtWidgets

UR = pint.UnitRegistry()
UR = units
UR.define("PVU = 10^-6 m^2 s^-1 K kg^-1")
UR.define("degrees_north = degrees")
UR.define("degrees_south = -degrees")
Expand Down

0 comments on commit e159e55

Please sign in to comment.