Skip to content

Commit

Permalink
MNT: Change wrapping around binary operators
Browse files Browse the repository at this point in the history
Recommended by pep8 for new code, and I kinda prefer it, so went ahead
and adjusted.
  • Loading branch information
dopplershift committed Oct 10, 2018
1 parent e5c8642 commit 67c68e6
Show file tree
Hide file tree
Showing 20 changed files with 191 additions and 191 deletions.
5 changes: 2 additions & 3 deletions examples/isentropic_example.py
Expand Up @@ -186,9 +186,8 @@
regrid_shape=20, transform=ccrs.PlateCarree())

# Make some titles
ax.set_title('{:.0f} K Montgomery Streamfunction '.format(isentlevs[level].m) +
r'($10^{-2} m^2 s^{-2}$), ' +
'Wind (kt), Relative Humidity (percent)', loc='left')
ax.set_title('{:.0f} K Montgomery Streamfunction '.format(isentlevs[level].m)
+ r'($10^{-2} m^2 s^{-2}$), Wind (kt), Relative Humidity (percent)', loc='left')
add_timestamp(ax, times[0].dt, y=0.02, pretext='Valid: ', high_contrast=True)

fig.tight_layout()
Expand Down
38 changes: 21 additions & 17 deletions metpy/calc/basic.py
Expand Up @@ -139,9 +139,9 @@ def get_wind_speed(u, v):
return wind_speed(u, v)


get_wind_speed.__doc__ = (wind_speed.__doc__ +
'\n .. deprecated:: 0.9.0\n Function has been renamed to '
'`wind_speed` and will be removed from MetPy in 0.12.0.')
get_wind_speed.__doc__ = (wind_speed.__doc__
+ '\n .. deprecated:: 0.9.0\n Function has been renamed to'
' `wind_speed` and will be removed from MetPy in 0.12.0.')


@exporter.export
Expand All @@ -153,9 +153,9 @@ def get_wind_dir(u, v):
return wind_direction(u, v)


get_wind_dir.__doc__ = (wind_direction.__doc__ +
'\n .. deprecated:: 0.9.0\n Function has been renamed to '
'`wind_direction` and will be removed from MetPy in 0.12.0.')
get_wind_dir.__doc__ = (wind_direction.__doc__
+ '\n .. deprecated:: 0.9.0\n Function has been renamed to '
'`wind_direction` and will be removed from MetPy in 0.12.0.')


@exporter.export
Expand All @@ -167,10 +167,10 @@ def get_wind_components(u, v):
return wind_components(u, v)


get_wind_components.__doc__ = (wind_components.__doc__ +
'\n .. deprecated:: 0.9.0\n Function has been '
'renamed to `wind_components` and will be removed from MetPy '
'in 0.12.0.')
get_wind_components.__doc__ = (wind_components.__doc__
+ '\n .. deprecated:: 0.9.0\n Function has been '
'renamed to `wind_components` and will be removed from MetPy '
'in 0.12.0.')


@exporter.export
Expand Down Expand Up @@ -223,8 +223,8 @@ def windchill(temperature, speed, face_level_winds=False, mask_undefined=True):

temp_limit, speed_limit = 10. * units.degC, 3 * units.mph
speed_factor = speed.to('km/hr').magnitude ** 0.16
wcti = units.Quantity((0.6215 + 0.3965 * speed_factor) * temperature.to('degC').magnitude -
11.37 * speed_factor + 13.12, units.degC).to(temperature.units)
wcti = units.Quantity((0.6215 + 0.3965 * speed_factor) * temperature.to('degC').magnitude
- 11.37 * speed_factor + 13.12, units.degC).to(temperature.units)

# See if we need to mask any undefined values
if mask_undefined:
Expand Down Expand Up @@ -275,11 +275,15 @@ def heat_index(temperature, rh, mask_undefined=True):
delta2 = delta * delta

