10
10
import scipy .optimize as so
11
11
import xarray as xr
12
12
13
+ from .basic import height_to_pressure_std
13
14
from .tools import (_greater_or_close , _less_or_close , _remove_nans , find_bounding_indices ,
14
15
find_intersections , first_derivative , get_layer )
15
16
from .. import constants as mpconsts
@@ -2337,8 +2338,8 @@ def mixed_layer_cape_cin(pressure, temperature, dewpoint, **kwargs):
2337
2338
of a given upper air profile and mixed-layer parcel path. CIN is integrated between the
2338
2339
surface and LFC, CAPE is integrated between the LFC and EL (or top of sounding).
2339
2340
Intersection points of the measured temperature profile and parcel profile are
2340
- logarithmically interpolated. Kwargs for `mixed_parcel` can be provided, such as `depth`.
2341
- Default mixed-layer depth is 100 hPa.
2341
+ logarithmically interpolated. Kwargs for `mixed_parcel` can be provided, such as `depth`
2342
+ and `height`. Default mixed-layer depth is 100 hPa.
2342
2343
2343
2344
Parameters
2344
2345
----------
@@ -2352,7 +2353,9 @@ def mixed_layer_cape_cin(pressure, temperature, dewpoint, **kwargs):
2352
2353
Dewpoint profile
2353
2354
2354
2355
kwargs
2355
- Additional keyword arguments to pass to `mixed_parcel`
2356
+ Additional keyword arguments to pass to `mixed_parcel`. If `depth` is passed with units
2357
+ of height without also passing a `height` profile, `depth` will be converted to a
2358
+ pressure with `height_to_pressure_std`.
2356
2359
2357
2360
Returns
2358
2361
-------
@@ -2372,14 +2375,29 @@ def mixed_layer_cape_cin(pressure, temperature, dewpoint, **kwargs):
2372
2375
Quantities even when given xarray DataArray profiles.
2373
2376
2374
2377
"""
2378
+ height = kwargs .get ('height' )
2375
2379
depth = kwargs .get ('depth' , units .Quantity (100 , 'hPa' ))
2380
+
2381
+ # Convert depth from a height to a presure if needed
2382
+ if depth .check ('[length]' ) and height is None :
2383
+ depth = height_to_pressure_std (units .Quantity (0 , 'm' )) - height_to_pressure_std (depth )
2384
+ kwargs ['depth' ] = depth
2385
+ warnings .warn ('Depth of the mixed layer was given as a height, but no height profile '
2386
+ 'was provided. Depth of mixed layer was converted to '
2387
+ + str (round (depth , 2 )) + ' using US standard atmosphere.' )
2388
+
2376
2389
parcel_pressure , parcel_temp , parcel_dewpoint = mixed_parcel (pressure , temperature ,
2377
2390
dewpoint , ** kwargs )
2378
2391
2379
2392
# Remove values below top of mixed layer and add in the mixed layer values
2380
- pressure_prof = pressure [pressure < (pressure [0 ] - depth )]
2381
- temp_prof = temperature [pressure < (pressure [0 ] - depth )]
2382
- dew_prof = dewpoint [pressure < (pressure [0 ] - depth )]
2393
+ if depth .check ('[length]' ): # Depth is given as a height
2394
+ pressure_prof = pressure [height > (depth - height [0 ])]
2395
+ temp_prof = temperature [height > (depth - height [0 ])]
2396
+ dew_prof = dewpoint [height > (depth - height [0 ])]
2397
+ else : # Depth is given as a pressure
2398
+ pressure_prof = pressure [pressure < (pressure [0 ] - depth )]
2399
+ temp_prof = temperature [pressure < (pressure [0 ] - depth )]
2400
+ dew_prof = dewpoint [pressure < (pressure [0 ] - depth )]
2383
2401
pressure_prof = concatenate ([parcel_pressure , pressure_prof ])
2384
2402
temp_prof = concatenate ([parcel_temp , temp_prof ])
2385
2403
dew_prof = concatenate ([parcel_dewpoint , dew_prof ])
0 commit comments