For my data array I have coordinates longitude and latitude and time. I want to reverse the array along latitude only so that [90, 85, ..., -80, -90]
becomes [-90, -80, ..., 85, 90]
.
Agree with @jhamman's response that a minimally reproducible example would help
I think you could use
da = xr.tutorial.open_dataset('air_temperature')
da.reindex(lat=list(reversed(da.lat)))
Base on this discussion, another option is to use isel
to get a reversed view:
da = xr.tutorial.open_dataset('air_temperature')
da.isel(lat=slice(None, None, -1)
I've found this approach to work better with large datasets backed by dask arrays. The reindex
approach in @Maximilian's answer causes the data to be rechunked into very large chunks. This approach avoids that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With