oafuncs 0.0.98.17__py3-none-any.whl → 0.0.98.19__py3-none-any.whl

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.
@@ -1,4 +1,3 @@
1
- import importlib.util
2
1
  from typing import List, Union
3
2
 
4
3
  import numpy as np
@@ -6,85 +5,6 @@ from scipy.interpolate import griddata
6
5
 
7
6
  from oafuncs.oa_tool import PEx
8
7
 
9
- # 检查 pykdtree 是否可用
10
- _has_pykdtree = importlib.util.find_spec("pykdtree.kdtree") is not None
11
-
12
-
13
- def _fill_nan_nearest(arr: np.ndarray) -> np.ndarray:
14
- """
15
- 用最近邻填充 NaN(只支持2D数组)
16
- """
17
- # 基础检查:如果输入为None,直接返回None
18
- if arr is None:
19
- return None
20
-
21
- # 确保是2D ndarray
22
- arr = np.asarray(arr)
23
- if arr.ndim != 2:
24
- raise ValueError(f"_fill_nan_nearest 只支持2D数组,但输入的维度是 {arr.ndim}")
25
-
26
- # 保存原始dtype并转为float
27
- orig_dtype = arr.dtype
28
- arr = arr.astype(float, copy=True) # 使用copy=True确保不修改原数据
29
-
30
- # 检查是否有NaN需要填充
31
- mask = np.isnan(arr)
32
- if not mask.any():
33
- return arr.copy()
34
-
35
- try:
36
- valid = np.array(np.where(~mask)).T
37
- invalid = np.array(np.where(mask)).T
38
-
39
- # 如果有效点为空,直接返回原数据
40
- if valid.shape[0] == 0:
41
- return arr.copy()
42
-
43
- # 使用KDTree进行最近邻填充
44
- if _has_pykdtree:
45
- from pykdtree.kdtree import KDTree
46
-
47
- tree = KDTree(valid)
48
- _, idx = tree.query(invalid, k=1)
49
- filled = arr.copy()
50
- filled[tuple(invalid.T)] = arr[tuple(valid[idx.flatten()].T)]
51
- else:
52
- # 备用方法:使用scipy的distance_transform_edt
53
- from scipy.ndimage import distance_transform_edt
54
-
55
- idx = distance_transform_edt(mask, return_distances=False, return_indices=True)
56
- filled = arr[tuple(idx)]
57
-
58
- return filled.astype(orig_dtype)
59
- except Exception as e:
60
- import warnings
61
-
62
- warnings.warn(f"Error in _fill_nan_nearest: {e}, shape={arr.shape}")
63
- return arr.copy() # 发生异常返回原始数据
64
-
65
-
66
- def _data_clip(data: np.ndarray, data_min, data_max) -> np.ndarray:
67
- """
68
- 将数据裁剪至 [data_min, data_max],超出或 NaN 用最近邻填补。
69
- 支持 1~4D。
70
- """
71
- arr = np.array(data, copy=True) # 使用副本避免修改原数据
72
- ndims = arr.ndim
73
- if ndims != 2:
74
- raise ValueError(f"_data_clip 只支持1~4维数组,但输入的维度是 {ndims}")
75
- dtype = arr.dtype
76
-
77
- # 检查是否需要裁剪
78
- mask = np.isnan(arr) | (arr < data_min) | (arr > data_max)
79
- if not np.any(mask):
80
- return arr.astype(dtype)
81
-
82
- # 将超出范围的值设为NaN
83
- arr[mask] = np.nan
84
-
85
- return _fill_nan_nearest(arr).astype(dtype)
86
-
87
-
88
8
 
89
9
  def _interp_single_worker(*args):