# Calculate the Heat Index -- constants converted for RH in [0, 1]
hi = (-42.379 * units.degF + 2.04901523 * delta +
1014.333127 * units.delta_degF * rh - 22.475541 * delta * rh -
6.83783e-3 / units.delta_degF * delta2 - 5.481717e2 * units.delta_degF * rh2 +
1.22874e-1 / units.delta_degF * delta2 * rh + 8.5282 * delta * rh2 -
1.99e-2 / units.delta_degF * delta2 * rh2)
hi = (-42.379 * units.degF
+ 2.04901523 * delta
+ 1014.333127 * units.delta_degF * rh
- 22.475541 * delta * rh
- 6.83783e-3 / units.delta_degF * delta2
- 5.481717e2 * units.delta_degF * rh2
+ 1.22874e-1 / units.delta_degF * delta2 * rh
+ 8.5282 * delta * rh2
- 1.99e-2 / units.delta_degF * delta2 * rh2)

# See if we need to mask any undefined values
if mask_undefined:
Expand Down
8 changes: 4 additions & 4 deletions metpy/calc/cross_sections.py
Expand Up @@ -33,8 +33,8 @@ def distances_from_cross_section(cross):
A tuple of the x and y distances as DataArrays
"""
if (CFConventionHandler.check_axis(cross.metpy.x, 'lon') and
CFConventionHandler.check_axis(cross.metpy.y, 'lat')):
if (CFConventionHandler.check_axis(cross.metpy.x, 'lon')
and CFConventionHandler.check_axis(cross.metpy.y, 'lat')):
# Use pyproj to obtain x and y distances
from pyproj import Geod

Expand All @@ -53,8 +53,8 @@ def distances_from_cross_section(cross):
x = xr.DataArray(x, coords=lon.coords, dims=lon.dims, attrs={'units': 'meters'})
y = xr.DataArray(y, coords=lat.coords, dims=lat.dims, attrs={'units': 'meters'})

elif (CFConventionHandler.check_axis(cross.metpy.x, 'x') and
CFConventionHandler.check_axis(cross.metpy.y, 'y')):
elif (CFConventionHandler.check_axis(cross.metpy.x, 'x')
and CFConventionHandler.check_axis(cross.metpy.y, 'y')):

# Simply return what we have
x = cross.metpy.x
Expand Down
29 changes: 14 additions & 15 deletions metpy/calc/indices.py
Expand Up @@ -59,8 +59,8 @@ def precipitable_water(dewpt, pressure, bottom=None, top=None):
w = mixing_ratio(saturation_vapor_pressure(dewpt_layer), pres_layer)

# Since pressure is in decreasing order, pw will be the opposite sign of that expected.
pw = -1. * (np.trapz(w.magnitude, pres_layer.magnitude) * (w.units * pres_layer.units) /
(mpconsts.g * mpconsts.rho_l))
pw = -1. * (np.trapz(w.magnitude, pres_layer.magnitude) * (w.units * pres_layer.units)
/ (mpconsts.g * mpconsts.rho_l))
return pw.to('millimeters')


Expand Down Expand Up @@ -155,8 +155,7 @@ def bunkers_storm_motion(pressure, u, v, heights):
# mean wind from 5.5-6km
wind_5500m = concatenate(mean_pressure_weighted(pressure, u, v, heights=heights,
depth=500 * units('meter'),
bottom=heights[0] +
5500 * units('meter')))
bottom=heights[0] + 5500 * units('meter')))

# Calculate the shear vector from sfc-500m to 5.5-6km
shear = wind_5500m - wind_500m
Expand Down Expand Up @@ -255,9 +254,9 @@ def supercell_composite(mucape, effective_storm_helicity, effective_shear):
effective_shear[effective_shear < 10 * units('m/s')] = 0 * units('m/s')
effective_shear = effective_shear / (20 * units('m/s'))

return ((mucape / (1000 * units('J/kg'))) *
(effective_storm_helicity / (50 * units('m^2/s^2'))) *
effective_shear).to('dimensionless')
return ((mucape / (1000 * units('J/kg')))
* (effective_storm_helicity / (50 * units('m^2/s^2')))
* effective_shear).to('dimensionless')


@exporter.export
Expand Down Expand Up @@ -300,18 +299,18 @@ def significant_tornado(sbcape, surface_based_lcl_height, storm_helicity_1km, sh
"""
surface_based_lcl_height = np.clip(atleast_1d(surface_based_lcl_height),
1000 * units('meter'), 2000 * units('meter'))
surface_based_lcl_height[surface_based_lcl_height >
2000 * units('meter')] = 0 * units('meter')
surface_based_lcl_height = ((2000. * units('meter') - surface_based_lcl_height) /
(1000. * units('meter')))
1000 * units.m, 2000 * units.m)
surface_based_lcl_height[surface_based_lcl_height > 2000 * units.m] = 0 * units.m
surface_based_lcl_height = ((2000. * units.m - surface_based_lcl_height)
/ (1000. * units.m))
shear_6km = np.clip(atleast_1d(shear_6km), None, 30 * units('m/s'))
shear_6km[shear_6km < 12.5 * units('m/s')] = 0 * units('m/s')
shear_6km /= 20 * units('m/s')

