You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this is another unintended consequence of #648. Consider the following case:
In [20]: arr=xr.DataArray(range(3), dims=['abc'])
In [21]: new_coord=xr.DataArray([1,2,3], dims=['abc'], coords=[[1,2,3]])
In [22]: arr['abc'] =new_coordIn [23]: arrOut[24]:
<xarray.DataArray (abc: 3)>array([0, 1, 2])
Coordinates:
*abc (abc) float64nan1.02.0
Note the nan. Before #648, this worked, in that arr's coordinates would consist of new_coord.
The use case: we have some data defined on the edges of pressure levels in an atmospheric model, and other data defined at the center of the pressure levels. In order to perform calculations involving both kinds of data, we average the edge-defined data (i.e. 0.5*(value at top edge + value at bottom edge)) to get the value at the level centers. But the resulting DataArray still has as its coord (from xarray's perspective, that is) the level edges, and so we replace that coord with the DataArray of the level centers.
A workaround would be arr['abc'].values = new_coord.values, but then any other metadata associated with the original coord is retained, which is not good.
Somewhat involved and not sure I described clearly, so let me know if clarification needed. Also I vaguely suspect there's a cleaner way of doing this in the first place. Thanks!
The text was updated successfully, but these errors were encountered:
There's clearly something missing in the DataArray path (which goes through merge_dataarray_coords)... possibly we need to be using the overwrite_vars argument?
I think this is another unintended consequence of #648. Consider the following case:
Note the
nan
. Before #648, this worked, in thatarr
's coordinates would consist ofnew_coord
.The use case: we have some data defined on the edges of pressure levels in an atmospheric model, and other data defined at the center of the pressure levels. In order to perform calculations involving both kinds of data, we average the edge-defined data (i.e. 0.5*(value at top edge + value at bottom edge)) to get the value at the level centers. But the resulting DataArray still has as its coord (from xarray's perspective, that is) the level edges, and so we replace that coord with the DataArray of the level centers.
A workaround would be
arr['abc'].values = new_coord.values
, but then any other metadata associated with the original coord is retained, which is not good.Somewhat involved and not sure I described clearly, so let me know if clarification needed. Also I vaguely suspect there's a cleaner way of doing this in the first place. Thanks!
The text was updated successfully, but these errors were encountered: