简体   繁体   English

xarray 的反向维度

[英]Reverse dimension of an xarray

I have a xarray Dataset with dimensions time, latitude, longitude and pressure levels.我有一个包含时间、纬度、经度和压力级别的 xarray 数据集。 The latitude goes from 90° to -90°.纬度从 90° 到 -90°。 But I need them from -90° to 90°.但我需要它们从 -90° 到 90°。 How can I turn around the dimension in a way that also the dimension of the variables are changed?如何以改变变量维度的方式改变维度?

在此处输入图像描述

You can use reindex:您可以使用重新索引:

da.reindex(lat = da.lat[::-1])

One option is to the.sortby method on your xarray dataset (ds):一种选择是 xarray 数据集(ds)上的 .sortby 方法:

ds = ds.sortby('lat', ascending=True)

You can use .isel() on the dataset object to return a new dataset object with the latitudes reversed for all of the data arrays.您可以在数据集 object 上使用.isel()以返回一个新的数据集 object,其中所有数据 arrays 的纬度都颠倒了。

ds = ds.isel(lat=slice(None, None, -1))

Note, this can also be done to a specific data array object, but if you assign that data array back to the dataset object, the coordinates will not be reversed because it will follow the coordinates as stored in the original dataset object.请注意,这也可以对特定数据数组 object 执行,但如果将该数据数组分配回数据集 object,则坐标将不会反转,因为它将遵循存储在原始数据集 ZA8CFDE6331BD59EB2AC96F8911ZB4 中的坐标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM