oafuncs 0.0.98.16__py3-none-any.whl → 0.0.98.18__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,52 +1,9 @@
1
- import importlib.util
2
1
  from typing import List, Union
3
2
 
4
3
  import numpy as np
5
- from oafuncs.oa_tool import PEx
6
4
  from scipy.interpolate import griddata
7
5
 
8
- _has_pykdtree = importlib.util.find_spec("pykdtree.kdtree") is not None
9
-
10
-
11
- def _fill_nan_nearest(arr):
12
- """用最近邻插值填充 NaN,优先用pykdtree加速"""
13
- mask = np.isnan(arr)
14
- if not mask.any():
15
- return arr
16
- if _has_pykdtree:
17
- from pykdtree.kdtree import KDTree
18
-
19
- valid_idx = np.array(np.where(~mask)).T
20
- nan_idx = np.array(np.where(mask)).T
21
- if len(valid_idx) == 0:
22
- # 全是nan,直接返回
23
- return arr
24
- tree = KDTree(valid_idx)
25
- dist, idx = tree.query(nan_idx, k=1)
26
- filled = arr.copy()
27
- # idx shape: (n_nan, 1),valid_idx shape: (n_valid, ndim)
28
- # valid_idx[idx].T shape: (ndim, n_nan)
29
- filled[tuple(nan_idx.T)] = arr[tuple(valid_idx[idx.flatten()].T)]
30
- return filled
31
- else:
32
- from scipy.ndimage import distance_transform_edt
33
-
34
- idx = distance_transform_edt(mask, return_distances=False, return_indices=True)
35
- return arr[tuple(idx)]
36
-
37
-
38
- def _data_clip(data, data_min, data_max):
39
- """
40
- 对data进行范围裁剪,超出范围的点设为nan,并用fill_nan_nearest填充,最后再次填充极端nan。
41
- """
42
- arr = np.asarray(data)
43
- mask = np.isnan(arr) | (arr < data_min) | (arr > data_max)
44
- if np.any(mask):
45
- arr = np.where(mask, np.nan, arr)
46
- arr = _fill_nan_nearest(arr)
47
- if np.any(np.isnan(arr)):
48
- arr = _fill_nan_nearest(arr)
49
- return arr
6
+ from oafuncs.oa_tool import PEx
50
7
 
51
8
 
52
9
  def _interp_single_worker(*args):
@@ -69,7 +26,7 @@ def _interp_single_worker(*args):
69
26
 
70
27
  # 第二步:用data_clip裁剪并填充
71
28
  data_min, data_max = np.nanmin(data_slice), np.nanmax(data_slice)
72
- result = _data_clip(result, data_min, data_max)
29
+ result = np.clip(result, data_min, data_max)
73
30
 
74
31
  return result
75
32
 
@@ -1,54 +1,11 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2025-04-26 11:54:21
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2025-04-26 11:54:22
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\_script\\data_interp_geo.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
-
16
- import importlib.util
17
1
  from typing import List, Union
18
2
 
19
3
  import numpy as np
20
4
  from scipy.interpolate import RectBivariateSpline
21
5
 
22
6
  from oafuncs.oa_tool import PEx
23
-
24
- _has_pykdtree = importlib.util.find_spec("pykdtree.kdtree") is not None
25
-
26
-
27
- def fill_nan_nearest(arr):
28
- """用最近邻插值填充 NaN,优先用pykdtree加速"""
29
- mask = np.isnan(arr)
30
- if not mask.any():
31
- return arr
32
- if _has_pykdtree:
33
- from pykdtree.kdtree import KDTree
34
-
35
- valid_idx = np.array(np.where(~mask)).T
36
- nan_idx = np.array(np.where(mask)).T
37
- if len(valid_idx) == 0:
38
- # 全是nan,直接返回
39
- return arr
40
- tree = KDTree(valid_idx)
41
- dist, idx = tree.query(nan_idx, k=1)
42
- filled = arr.copy()
43
- # idx shape: (n_nan, 1),valid_idx shape: (n_valid, ndim)
44
- # valid_idx[idx].T shape: (ndim, n_nan)
45
- filled[tuple(nan_idx.T)] = arr[tuple(valid_idx[idx.flatten()].T)]
46
- return filled
47
- else:
48
- from scipy.ndimage import distance_transform_edt
49
-
50
- idx = distance_transform_edt(mask, return_distances=False, return_indices=True)
51
- return arr[tuple(idx)]
7
+ from oafuncs.oa_data import data_clip
8
+ from oafuncs._script.data_interp import _fill_nan_nearest
52
9
 
53
10
 
54
11
  def _interp_single_worker(*args):
@@ -63,7 +20,7 @@ def _interp_single_worker(*args):
63
20
  if np.isnan(data_slice).any():
64
21
  mask = np.isnan(data_slice)
65
22
  if mask.any():
66
- data_slice = fill_nan_nearest(data_slice)
23
+ data_slice = _fill_nan_nearest(data_slice)
67
24
  x1d = np.unique(sx[0, :])
68
25
  y1d = np.unique(sy[:, 0])
69
26
  if sx.shape != (len(y1d), len(x1d)) or sy.shape != (len(y1d), len(x1d)):
@@ -80,13 +37,7 @@ def _interp_single_worker(*args):
80
37
  out = interp_func(ty[:, 0], tx[0, :])
81
38
  # 优化裁剪逻辑:超出范围的点设为nan,再用fill_nan_nearest填充
82
39
  arr = np.asarray(out)
83
- mask = np.isnan(arr) | (arr < data_min) | (arr > data_max)
84
- if np.any(mask):
85
- arr = np.where(mask, np.nan, arr)
86
- arr = fill_nan_nearest(arr)
87
- # 最后再填充nan(极端情况)
88
- if np.any(np.isnan(arr)):
89
- arr = fill_nan_nearest(arr)
40
+ arr = data_clip(arr,data_min,data_max)
90
41
  return arr
91
42
 
92
43
 
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.16
3
+ Version: 0.0.98.18
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,8 +11,8 @@ 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=W4kYZmkZxWJqKfZVdQOd8jUv0y11t6k8tsukRQt670I,6373
15
- oafuncs/_script/data_interp_geo.py,sha256=Fv-l8MeKhx6e7UVtzk2b6Pb2Cfcg-RNnMFmkcd0ng64,5296
14
+ oafuncs/_script/data_interp.py,sha256=zfxrYdseAwJdIr-2DtqvZYJ74slhnWGAfxuyBkoX12U,4858
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
18
18
  oafuncs/_script/netcdf_modify.py,sha256=sGRUYNhfGgf9JV70rnBzw3bzuTRSXzBTL_RMDnDPeLQ,4552
@@ -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.16.dist-info/licenses/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
43
- oafuncs-0.0.98.16.dist-info/METADATA,sha256=yPzl7v8ASdNRSjiXasAGuxPKA9rM_zCIQBQHfmz4I0k,4273
44
- oafuncs-0.0.98.16.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
45
- oafuncs-0.0.98.16.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
46
- oafuncs-0.0.98.16.dist-info/RECORD,,
42
+ oafuncs-0.0.98.18.dist-info/licenses/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
43
+ oafuncs-0.0.98.18.dist-info/METADATA,sha256=T-WJgDwO5iPo3j15bDHUDKYOuIOTgrZGeHY9wHEuS_Q,4273
44
+ oafuncs-0.0.98.18.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
45
+ oafuncs-0.0.98.18.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
46
+ oafuncs-0.0.98.18.dist-info/RECORD,,