简体   繁体   中英

Reverse dimension of an xarray

I have a xarray Dataset with dimensions time, latitude, longitude and pressure levels. The latitude goes from 90° to -90°. But I need them from -90° to 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):

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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