특정 그룹을 기반으로하는 xarray 데이터 세트를 다운 샘플링하고자하므로 groupby
을 사용하여 그룹을 선택한 다음 각 그룹 내에서 샘플의 10 %를 가져옵니다. 아래 코드를 사용하고 있지만 내 함수가 빈 배열을 반환하는 것을 제안하는 IndexError: index 1330 is out of bounds for axis 0 with size 1330
을 얻지 만 subset
에는 확실히 0이 아닌 차원이 있습니다.groupby를 사용하여 xarray 데이터 세트를 다운 샘플링하는 방법은 무엇입니까?
나는 내가 GroupBy documentation에 따라 새로운 차원을 허용 것이라고 생각 squeeze=True
를 사용했지만 그 도움이되지 않았다, 그래서 나는 squeeze=False
로 변경되었습니다.
무슨 일이 일어날 지 알고 있습니까? 감사합니다.
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-44-39c7803e9e40> in <module>()
12
13 # squeeze=False because the final dataset is smaller than the original
---> 14 ds_subset = ds.groupby('group', squeeze=True).apply(select_random_cell_subset)
15 ds_subset
~/anaconda3/envs/cshl-sca-2017/lib/python3.6/site-packages/xarray/core/groupby.py in apply(self, func, **kwargs)
615 kwargs.pop('shortcut', None) # ignore shortcut if set (for now)
616 applied = (func(ds, **kwargs) for ds in self._iter_grouped())
--> 617 return self._combine(applied)
618
619 def _combine(self, applied):
~/anaconda3/envs/cshl-sca-2017/lib/python3.6/site-packages/xarray/core/groupby.py in _combine(self, applied)
622 coord, dim, positions = self._infer_concat_args(applied_example)
623 combined = concat(applied, dim)
--> 624 combined = _maybe_reorder(combined, dim, positions)
625 if coord is not None:
626 combined[coord.name] = coord
~/anaconda3/envs/cshl-sca-2017/lib/python3.6/site-packages/xarray/core/groupby.py in _maybe_reorder(xarray_obj, dim, positions)
443 return xarray_obj
444 else:
--> 445 return xarray_obj[{dim: order}]
446
447
~/anaconda3/envs/cshl-sca-2017/lib/python3.6/site-packages/xarray/core/dataset.py in __getitem__(self, key)
716 """
717 if utils.is_dict_like(key):
--> 718 return self.isel(**key)
719
720 if hashable(key):
~/anaconda3/envs/cshl-sca-2017/lib/python3.6/site-packages/xarray/core/dataset.py in isel(self, drop, **indexers)
1141 for name, var in iteritems(self._variables):
1142 var_indexers = dict((k, v) for k, v in indexers if k in var.dims)
-> 1143 new_var = var.isel(**var_indexers)
1144 if not (drop and name in var_indexers):
1145 variables[name] = new_var
~/anaconda3/envs/cshl-sca-2017/lib/python3.6/site-packages/xarray/core/variable.py in isel(self, **indexers)
568 if dim in indexers:
569 key[i] = indexers[dim]
--> 570 return self[tuple(key)]
571
572 def squeeze(self, dim=None):
~/anaconda3/envs/cshl-sca-2017/lib/python3.6/site-packages/xarray/core/variable.py in __getitem__(self, key)
398 dims = tuple(dim for k, dim in zip(key, self.dims)
399 if not isinstance(k, integer_types))
--> 400 values = self._indexable_data[key]
401 # orthogonal indexing should ensure the dimensionality is consistent
402 if hasattr(values, 'ndim'):
~/anaconda3/envs/cshl-sca-2017/lib/python3.6/site-packages/xarray/core/indexing.py in __getitem__(self, key)
476 def __getitem__(self, key):
477 key = self._convert_key(key)
--> 478 return self._ensure_ndarray(self.array[key])
479
480 def __setitem__(self, key, value):
IndexError: index 1330 is out of bounds for axis 0 with size 1330