xarray-重新采样一个DataArray的索引并将其应用于另一个DataArray对象

时间:2019-05-16 06:40:47

标签: python numpy python-xarray

我在xarray上有两个DataArray对象,分别名为da_ffdirio

In [58]: da_ffdi
Out[58]: 
<xarray.DataArray 'FFDI' (time: 8760, latitude: 106, longitude: 193)>
dask.array<shape=(8760, 106, 193), dtype=float32, chunksize=(744, 106, 193)>
Coordinates:
  * latitude   (latitude) float32 -39.2 -39.149525 ... -33.950478 -33.9
  * longitude  (longitude) float32 140.8 140.84792 140.89584 ... 149.95209 150.0
  * time       (time) datetime64[ns] 2005-01-01 ... 2005-12-31T23:00:00
Attributes:
    projectionType:  MERCATOR
    level:           SFC
    units:           
    gridType:        SCALAR
    lonCentre:       145.4
    latIntersect:    0.0

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,)

在rio中,y和x分别表示纬度和经度。

我想要实现的是通过将da_ffdi的纬度和经度坐标应用于rio的y和x坐标来对rio重新采样。重采样方法将是“最近的”。同样,“ y”需要重命名为“纬度”,而“ x”需要重命名为“经度”。

因此,生成的rio对象将是:

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) float32 -39.2 -39.149525 ... -33.950478 -33.9
  * longitude  (longitude) float32 140.8 140.84792 140.89584 ... 149.95209 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,)

关于需要执行的步骤以及需要使用的xarray内置函数,我需要一些指导。

0 个答案:

没有答案