Alaea 2.6.8__tar.gz → 2.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- alaea-2.7.0/.VERSION +1 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Standard/xr_atmos.py +27 -3
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/baysalt/erosion_coastline.py +35 -18
- {alaea-2.6.8 → alaea-2.7.0/Alaea.egg-info}/PKG-INFO +1 -1
- {alaea-2.6.8 → alaea-2.7.0}/Alaea.egg-info/SOURCES.txt +1 -0
- {alaea-2.6.8 → alaea-2.7.0}/ChangeLog.md +14 -0
- {alaea-2.6.8/Alaea.egg-info → alaea-2.7.0}/PKG-INFO +1 -1
- {alaea-2.6.8 → alaea-2.7.0}/setup.py +1 -1
- alaea-2.7.0/tests/test_cumulative_maximum.py +134 -0
- {alaea-2.6.8 → alaea-2.7.0}/tests/test_erosion_dataarray.py +97 -0
- alaea-2.6.8/.VERSION +0 -1
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Blogging.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Pyshell/RS_File.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Pyshell/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/S_DateTime.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/SameAsMATLAB/CoorTrans.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/SameAsMATLAB/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/SameAsMATLAB/calculatefuns.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Standard/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Standard/vars_name.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Standard/xr_attrs.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Standard/xr_ice.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Standard/xr_netcdf.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Standard/xr_vars.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Standard/xr_wave.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/Standard/xr_wind.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/baysalt/Forage/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/baysalt/Forage/erosion_data/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/baysalt/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/commonCode.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/cprintfs.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/exutils/Interp/Interp_g2s.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/exutils/Interp/Interp_s2g.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/exutils/Interp/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/exutils/Interp/interpolate.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/exutils/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/netcdf_input.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/pFVCOM/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/pFVCOM/fvcom_class.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/pFVCOM/fvcom_image.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/pFVCOM/fvcom_load.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/pFVCOM/fvcom_tools.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/pFVCOM/writeFile.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/processBar.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/read_conf.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/server_info.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/storage.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/tools/P_params.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/tools/Read.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/tools/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/tools/download_check.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/tools/geo_distance.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/tools/kml2shp.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea/warningTools/__init__.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea.egg-info/dependency_links.txt +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea.egg-info/requires.txt +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/Alaea.egg-info/top_level.txt +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/LICENSE +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/MANIFEST.in +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/README.md +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/pyproject.toml +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/setup.cfg +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/tests/test_atmos_weather.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/tests/test_core.py +0 -0
- {alaea-2.6.8 → alaea-2.7.0}/tests/test_logging_multiprocess.py +0 -0
alaea-2.7.0/.VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v2.7.0
|
|
@@ -12,7 +12,7 @@ import xarray as xr
|
|
|
12
12
|
from .. import Ttime
|
|
13
13
|
from .xr_attrs import add_attrs_lat, add_attrs_lon, add_attrs_precipitation, add_attrs_slp, add_attrs_temperature, add_attrs_time, add_attrs_TIME, add_attrs_wind, calc_dtype, calc_fillvalue, compress_scale_offset, fixed_encoding
|
|
14
14
|
|
|
15
|
-
__all__ = ['xr_atmos_dataset', 'xr_wind_dataset', 'xr_air_temperature_dataset', 'xr_precipitation_dataset', 'xr_slp_dataset', 'resample_atmos_accumulation', 'resample_atmos_category', 'add_atmos_accumulation_precision']
|
|
15
|
+
__all__ = ['xr_atmos_dataset', 'xr_wind_dataset', 'xr_air_temperature_dataset', 'xr_precipitation_dataset', 'xr_slp_dataset', 'resample_atmos_accumulation', 'resample_atmos_category', 'add_atmos_accumulation_precision', 'cumulative_maximum']
|
|
16
16
|
|
|
17
17
|
_ATMOS_VARIABLE_ATTRS = {
|
|
18
18
|
# 天气判定输入保留原物理量;分类码及比例不等同于已判定的天气现象。
|
|
@@ -306,6 +306,30 @@ def xr_slp_dataset(_lon: np.ndarray, _lat: np.ndarray, _time, slp, **kwargs) ->
|
|
|
306
306
|
return xr_atmos_dataset(_lon, _lat, _time, slp=slp, **kwargs)
|
|
307
307
|
|
|
308
308
|
|
|
309
|
+
def cumulative_maximum(source, dim='time'):
|
|
310
|
+
"""按指定维度计算跳过 NaN 的前缀最大值,Dask 输入保留原分块而不展开滑动窗口。
|
|
311
|
+
|
|
312
|
+
:param source: xarray.DataArray,NumPy 或 Dask 支持的浮点数组;全缺测前缀仍为 NaN。
|
|
313
|
+
:param dim: str,累计维度名,默认 'time';按现有顺序扫描,不排序或填补缺测。
|
|
314
|
+
:return: xarray.DataArray,形状、维度、坐标、名称、属性和 dtype 保持;清除源 packing 编码,Dask 输入仍懒计算且 chunks 不变。
|
|
315
|
+
:raises ValueError: 输入不是浮点 DataArray,或累计维度缺失、为空。
|
|
316
|
+
"""
|
|
317
|
+
if not isinstance(source, xr.DataArray) or not np.issubdtype(source.dtype, np.floating):
|
|
318
|
+
raise ValueError('累计最大值要求浮点 DataArray')
|
|
319
|
+
if not isinstance(dim, str) or dim not in source.dims or source.sizes[dim] == 0:
|
|
320
|
+
raise ValueError('累计维度必须存在且非空')
|
|
321
|
+
axis = source.get_axis_num(dim)
|
|
322
|
+
if source.chunks is None:
|
|
323
|
+
result = np.fmax.accumulate(source.data, axis=axis)
|
|
324
|
+
else:
|
|
325
|
+
from dask.array.reductions import cumreduction
|
|
326
|
+
# NaN 是跳过缺测最大值的单位元;-inf 会把全缺测前缀误写为有效值。
|
|
327
|
+
result = cumreduction(np.fmax.accumulate, np.fmax, np.nan, source.data, axis=axis, dtype=source.dtype)
|
|
328
|
+
output = source.copy(data=result)
|
|
329
|
+
output.encoding = {}
|
|
330
|
+
return output
|
|
331
|
+
|
|
332
|
+
|
|
309
333
|
def resample_atmos_accumulation(source, target_times, unit_scale=1.0, quantization_error=None):
|
|
310
334
|
"""将同一起报的累计水当量守恒分配到输出区间,缺测不补零。
|
|
311
335
|
|
|
@@ -334,7 +358,7 @@ def resample_atmos_accumulation(source, target_times, unit_scale=1.0, quantizati
|
|
|
334
358
|
zero = xr.zeros_like(values.isel(time=0, drop=True)).expand_dims(time=[times[0]])
|
|
335
359
|
values = xr.concat([zero, values.isel(time=slice(1, None))], dim='time')
|
|
336
360
|
finite = np.isfinite(values)
|
|
337
|
-
repaired = values
|
|
361
|
+
repaired = cumulative_maximum(values)
|
|
338
362
|
if quantization_error is None:
|
|
339
363
|
unexplained = repaired - values
|
|
340
364
|
else:
|
|
@@ -343,7 +367,7 @@ def resample_atmos_accumulation(source, target_times, unit_scale=1.0, quantizati
|
|
|
343
367
|
if bool((quantization_error < 0).any().compute().item()) or bool(np.isinf(quantization_error).any().compute().item()):
|
|
344
368
|
raise ValueError('累计量误差界不得为负或无穷值')
|
|
345
369
|
errors = quantization_error.fillna(0).astype(np.float64)
|
|
346
|
-
unexplained = (values - errors)
|
|
370
|
+
unexplained = cumulative_maximum(values - errors) - values - errors
|
|
347
371
|
if bool((unexplained > 1e-9).any().compute().item()):
|
|
348
372
|
raise ValueError('累计水当量回退超出源量化误差界')
|
|
349
373
|
# 累计最大值只修复受误差界约束的小回退,恢复缺测掩码以禁止跨缺测插值。
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
"""
|
|
17
17
|
import os
|
|
18
18
|
import time
|
|
19
|
-
import warnings
|
|
20
19
|
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
|
|
21
20
|
from typing import List
|
|
22
21
|
|
|
@@ -280,7 +279,8 @@ def judge_nan_txtmask(latli, lonli, value, k, judge_num):
|
|
|
280
279
|
def erosion_via_id(_weight, value, is_direction=False, min_valid=None):
|
|
281
280
|
"""根据预先计算的邻居索引回填NumPy数组,支持任意前导维。
|
|
282
281
|
|
|
283
|
-
|
|
282
|
+
先筛选满足有效供点数的邻域再求均值,不对空邻域归约。
|
|
283
|
+
默认行为保持普通邻域均值及空邻域的NaN/掩膜结果;方向及有效阈值由调用方显式启用。
|
|
284
284
|
|
|
285
285
|
:param _weight: dict,erosion_cal_id返回的目标点和邻居索引。
|
|
286
286
|
:param value: numpy.ndarray或MaskedArray,末两维为纬度、经度;不修改输入。
|
|
@@ -313,22 +313,39 @@ def erosion_via_id(_weight, value, is_direction=False, min_valid=None):
|
|
|
313
313
|
if is_direction or min_valid is not None:
|
|
314
314
|
samples = np.ma.filled(np.asanyarray(samples, dtype=np.float64), np.nan)
|
|
315
315
|
samples = np.where(np.isfinite(samples), samples, np.nan)
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if
|
|
330
|
-
|
|
331
|
-
|
|
316
|
+
# 先筛选合格邻域,避免对全空或供点不足的行求均值;不修改线程共享的 warning 过滤器。
|
|
317
|
+
if is_direction or min_valid is not None:
|
|
318
|
+
valid_count = np.isfinite(samples).sum(axis=-1)
|
|
319
|
+
else:
|
|
320
|
+
valid_count = (~np.ma.getmaskarray(samples) & ~np.isnan(np.ma.getdata(samples))).sum(axis=-1)
|
|
321
|
+
usable = valid_count >= (1 if min_valid is None else min_valid)
|
|
322
|
+
replacement = value[..., change_lat, change_lon].copy()
|
|
323
|
+
if min_valid is None:
|
|
324
|
+
empty = ~usable
|
|
325
|
+
if np.ma.isMaskedArray(samples):
|
|
326
|
+
all_masked = np.ma.getmaskarray(samples).all(axis=-1)
|
|
327
|
+
replacement[empty & all_masked] = np.ma.masked
|
|
328
|
+
empty &= ~all_masked
|
|
329
|
+
if np.any(empty):
|
|
330
|
+
replacement[empty] = np.nan
|
|
331
|
+
if np.any(usable):
|
|
332
|
+
selected = samples[usable]
|
|
333
|
+
# 保持原邻居轴的连续性,避免 float16 标量均值因归约顺序变化而改变舍入结果。
|
|
334
|
+
if samples.strides[-1] != samples.dtype.itemsize:
|
|
335
|
+
selected = np.array(selected, order='F', subok=True)
|
|
336
|
+
with np.errstate(invalid='ignore', over='ignore'):
|
|
337
|
+
if is_direction:
|
|
338
|
+
radians = np.deg2rad(selected)
|
|
339
|
+
sine = np.nanmean(np.sin(radians), axis=-1)
|
|
340
|
+
cosine = np.nanmean(np.cos(radians), axis=-1)
|
|
341
|
+
has_direction = np.hypot(sine, cosine) > 1e-12
|
|
342
|
+
calculated = np.where(has_direction, np.rad2deg(np.arctan2(sine, cosine)) % 360, np.nan)
|
|
343
|
+
calculated = calculated.astype(value.dtype) % value.dtype.type(360)
|
|
344
|
+
if min_valid is not None:
|
|
345
|
+
calculated = np.ma.where(has_direction, calculated, replacement[usable]) if np.ma.isMaskedArray(value) else np.where(has_direction, calculated, replacement[usable])
|
|
346
|
+
else:
|
|
347
|
+
calculated = np.nanmean(selected, axis=-1)
|
|
348
|
+
replacement[usable] = calculated
|
|
332
349
|
new[..., change_lat, change_lon] = replacement
|
|
333
350
|
return new
|
|
334
351
|
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## v2.7.0
|
|
4
|
+
|
|
5
|
+
- 发布前源码与隔离安装 wheel 各 71 项回归通过;源码包和 wheel 的 2.7.0 版本、Python >=3.9 元数据、源码内容、隐藏文件及 Twine 检查通过。
|
|
6
|
+
|
|
7
|
+
- 新增公共 `cumulative_maximum`:用 NumPy 前缀扫描和 Dask 原分块累计归约代替全长滑动窗口,保持跳过 NaN、全缺测前缀、浮点 dtype、坐标和属性,清除不适用的源 packing 编码;NumPy 使用方不新增 Dask 依赖。现有累计水当量重采样复用该函数,累计守恒、缺测和量化误差判断不变。
|
|
8
|
+
- GFS/ECMWF 共用本接口处理总降水、累计误差下界和异常源时效定位,GFS 日照也复用;不修改科学阈值、文件字段或发布规则。本库 71 项、GFS 113 项及 ECMWF 98 项源码回归通过;额外覆盖跨块 NaN、非首轴、不规则分块、线性任务图和真实 NC packing 回读。
|
|
9
|
+
- 版本由上个已发布的 2.6.9 升级到 2.7.0,纳入此前未发布的 2.6.10 累计量优化;按用户要求通过 `run_twine.py` 发布到 PyPI。保留 Python >=3.9 和原有接口,下游最低依赖统一升级至 2.7.0,并在发布后定向刷新锁文件。
|
|
10
|
+
|
|
11
|
+
## v2.6.9
|
|
12
|
+
|
|
13
|
+
- 版本从2.6.8提升到2.6.9。源码包与wheel的版本、Python>=3.9、文件清单、隐藏元数据及Twine检查通过;隔离安装wheel后的14项岸边回归通过。
|
|
14
|
+
|
|
15
|
+
- 岸边填补先筛选满足有效供点数的邻域,再计算算术/圆周均值,避免空邻域 `Mean of empty slice` 警告和无效计算;移除该路径对进程共享 warning 过滤器的修改。有效点不足仍保留原值,旧接口空邻域的 NaN/掩膜结果、方向抵消规则、类型与共享权重保持。 保留旧 float16 标量归约的舍入行为;新增空邻域、阈值、掩膜、多线程和精度回归,Alaea 64 项测试、GFS/ECMWF 各 5 项集成测试及 2,592 组新旧数值对照通过。
|
|
16
|
+
|
|
3
17
|
## v2.6.8
|
|
4
18
|
|
|
5
19
|
- 发布前源码包与wheel通过版本、Python下限、文件清单、隐藏元数据和Twine检查;独立临时目录安装wheel后,共享参考接口最小验证通过。
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""累计最大值逐块扫描的科学语义和有界任务图回归。"""
|
|
2
|
+
import importlib.util
|
|
3
|
+
import unittest
|
|
4
|
+
import warnings
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
import pandas as pd
|
|
8
|
+
import xarray as xr
|
|
9
|
+
|
|
10
|
+
from Alaea.Standard import cumulative_maximum, resample_atmos_accumulation
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CumulativeMaximumTest(unittest.TestCase):
|
|
14
|
+
"""与旧滚动实现对照,覆盖缺测前缀、跨块状态和误差区间。"""
|
|
15
|
+
|
|
16
|
+
def test_numpy_prefix_nan_infinity_and_dtype(self):
|
|
17
|
+
"""跳过中间 NaN,保留全缺测前缀及 dtype;输入不被原地修改。
|
|
18
|
+
|
|
19
|
+
:return: None。
|
|
20
|
+
"""
|
|
21
|
+
matrix = np.array([[np.nan, np.nan, -np.inf], [np.nan, 2, -3], [1, np.nan, np.nan], [np.nan, -1, 5], [3, np.inf, 4]], dtype=float)
|
|
22
|
+
for dtype in (np.float16, np.float32, np.float64):
|
|
23
|
+
source = xr.DataArray(matrix.astype(dtype), dims=('time', 'point'))
|
|
24
|
+
original = source.copy(deep=True)
|
|
25
|
+
result = cumulative_maximum(source)
|
|
26
|
+
xr.testing.assert_equal(result, source.cumulative('time').max())
|
|
27
|
+
xr.testing.assert_equal(source, original)
|
|
28
|
+
self.assertEqual(result.dtype, source.dtype)
|
|
29
|
+
self.assertTrue(np.isnan(result[0, 0]))
|
|
30
|
+
self.assertTrue(np.isnan(result[1, 0]))
|
|
31
|
+
|
|
32
|
+
def test_preserves_axis_metadata_and_discards_source_packing(self):
|
|
33
|
+
"""任意维度顺序均按命名维累计,沿用属性但清除不适用的源 packing。
|
|
34
|
+
|
|
35
|
+
:return: None。
|
|
36
|
+
"""
|
|
37
|
+
source = xr.DataArray([[np.nan, 2., 1.], [-3., np.nan, 4.]], dims=('point', 'time'), coords={'time': pd.date_range('2026-01-01', periods=3, freq='h'), 'point': [1, 2]}, name='amount', attrs={'units': 'mm'})
|
|
38
|
+
source.encoding.update({'dtype': 'int16', 'scale_factor': .01, 'add_offset': 2.})
|
|
39
|
+
result = cumulative_maximum(source)
|
|
40
|
+
self.assertEqual(result.dims, source.dims)
|
|
41
|
+
self.assertEqual(result.name, source.name)
|
|
42
|
+
self.assertEqual(result.attrs, source.attrs)
|
|
43
|
+
self.assertEqual(result.encoding, {})
|
|
44
|
+
self.assertEqual(source.encoding['scale_factor'], .01)
|
|
45
|
+
xr.testing.assert_equal(result, source.cumulative('time').max())
|
|
46
|
+
|
|
47
|
+
def test_invalid_contract_is_rejected(self):
|
|
48
|
+
"""拒绝非浮点输入、无累计维及空累计轴。
|
|
49
|
+
|
|
50
|
+
:return: None。
|
|
51
|
+
"""
|
|
52
|
+
for source, dim in ((np.array([1.]), 'time'), (xr.DataArray([1], dims='time'), 'time'), (xr.DataArray([1j], dims='time'), 'time'), (xr.DataArray([1.], dims='time'), 'missing'), (xr.DataArray([], dims='time'), 'time'), (xr.DataArray([1.], dims='time'), None)):
|
|
53
|
+
with self.subTest(source=str(source), dim=dim), self.assertRaises(ValueError):
|
|
54
|
+
cumulative_maximum(source, dim)
|
|
55
|
+
|
|
56
|
+
@unittest.skipUnless(importlib.util.find_spec('dask'), 'Dask not installed')
|
|
57
|
+
def test_dask_is_lazy_keeps_chunks_and_cross_chunk_nan_prefix(self):
|
|
58
|
+
"""每个空间块独立跨时间块传递前缀,创建结果不读取源块。
|
|
59
|
+
|
|
60
|
+
:return: None。
|
|
61
|
+
"""
|
|
62
|
+
import dask.array as da
|
|
63
|
+
from dask import delayed
|
|
64
|
+
|
|
65
|
+
reads = []
|
|
66
|
+
values = np.array([[np.nan, 1., np.nan], [np.nan, np.nan, 2.], [3., -1., np.nan], [1., 4., 3.]])
|
|
67
|
+
@delayed
|
|
68
|
+
def read_source():
|
|
69
|
+
"""模拟源读取,返回二维 ndarray 并记录一次调用。"""
|
|
70
|
+
reads.append(1)
|
|
71
|
+
return values
|
|
72
|
+
source = xr.DataArray(da.from_delayed(read_source(), shape=values.shape, dtype=float).rechunk((1, 2)), dims=('time', 'point'))
|
|
73
|
+
result = cumulative_maximum(source)
|
|
74
|
+
self.assertEqual(reads, [])
|
|
75
|
+
self.assertEqual(result.chunks, source.chunks)
|
|
76
|
+
xr.testing.assert_equal(result.compute(), xr.DataArray(values, dims=source.dims).cumulative('time').max())
|
|
77
|
+
self.assertEqual(reads, [1])
|
|
78
|
+
|
|
79
|
+
@unittest.skipUnless(importlib.util.find_spec('dask'), 'Dask not installed')
|
|
80
|
+
def test_graph_remains_linear_without_spatial_rechunk(self):
|
|
81
|
+
"""长时间轴只增加线性任务,空间分块不能因累计窗口展开而碎化。
|
|
82
|
+
|
|
83
|
+
:return: None。
|
|
84
|
+
"""
|
|
85
|
+
import dask.array as da
|
|
86
|
+
|
|
87
|
+
for length in (13, 49, 145):
|
|
88
|
+
source = xr.DataArray(da.ones((length, 8, 16), chunks=(1, 4, 8), dtype=np.float32), dims=('time', 'latitude', 'longitude'))
|
|
89
|
+
with warnings.catch_warnings():
|
|
90
|
+
warnings.simplefilter('error', da.core.PerformanceWarning)
|
|
91
|
+
result = cumulative_maximum(source)
|
|
92
|
+
self.assertEqual(result.chunks, source.chunks)
|
|
93
|
+
self.assertLessEqual(len(result.data.__dask_graph__()), 5 * source.data.npartitions)
|
|
94
|
+
self.assertEqual(result.sizes, source.sizes)
|
|
95
|
+
|
|
96
|
+
@unittest.skipUnless(importlib.util.find_spec('dask'), 'Dask not installed')
|
|
97
|
+
def test_random_axis_chunk_layout_matches_rolling(self):
|
|
98
|
+
"""不规则时间/空间分块、不同轴顺序的累计值与旧实现一致。
|
|
99
|
+
|
|
100
|
+
:return: None。
|
|
101
|
+
"""
|
|
102
|
+
rng = np.random.default_rng(410)
|
|
103
|
+
raw = rng.normal(size=(7, 3, 4))
|
|
104
|
+
raw[rng.random(raw.shape) < .3] = np.nan
|
|
105
|
+
raw[:3, 0, 0] = np.nan
|
|
106
|
+
for dtype in (np.float32, np.float64):
|
|
107
|
+
for axis in (0, 1, 2):
|
|
108
|
+
source = xr.DataArray(raw.astype(dtype), dims=('time', 'latitude', 'longitude')).transpose(*np.roll(['time', 'latitude', 'longitude'], axis))
|
|
109
|
+
for size in (1, 3, 7):
|
|
110
|
+
chunked = source.chunk({'time': size, 'latitude': 2, 'longitude': 2})
|
|
111
|
+
result = cumulative_maximum(chunked)
|
|
112
|
+
self.assertEqual(result.chunks, chunked.chunks)
|
|
113
|
+
xr.testing.assert_allclose(result.compute(), source.cumulative('time').max())
|
|
114
|
+
|
|
115
|
+
@unittest.skipUnless(importlib.util.find_spec('dask'), 'Dask not installed')
|
|
116
|
+
def test_accumulation_missing_support_and_quantization_unchanged(self):
|
|
117
|
+
"""原误差界内回退仍修复,无法解释的回退仍拒绝,缺测端点不跨越填补。
|
|
118
|
+
|
|
119
|
+
:return: None。
|
|
120
|
+
"""
|
|
121
|
+
times = pd.date_range('2026-01-01', periods=4, freq='3h')
|
|
122
|
+
target = pd.date_range('2026-01-01', periods=10, freq='h')
|
|
123
|
+
source = xr.DataArray([0., 3., 2.99, 9.], dims='time', coords={'time': times}).chunk({'time': 1})
|
|
124
|
+
errors = xr.DataArray([0., .01, .01, .01], dims='time', coords={'time': times})
|
|
125
|
+
result = resample_atmos_accumulation(source, target, quantization_error=errors).compute()
|
|
126
|
+
self.assertAlmostEqual(float(result.sum()), 9.)
|
|
127
|
+
self.assertTrue(bool((result >= 0).all()))
|
|
128
|
+
with self.assertRaisesRegex(ValueError, '量化误差'):
|
|
129
|
+
resample_atmos_accumulation(source, target)
|
|
130
|
+
missing = source.where(source.time != times[1])
|
|
131
|
+
actual = resample_atmos_accumulation(missing, target, quantization_error=errors).compute()
|
|
132
|
+
eager = resample_atmos_accumulation(missing.compute(), target, quantization_error=errors)
|
|
133
|
+
xr.testing.assert_equal(actual, eager)
|
|
134
|
+
self.assertTrue(bool(actual.isel(time=slice(1, 7)).isnull().all()))
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import importlib
|
|
4
4
|
import unittest
|
|
5
|
+
import warnings
|
|
5
6
|
from unittest import mock
|
|
6
7
|
|
|
7
8
|
import numpy as np
|
|
@@ -138,6 +139,102 @@ class ErosionDataArrayTest(unittest.TestCase):
|
|
|
138
139
|
self.assertTrue(np.ma.is_masked(erosion_via_id(weight, masked, min_valid=2)[1, 1, 1]))
|
|
139
140
|
|
|
140
141
|
|
|
142
|
+
def test_reductions_skip_insufficient_neighbors_without_changing_warning_filters(self):
|
|
143
|
+
"""四维输入仅归约合格邻域;全空、稀疏邻域及方向抵消保留原值。
|
|
144
|
+
|
|
145
|
+
:return: None;均值收到不合格邻域、全局过滤器变化或数值不正确时断言失败。
|
|
146
|
+
"""
|
|
147
|
+
weight = {'change_lat': [1], 'change_lon': [1], 'value_lat': [[0, 0, 0]], 'value_lon': [[0, 1, 2]]}
|
|
148
|
+
values = np.full((2, 2, 2, 3), np.nan, dtype=np.float32)
|
|
149
|
+
values.reshape(4, 2, 3)[:, 0] = [[359, 0, 1], [np.nan, np.nan, np.nan], [30, np.nan, np.nan], [0, 120, 240]]
|
|
150
|
+
values.reshape(4, 2, 3)[:, 1, 1] = [8, 7, 11, 17]
|
|
151
|
+
original = values.copy()
|
|
152
|
+
original_mean = np.nanmean
|
|
153
|
+
for direction in (False, True):
|
|
154
|
+
with self.subTest(direction=direction), warnings.catch_warnings():
|
|
155
|
+
warnings.simplefilter('error', RuntimeWarning)
|
|
156
|
+
filters_before = warnings.filters.copy()
|
|
157
|
+
|
|
158
|
+
def checked_mean(samples, axis):
|
|
159
|
+
"""检查归约输入与线程共享的警告过滤器,再调用 NumPy 均值。
|
|
160
|
+
|
|
161
|
+
:param samples: numpy.ndarray,仅包含满足最少供点数的邻域。
|
|
162
|
+
:param axis: int,邻居所在的归约轴。
|
|
163
|
+
:return: numpy.ndarray,独立 NumPy 算出的邻域均值。
|
|
164
|
+
"""
|
|
165
|
+
self.assertEqual(samples.shape, (2, 3))
|
|
166
|
+
self.assertTrue(np.all(np.isfinite(samples).sum(axis=axis) >= 3))
|
|
167
|
+
self.assertEqual(warnings.filters, filters_before)
|
|
168
|
+
return original_mean(samples, axis=axis)
|
|
169
|
+
|
|
170
|
+
with mock.patch.object(np, 'nanmean', side_effect=checked_mean):
|
|
171
|
+
result = erosion_via_id(weight, values, is_direction=direction, min_valid=3)
|
|
172
|
+
targets = result.reshape(4, 2, 3)[:, 1, 1]
|
|
173
|
+
self.assertEqual(result.dtype, values.dtype)
|
|
174
|
+
np.testing.assert_array_equal(targets[1:3], [7, 11])
|
|
175
|
+
if direction:
|
|
176
|
+
self.assertLess(min(abs(float(targets[0])), abs(float(targets[0]) - 360)), 1e-4)
|
|
177
|
+
self.assertEqual(targets[3], 17)
|
|
178
|
+
else:
|
|
179
|
+
np.testing.assert_allclose(targets[[0, 3]], [120, 120])
|
|
180
|
+
np.testing.assert_array_equal(values, original)
|
|
181
|
+
with mock.patch.object(np, 'nanmean', side_effect=AssertionError('ineligible neighborhood reduced')):
|
|
182
|
+
np.testing.assert_array_equal(erosion_via_id(weight, values, min_valid=4), values)
|
|
183
|
+
|
|
184
|
+
def test_empty_legacy_neighbors_keep_nan_and_mask_semantics_without_warnings(self):
|
|
185
|
+
"""旧标量接口保留全空结果与全掩膜结果,整数和浮点类型不变。
|
|
186
|
+
|
|
187
|
+
:return: None;空均值产生警告、旧接口数值或掩膜语义变化时断言失败。
|
|
188
|
+
"""
|
|
189
|
+
weight = {'change_lat': [1], 'change_lon': [1], 'value_lat': [[0, 0]], 'value_lon': [[0, 1]]}
|
|
190
|
+
with warnings.catch_warnings():
|
|
191
|
+
warnings.simplefilter('error', RuntimeWarning)
|
|
192
|
+
for direction in (False, True):
|
|
193
|
+
values = np.full((2, 2), np.nan, dtype=np.float32)
|
|
194
|
+
values[1, 1] = 7
|
|
195
|
+
result = erosion_via_id(weight, values, is_direction=direction)
|
|
196
|
+
self.assertTrue(np.isnan(result[1, 1]))
|
|
197
|
+
self.assertEqual(values[1, 1], 7)
|
|
198
|
+
masked = np.ma.array([[1, 2], [3, 4]], mask=[[True, True], [False, False]])
|
|
199
|
+
result = erosion_via_id(weight, masked)
|
|
200
|
+
self.assertTrue(np.ma.is_masked(result[1, 1]))
|
|
201
|
+
self.assertEqual(result.dtype, masked.dtype)
|
|
202
|
+
partial = np.ma.array([[np.nan, 2], [3, 4]], mask=[[False, True], [False, False]])
|
|
203
|
+
result = erosion_via_id(weight, partial)
|
|
204
|
+
self.assertFalse(np.ma.is_masked(result[1, 1]))
|
|
205
|
+
self.assertTrue(np.isnan(result[1, 1]))
|
|
206
|
+
|
|
207
|
+
def test_legacy_float16_preserves_reduction_rounding(self):
|
|
208
|
+
"""筛选邻域后仍保持旧 float16 标量接口的求和顺序与舍入结果。
|
|
209
|
+
|
|
210
|
+
:return: None;连续/跨步邻居轴的结果与原归约不同则断言失败。
|
|
211
|
+
"""
|
|
212
|
+
weight = {'change_lat': [1], 'change_lon': [0], 'value_lat': [[0, 0, 0, 0]], 'value_lon': [[0, 1, 2, 3]]}
|
|
213
|
+
values = np.zeros((2, 2, 4), dtype=np.float16)
|
|
214
|
+
values[:, 0] = [10.195, 44.75, 138.1, np.nan]
|
|
215
|
+
for source in (values, values[0], np.ma.array(values, mask=False)):
|
|
216
|
+
with self.subTest(shape=source.shape, masked=np.ma.isMaskedArray(source)):
|
|
217
|
+
expected = np.nanmean(source[..., weight['value_lat'], weight['value_lon']], axis=-1)
|
|
218
|
+
result = erosion_via_id(weight, source)
|
|
219
|
+
np.testing.assert_array_equal(result[..., weight['change_lat'], weight['change_lon']], expected)
|
|
220
|
+
|
|
221
|
+
def test_threaded_direction_blocks_allow_entirely_missing_component_frames(self):
|
|
222
|
+
"""共享 swh 索引的 Dask 多线程方向回填不对全空分量帧发出警告。
|
|
223
|
+
|
|
224
|
+
:return: None;合法岸边填补错误、全空帧被填值或运行警告出现时断言失败。
|
|
225
|
+
"""
|
|
226
|
+
heights = np.full((1, 9, 9), np.nan, dtype=np.float32)
|
|
227
|
+
heights[:, :, :4] = 1
|
|
228
|
+
reference = field(heights).isel(time=0, drop=True)
|
|
229
|
+
values = np.full((12, 9, 9), np.nan, dtype=np.float32)
|
|
230
|
+
values[::3, :, :4] = 45
|
|
231
|
+
with warnings.catch_warnings(record=True) as captured:
|
|
232
|
+
warnings.simplefilter('always', RuntimeWarning)
|
|
233
|
+
result = erosion_fill_dataarray(field(values).chunk({'time': 1}), 1, 16, 3, is_direction=True, reference=reference).compute(scheduler='threads', num_workers=4)
|
|
234
|
+
self.assertFalse([item for item in captured if issubclass(item.category, RuntimeWarning)])
|
|
235
|
+
np.testing.assert_allclose(result.values[::3, 4, 4], 45)
|
|
236
|
+
self.assertTrue(np.isnan(result.values[np.arange(12) % 3 != 0]).all())
|
|
237
|
+
|
|
141
238
|
def test_shared_reference_does_not_fill_component_only_ocean_holes(self):
|
|
142
239
|
"""全部变量复用swh索引,分区独有海上缺测不成为填补目标;返回None。"""
|
|
143
240
|
heights = np.full((2, 9, 9), np.nan, dtype=np.float32)
|
alaea-2.6.8/.VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
v2.6.8
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|