Skip to content

Commit

Permalink
fixes for black
Browse files Browse the repository at this point in the history
  • Loading branch information
leifdenby committed Aug 17, 2020
1 parent 91036a9 commit 4060ef6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import xarray as xr


def find_inversion_height_grad_RH(
ds, altitude="alt", rh="rh", smoothing_win_size=None, z_min=1500, z_max=4000.0
):
Expand All @@ -11,15 +12,17 @@ def find_inversion_height_grad_RH(
if smoothing_win_size:
RH = (
ds_lowertroposhere[rh]
.rolling(alt=smoothing_win_size, min_periods=smoothing_win_size, center=True)
.rolling(
alt=smoothing_win_size, min_periods=smoothing_win_size, center=True
)
.mean(skipna=True)
)
else:
RH = ds_lowertroposhere[rh]

RHg = RH.differentiate(coord=altitude)
ix = RHg.argmin(dim=altitude, skipna=True)
da_z = RHg.isel({ altitude: ix }).alt
da_z = RHg.isel({altitude: ix}).alt
da_z.attrs["long_name"] = "inversion layer height (from RH gradient)"
da_z.attrs["units"] = "m"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from ... import nomenclature as nom


def calc_peak_RH(ds, altitude=nom.ALTITUDE, rh=nom.RELATIVE_HUMIDITY, z_min=200.0, z_max=900.0):
def calc_peak_RH(
ds, altitude=nom.ALTITUDE, rh=nom.RELATIVE_HUMIDITY, z_min=200.0, z_max=900.0
):
"""
Calculate height at maximum relative humidity values
"""
Expand Down
3 changes: 2 additions & 1 deletion eurec4a_environment/variables/calc_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import numpy as np
import xarray as xr
from ..constants import Rd, Rv, eps
#from constants import Rd, Rv, eps

# from constants import Rd, Rv, eps


def calc_density(ds, pres="p", temp="T", specific_humidity="q", altitude="height"):
Expand Down
15 changes: 9 additions & 6 deletions tests/test_boundary_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ def test_LCL_Bolton(ds_isentropic_test_profiles):
def test_mixed_layer_height_RHmax(ds_isentropic_test_profiles):
ds = ds_isentropic_test_profiles
# set the RH profile so we know where the peak should be
z0 = 600.
z0 = 600.0
z = ds.alt
ds['rh'] = 1.0 - np.maximum(np.abs(z0 - z), 0) / z0
ds["rh"] = 1.0 - np.maximum(np.abs(z0 - z), 0) / z0
da_rh_peak = boundary_layer.mixed_layer_height.calc_peak_RH(
ds=ds, altitude="alt", rh="rh"
)
assert np.allclose(da_rh_peak, z0)


def test_inversion_height_gradient_RH(ds_isentropic_test_profiles):
ds = ds_isentropic_test_profiles.copy()
z_INV = 2000.
ds['RH'] = ds.RH.where(ds.alt < z_INV, other=0.5)
da_inv = boundary_layer.inversion_height.find_inversion_height_grad_RH(ds=ds, rh = 'RH')
assert np.allclose(da_inv,z_INV, atol=20) ## within 20m
z_INV = 2000.0
ds["RH"] = ds.RH.where(ds.alt < z_INV, other=0.5)
da_inv = boundary_layer.inversion_height.find_inversion_height_grad_RH(
ds=ds, rh="RH"
)
assert np.allclose(da_inv, z_INV, atol=20) ## within 20m

0 comments on commit 4060ef6

Please sign in to comment.