html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue https://github.com/pydata/xarray/issues/1005#issuecomment-470546895,https://api.github.com/repos/pydata/xarray/issues/1005,470546895,MDEyOklzc3VlQ29tbWVudDQ3MDU0Njg5NQ==,7933853,2019-03-07T14:29:53Z,2019-03-07T14:29:53Z,NONE,"Stephan, thanks a lot for your code snippet from December, this is an elegant solution to the problem. One minor correction though, because I found that it fails to infer the period if none is given. The divide should be a multiplication I believe, i.e. ```python import xarray import numpy as np def add_cyclic_point(xarray_obj, dim, period=None): if period is None: period = xarray_obj.sizes[dim] * xarray_obj.coords[dim][:2].diff(dim).item() first_point = xarray_obj.isel({dim: slice(1)}) first_point.coords[dim] = first_point.coords[dim]+period return xarray.concat([xarray_obj, first_point], dim=dim) ```","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,177484162 https://github.com/pydata/xarray/issues/1005#issuecomment-447043519,https://api.github.com/repos/pydata/xarray/issues/1005,447043519,MDEyOklzc3VlQ29tbWVudDQ0NzA0MzUxOQ==,1217238,2018-12-13T16:59:55Z,2018-12-13T16:59:55Z,MEMBER,"Something like this might work for you: ```python import xarray import numpy as np def add_cyclic_point(xarray_obj, dim, period=None): if period is None: period = xarray_obj.sizes[dim] / xarray_obj.coords[dim][:2].diff(dim).item() first_point = xarray_obj.isel({dim: slice(1)}) first_point.coords[dim] = first_point.coords[dim]+period return xarray.concat([xarray_obj, first_point], dim=dim) ``` Example usage: ``` >>> ds = xarray.Dataset({'foo': ('x', np.arange(10))}, {'x': np.arange(10)}) >>> add_cyclic_point(ds, dim='x', period=10) Dimensions: (x: 11) Coordinates: * x (x) int64 0 1 2 3 4 5 6 7 8 9 10 Data variables: foo (x) int64 0 1 2 3 4 5 6 7 8 9 0 ``` It would also make sense to add a more generic `.pad()` method, which this function would be a special case of (if `mode='wrap'`).","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,177484162 https://github.com/pydata/xarray/issues/1005#issuecomment-447034484,https://api.github.com/repos/pydata/xarray/issues/1005,447034484,MDEyOklzc3VlQ29tbWVudDQ0NzAzNDQ4NA==,7933853,2018-12-13T16:34:13Z,2018-12-13T16:34:29Z,NONE,"Any update on this issue? It would be great if `add_cyclic_point` could be applied to all variables automatically. Just for other peoples reference, I now have this workaround, creating `erai_jja_cy` a 'cyclic' version of `erai_jja`: ```python dd, ll = add_cyclic_point(erai_jja.values, erai_jja.lon) erai_jja_cy = xr.DataArray(dd, coords={'lat':erai_jja.lat, 'lon':ll}, dims=('lat','lon')) ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,177484162 https://github.com/pydata/xarray/issues/1005#issuecomment-248151652,https://api.github.com/repos/pydata/xarray/issues/1005,248151652,MDEyOklzc3VlQ29tbWVudDI0ODE1MTY1Mg==,1217238,2016-09-19T22:49:38Z,2016-09-19T22:49:38Z,MEMBER,"Note that `xarray.apply` doesn't solve this _yet_, but hopefully it will soon. I'll update this issue when it does. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,177484162 https://github.com/pydata/xarray/issues/1005#issuecomment-248045734,https://api.github.com/repos/pydata/xarray/issues/1005,248045734,MDEyOklzc3VlQ29tbWVudDI0ODA0NTczNA==,1217238,2016-09-19T16:35:42Z,2016-09-19T16:35:42Z,MEMBER,"> Do I need to create a new Xarray DataArray from the output of add_cyclic_point? Yes, that would be my suggested approach. This would be a good use case for `xarray.apply` (#964). ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,177484162