Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

xarray add coordinate

>>> da = xr.DataArray(
...     np.random.rand(4),
...     coords=[np.array([358, 359, 0, 1])],
...     dims="lon",
... )
>>> da
<xarray.DataArray (lon: 4)>
array([0.5488135 , 0.71518937, 0.60276338, 0.54488318])
Coordinates:
  * lon      (lon) int64 358 359 0 1
  
>>> da.assign_coords(lon=(((da.lon + 180) % 360) - 180))
<xarray.DataArray (lon: 4)>
array([0.5488135 , 0.71518937, 0.60276338, 0.54488318])
Coordinates:
  * lon      (lon) int64 -2 -1 0 1
Source by xarray.pydata.org #
 
PREVIOUS NEXT
Tagged: #xarray #add #coordinate
ADD COMMENT
Topic
Name
5+5 =