arraysize和consistent get的关系

 首先看一下两个词的定义

arraysize
Arraysize specifies how many rows SQL*Plus will fetch in a call. The number n can be between 1 and 5000.
arraysize定义了一次返回到客户端的行数,当扫描了arraysize 行后,停止扫描,返回数据,然后继续扫描。所以假如一个数据块超过Arraysize设置的值就要被扫描多次.

consistent gets
Number of times a consistent read was requested for a block.

在使用sqlplus查看执行计划的时候,经常看consistent gets这个值,如下:

表CS_PERFORMANCE_CURRENT有15472条数据,3072个数据块,因此consistent gets =15472/15+472=1503.46666666667.当arraysize设置成400时,consistent gets =15472/400+472=510.68,当arraysize设置成5000时,consistent gets =15472/5000+472=475.0944。
Warning (from warnings module): File "C:/Users/ASUS/AppData/Local/Programs/Python/Python313/DC-run/8.27程序包/耦合运算.py", line 12 for _ in range(ds.dims['time']) # 确保广播兼容 FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`. Warning (from warnings module): File "C:/Users/ASUS/AppData/Local/Programs/Python/Python313/DC-run/8.27程序包/耦合运算.py", line 12 for _ in range(ds.dims['time']) # 确保广播兼容 FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`. Warning (from warnings module): File "C:/Users/ASUS/AppData/Local/Programs/Python/Python313/DC-run/8.27程序包/耦合运算.py", line 12 for _ in range(ds.dims['time']) # 确保广播兼容 FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`. Traceback (most recent call last): File "C:/Users/ASUS/AppData/Local/Programs/Python/Python313/DC-run/8.27程序包/耦合运算.py", line 27, in <module> npp_common = ds_npp.sel(time=np.isin(get_month_str(ds_npp).values, common_months)) File "C:\Users\ASUS\AppData\Local\Programs\Python\Python313\Lib\site-packages\xarray\core\dataset.py", line 2924, in sel result = self.isel(indexers=query_results.dim_indexers, drop=drop) File "C:\Users\ASUS\AppData\Local\Programs\Python\Python313\Lib\site-packages\xarray\core\dataset.py", line 2768, in isel indexes, index_variables = isel_indexes(self.xindexes, indexers) File "C:\Users\ASUS\AppData\Local\Programs\Python\Python313\Lib\site-packages\xarray\core\indexes.py", line 2123, in isel_indexes return _apply_indexes_fast(indexes, indexers, "isel") File "C:\Users\ASUS\AppData\Local\Programs\Python\Python313\Lib\site-packages\xarray\core\indexes.py", line 2077, in _apply_indexes_fast new_index = getattr(index, func)(index_args) File "C:\Users\ASUS\AppData\Local\Programs\Python\Python313\Lib\site-packages\xarray\core\indexes.py", line 820, in isel return self._replace(self.index[indxr]) # type: ignore[index] File "C:\Users\ASUS\AppData\Local\Programs\Python\Python313\Lib\site-packages\pandas\core\indexes\base.py", line 5428, in __getitem__ result = getitem(key) IndexError: boolean index did not match indexed array along axis 0; size of axis is 648 but size of corresponding boolean axis is 419904
最新发布
09-15
你遇到的错误如下: ``` IndexError: boolean index did not match indexed array along axis 0; size of axis is 648 but size of corresponding boolean axis is 419904 ``` 这是由于你在使用 `np.isin(...)` 构造布尔索引时,返回的布尔数组形状不匹配造成的。 --- ## ❓ 问题分析 你使用了如下方式构造布尔索引: ```python np.isin(get_month_str(ds_npp).values, common_months) ``` 但 `get_month_str(ds_npp)` 是通过如下方式构造的: ```python xr.concat([ ... for _ in range(ds.dims['time'])], dim='time') ``` 这个方式构造的 `DataArray` 是一个 **单时间点重复多次** 的数组,导致其扁平化为一维数组,与原始 `time` 维度不一致。最终 `np.isin(...)` 返回的布尔数组长度远远大于原始 `time` 的长度(648 vs 419904),因此 `sel(time=...)` 报错。 --- ## ✅ 正确做法:直接使用 `xarray` 的 `.dt` 方法提取年月 我们不需要手动构造时间字符串,`xarray` 提供了 `.dt` 接口来提取年、月、日等信息,并且可以自然地进行匹配。 --- ## ✅ 修改后的完整代码 ```python import xarray as xr import numpy as np # 加载数据 ds_npp = xr.open_dataset(r'E:\Except-Desktop\DC\CMIP6-download\historical-npp\npp_c2.nc') ds_soil = xr.open_dataset(r'E:\Except-Desktop\DC\CMIP6-download\historical-fLitterSoil\fLitterSoil_c12.nc') # 提取年月(自动兼容 cftime) npp_month = ds_npp.time.dt.strftime('%Y-%m') soil_month = ds_soil.time.dt.strftime('%Y-%m') # 找出共同月份 common_months = np.intersect1d(npp_month.values, soil_month.values) # 检查是否有共同月份 if len(common_months) == 0: raise ValueError("两个数据集没有共同月份") # 提取对应月份的数据 npp_common = ds_npp.sel(time=npp_month.isin(common_months)) soil_common = ds_soil.sel(time=soil_month.isin(common_months)) # 排序时间,确保顺序一致 npp_common = npp_common.sortby('time') soil_common = soil_common.sortby('time') # 打印维度检查 print("npp_common shape:", npp_common.shape) print("soil_common shape:", soil_common.shape) # 执行减法 difference = npp_common['npp'] - soil_common['fLitterSoil'] # 构建结果数据集,使用 npp 的时间作为统一时间轴 result_ds = xr.Dataset( {'npp_minus_soil': difference}, coords={ 'time': npp_common.time, 'lat': npp_common.lat, 'lon': npp_common.lon } ) # 输出结果 print(result_ds) result_ds.to_netcdf(r'E:\Except-Desktop\DC\CMIP6-download\results\npp_minus_soil_monthly_aligned.nc') ``` --- ## ✅ 代码解释 - `dt.strftime('%Y-%m')`:提取时间的年月信息,兼容 `cftime` 类型。 - `isin(...)`:构造布尔索引,筛选出共同月份对应的时间点。 - `sortby('time')`:确保两个数据集的时间顺序一致。 - 最终构建的 `Dataset` 使用 `npp` 的时间作为统一时间轴。 --- ## ✅ 优势 - 完全兼容 `cftime` 时间格式。 - 无需手动构造字符串或使用 `pandas`。 - 避免了布尔索引长度不一致的问题。 - 更加简洁、高效、可读性强。 --- ##
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值