使用Python xarray屏蔽'where'不再有效

s_meirelles

更新后,我遇到了麻烦xarray

我有一个盐度数据集,其维度为:

(u'time', u'stations', u'layer')

对于特定的测站,我想获得选定深度的盐度,例如-10 m。尺寸图层包含随时间变化的深度值,即,给定图层包含随时间变化的深度值(由于水位变化)。

以前,我正在执行以下操作:

ds.salinity.sel(stations='mystation').where( np.ceil(ds.layer(stations='mystation')) ==-10 )

一切正常。

但是现在我得到了这个错误:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-27-7e83f5e839cc> in <module>()
      1 fmstation = 'T1_50'
      2 
----> 3 sal10m = ds.salinity.sel(stations = ds.stations[ds.station_name == fmstation]).where(np.ceil(ds.Zcoordinate_c.isel(stations = ds.stations[ds.station_name == fmstation])) == -10) #.mean(axis=2).plot()
      4 sal10m #.plot()

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\xarray\core\common.pyc in where(self, cond)
    481           * x        (x) int64 0 1 2 3 4
    482         """
--> 483         return self._where(cond)
    484 
    485     # this has no runtime function - these are listed so IDEs know these methods

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\xarray\core\dataarray.pyc in func(self, other)
   1193                         if not reflexive
   1194                         else f(other_variable, self.variable))
-> 1195             coords = self.coords.merge(other_coords)._variables
   1196             name = self._result_name(other)
   1197 

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\xarray\core\coordinates.pyc in merge(self, other)
    139         ds = self.to_dataset()
    140         if other is not None:
--> 141             conflicts = self._merge_validate(other)
    142             _coord_merge_finalize(ds.coords, other, *conflicts)
    143         return ds

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\xarray\core\coordinates.pyc in _merge_validate(self, other)
     89                 self_var = self._variables[k]
     90                 other_var = other[k].variable
---> 91                 if not self_var.broadcast_equals(other_var):
     92                     if k in self.dims and k in other.dims:
     93                         raise ValueError('index %r not aligned' % k)

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\xarray\core\variable.pyc in broadcast_equals(self, other)
    976         except (ValueError, AttributeError):
    977             return False
--> 978         return self.equals(other)
    979 
    980     def identical(self, other):

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\xarray\core\variable.pyc in equals(self, other)
    961         other = getattr(other, 'variable', other)
    962         try:
--> 963             return (self.dims == other.dims and self._data_equals(other))
    964         except (TypeError, AttributeError):
    965             return False

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\xarray\core\variable.pyc in _data_equals(self, other)
    947     def _data_equals(self, other):
    948         return (self._data is other._data or
--> 949                 ops.array_equiv(self.data, other.data))
    950 
    951     def equals(self, other):

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\xarray\core\ops.pyc in array_equiv(arr1, arr2)
    188     if arr1.shape != arr2.shape:
    189         return False
--> 190     return bool(((arr1 == arr2) | (isnull(arr1) & isnull(arr2))).all())
    191 
    192 

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\dask\array\core.pyc in all(self, axis, keepdims, split_every)
   1146     def all(self, axis=None, keepdims=False, split_every=None):
   1147         from .reductions import all
-> 1148         return all(self, axis=axis, keepdims=keepdims, split_every=split_every)
   1149 
   1150     @wraps(np.min)

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\dask\array\reductions.pyc in all(a, axis, keepdims, split_every)
    161 def all(a, axis=None, keepdims=False, split_every=None):
    162     return reduction(a, chunk.all, chunk.all, axis=axis, keepdims=keepdims,
--> 163                      dtype='bool', split_every=split_every)
    164 
    165 

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\dask\array\reductions.pyc in reduction(x, chunk, aggregate, axis, keepdims, dtype, split_every, combine, name)
     42 
     43     return _tree_reduce(tmp, aggregate, axis, keepdims, dtype, split_every,
---> 44                        combine, name=name)
     45 
     46 

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\dask\array\reductions.pyc in _tree_reduce(x, aggregate, axis, keepdims, dtype, split_every, combine, name)
     75     return partial_reduce(func, x, split_every, keepdims=keepdims,
     76                           dtype=dtype,
---> 77                           name=(name or funcname(aggregate)) + '-aggregate')
     78 
     79 

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\dask\array\reductions.pyc in partial_reduce(func, x, split_every, keepdims, dtype, name)
    105         out_axis = [i for i in range(x.ndim) if i not in split_every]
    106         getter = lambda k: get(out_axis, k)
--> 107         keys = map(getter, keys)
    108         out_chunks = list(getter(out_chunks))
    109     dsk = {}

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\dask\array\reductions.pyc in <lambda>(k)
    104     if not keepdims:
    105         out_axis = [i for i in range(x.ndim) if i not in split_every]
--> 106         getter = lambda k: get(out_axis, k)
    107         keys = map(getter, keys)
    108         out_chunks = list(getter(out_chunks))

C:\Users\Smeirellesnune\AppData\Local\Continuum\Miniconda\lib\site-packages\toolz\itertoolz.pyc in get(ind, seq, default)
    374                     return operator.itemgetter(*ind)(seq)
    375                 else:
--> 376                     return (seq[ind[0]],)
    377             else:
    378                 return tuple(_get(i, seq, default) for i in ind)

IndexError: list index out of range

有人知道这是怎么回事吗?

还是有任何更智能的方式来分割我的数据集?

我正在使用的xarray版本是:

xarray 0.7.2

sys.version:

'2.7.11 |Anaconda 2.1.0 (64-bit)| (default, Feb 16 2016, 09:58:36) [MSC v.1500 64 bit (AMD64)]'

编辑:添加的数据集详细信息

<xarray.Dataset>
Dimensions:                              (cross_section: 15, cross_section_pts: 3, laydim: 20, laydimw: 21, stations: 979, time: 2512)
Coordinates:
    station_x_coordinate                 (stations) float64 4.194 4.008 ...
    station_y_coordinate                 (stations) float64 52.07 51.99 52.0 ...
    station_name                         (stations) |S64 'zmBoei_wav' ...
    Zcoordinate_c                        (time, stations, laydim) float64 -10.98 ...
    Zcoordinate_w                        (time, stations, laydimw) float64 -11.28 ...
    cross_section_name                   (cross_section) |S64 'L1' 'L2' 'L3' ...
  * time                                 (time) datetime64[ns] 2014-10-02T06:00:00 ...
  * cross_section                        (cross_section) int64 0 1 2 3 4 5 6 ...
  * cross_section_pts                    (cross_section_pts) int64 0 1 2
  * laydim                               (laydim) int64 0 1 2 3 4 5 6 7 8 9 ...
  * laydimw                              (laydimw) int64 0 1 2 3 4 5 6 7 8 9 ...
  * stations                             (stations) int64 0 1 2 3 4 5 6 7 8 ...
Data variables:
    station_id                           (stations) |S64 'zmBoei_wav' ...
    waterlevel                           (time, stations) float64 0.6178 ...
    Waterdepth                           (time, stations) float64 11.9 20.36 ...
    x_velocity                           (time, stations, laydim) float64 0.1941 ...
    y_velocity                           (time, stations, laydim) float64 0.0954 ...
    z_velocity                           (time, stations, laydim) float64 0.000392 ...
    Tke                                  (time, stations, laydimw) float64 1e-32 ...
    Eps                                  (time, stations, laydimw) float64 1e-32 ...
    Vicww                                (time, stations, laydimw) float64 0.0 ...
    salinity                             (time, stations, laydim) float64 26.26 ...
    cross_section_x_coordinate           (cross_section, cross_section_pts) float64 4.206 ...
    cross_section_y_coordinate           (cross_section, cross_section_pts) float64 51.94 ...
    cross_section_discharge              (time, cross_section) float64 0.0 ...
    cross_section_area                   (time, cross_section) float64 8.762e+03 ...
    cross_section_velocity               (time, cross_section) float64 0.0 ...
    cross_section_salt                   (time, cross_section) float64 -1.142e+05 ...
    WaterBalance_total_volume            (time) float64 0.0 1.227e+11 ...
    WaterBalance_storage                 (time) float64 0.0 1.227e+11 ...
    WaterBalance_volume_error            (time) float64 0.0 -1.499e+07 ...
    WaterBalance_boundaries_in           (time) float64 0.0 3.827e+08 ...
    WaterBalance_boundaries_out          (time) float64 0.0 6.048e+07 ...
    WaterBalance_boundaries_total        (time) float64 0.0 3.222e+08 ...
    WaterBalance_exchange_with_1D_in     (time) float64 0.0 0.0 0.0 0.0 0.0 ...
    WaterBalance_exchange_with_1D_out    (time) float64 0.0 0.0 0.0 0.0 0.0 ...
    WaterBalance_exchange_with_1D_total  (time) float64 0.0 0.0 0.0 0.0 0.0 ...
    WaterBalance_precipitation           (time) float64 0.0 0.0 0.0 0.0 0.0 ...
    WaterBalance_source_sink             (time) float64 0.0 0.0 0.0 0.0 0.0 ...
Attributes:
    institution: Deltares
    references: http://www.deltares.nl
    source: Deltares, D-Flow FM Version 1.1.182.45395, Apr 07 2016, 10:16:58, model
    history: Created on 2016-05-23T21:50:20+0200, D-Flow FM
    date_created: 2016-05-23T21:50:20+0200
    date_modified: 2016-05-23T21:50:20+0200
    Conventions: CF-1.5 Deltares-0.1
s_meirelles

通过IOOS通道与dask一起安装软件包可以解决该问题。要设置IOOS Python环境,请遵循以下步骤:

https://github.com/ioos/conda-recipes/wiki/Setting-up-the-IOOS-Python-environment

正如@Stephan所指出的:通用的“ conda- forge ”通道现在应该比IOOS更受青睐。了解更多信息:

https://conda-forge.github.io/

其次,安装dask,如下所示:

conda install dask -c conda-forge

在启动Python之前激活IOOS:

source activate IOOS #(OSX and Linux)
activate IOOS #(Windows) 

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用Python xarray屏蔽'where'不再有效

来自分类Dev

Selenium Python通过表循环打印我得到的列值Element不再有效

来自分类Dev

使用嵌套的EL动态读取编号的标头值不再有效

来自分类Dev

在 iOS 10 中使用 URL 方案打开游戏中心不再有效

来自分类Dev

历史上建议使用哪种x86 C优化实践不再有效?

来自分类Dev

历史上建议使用哪种x86 C优化实践不再有效?

来自分类Dev

Android:“ slideEdge”不再有效

来自分类Dev

在Python中从多个xarray.Datasets中屏蔽NaN

来自分类Dev

从Python中的多个xarray.Datasets中屏蔽NaN

来自分类Dev

Android Play商店market://链接不再有效?

来自分类Dev

雅虎财务不再有效吗?

来自分类Dev

获取不再有效的Google Cache for PDF副本

来自分类Dev

可用指针偏移量不再有效?

来自分类Dev

提交密码表格不再有效

来自分类Dev

CSS损坏-自动调整大小不再有效

来自分类Dev

stringByAppendingPathComponent对swift2不再有效

来自分类Dev

systemctl重装网络不再有效

来自分类Dev

Liberty SSL 证书密钥不再有效

来自分类Dev

Firebase 崩溃 - 批量上传不再有效

来自分类Dev

Arrow 和 canc 确实不再有效

来自分类Dev

Xtext 交叉引用不再有效?

来自分类Dev

Tidyverse 更新和 rlang - 代码不再有效

来自分类Dev

通过bash发送邮件曾经有效,现在不再有效

来自分类Dev

Oracle SQL:在子查询中或在联接之后使用WHERE子句是否更有效?

来自分类Dev

删除具有子对象的RLMObject时,Realm.io'RLMArray不再有效'

来自分类Dev

带有 Ubuntu 18.04 的 Lenovo P1 上的 Wifi 不再有效

来自分类Dev

ES6数组理解不再有效吗?

来自分类Dev

无法安装该应用,因为开发者证书不再有效

来自分类Dev

当std :: vector增长时,其中元素的地址不再有效吗?

Related 相关文章

  1. 1

    使用Python xarray屏蔽'where'不再有效

  2. 2

    Selenium Python通过表循环打印我得到的列值Element不再有效

  3. 3

    使用嵌套的EL动态读取编号的标头值不再有效

  4. 4

    在 iOS 10 中使用 URL 方案打开游戏中心不再有效

  5. 5

    历史上建议使用哪种x86 C优化实践不再有效?

  6. 6

    历史上建议使用哪种x86 C优化实践不再有效?

  7. 7

    Android:“ slideEdge”不再有效

  8. 8

    在Python中从多个xarray.Datasets中屏蔽NaN

  9. 9

    从Python中的多个xarray.Datasets中屏蔽NaN

  10. 10

    Android Play商店market://链接不再有效?

  11. 11

    雅虎财务不再有效吗?

  12. 12

    获取不再有效的Google Cache for PDF副本

  13. 13

    可用指针偏移量不再有效?

  14. 14

    提交密码表格不再有效

  15. 15

    CSS损坏-自动调整大小不再有效

  16. 16

    stringByAppendingPathComponent对swift2不再有效

  17. 17

    systemctl重装网络不再有效

  18. 18

    Liberty SSL 证书密钥不再有效

  19. 19

    Firebase 崩溃 - 批量上传不再有效

  20. 20

    Arrow 和 canc 确实不再有效

  21. 21

    Xtext 交叉引用不再有效?

  22. 22

    Tidyverse 更新和 rlang - 代码不再有效

  23. 23

    通过bash发送邮件曾经有效,现在不再有效

  24. 24

    Oracle SQL:在子查询中或在联接之后使用WHERE子句是否更有效?

  25. 25

    删除具有子对象的RLMObject时,Realm.io'RLMArray不再有效'

  26. 26

    带有 Ubuntu 18.04 的 Lenovo P1 上的 Wifi 不再有效

  27. 27

    ES6数组理解不再有效吗?

  28. 28

    无法安装该应用,因为开发者证书不再有效

  29. 29

    当std :: vector增长时,其中元素的地址不再有效吗?

热门标签

归档