Last active
November 15, 2022 14:23
-
-
Save mathause/f545a3f42c00cbe98f559f9220e5e5bd to your computer and use it in GitHub Desktop.
roll coords
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 lon_to_180(ds, lon_coords="lon"): | |
# https://git.iac.ethz.ch/utility_functions/utility_functions_python/-/blob/master/xarray.py#L149 | |
lon_orig = ds[lon_coords] | |
if lon_orig.ndim != 1: | |
raise ValueError("Currently only handels 1D grids") | |
with xr.set_options(keep_attrs=True): | |
lon = ((lon_orig + 180) % 360) - 180 | |
ds = ds.assign_coords({lon_coords: lon}) | |
return ds.sortby(ds[lon_coords]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment