[英]python-xarray: multidimensional coordinates for single dimension of data
I have a number of datasets in xarray that I eventually would like to combine into one.我在 xarray 中有许多数据集,我最终希望将它们合并为一个。 One such dataset could have, for example, a datarray named
'x'
, which has dimensions 'a'
, 'b'
and 'c_d_e'
.例如,一个这样的数据集可以有一个名为
'x'
的数据阵列,它具有维度'a'
、 'b'
和'c_d_e'
。 I have corresponding parameters that were used to generate the data, and I would like to use these as coordinates.我有用于生成数据的相应参数,我想将它们用作坐标。 In case of the dimension
c_d_e
, it is actually three different parameters that were varied together, ie only one dimension of data is necessary for them.在维度
c_d_e
情况下,实际上是三个不同的参数一起变化,即它们只需要一个维度的数据。
So while my dimensions are ['a', 'b', 'c_d_e']
, I would like my coordinates to be 'a', 'b', 'c', 'd', 'e'
, and later combine datasets along these dimensions.所以虽然我的维度是
['a', 'b', 'c_d_e']
,我希望我的坐标是'a', 'b', 'c', 'd', 'e'
,然后结合数据集沿着这些维度。
Code example (of what I would like):代码示例(我想要的):
xr.Dataset({'x': (['d1', 'd2', 'd3_d4_d5'], x), coords=['d1coord':d1arr, 'd2coord': d2arr, 'd3coord': d3arr, 'd4coord': d4arr, 'd5coord': d5arr])
I could of course use all the 'a', 'b', 'c'
as dimensions, but that would make xarray fill the array with NaNs in places that don't correspond to and combination of coordinates, greatly bloating the amount of space that this takes up.我当然可以使用所有的
'a', 'b', 'c'
作为维度,但这会使 xarray 在与坐标和坐标组合不对应的地方用 NaN 填充数组,大大增加空间量这占用了。
Okay, I have found a solution, and it is so stupidly simple that I cannot believe that I didn't think of that earlier.好的,我找到了一个解决方案,它是如此的愚蠢,以至于我无法相信我之前没有想到这一点。
I simply specify one of the variables 'c', 'd', 'e'
as a dimensional variable and the others as non-dimensional (they are just a function of the former).我只是将变量
'c', 'd', 'e'
中的一个指定为维度变量,将其他变量指定为非维度变量(它们只是前者的函数)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.