90
10
  """
@@ -104,10 +24,6 @@ def _interp_single_worker(*args):
104
24
  result = griddata(valid_points, valid_data, target_points, method=interpolation_method)
105
25
  result = result.reshape(target_shape)
106
26
 
107
- # 第二步:用data_clip裁剪并填充
108
- data_min, data_max = np.nanmin(data_slice), np.nanmax(data_slice)
109
- result = _data_clip(result, data_min, data_max)
110
-
111
27
  return result
112
28
 
113
29
 
oafuncs/oa_data.py CHANGED
@@ -23,7 +23,7 @@ from rich import print
23
23
  from scipy.interpolate import interp1d
24
24
 
25
25
 
26
- __all__ = ["interp_along_dim", "interp_2d", "ensure_list", "mask_shapefile", "data_clip"]
26
+ __all__ = ["interp_along_dim", "interp_2d", "ensure_list", "mask_shapefile"]
27
27
 
28
28
 
29
29
  def ensure_list(input_value: Any) -> List[str]:
@@ -114,11 +114,6 @@ def interp_along_dim(
114
114
  return np.apply_along_axis(apply_interp_extrap, interpolation_axis, source_data)
115
115
 
116
116
 
117
- def data_clip(data: np.ndarray, data_min: float, data_max: float) -> np.ndarray:
118
- from ._script.data_interp import _data_clip
119
- _data_clip(data, data_min, data_max)
120
-
121
-
122
117
  def interp_2d(
123
118
  target_x_coordinates: Union[np.ndarray, List[float]],
124
119
  target_y_coordinates: Union[np.ndarray, List[float]],
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oafuncs
3
- Version: 0.0.98.17
3
+ Version: 0.0.98.19
4
4
  Summary: Oceanic and Atmospheric Functions
5
5
  Home-page: https://github.com/Industry-Pays/OAFuncs
6
6
  Author: Kun Liu
@@ -1,6 +1,6 @@
1
1
  oafuncs/__init__.py,sha256=T_-VtnWWllV3Q91twT5Yt2sUapeA051QbPNnBxmg9nw,1456
2
2
  oafuncs/oa_cmap.py,sha256=DimWT4Bg7uE5Lx8hSw1REp7whpsR2pFRStAwk1cowEM,11494
3
- oafuncs/oa_data.py,sha256=NOp7Rmjjypb17CNjk3Ksz08R7LygCEP6K4mna9mSXa8,8626
3
+ oafuncs/oa_data.py,sha256=y11xxaVNZ6_eveVjSG4PisRXYpKr_FFsBBh0mj_ss2g,8436
4
4
  oafuncs/oa_date.py,sha256=WhM6cyD4G3IeghjLTHhAMtlvJbA7kwQG2sHnxdTgyso,6303
5
5
  oafuncs/oa_draw.py,sha256=Wj2QBgyIPpV_dxaDrH10jqj_puK9ZM9rd-si-3VrsrE,17631
6
6
  oafuncs/oa_file.py,sha256=j9gXJgPOJsliu4IOUc4bc-luW4yBvQyNCEmMyDVjUwQ,16404
@@ -11,7 +11,7 @@ oafuncs/oa_tool.py,sha256=rpPkLqWhqMmqlCc5wjL8qMTg3gThCkSrYJckbX_0iJc,8631
11
11
  oafuncs/_data/hycom.png,sha256=MadKs6Gyj5n9-TOu7L4atQfTXtF9dvN9w-tdU9IfygI,10945710
12
12
  oafuncs/_data/oafuncs.png,sha256=o3VD7wm-kwDea5E98JqxXl04_78cBX7VcdUt7uQXGiU,3679898
13
13
  oafuncs/_script/cprogressbar.py,sha256=UIgGcLFs-6IgWlITuBLaQqrpt4OAK3Mst5RlCiNfZdQ,15772
14
- oafuncs/_script/data_interp.py,sha256=_k8EMSiFxutrqEVTLsL4mEPE6ssYq8bzmBlksCZ9nAE,7428
14
+ oafuncs/_script/data_interp.py,sha256=KJ-p-UN3Op1MmtCoN4KdjFVHFE3GNHrTD3vBjzaYSjQ,4688
15
15
  oafuncs/_script/data_interp_geo.py,sha256=X89KxLYhpltWi0Sf96gIhBL3r1M5aExd_JCmgBmmvUc,3742
16
16
  oafuncs/_script/email.py,sha256=lL4HGKrr524-g0xLlgs-4u7x4-u7DtgNoD9AL8XJKj4,3058
17
17
  oafuncs/_script/netcdf_merge.py,sha256=9hCyxfeUHnBzs50_0v0jzVfxpMxTX4dNTo0pmsp_T6g,4226
@@ -39,8 +39,8 @@ oafuncs/oa_sign/__init__.py,sha256=QKqTFrJDFK40C5uvk48GlRRbGFzO40rgkYwu6dYxatM,5
39
39
  oafuncs/oa_sign/meteorological.py,sha256=8091SHo2L8kl4dCFmmSH5NGVHDku5i5lSiLEG5DLnOQ,6489
40
40
  oafuncs/oa_sign/ocean.py,sha256=xrW-rWD7xBWsB5PuCyEwQ1Q_RDKq2KCLz-LOONHgldU,5932
41
41
  oafuncs/oa_sign/scientific.py,sha256=a4JxOBgm9vzNZKpJ_GQIQf7cokkraV5nh23HGbmTYKw,5064
42
- oafuncs-0.0.98.17.dist-info/licenses/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
43
- oafuncs-0.0.98.17.dist-info/METADATA,sha256=8-0Gp7bgVD7qR4sfSQtKmoCl5yV8f7YBnEROZV28oJY,4273
44
- oafuncs-0.0.98.17.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
45
- oafuncs-0.0.98.17.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
46
- oafuncs-0.0.98.17.dist-info/RECORD,,
42
+ oafuncs-0.0.98.19.dist-info/licenses/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
43
+ oafuncs-0.0.98.19.dist-info/METADATA,sha256=PJ_1BA6QOeA2QHSb61jwOFA2pDD2H4QT--m3tf_f44I,4273
44
+ oafuncs-0.0.98.19.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
45
+ oafuncs-0.0.98.19.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
46
+ oafuncs-0.0.98.19.dist-info/RECORD,,