xarray-如何重命名DataArray对象上的尺寸

时间:2019-05-16 06:46:11

标签: 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类上使用哪些方法的帮助?

1 个答案:

答案 0 :(得分:0)

我知道了:

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