Skip to content

Commit

Permalink
Merge pull request #1266 from dopplershift/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
dopplershift committed Jan 5, 2020
2 parents d364e99 + fde839f commit e56e12d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 26 deletions.
10 changes: 5 additions & 5 deletions examples/plots/upperair_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""
=========================================
Surface Analysis using Declarative Syntax
=========================================
===========================================
Upper Air Analysis using Declarative Syntax
===========================================
The MetPy declarative syntax allows for a simplified interface to creating common
meteorological analyses including surface observation plots.
meteorological analyses including upper air observation plots.
"""

########################################
Expand All @@ -25,7 +25,7 @@
#
# In this example, data is originally from the Iowa State Upper-air archive
# (https://mesonet.agron.iastate.edu/archive/raob/) available through a Siphon method.
# The data are pre-processed to attach latitude/lognitude locations for each RAOB site.
# The data are pre-processed to attach latitude/longitude locations for each RAOB site.

data = pd.read_csv(get_test_data('UPA_obs.csv', as_file_obj=False))

Expand Down
4 changes: 2 additions & 2 deletions src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,8 @@ def _parcel_profile_helper(pressure, temperature, dewpt):

# If the pressure profile doesn't make it to the lcl, we can stop here
if _greater_or_close(np.nanmin(pressure.m), press_lcl.m):
return (press_lower[:-1], press_lcl, np.array([]) * press_lower.units,
temp_lower[:-1], temp_lcl, np.array([]) * temp_lower.units)
return (press_lower[:-1], press_lcl, units.Quantity(np.array([]), press_lower.units),
temp_lower[:-1], temp_lcl, units.Quantity(np.array([]), temp_lower.units))

# Find moist pseudo-adiabatic profile starting at the LCL
press_upper = concatenate((press_lcl, pressure[pressure < press_lcl]))
Expand Down
6 changes: 4 additions & 2 deletions src/metpy/calc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,11 @@ def get_layer_heights(heights, depth, *args, bottom=None, interpolate=True, with
if interpolate:
# If we don't have the bottom or top requested, append them
if top not in heights_interp:
heights_interp = np.sort(np.append(heights_interp.m, top.m)) * heights.units
heights_interp = units.Quantity(np.sort(np.append(heights_interp.m, top.m)),
heights.units)
if bottom not in heights_interp:
heights_interp = np.sort(np.append(heights_interp.m, bottom.m)) * heights.units
heights_interp = units.Quantity(np.sort(np.append(heights_interp.m, bottom.m)),
heights.units)

ret.append(heights_interp)

Expand Down
15 changes: 8 additions & 7 deletions tests/calc/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def test_windchill_invalid():

wc = windchill(temp, speed)
# We don't care about the masked values
truth = np.ma.array([2.6230789, np.nan, np.nan, np.nan, np.nan, np.nan],
mask=[False, True, True, True, True, True]) * units.degF
truth = units.Quantity(np.ma.array([2.6230789, np.nan, np.nan, np.nan, np.nan, np.nan],
mask=[False, True, True, True, True, True]), units.degF)
assert_array_almost_equal(truth, wc)


Expand Down Expand Up @@ -219,7 +219,7 @@ def test_heat_index_invalid():
def test_heat_index_undefined_flag():
"""Test whether masking values can be disabled for heat index."""
temp = units.Quantity(np.ma.array([80, 88, 92, 79, 30, 81]), units.degF)
rh = np.ma.array([40, 39, 2, 70, 50, 39]) * units.percent
rh = units.Quantity(np.ma.array([40, 39, 2, 70, 50, 39]), units.percent)

hi = heat_index(temp, rh, mask_undefined=False)
mask = np.array([False] * 6)
Expand Down Expand Up @@ -248,7 +248,8 @@ def test_heat_index_vs_nws():
temp = units.Quantity(np.array([86, 111, 40, 96]), units.degF)
rh = np.ma.array([45, 27, 99, 60]) * units.percent
hi = heat_index(temp, rh)
truth = np.ma.array([87, 121, 40, 116], mask=[False, False, True, False]) * units.degF
truth = units.Quantity(np.ma.array([87, 121, 40, 116], mask=[False, False, True, False]),
units.degF)
assert_array_almost_equal(hi, truth, 0)


Expand Down Expand Up @@ -412,9 +413,9 @@ def test_apparent_temperature():
[10, 10, 10]]) * units.percent
wind = np.array([[5, 3, 3],
[10, 1, 10]]) * units.mph
truth = np.ma.array([[99.6777178, 86.3357671, 70],
[8.8140662, 20, 60]],
mask=[[False, False, True], [False, True, True]]) * units.degF
truth = units.Quantity(np.ma.array([[99.6777178, 86.3357671, 70], [8.8140662, 20, 60]],
mask=[[False, False, True], [False, True, True]]),
units.degF)
res = apparent_temperature(temperature, rel_humidity, wind)
assert_array_almost_equal(res, truth, 6)

Expand Down
11 changes: 4 additions & 7 deletions tests/calc/test_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,10 @@ def test_storm_relative_helicity_agl():
@check_and_silence_warning(FutureWarning)
def test_storm_relative_helicity_masked():
"""Test that srh does not return masked values."""
h = np.ma.array([20.72, 234.85, 456.69, 683.21])
u = np.ma.array([-2.32, -3.23, 0.736, 9.07])
v = np.ma.array([8.31, 13.57, 25.56, 30.55])
u = np.ma.array(np.zeros((4,)))
v = np.zeros_like(u)
pos, neg, com = storm_relative_helicity(units.knot * u, units.knot * v, units.meter * h,
depth=500 * units.meter,
h = units.Quantity(np.ma.array([20.72, 234.85, 456.69, 683.21]), units.meter)
u = units.Quantity(np.ma.array(np.zeros((4,))), units.knot)
v = units.Quantity(np.zeros_like(u), units.knot)
pos, neg, com = storm_relative_helicity(u, v, h, depth=500 * units.meter,
storm_u=15.77463015050421 * units('m/s'),
storm_v=21.179437759755647 * units('m/s'))

Expand Down
3 changes: 2 additions & 1 deletion tests/calc/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,8 @@ def test_isentropic_pressure_masked_column():
tmp[0, :] = 296.
tmp[1, :] = 292.
tmp[:, :, -1] = np.ma.masked
isentprs = isentropic_interpolation([296.] * units.kelvin, lev, tmp * units.kelvin)
tmp = units.Quantity(tmp, units.kelvin)
isentprs = isentropic_interpolation([296.] * units.kelvin, lev, tmp)
trueprs = np.ones((1, 5, 5)) * (1000. * units.hPa)
trueprs[:, :, -1] = np.nan
assert isentprs[0].shape == (1, 5, 5)
Expand Down
4 changes: 2 additions & 2 deletions tests/interpolate/test_one_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def test_interpolate_end_point():

def test_interpolate_masked_units():
"""Test interpolating with masked arrays with units."""
x = np.ma.array([1., 2., 3., 4.]) * units.m
y = np.ma.array([50., 60., 70., 80.]) * units.degC
x = units.Quantity(np.ma.array([1., 2., 3., 4.]), units.m)
y = units.Quantity(np.ma.array([50., 60., 70., 80.]), units.degC)
x_interp = np.array([250., 350.]) * units.cm
y_interp_truth = np.array([65., 75.]) * units.degC
y_interp = interpolate_1d(x_interp, x, y)
Expand Down

0 comments on commit e56e12d

Please sign in to comment.