return ((sbcape / (1500. * units('J/kg'))) *
surface_based_lcl_height *
(storm_helicity_1km / (150. * units('m^2/s^2'))) * shear_6km)
return ((sbcape / (1500. * units('J/kg')))
* surface_based_lcl_height
* (storm_helicity_1km / (150. * units('m^2/s^2')))
* shear_6km)


@exporter.export
Expand Down
8 changes: 4 additions & 4 deletions metpy/calc/kinematics.py
Expand Up @@ -568,8 +568,8 @@ def storm_relative_helicity(u, v, heights, depth, bottom=0 * units.m,
storm_relative_u = u - storm_u
storm_relative_v = v - storm_v

int_layers = (storm_relative_u[1:] * storm_relative_v[:-1] -
storm_relative_u[:-1] * storm_relative_v[1:])
int_layers = (storm_relative_u[1:] * storm_relative_v[:-1]
- storm_relative_u[:-1] * storm_relative_v[1:])

# Need to manually check for masked value because sum() on masked array with non-default
# mask will return a masked value rather than 0. See numpy/numpy#11736
Expand Down Expand Up @@ -680,8 +680,8 @@ def potential_vorticity_baroclinic(potential_temperature, pressure, u, v, dx, dy
# Get the middle layer stability derivative (index 1)
slices = [slice(None)] * stability.ndim
slices[axis] = 1
return (-1 * avor * mpconsts.g * stability[slices]).to(units.kelvin * units.meter**2 /
(units.second * units.kilogram))
return (-1 * avor * mpconsts.g * stability[slices]).to(units.kelvin * units.meter**2
/ (units.second * units.kilogram))


@exporter.export
Expand Down
4 changes: 2 additions & 2 deletions metpy/calc/tests/test_calc_tools.py
Expand Up @@ -510,8 +510,8 @@ def test_lat_lon_grid_deltas_extra_dimensions():
[187797.3216, 187797.3216, 187797.3216]]]]) * units.meter
dy_truth = (np.array([[[[277987.1857, 277987.1857, 277987.1857, 277987.1857],
[277987.1857, 277987.1857, 277987.1857, 277987.1857],
[277987.1857, 277987.1857, 277987.1857, 277987.1857]]]]) *
units.meter)
[277987.1857, 277987.1857, 277987.1857, 277987.1857]]]])
* units.meter)
dx, dy = lat_lon_grid_deltas(lon, lat)
assert_almost_equal(dx, dx_truth, 4)
assert_almost_equal(dy, dy_truth, 4)
Expand Down
28 changes: 14 additions & 14 deletions metpy/calc/tests/test_kinematics.py
Expand Up @@ -522,8 +522,8 @@ def test_potential_vorticity_baroclinic_unity_axis0(pv_data):

vort_difference = pvor - (abs_vorticity * g * (-1 * (units.kelvin / units.hPa)))

true_vort = np.zeros_like(u) * (units.kelvin * units.meter**2 /
(units.second * units.kilogram))
true_vort = np.zeros_like(u) * (units.kelvin * units.meter**2
/ (units.second * units.kilogram))

assert_almost_equal(vort_difference, true_vort, 10)

Expand Down Expand Up @@ -556,8 +556,8 @@ def test_potential_vorticity_baroclinic_unity_axis2(pv_data):

vort_difference = pvor - (abs_vorticity * g * (-1 * (units.kelvin / units.hPa)))

true_vort = np.zeros_like(u) * (units.kelvin * units.meter ** 2 /
(units.second * units.kilogram))
true_vort = np.zeros_like(u) * (units.kelvin * units.meter ** 2
/ (units.second * units.kilogram))

assert_almost_equal(vort_difference, true_vort, 10)

