@ -322,6 +322,7 @@ def set_wind_metadata(copy_varname, name, description,
return func_wrapper
return func_wrapper
def set_cape_metadata ( is2d ) :
def set_cape_metadata ( is2d ) :
""" A decorator that sets the metadata for a wrapped CAPE function ' s output.
""" A decorator that sets the metadata for a wrapped CAPE function ' s output.
@ -468,14 +469,22 @@ def set_cloudfrac_metadata():
return wrapped ( * args , * * kwargs )
return wrapped ( * args , * * kwargs )
argvars = from_args ( wrapped , ( " wrfin " , " timeidx " , " method " , " squeeze " ,
argvars = from_args ( wrapped , ( " wrfin " , " timeidx " , " method " , " squeeze " ,
" cache " , " _key " ) ,
" cache " , " _key " , " vert_type " ,
* args , * * kwargs )
" low_thresh " , " mid_thresh " ,
" high_thresh " , " missing " ) ,
* args , * * kwargs )
wrfin = argvars [ " wrfin " ]
wrfin = argvars [ " wrfin " ]
timeidx = argvars [ " timeidx " ]
timeidx = argvars [ " timeidx " ]
method = argvars [ " method " ]
method = argvars [ " method " ]
squeeze = argvars [ " squeeze " ]
squeeze = argvars [ " squeeze " ]
cache = argvars [ " cache " ]
cache = argvars [ " cache " ]
_key = argvars [ " _key " ]
_key = argvars [ " _key " ]
vert_type = argvars [ " vert_type " ]
low_thresh = argvars [ " low_thresh " ]
mid_thresh = argvars [ " mid_thresh " ]
high_thresh = argvars [ " high_thresh " ]
missing = argvars [ " missing " ]
if cache is None :
if cache is None :
cache = { }
cache = { }
@ -499,6 +508,20 @@ def set_cloudfrac_metadata():
outattrs . update ( copy_var . attrs )
outattrs . update ( copy_var . attrs )
outdimnames = [ None ] * result . ndim
outdimnames = [ None ] * result . ndim
# For printing units
unitstr = ( " Pa " if vert_type . lower ( ) == " pres "
or vert_type . lower ( ) == " pressure " else " m " )
# For setting the threholds in metdata
if vert_type . lower ( ) == " pres " or vert_type . lower ( ) == " pressure " :
_low_thresh = 97000. if low_thresh is None else low_thresh
_mid_thresh = 80000. if mid_thresh is None else mid_thresh
_high_thresh = 45000. if high_thresh is None else high_thresh
elif vert_type . lower ( ) == " height_msl " or " height_agl " :
_low_thresh = 300. if low_thresh is None else low_thresh
_mid_thresh = 2000. if mid_thresh is None else mid_thresh
_high_thresh = 6000. if high_thresh is None else high_thresh
# Right dims
# Right dims
outdimnames [ - 2 : ] = copy_var . dims [ - 2 : ]
outdimnames [ - 2 : ] = copy_var . dims [ - 2 : ]
# Left dims
# Left dims
@ -507,6 +530,11 @@ def set_cloudfrac_metadata():
outattrs [ " description " ] = " low, mid, high clouds "
outattrs [ " description " ] = " low, mid, high clouds "
outattrs [ " MemoryOrder " ] = " XY "
outattrs [ " MemoryOrder " ] = " XY "
outattrs [ " units " ] = " % "
outattrs [ " units " ] = " % "
outattrs [ " low_thresh " ] = " {} {} " . format ( _low_thresh , unitstr )
outattrs [ " mid_thresh " ] = " {} {} " . format ( _mid_thresh , unitstr )
outattrs [ " high_thresh " ] = " {} {} " . format ( _high_thresh , unitstr )
outattrs [ " _FillValue " ] = missing
outattrs [ " missing_value " ] = missing
outname = " cloudfrac "
outname = " cloudfrac "
# xarray doesn't line up coordinate dimensions based on
# xarray doesn't line up coordinate dimensions based on
@ -529,6 +557,7 @@ def set_cloudfrac_metadata():
return func_wrapper
return func_wrapper
def set_latlon_metadata ( xy = False ) :
def set_latlon_metadata ( xy = False ) :
""" A decorator that sets the metadata for a wrapped latlon function ' s
""" A decorator that sets the metadata for a wrapped latlon function ' s
output .
output .
@ -614,6 +643,7 @@ def set_latlon_metadata(xy=False):
return func_wrapper
return func_wrapper
def set_height_metadata ( geopt = False ) :
def set_height_metadata ( geopt = False ) :
""" A decorator that sets the metadata for a wrapped height function ' s
""" A decorator that sets the metadata for a wrapped height function ' s
output .
output .
@ -704,6 +734,7 @@ def set_height_metadata(geopt=False):
dims = outdimnames , coords = outcoords , attrs = outattrs )
dims = outdimnames , coords = outcoords , attrs = outattrs )
return func_wrapper
return func_wrapper
def _set_horiz_meta ( wrapped , instance , args , kwargs ) :
def _set_horiz_meta ( wrapped , instance , args , kwargs ) :
""" A decorator implementation that sets the metadata for a wrapped
""" A decorator implementation that sets the metadata for a wrapped
horizontal interpolation function .
horizontal interpolation function .
@ -799,6 +830,7 @@ def _set_horiz_meta(wrapped, instance, args, kwargs):
return DataArray ( result , name = outname , dims = outdimnames ,
return DataArray ( result , name = outname , dims = outdimnames ,
coords = outcoords , attrs = outattrs )
coords = outcoords , attrs = outattrs )
def _set_cross_meta ( wrapped , instance , args , kwargs ) :
def _set_cross_meta ( wrapped , instance , args , kwargs ) :
""" A decorator implementation that sets the metadata for a wrapped cross \
""" A decorator implementation that sets the metadata for a wrapped cross \
section interpolation function .
section interpolation function .
@ -1013,7 +1045,6 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
coords = outcoords , attrs = outattrs )
coords = outcoords , attrs = outattrs )
def _set_line_meta ( wrapped , instance , args , kwargs ) :
def _set_line_meta ( wrapped , instance , args , kwargs ) :
""" A decorator implementation that sets the metadata for a wrapped line
""" A decorator implementation that sets the metadata for a wrapped line
interpolation function .
interpolation function .
@ -1770,6 +1801,7 @@ def set_alg_metadata(alg_ndims, refvarname,
return func_wrapper
return func_wrapper
def set_smooth_metdata ( ) :
def set_smooth_metdata ( ) :
@wrapt . decorator
@wrapt . decorator
def func_wrapper ( wrapped , instance , args , kwargs ) :
def func_wrapper ( wrapped , instance , args , kwargs ) :
@ -1994,14 +2026,14 @@ def set_cape_alg_metadata(is2d, copyarg="pres_hpa"):
return func_wrapper
return func_wrapper
def set_cloudfrac_alg_metadata ( copyarg = " pres " ) :
def set_cloudfrac_alg_metadata ( copyarg = " vert " ) :
""" A decorator that sets the metadata for the wrapped raw cloud fraction
""" A decorator that sets the metadata for the wrapped raw cloud fraction
diagnostic function .
diagnostic function .
Args :
Args :
copyarg ( : obj : ` str ` ) : The wrapped function argument to use for
copyarg ( : obj : ` str ` ) : The wrapped function argument to use for
copying dimension names . Default is ' pres ' .
copying dimension names . Default is ' vert ' .
Returns :
Returns :
@ -2025,6 +2057,16 @@ def set_cloudfrac_alg_metadata(copyarg="pres"):
result = wrapped ( * args , * * kwargs )
result = wrapped ( * args , * * kwargs )
argvals = from_args ( wrapped , ( copyarg , " low_thresh " ,
" mid_thresh " , " high_thresh " ,
" missing " ) ,
* args , * * kwargs )
cp = argvals [ copyarg ]
low_thresh = argvals [ " low_thresh " ]
mid_thresh = argvals [ " mid_thresh " ]
high_thresh = argvals [ " high_thresh " ]
missing = argvals [ " missing " ]
# Default dimension names
# Default dimension names
outdims = [ " dim_ {} " . format ( i ) for i in py3range ( result . ndim ) ]
outdims = [ " dim_ {} " . format ( i ) for i in py3range ( result . ndim ) ]
@ -2034,15 +2076,17 @@ def set_cloudfrac_alg_metadata(copyarg="pres"):
outattrs [ " description " ] = " low, mid, high clouds "
outattrs [ " description " ] = " low, mid, high clouds "
outattrs [ " units " ] = " % "
outattrs [ " units " ] = " % "
outattrs [ " MemoryOrder " ] = " XY "
outattrs [ " MemoryOrder " ] = " XY "
outattrs [ " low_thresh " ] = low_thresh
outattrs [ " mid_thresh " ] = mid_thresh
outattrs [ " high_thresh " ] = high_thresh
outattrs [ " _FillValue " ] = missing
outattrs [ " missing_value " ] = missing
if isinstance ( cp , DataArray ) :
p = from_args ( wrapped , copyarg , * args , * * kwargs ) [ copyarg ]
if isinstance ( p , DataArray ) :
# Right dims
# Right dims
outdims [ - 2 : ] = p . dims [ - 2 : ]
outdims [ - 2 : ] = cp . dims [ - 2 : ]
# Left dims
# Left dims
outdims [ 1 : - 2 ] = p . dims [ 0 : - 3 ]
outdims [ 1 : - 2 ] = c p. dims [ 0 : - 3 ]
outcoords = { }
outcoords = { }