From 4060ef6fa5f1464b8557df1cfb09df994a3ae324 Mon Sep 17 00:00:00 2001 From: Leif Denby Date: Mon, 17 Aug 2020 14:14:54 +0100 Subject: [PATCH] fixes for black --- .../variables/boundary_layer/inversion_height.py | 7 +++++-- .../boundary_layer/mixed_layer_height.py | 4 +++- eurec4a_environment/variables/calc_density.py | 3 ++- tests/test_boundary_layer.py | 15 +++++++++------ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/eurec4a_environment/variables/boundary_layer/inversion_height.py b/eurec4a_environment/variables/boundary_layer/inversion_height.py index 8b4b7ae..2061668 100644 --- a/eurec4a_environment/variables/boundary_layer/inversion_height.py +++ b/eurec4a_environment/variables/boundary_layer/inversion_height.py @@ -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 ): @@ -11,7 +12,9 @@ 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: @@ -19,7 +22,7 @@ def find_inversion_height_grad_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" diff --git a/eurec4a_environment/variables/boundary_layer/mixed_layer_height.py b/eurec4a_environment/variables/boundary_layer/mixed_layer_height.py index 3ade6ff..3180755 100644 --- a/eurec4a_environment/variables/boundary_layer/mixed_layer_height.py +++ b/eurec4a_environment/variables/boundary_layer/mixed_layer_height.py @@ -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 """ diff --git a/eurec4a_environment/variables/calc_density.py b/eurec4a_environment/variables/calc_density.py index 353a819..ed743a1 100644 --- a/eurec4a_environment/variables/calc_density.py +++ b/eurec4a_environment/variables/calc_density.py @@ -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"): diff --git a/tests/test_boundary_layer.py b/tests/test_boundary_layer.py index bf21076..6d7a430 100644 --- a/tests/test_boundary_layer.py +++ b/tests/test_boundary_layer.py @@ -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