Expand Down Expand Up @@ -589,8 +589,8 @@ def test_potential_vorticity_baroclinic_non_unity_derivative(pv_data):

vort_difference = pvor - (abs_vorticity * g * (-100 * (units.kelvin / units.hPa)))

true_vort = np.zeros_like(u) * (units.kelvin * units.meter ** 2 /
(units.second * units.kilogram))
true_vort = np.zeros_like(u) * (units.kelvin * units.meter ** 2
/ (units.second * units.kilogram))

assert_almost_equal(vort_difference, true_vort, 10)

Expand Down Expand Up @@ -915,13 +915,13 @@ def test_q_vector_without_static_stability(q_vector_data):
q1_truth = (np.array([[-2.7454089e-14, -3.0194267e-13, -3.0194267e-13, -2.7454089e-14],
[-1.8952185e-13, -2.2269905e-14, -2.2269905e-14, -1.8952185e-13],
[-1.9918390e-13, -2.3370829e-14, -2.3370829e-14, -1.9918390e-13],
[-5.6160772e-14, -3.5145951e-13, -3.5145951e-13, -5.6160772e-14]]) *
units('m^2 kg^-1 s^-1'))
[-5.6160772e-14, -3.5145951e-13, -3.5145951e-13, -5.6160772e-14]])
* units('m^2 kg^-1 s^-1'))
q2_truth = (np.array([[-4.4976059e-14, -4.3582378e-13, 4.3582378e-13, 4.4976059e-14],
[-3.0124244e-13, -3.5724617e-14, 3.5724617e-14, 3.0124244e-13],
[3.1216232e-13, 3.6662900e-14, -3.6662900e-14, -3.1216232e-13],
[8.6038280e-14, 4.6968342e-13, -4.6968342e-13, -8.6038280e-14]]) *
units('m^2 kg^-1 s^-1'))
[8.6038280e-14, 4.6968342e-13, -4.6968342e-13, -8.6038280e-14]])
* units('m^2 kg^-1 s^-1'))

assert_almost_equal(q1, q1_truth, 20)
assert_almost_equal(q2, q2_truth, 20)
Expand All @@ -939,13 +939,13 @@ def test_q_vector_with_static_stability(q_vector_data):
q1_truth = (np.array([[-1.4158140e-08, -1.6197987e-07, -1.6875014e-07, -1.6010616e-08],
[-9.3971386e-08, -1.1252476e-08, -1.1252476e-08, -9.7617234e-08],
[-1.0785670e-07, -1.2403513e-08, -1.2403513e-08, -1.0364793e-07],
[-2.9186946e-08, -1.7577703e-07, -1.6937879e-07, -2.6112047e-08]]) *
units('kg m^-2 s^-3'))
[-2.9186946e-08, -1.7577703e-07, -1.6937879e-07, -2.6112047e-08]])
* units('kg m^-2 s^-3'))
q2_truth = (np.array([[-2.3194263e-08, -2.3380160e-07, 2.4357380e-07, 2.6229040e-08],
[-1.4936626e-07, -1.8050836e-08, 1.8050836e-08, 1.5516129e-07],
[1.6903373e-07, 1.9457964e-08, -1.9457964e-08, -1.6243771e-07],
[4.4714390e-08, 2.3490489e-07, -2.2635441e-07, -4.0003646e-08]]) *
units('kg m^-2 s^-3'))
[4.4714390e-08, 2.3490489e-07, -2.2635441e-07, -4.0003646e-08]])
* units('kg m^-2 s^-3'))

assert_almost_equal(q1, q1_truth, 14)
assert_almost_equal(q2, q2_truth, 14)
Expand Down
4 changes: 2 additions & 2 deletions metpy/calc/tests/test_thermo.py
Expand Up @@ -958,8 +958,8 @@ def test_mixing_ratio_from_rh_dimensions():
p = 1000. * units.mbar
temperature = 0. * units.degC
rh = 100. * units.percent
assert (str(mixing_ratio_from_relative_humidity(rh, temperature, p).units) ==
'dimensionless')
assert (str(mixing_ratio_from_relative_humidity(rh, temperature, p).units)
== 'dimensionless')


@pytest.fixture
Expand Down

0 comments on commit 67c68e6

Please sign in to comment.