Skip to content

Commit 1de456c

Browse files
committed
add tests for mean sea level pressure
1 parent a4f68b1 commit 1de456c

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/metpy/calc/basic.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ def _check_radians(value, max_radians=2 * np.pi):
12051205

12061206

12071207
@exporter.export
1208-
@preprocess_xarray
1208+
@preprocess_and_wrap(wrap_like='pressure')
12091209
@check_units('[pressure]', '[temperature]', '[length]', '[pressure]')
12101210
def mean_sea_level_pressure(pressure, temperature, geopotential_height, vapor_pressure):
12111211
"""Reduce surface pressure to mean sea level.
@@ -1231,15 +1231,15 @@ def mean_sea_level_pressure(pressure, temperature, geopotential_height, vapor_pr
12311231
12321232
Notes
12331233
-----
1234-
This function is an implementation of the method used in [NWS1963]_, Ch. 7. The humidity correction term has been
1235-
fitted to be continuous and the local station correction has been ignored. See also [Pauley1998]_.
1234+
This function is an implementation of the method used in [NWS1963]_, Ch. 7. The humidity
1235+
correction term has been fitted to be continuous and the local station correction has been
1236+
ignored. See also [Pauley1998]_.
12361237
"""
12371238
# define function for empirical humidity correction
12381239
def humidity_correction(height):
1239-
"""
1240-
Calculate humidity correction term
1240+
"""Calculate humidity correction term.
12411241
1242-
Fitted from table of empirically derived values found in NWS Manual of Barometry, Ch. 7.
1242+
Fitted from table of empirically derived values found in NWS Manual of Barometry.
12431243
"""
12441244
const = np.array([5.04969979e-6, 1.30236277, 1.96926239e-1])
12451245
return (const[0] * (height.to('meter').m**const[1]) + const[2]) * units('degF / hPa')
@@ -1249,8 +1249,9 @@ def humidity_correction(height):
12491249
lapse_rate = 6.5 * units('kelvin / kilometer')
12501250

12511251
# calculate mean temperature for extrapolation
1252-
mean_temp = (temperature.to('kelvin') + ((lapse_rate * geopotential_height) / 2.).to('kelvin') +
1253-
(vapor_pressure * humidity_correction(geopotential_height)).to('kelvin'))
1252+
mean_temp = temperature.to('kelvin') + \
1253+
((lapse_rate * geopotential_height) / 2.).to('kelvin') + \
1254+
(vapor_pressure * humidity_correction(geopotential_height)).to('kelvin')
12541255

12551256
# calculate mslp from hypsometric equation
12561257
return pressure * np.exp(geopotential_height / (k * mean_temp))

tests/calc/test_basic.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
altimeter_to_sea_level_pressure, altimeter_to_station_pressure,
1313
apparent_temperature, coriolis_parameter, geopotential_to_height,
1414
heat_index, height_to_geopotential, height_to_pressure_std,
15-
pressure_to_height_std, sigma_to_pressure, smooth_circular,
16-
smooth_gaussian, smooth_n_point, smooth_rectangular, smooth_window,
17-
wind_components, wind_direction, wind_speed, windchill)
15+
mean_sea_level_pressure, pressure_to_height_std, sigma_to_pressure,
16+
smooth_circular, smooth_gaussian, smooth_n_point, smooth_rectangular,
17+
smooth_window, wind_components, wind_direction, wind_speed, windchill)
1818
from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal)
1919
from metpy.units import units
2020

@@ -796,3 +796,23 @@ def test_altimeter_to_sea_level_pressure_hpa():
796796
res = altimeter_to_sea_level_pressure(altim, elev, temp)
797797
truth = 1016.246 * units.hectopascal
798798
assert_almost_equal(res, truth, 3)
799+
800+
801+
def test_mean_sea_level_pressure():
802+
"""Test mean sea level pressure."""
803+
p = 1013.25 * units('hPa')
804+
T = 20. * units.degC
805+
es = 3 * units('hPa')
806+
z = 0. * units.meter
807+
p0 = mean_sea_level_pressure(p, T, z, es)
808+
assert_almost_equal(p, p0, 7)
809+
810+
811+
def test_mean_sea_level_pressure_1000m():
812+
"""Test mean sea level pressure with height above sea level."""
813+
p = 920. * units('hPa')
814+
T = 20. * units.degC
815+
es = 1 * units('hPa')
816+
z = 3270. * units.feet
817+
p0 = mean_sea_level_pressure(p, T, z, es)
818+
assert_almost_equal(1011.9606088890467 * units('hPa'), p0, 7)

0 commit comments

Comments
 (0)