Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions act/retrievals/sonde.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,28 @@ def calculate_stability_indicies(
ds['parcel_temperature'] = t_profile.magnitude
ds['parcel_temperature'].attrs['units'] = t_profile.units

# Calculate CAPE, CIN, LCL
sbcape, sbcin = mpcalc.surface_based_cape_cin(p_sorted, t_sorted, td_sorted)
# Calculate SBCAPE, SBCIN
try:
sbcape, sbcin = mpcalc.surface_based_cape_cin(p_sorted, t_sorted, td_sorted)
except IndexError:
sbcape = units.Quantity(np.nan, 'J/kg')
sbcin = units.Quantity(np.nan, 'J/kg')

# Calculate lifting condensation level
lcl = mpcalc.lcl(p_sorted[0], t_sorted[0], td_sorted[0])

# Calculate level of free convection
try:
lfc = mpcalc.lfc(p_sorted[0], t_sorted[0], td_sorted[0])
except IndexError:
lfc = np.nan * p_sorted.units

mucape, mucin = mpcalc.most_unstable_cape_cin(p_sorted, t_sorted, td_sorted)
# Calculate MUCAPE, MUCIN
try:
mucape, mucin = mpcalc.most_unstable_cape_cin(p_sorted, t_sorted, td_sorted)
except IndexError:
mucape = units.Quantity(np.nan, 'J/kg')
mucin = units.Quantity(np.nan, 'J/kg')

where_500 = np.argmin(np.abs(p_sorted - 500 * units.hPa))
li = t_sorted[where_500] - t_profile[where_500]
Expand Down
2 changes: 1 addition & 1 deletion tests/retrievals/test_sonde.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_get_stability_indices():
rtol=1e-5,
)
assert sonde_ds['parcel_temperature'].attrs['units'] == 'kelvin'
np.testing.assert_almost_equal(sonde_ds['surface_based_cape'], 0.98, decimal=2)
np.testing.assert_almost_equal(sonde_ds['surface_based_cape'], 0.96, decimal=2)
assert sonde_ds['surface_based_cape'].attrs['units'] == 'J/kg'
assert sonde_ds['surface_based_cape'].attrs['long_name'] == 'Surface-based CAPE'
np.testing.assert_almost_equal(sonde_ds['surface_based_cin'], 0.000, decimal=3)
Expand Down
Loading