本文整理汇总了Python中xarray.DataArray.attrs[att]方法的典型用法代码示例。如果您正苦于以下问题:Python DataArray.attrs[att]方法的具体用法?Python DataArray.attrs[att]怎么用?Python DataArray.attrs[att]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xarray.DataArray
的用法示例。
在下文中一共展示了DataArray.attrs[att]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cyclic_dataarray
# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import attrs[att] [as 别名]
def cyclic_dataarray(da, coord='lon'):
""" Add a cyclic coordinate point to a DataArray along a specified
named coordinate dimension.
>>> from xarray import DataArray
>>> data = DataArray([[1, 2, 3], [4, 5, 6]],
... coords={'x': [1, 2], 'y': range(3)},
... dims=['x', 'y'])
>>> cd = cyclic_dataarray(data, 'y')
>>> print cd.data
array([[1, 2, 3, 1],
[4, 5, 6, 4]])
"""
assert isinstance(da, DataArray)
lon_idx = da.dims.index(coord)
cyclic_data, cyclic_coord = add_cyclic_point(da.values,
coord=da.coords[coord],
axis=lon_idx)
# Copy and add the cyclic coordinate and data
new_coords = dict(da.coords)
new_coords[coord] = cyclic_coord
new_values = cyclic_data
new_da = DataArray(new_values, dims=da.dims, coords=new_coords)
# Copy the attributes for the re-constructed data and coords
for att, val in da.attrs.items():
new_da.attrs[att] = val
for c in da.coords:
for att in da.coords[c].attrs:
new_da.coords[c].attrs[att] = da.coords[c].attrs[att]
return new_da
示例2: _master_dataarray
# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import attrs[att] [as 别名]
def _master_dataarray(exp, data_dict):
all_case_vals = exp.all_case_vals()
first_case = next(exp.all_cases())
proto = data_dict[first_case]
n_case_vals = [ len(case_vals) for case_vals in all_case_vals ]
n_cases = len(n_case_vals)
new_dims = exp.cases + [str(x) for x in proto.dims]
new_values = empty(n_case_vals + list(proto.values.shape))
it = nditer(empty(n_case_vals), flags=['multi_index', ])
# The logic of this iterator is slightly complicated, but what we're
# doing is constructing an n-dimensional array where n is the number
# of cases we're considering. We're looping over the *indices* of that
# dimension, and performing a lookup in the record of all the case values
# for all the dimensions (all_case_vals) to create the key which
# corresponds to this data in the data dictionary which holds the data.
while not it.finished:
indx = it.multi_index
case_indx = tuple([ all_case_vals[n][i] \
for i, n in zip(indx, range(n_cases)) ])
new_values[indx] = data_dict[case_indx].values
it.iternext()
# Copy and add the case coordinates
new_coords = dict(proto.coords)
for case, vals in zip(exp.cases, all_case_vals):
new_coords[case] = vals
da_new = DataArray(new_values, dims=new_dims, coords=new_coords)
# Copy the attributes for act/aer coords, data itself
for att, val in proto.attrs.items():
da_new.attrs[att] = val
for case, long, _ in exp.itercases():
da_new.coords[case].attrs['long_name'] = long
return da_new