python-xarray

xarray: reverse an array along one coordinate


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].


Solution

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