python-xarray - xarray - 如何重命名 DataArray 对象上的维度

标签 python-xarray

我有一个名为 rio 的 DataArray 对象。

In [59]: rio
Out[59]: 
<xarray.DataArray (band: 1, y: 106, x: 193)>
array([[[0, 0, ..., 0, 0],
        [0, 0, ..., 0, 0],
        ...,
        [0, 0, ..., 0, 0],
        [0, 0, ..., 0, 0]]], dtype=uint8)
Coordinates:
  * band     (band) int32 1
  * y        (y) float64 -33.9 -33.95 -34.0 -34.05 ... -39.05 -39.1 -39.15 -39.2
  * x        (x) float64 140.8 140.8 140.9 140.9 ... 149.9 149.9 150.0 150.0
Attributes:
    transform:   (0.04791259799999997, 0.0, 140.776046753, 0.0, -0.0504760740...
    crs:         +init=epsg:4326
    res:         (0.04791259799999997, 0.05047607400000004)
    is_tiled:    1
    nodatavals:  (255.0,)

我想将 y 重命名为纬度,将 x 重命名为经度。所以产生的 rio 对象将是:
In [59]: rio
Out[59]: 
<xarray.DataArray (band: 1, latitude: 106, longitude: 193)>
array([[[0, 0, ..., 0, 0],
        [0, 0, ..., 0, 0],
        ...,
        [0, 0, ..., 0, 0],
        [0, 0, ..., 0, 0]]], dtype=uint8)
Coordinates:
  * band     (band) int32 1
  * latitude         (latitude) float64 -33.9 -33.95 -34.0 -34.05 ... -39.05 -39.1 -39.15 -39.2
  * longitude        (longitude) float64 140.8 140.8 140.9 140.9 ... 149.9 149.9 150.0 150.0
Attributes:
    transform:   (0.04791259799999997, 0.0, 140.776046753, 0.0, -0.0504760740...
    crs:         +init=epsg:4326
    res:         (0.04791259799999997, 0.05047607400000004)
    is_tiled:    1
    nodatavals:  (255.0,)

我需要关于应该在 DataArray 类上使用哪些方法的帮助?

最佳答案

我想到了:

rio.rename({'x': 'longitude','y': 'latitude'})

关于python-xarray - xarray - 如何重命名 DataArray 对象上的维度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56162366/

相关文章:

python - Xarray combine_by_coords 返回单调全局索引错误

python - xarray 的 open_mfdataset 找不到坐标

python - 使用 xarray 将单个月度 NetCDF 文件拆分为每日平均的 NetCDF 多个文件

python - 获取一维结果列表并将其转换为 N 维 xarray.DataArray

python - 根据索引列表组合/求和 numpy 数组的行

python-3.x - xarray 中的乘法

python - 如何使用 groupby 为 xarray 数据集添加新变量并应用?

python - 基于其他相同大小的数组过滤多维数组

python - 沿轴计算多维数组中某个值的百分位等级

numpy - 获取 xarray 数据集的非 nan 值的坐标