@ -112,7 +112,6 @@ def copy_and_set_metadata(copy_varname=None, delete_attrs=None, name=None,
@@ -112,7 +112,6 @@ def copy_and_set_metadata(copy_varname=None, delete_attrs=None, name=None,
var_to_copy = None if cache is None else cache . get ( _copy_varname ,
None )
if var_to_copy is None :
var_to_copy = extract_vars ( wrfin , timeidx , ( _copy_varname , ) ,
method , squeeze , cache ,
@ -155,7 +154,6 @@ def copy_and_set_metadata(copy_varname=None, delete_attrs=None, name=None,
@@ -155,7 +154,6 @@ def copy_and_set_metadata(copy_varname=None, delete_attrs=None, name=None,
except KeyError :
pass
if name is not None :
outname = name
@ -277,10 +275,8 @@ def set_wind_metadata(copy_varname, name, description,
@@ -277,10 +275,8 @@ def set_wind_metadata(copy_varname, name, description,
outattrs = OrderedDict ( )
outdimnames = list ( copy_var . dims )
#outcoords.update(copy_var.coords)
outattrs . update ( copy_var . attrs )
if wind_ncvar :
outcoords . update ( copy_var . coords )
elif not wspd_wdir :
@ -414,7 +410,6 @@ def set_cape_metadata(is2d):
@@ -414,7 +410,6 @@ def set_cape_metadata(is2d):
outattrs [ " _FillValue " ] = missing
outattrs [ " missing_value " ] = missing
# xarray doesn't line up coordinate dimensions based on
# names, it just remembers the index it originally mapped to.
# So, need to rebuild the XLAT, XLONG, coordinates again since the
@ -433,7 +428,6 @@ def set_cape_metadata(is2d):
@@ -433,7 +428,6 @@ def set_cape_metadata(is2d):
else :
outcoords [ " cape_cin " ] = [ " cape " , " cin " ]
return DataArray ( result , name = outname , coords = outcoords ,
dims = outdimnames , attrs = outattrs )
@ -632,8 +626,8 @@ def set_latlon_metadata(xy=False):
@@ -632,8 +626,8 @@ def set_latlon_metadata(xy=False):
for x in zip ( arr1 , arr2 ) ] )
coords [ dimnames [ 0 ] ] = [ " lat " , " lon " ]
else :
coords [ " latlon_coord " ] = ( dimnames [ - 1 ] , [ CoordPair ( lat = x [ 0 ] ,
lon = x [ 1 ] )
coords [ " latlon_coord " ] = ( dimnames [ - 1 ] ,
[ CoordPair ( lat = x [ 0 ] , lon = x [ 1 ] )
for x in zip ( arr1 , arr2 ) ] )
coords [ dimnames [ 0 ] ] = [ " x " , " y " ]
@ -750,11 +744,12 @@ def set_height_metadata(geopt=False, stag=False):
@@ -750,11 +744,12 @@ def set_height_metadata(geopt=False, stag=False):
" (mass grid) " . format ( height_type ) )
else :
outattrs [ " description " ] = ( " model height - [ {} ] (vertically "
" staggered grid) " . format ( height_type ) )
" staggered grid) " . format (
height_type ) )
return DataArray ( result , name = outname , dims = outdimnames ,
coords = outcoords , attrs = outattrs )
return DataArray ( result , name = outname ,
dims = outdimnames , coords = outcoords , attrs = outattrs )
return func_wrapper
@ -819,7 +814,6 @@ def _set_horiz_meta(wrapped, instance, args, kwargs):
@@ -819,7 +814,6 @@ def _set_horiz_meta(wrapped, instance, args, kwargs):
if isinstance ( z , DataArray ) :
vert_units = z . attrs . get ( " units " , None )
if isinstance ( field3d , DataArray ) :
outcoords = OrderedDict ( )
outdimnames = list ( field3d . dims )
@ -993,7 +987,8 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
@@ -993,7 +987,8 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
end_point_xy = ( end_point . x , end_point . y )
xy , var2dz , z_var2d = get_xy_z_params ( to_np ( z ) , pivot_point_xy , angle ,
start_point_xy , end_point_xy , levels , autolevels )
start_point_xy , end_point_xy ,
levels , autolevels )
# Make a copy so we don't modify a user supplied cache
if cache is not None :
@ -1039,7 +1034,6 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
@@ -1039,7 +1034,6 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
except KeyError :
pass # Xarray 0.9
# Delete any lat,lon coords
delkeys = [ key for key in viewkeys ( outcoords ) if is_coordvar ( key ) ]
for key in delkeys :
@ -1069,12 +1063,10 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
@@ -1069,12 +1063,10 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
lats = _interpline ( latcoord , xy )
lons = _interpline ( loncoord , xy )
outcoords [ " xy_loc " ] = ( " cross_line_idx " ,
np . asarray ( tuple (
outcoords [ " xy_loc " ] = ( " cross_line_idx " , np . asarray ( tuple (
CoordPair ( x = xy [ i , 0 ] , y = xy [ i , 1 ] ,
lat = lats [ i ] , lon = lons [ i ] )
for i in py3range ( xy . shape [ - 2 ] ) ) )
)
for i in py3range ( xy . shape [ - 2 ] ) ) ) )
# Moving domain
else :
extra_dims = latcoord . shape [ 0 : - 2 ]
@ -1086,12 +1078,11 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
@@ -1086,12 +1078,11 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
lats = _interpline ( latcoord [ idxs ] , xy )
lons = _interpline ( loncoord [ idxs ] , xy )
latlon_loc [ idxs ] = np . asarray ( tuple (
CoordPair ( x = xy [ i , 0 ] , y = xy [ i , 1 ] ,
latlon_loc [ idxs ] = np . asarray (
tuple ( CoordPair (
x = xy [ i , 0 ] , y = xy [ i , 1 ] ,
lat = lats [ i ] , lon = lons [ i ] )
for i in py3range ( xy . shape [ - 2 ] ) )
) [ : ]
for i in py3range ( xy . shape [ - 2 ] ) ) ) [ : ]
extra_dimnames = latcoord . dims [ 0 : - 2 ]
loc_dimnames = extra_dimnames + ( " cross_line_idx " , )
@ -1100,12 +1091,14 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
@@ -1100,12 +1091,14 @@ def _set_cross_meta(wrapped, instance, args, kwargs):
else :
warnings . warn ( " ' latlon ' is set to True, but ' field3d ' "
" contains no coordinate information " )
outcoords [ " xy_loc " ] = ( " cross_line_idx " , np . asarray ( tuple (
outcoords [ " xy_loc " ] = ( " cross_line_idx " ,
np . asarray ( tuple (
CoordPair ( xy [ i , 0 ] , xy [ i , 1 ] )
for i in py3range ( xy . shape [ - 2 ] ) ) ) )
else :
outcoords [ " xy_loc " ] = ( " cross_line_idx " , np . asarray ( tuple (
outcoords [ " xy_loc " ] = ( " cross_line_idx " ,
np . asarray ( tuple (
CoordPair ( xy [ i , 0 ] , xy [ i , 1 ] )
for i in py3range ( xy . shape [ - 2 ] ) ) ) )
@ -1160,11 +1153,10 @@ def _set_line_meta(wrapped, instance, args, kwargs):
@@ -1160,11 +1153,10 @@ def _set_line_meta(wrapped, instance, args, kwargs):
: mod : ` wrapt `
"""
argvars = from_args ( wrapped , ( " field2d " ,
" wrfin " , " timeidx " , " stagger " , " projection " ,
" ll_point " , " pivot_point " , " angle " ,
" start_point " , " end_point " , " latlon " ,
" cache " ) ,
argvars = from_args ( wrapped , ( " field2d " , " wrfin " , " timeidx " , " stagger " ,
" projection " , " ll_point " , " pivot_point " ,
" angle " , " start_point " , " end_point " ,
" latlon " , " cache " ) ,
* args , * * kwargs )
field2d = argvars [ " field2d " ]
@ -1223,7 +1215,6 @@ def _set_line_meta(wrapped, instance, args, kwargs):
@@ -1223,7 +1215,6 @@ def _set_line_meta(wrapped, instance, args, kwargs):
# to avoid problems downstream
_timeidx = 0
if pivot_point is not None :
if pivot_point . lat is not None and pivot_point . lon is not None :
xy_coords = to_xy_coords ( pivot_point , wrfin , _timeidx ,
@ -1232,7 +1223,6 @@ def _set_line_meta(wrapped, instance, args, kwargs):
@@ -1232,7 +1223,6 @@ def _set_line_meta(wrapped, instance, args, kwargs):
else :
pivot_point_xy = ( pivot_point . x , pivot_point . y )
if start_point is not None and end_point is not None :
if start_point . lat is not None and start_point . lon is not None :
xy_coords = to_xy_coords ( start_point , wrfin , _timeidx ,
@ -1248,7 +1238,6 @@ def _set_line_meta(wrapped, instance, args, kwargs):
@@ -1248,7 +1238,6 @@ def _set_line_meta(wrapped, instance, args, kwargs):
else :
end_point_xy = ( end_point . x , end_point . y )
xy = get_xy ( field2d , pivot_point_xy , angle , start_point_xy , end_point_xy )
# Make a copy so we don't modify a user supplied cache
@ -1276,8 +1265,7 @@ def _set_line_meta(wrapped, instance, args, kwargs):
@@ -1276,8 +1265,7 @@ def _set_line_meta(wrapped, instance, args, kwargs):
cross_str = " ( {0} , {1} ) to ( {2} , {3} ) " . format ( st_x , st_y , ed_x , ed_y )
if angle is not None :
cross_str + = " ; center= {0} ; angle= {1} " . format ( pivot_point ,
angle )
cross_str + = " ; center= {0} ; angle= {1} " . format ( pivot_point , angle )
if isinstance ( field2d , DataArray ) :
outcoords = OrderedDict ( )
@ -1318,12 +1306,10 @@ def _set_line_meta(wrapped, instance, args, kwargs):
@@ -1318,12 +1306,10 @@ def _set_line_meta(wrapped, instance, args, kwargs):
lats = _interpline ( latcoord , xy )
lons = _interpline ( loncoord , xy )
outcoords [ " xy_loc " ] = ( " line_idx " ,
np . asarray ( tuple (
outcoords [ " xy_loc " ] = ( " line_idx " , np . asarray ( tuple (
CoordPair ( x = xy [ i , 0 ] , y = xy [ i , 1 ] ,
lat = lats [ i ] , lon = lons [ i ] )
for i in py3range ( xy . shape [ - 2 ] ) ) )
)
for i in py3range ( xy . shape [ - 2 ] ) ) ) )
# Moving domain
else :
@ -1339,9 +1325,7 @@ def _set_line_meta(wrapped, instance, args, kwargs):
@@ -1339,9 +1325,7 @@ def _set_line_meta(wrapped, instance, args, kwargs):
latlon_loc [ idxs ] = np . asarray ( tuple (
CoordPair ( x = xy [ i , 0 ] , y = xy [ i , 1 ] ,
lat = lats [ i ] , lon = lons [ i ] )
for i in py3range ( xy . shape [ - 2 ] ) )
) [ : ]
for i in py3range ( xy . shape [ - 2 ] ) ) ) [ : ]
extra_dimnames = latcoord . dims [ 0 : - 2 ]
loc_dimnames = extra_dimnames + ( " line_idx " , )
@ -1350,15 +1334,13 @@ def _set_line_meta(wrapped, instance, args, kwargs):
@@ -1350,15 +1334,13 @@ def _set_line_meta(wrapped, instance, args, kwargs):
else :
warnings . warn ( " ' latlon ' is set to True, but ' field2d ' "
" contains no coordinate information " )
outcoords [ " xy_loc " ] = ( " line_idx " , np . asarray ( tuple (
CoordPair ( xy [ i , 0 ] , xy [ i , 1 ] )
outcoords [ " xy_loc " ] = ( " line_idx " , np . asarray (
tuple ( CoordPair ( xy [ i , 0 ] , xy [ i , 1 ] )
for i in py3range ( xy . shape [ - 2 ] ) ) ) )
else :
outcoords [ " xy_loc " ] = ( " line_idx " , np . asarray ( tuple (
CoordPair ( xy [ i , 0 ] , xy [ i , 1 ] )
outcoords [ " xy_loc " ] = ( " line_idx " , np . asarray (
tuple ( CoordPair ( xy [ i , 0 ] , xy [ i , 1 ] )
for i in py3range ( xy . shape [ - 2 ] ) ) ) )
else :
if inc_latlon :
warnings . warn ( " ' latlon ' is set to True, but ' field2d ' is "
@ -1427,7 +1409,6 @@ def _set_vinterp_meta(wrapped, instance, args, kwargs):
@@ -1427,7 +1409,6 @@ def _set_vinterp_meta(wrapped, instance, args, kwargs):
outcoords = None
outattrs = OrderedDict ( )
if isinstance ( field , DataArray ) :
outcoords = OrderedDict ( )
outdimnames = list ( field . dims )
@ -1443,7 +1424,6 @@ def _set_vinterp_meta(wrapped, instance, args, kwargs):
@@ -1443,7 +1424,6 @@ def _set_vinterp_meta(wrapped, instance, args, kwargs):
outcoords [ " interp_level " ] = interp_levels
outattrs . update ( field . attrs )
outname = field . name
else :
@ -1503,8 +1483,7 @@ def _set_2dxy_meta(wrapped, instance, args, kwargs):
@@ -1503,8 +1483,7 @@ def _set_2dxy_meta(wrapped, instance, args, kwargs):
ed_x = xy [ - 1 , 0 ]
ed_y = xy [ - 1 , 1 ]
cross_str = " ( {0} , {1} ) to ( {2} , {3} ) " . format ( st_x , st_y ,
ed_x , ed_y )
cross_str = " ( {0} , {1} ) to ( {2} , {3} ) " . format ( st_x , st_y , ed_x , ed_y )
outname = None
outdimnames = None
@ -1532,7 +1511,6 @@ def _set_2dxy_meta(wrapped, instance, args, kwargs):
@@ -1532,7 +1511,6 @@ def _set_2dxy_meta(wrapped, instance, args, kwargs):
del outcoords [ key ]
outdimnames . append ( " line_idx " )
#outattrs.update(field3d.attrs)
desc = field3d . attrs . get ( " description " , None )
if desc is not None :
@ -1544,7 +1522,8 @@ def _set_2dxy_meta(wrapped, instance, args, kwargs):
@@ -1544,7 +1522,8 @@ def _set_2dxy_meta(wrapped, instance, args, kwargs):
outname = " {0} _2dxy " . format ( field3d . name )
outcoords [ " xy_loc " ] = ( " line_idx " , [ CoordPair ( xy [ i , 0 ] , xy [ i , 1 ] )
outcoords [ " xy_loc " ] = ( " line_idx " ,
[ CoordPair ( xy [ i , 0 ] , xy [ i , 1 ] )
for i in py3range ( xy . shape [ - 2 ] ) ] )
for key in ( " MemoryOrder " , ) :
@ -1824,7 +1803,6 @@ def set_alg_metadata(alg_ndims, refvarname,
@@ -1824,7 +1803,6 @@ def set_alg_metadata(alg_ndims, refvarname,
if not xarray_enabled ( ) or not do_meta :
return wrapped ( * args , * * kwargs )
result = wrapped ( * args , * * kwargs )
outname = wrapped . __name__
@ -1858,7 +1836,6 @@ def set_alg_metadata(alg_ndims, refvarname,
@@ -1858,7 +1836,6 @@ def set_alg_metadata(alg_ndims, refvarname,
if _units is not None :
outattrs [ " units " ] = _units
if description is not None :
if isinstance ( description , from_var ) :
desc = description ( wrapped , * args , * * kwargs )
@ -1867,7 +1844,6 @@ def set_alg_metadata(alg_ndims, refvarname,
@@ -1867,7 +1844,6 @@ def set_alg_metadata(alg_ndims, refvarname,
else :
outattrs [ " description " ] = description
# Copy the dimnames from the reference variable, otherwise, use
# the supplied dimnames
if refvarname is not None :
@ -2094,7 +2070,6 @@ def set_cape_alg_metadata(is2d, copyarg="pres_hpa"):
@@ -2094,7 +2070,6 @@ def set_cape_alg_metadata(is2d, copyarg="pres_hpa"):
outattrs = OrderedDict ( )
if is2d :
if is1d :
outname = " cape_2d "
@ -2114,7 +2089,6 @@ def set_cape_alg_metadata(is2d, copyarg="pres_hpa"):
@@ -2114,7 +2089,6 @@ def set_cape_alg_metadata(is2d, copyarg="pres_hpa"):
outattrs [ " description " ] = " cape; cin "
outattrs [ " units " ] = " J kg-1 ; J kg-1 "
if isinstance ( p , DataArray ) :
if is2d :
if not is1d :
@ -2131,7 +2105,6 @@ def set_cape_alg_metadata(is2d, copyarg="pres_hpa"):
@@ -2131,7 +2105,6 @@ def set_cape_alg_metadata(is2d, copyarg="pres_hpa"):
else :
outdims [ 1 ] = p . dims [ 0 ]
outcoords = { }
# Left-most is always cape_cin or cape_cin_lcl_lfc
if is2d :
@ -2214,7 +2187,6 @@ def set_cloudfrac_alg_metadata(copyarg="vert"):
@@ -2214,7 +2187,6 @@ def set_cloudfrac_alg_metadata(copyarg="vert"):
# Left dims
outdims [ 1 : - 2 ] = cp . dims [ 0 : - 3 ]
outcoords = { }
# Left-most is always low_mid_high
outdims [ 0 ] = " low_mid_high "
@ -2294,8 +2266,3 @@ def set_destag_metadata():
@@ -2294,8 +2266,3 @@ def set_destag_metadata():
return out
return func_wrapper