简体   繁体   English

python-xarray:单维数据的多维坐标

[英]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.

相关问题 使用 Python-Xarray 重新网格坐标 - Regridding coordinates with Python-Xarray 使用 python-xarray 从多维 netcdf 文件中提取单个变量,同时保留属性/元数据 - Using python-xarray to extract a single variable from a multidimensional netcdf file while keeping attributes/metadata 禁止python-xarray警告 - Suppress warnings for python-xarray 如何使用python xarray使用多维坐标子集数据? - How to subset data using multidimensional coordinates using python xarray? Python-xarray:如何将多个 3D DataArray 组合成一个具有 6 维的单个? - Python-xarray: How to combine multiples 3D DataArray into a single one with 6 dimensions? python-xarray:如何将多个波段和日期的单波段栅格数据转换为xarray-Dataset或DataArray? - python-xarray: how to convert individual-band raster data, for multiple bands and dates, to xarray-Dataset or DataArray? 如何基于XArray的多维物理坐标为数据建立索引 - How to index data based on multi-dimension physical coordinates of xarray 在多维数组上应用 Mann Whitney U 检验并替换 Python 中 xarray 数据数组变量的单个值? - Apply Mann Whitney U test on multidimensional array and replace single values of variable of xarray data array in Python? 重新网格化 Python xarray 坐标 - Regridding Python xarray coordinates xarray:Plot 单个 plot 中跨坐标的所有变量数据 - xarray: Plot all variable data across coordinates in a single plot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM