Created
June 20, 2019 14:40
-
-
Save dennissergeev/90444bdc3e2da7e9cd3e7f865ce2a380 to your computer and use it in GitHub Desktop.
Functions for rolling xarray DataArray along its longitudinal axis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def roll_da_to0360(da, lon_name='longitude'): | |
"""Roll DataArray's data with longitudes from (-180, 180) to (0, 360).""" | |
# Roll longitudes and corresponding data | |
out = da.roll(longitude=da[lon_name].shape[0]//2, roll_coords=True) | |
# Reset western (negative) longitudes to values within (180, 360) range | |
out[lon_name] = out[lon_name] - (out[lon_name] // 360) * 360 | |
return out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment