oafuncs 0.0.98.24__py3-none-any.whl → 0.0.98.26__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.
- oafuncs/_script/data_interp_geo.py +35 -16
- oafuncs/oa_data.py +6 -1
- {oafuncs-0.0.98.24.dist-info → oafuncs-0.0.98.26.dist-info}/METADATA +1 -1
- {oafuncs-0.0.98.24.dist-info → oafuncs-0.0.98.26.dist-info}/RECORD +7 -7
- {oafuncs-0.0.98.24.dist-info → oafuncs-0.0.98.26.dist-info}/WHEEL +0 -0
- {oafuncs-0.0.98.24.dist-info → oafuncs-0.0.98.26.dist-info}/licenses/LICENSE.txt +0 -0
- {oafuncs-0.0.98.24.dist-info → oafuncs-0.0.98.26.dist-info}/top_level.txt +0 -0
@@ -78,17 +78,18 @@ def _interp_single_worker(*args):
|
|
78
78
|
data_filled = data_slice
|
79
79
|
|
80
80
|
# 创建xarray DataArray
|
81
|
+
|
81
82
|
da = xr.DataArray(
|
82
83
|
data_filled,
|
83
|
-
coords={"
|
84
|
-
dims=("
|
84
|
+
coords={"lat": source_lats, "lon": source_lons},
|
85
|
+
dims=("lat", "lon"),
|
85
86
|
)
|
86
87
|
|
87
88
|
# 创建Grid2D对象
|
88
89
|
grid = pyxr.Grid2D(da)
|
89
90
|
|
90
91
|
# 使用bicubic方法插值
|
91
|
-
result = grid.bicubic(coords={"
|
92
|
+
result = grid.bicubic(coords={"lon": target_lons.flatten(), "lat": target_lats.flatten()}, bounds_error=False, num_threads=1).reshape(target_lons.shape)
|
92
93
|
|
93
94
|
return result
|
94
95
|
|
@@ -99,6 +100,7 @@ def interp_2d_func_geo(
|
|
99
100
|
source_x_coordinates: Union[np.ndarray, List[float]],
|
100
101
|
source_y_coordinates: Union[np.ndarray, List[float]],
|
101
102
|
source_data: np.ndarray,
|
103
|
+
use_parallel: bool = True,
|
102
104
|
) -> np.ndarray:
|
103
105
|
"""
|
104
106
|
使用pyinterp进行地理插值,只使用bicubic方法。
|
@@ -150,23 +152,40 @@ def interp_2d_func_geo(
|
|
150
152
|
source_data = source_data.reshape((1,) * num_dims_to_add + source_data.shape)
|
151
153
|
t, z, y, x = source_data.shape
|
152
154
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
for
|
157
|
-
|
158
|
-
(
|
155
|
+
if use_parallel:
|
156
|
+
# 准备并行处理参数
|
157
|
+
params = []
|
158
|
+
for t_index in range(t):
|
159
|
+
for z_index in range(z):
|
160
|
+
params.append(
|
161
|
+
(
|
162
|
+
source_data[t_index, z_index],
|
163
|
+
source_x_coordinates[0, :], # 假设经度在每行都相同
|
164
|
+
source_y_coordinates[:, 0], # 假设纬度在每列都相同
|
165
|
+
target_x_coordinates,
|
166
|
+
target_y_coordinates,
|
167
|
+
)
|
168
|
+
)
|
169
|
+
|
170
|
+
# 并行执行插值
|
171
|
+
with PEx() as executor:
|
172
|
+
results = executor.run(_interp_single_worker, params)
|
173
|
+
|
174
|
+
# 还原到原始维度
|
175
|
+
return np.squeeze(np.array(results).reshape((t, z) + target_x_coordinates.shape))
|
176
|
+
else:
|
177
|
+
# 单线程处理
|
178
|
+
results = []
|
179
|
+
for t_index in range(t):
|
180
|
+
for z_index in range(z):
|
181
|
+
result = _interp_single_worker(
|
159
182
|
source_data[t_index, z_index],
|
160
183
|
source_x_coordinates[0, :], # 假设经度在每行都相同
|
161
184
|
source_y_coordinates[:, 0], # 假设纬度在每列都相同
|
162
185
|
target_x_coordinates,
|
163
186
|
target_y_coordinates,
|
164
187
|
)
|
165
|
-
|
166
|
-
|
167
|
-
# 并行执行插值
|
168
|
-
with PEx() as executor:
|
169
|
-
results = executor.run(_interp_single_worker, params)
|
188
|
+
results.append(result)
|
170
189
|
|
171
|
-
|
172
|
-
|
190
|
+
# 还原到原始维度
|
191
|
+
return np.squeeze(np.array(results).reshape((t, z) + target_x_coordinates.shape))
|
oafuncs/oa_data.py
CHANGED
@@ -150,6 +150,8 @@ def interp_2d(
|
|
150
150
|
>>> print(result.shape) # Expected output: (3, 3)
|
151
151
|
"""
|
152
152
|
from ._script.data_interp import interp_2d_func
|
153
|
+
|
154
|
+
source_data = np.asarray(source_data)
|
153
155
|
|
154
156
|
return interp_2d_func(
|
155
157
|
target_x_coordinates=target_x_coordinates,
|
@@ -167,6 +169,7 @@ def interp_2d_geo(
|
|
167
169
|
source_x_coordinates: Union[np.ndarray, List[float]],
|
168
170
|
source_y_coordinates: Union[np.ndarray, List[float]],
|
169
171
|
source_data: np.ndarray,
|
172
|
+
use_parallel: bool = True,
|
170
173
|
) -> np.ndarray:
|
171
174
|
"""
|
172
175
|
使用pyinterp进行地理插值,适用于全球尺度的地理数据与区域数据。
|
@@ -184,6 +187,7 @@ def interp_2d_geo(
|
|
184
187
|
source_y_coordinates: 源数据纬度 (-90 to 90)
|
185
188
|
source_data: 多维数组,最后两个维度为空间维度
|
186
189
|
interpolation_method: 插值方法: 只会使用 'bicubic' 方法。
|
190
|
+
use_parallel: 是否使用并行处理,默认开启。
|
187
191
|
|
188
192
|
Returns:
|
189
193
|
np.ndarray: 插值后的数据数组
|
@@ -211,7 +215,8 @@ def interp_2d_geo(
|
|
211
215
|
target_y_coordinates=target_y_coordinates,
|
212
216
|
source_x_coordinates=source_x_coordinates,
|
213
217
|
source_y_coordinates=source_y_coordinates,
|
214
|
-
source_data=source_data,
|
218
|
+
source_data=np.array(source_data),
|
219
|
+
use_parallel=use_parallel,
|
215
220
|
)
|
216
221
|
else:
|
217
222
|
print("[yellow]警告: pyinterp模块未安装,无法使用球面坐标插值。尝试使用平面插值作为备选方案。[/yellow]")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
oafuncs/__init__.py,sha256=T_-VtnWWllV3Q91twT5Yt2sUapeA051QbPNnBxmg9nw,1456
|
2
2
|
oafuncs/oa_cmap.py,sha256=pUFAGzbIg0WLxObBP2t_--ZIg00Dxdojx0y7OjTeqEo,11551
|
3
|
-
oafuncs/oa_data.py,sha256=
|
3
|
+
oafuncs/oa_data.py,sha256=vjQrCgzNlureBjGk0SK9luKmoPwfwmBsF_gX50xQvHQ,11594
|
4
4
|
oafuncs/oa_date.py,sha256=WhM6cyD4G3IeghjLTHhAMtlvJbA7kwQG2sHnxdTgyso,6303
|
5
5
|
oafuncs/oa_draw.py,sha256=IaBGDx-EOxyMM2IuJ4zLZt6ruHHV5qFStPItmUOXoWk,17635
|
6
6
|
oafuncs/oa_file.py,sha256=j9gXJgPOJsliu4IOUc4bc-luW4yBvQyNCEmMyDVjUwQ,16404
|
@@ -12,7 +12,7 @@ oafuncs/_data/hycom.png,sha256=MadKs6Gyj5n9-TOu7L4atQfTXtF9dvN9w-tdU9IfygI,10945
|
|
12
12
|
oafuncs/_data/oafuncs.png,sha256=o3VD7wm-kwDea5E98JqxXl04_78cBX7VcdUt7uQXGiU,3679898
|
13
13
|
oafuncs/_script/cprogressbar.py,sha256=UIgGcLFs-6IgWlITuBLaQqrpt4OAK3Mst5RlCiNfZdQ,15772
|
14
14
|
oafuncs/_script/data_interp.py,sha256=EiZbt6n5BEaRKcng88UgX7TFPhKE6TLVZniS01awXjg,5146
|
15
|
-
oafuncs/_script/data_interp_geo.py,sha256=
|
15
|
+
oafuncs/_script/data_interp_geo.py,sha256=5ozhMcTTKiw-182scSvBa2s7EuF43P0tv9rLcQv37kc,7313
|
16
16
|
oafuncs/_script/email.py,sha256=lL4HGKrr524-g0xLlgs-4u7x4-u7DtgNoD9AL8XJKj4,3058
|
17
17
|
oafuncs/_script/netcdf_merge.py,sha256=tM9ePqLiEsE7eIsNM5XjEYeXwxjYOdNz5ejnEuI7xKw,6066
|
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.
|
43
|
-
oafuncs-0.0.98.
|
44
|
-
oafuncs-0.0.98.
|
45
|
-
oafuncs-0.0.98.
|
46
|
-
oafuncs-0.0.98.
|
42
|
+
oafuncs-0.0.98.26.dist-info/licenses/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
|
43
|
+
oafuncs-0.0.98.26.dist-info/METADATA,sha256=jZe0cEvft0kKDqsA46aPF79paC0i7NPSx95QCDNAbVg,4273
|
44
|
+
oafuncs-0.0.98.26.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
45
|
+
oafuncs-0.0.98.26.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
|
46
|
+
oafuncs-0.0.98.26.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|