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