Created
October 26, 2021 17:30
-
-
Save brews/b3e9e4e97bacd3f868f339b2f626692f to your computer and use it in GitHub Desktop.
xarray-native approach to adding a cyclic pixel (aka wrap-around pixel) to arrays in an xarray.Dataset.
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
import xarray as xr | |
def add_cyclic(ds, dim): | |
""" | |
Adds wrap-around, appending first value to end of data for named dimension. | |
Basically an xarray version of ``cartopy.util.add_cyclic_point()``. | |
""" | |
return ds.map( | |
lambda x, d: xr.concat([x, x.isel({d: 0})], dim=d), | |
keep_attrs=True, | |
d=str(dim), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment