Sorted coordinates for combining #5194
-
Hello, I'm very new to xarray. I'm trying to read in many netCDF files as a dataset using
I know that Also, is it a general rule that coordinates should be sorted so it's easier to combine them? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@Zepeng-Mu, would In [10]: ds['x'] = xr.DataArray(np.arange(10).reshape(2, 5), dims=['junc', 'rail_id'], coords={'junc': [1, 2], 'rail_id': ['a', 'd', 'b', 'e', 'c']})
In [11]: ds
Out[11]:
<xarray.Dataset>
Dimensions: (junc: 2, rail_id: 5)
Coordinates:
* junc (junc) int64 1 2
* rail_id (rail_id) <U1 'a' 'd' 'b' 'e' 'c'
Data variables:
x (junc, rail_id) int64 0 1 2 3 4 5 6 7 8 9
In [12]: ds.sortby('rail_id')
Out[12]:
<xarray.Dataset>
Dimensions: (junc: 2, rail_id: 5)
Coordinates:
* junc (junc) int64 1 2
* rail_id (rail_id) <U1 'a' 'b' 'c' 'd' 'e'
Data variables:
x (junc, rail_id) int64 0 2 4 1 3 5 7 9 6 8 |
Beta Was this translation helpful? Give feedback.
-
Hi @Zepeng-Mu , thank you for raising this, and apologies for not seeing this earlier.
By using
That's the source of the ValueError you're seeing. What There two options:
result = combine_nested([[ds1, ds2], [ds3, ds4]], concat_dim=['rail_id', 'junc']) |
Beta Was this translation helpful? Give feedback.
Hi @Zepeng-Mu , thank you for raising this, and apologies for not seeing this earlier.
By using
open_mfdataset
with it's default values, the combining of datasets is delegated to the functionxarray.combine_by_coords
. The docstring forcombine_by_coords
saysThat's the source of the ValueError you're seeing. What
combine_by_coords
wants to do is arrange all your datasets so that …