oafuncs 0.0.81__tar.gz → 0.0.83__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.
- oafuncs-0.0.83/MANIFEST.in +2 -0
- oafuncs-0.0.83/PKG-INFO +91 -0
- oafuncs-0.0.83/README.md +58 -0
- oafuncs-0.0.83/oafuncs/data_store/OAFuncs.png +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_cmap.py +1 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_data.py +107 -28
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_down/__init__.py +5 -4
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_down/hycom_3hourly.py +152 -35
- oafuncs-0.0.83/oafuncs/oa_down/user_agent.py +34 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_draw.py +165 -103
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_file.py +66 -53
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_help.py +19 -16
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_nc.py +82 -114
- oafuncs-0.0.83/oafuncs.egg-info/PKG-INFO +91 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs.egg-info/SOURCES.txt +2 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/setup.py +1 -1
- oafuncs-0.0.81/MANIFEST.in +0 -1
- oafuncs-0.0.81/PKG-INFO +0 -918
- oafuncs-0.0.81/README.md +0 -885
- oafuncs-0.0.81/oafuncs.egg-info/PKG-INFO +0 -918
- {oafuncs-0.0.81 → oafuncs-0.0.83}/LICENSE.txt +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/__init__.py +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_down/User_Agent-list.txt +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_down/literature.py +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_down/test_ua.py +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_python.py +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_sign/__init__.py +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_sign/meteorological.py +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_sign/ocean.py +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_sign/scientific.py +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_tool/__init__.py +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs/oa_tool/email.py +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs.egg-info/dependency_links.txt +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs.egg-info/requires.txt +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/oafuncs.egg-info/top_level.txt +0 -0
- {oafuncs-0.0.81 → oafuncs-0.0.83}/setup.cfg +0 -0
oafuncs-0.0.83/PKG-INFO
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: oafuncs
|
3
|
+
Version: 0.0.83
|
4
|
+
Summary: My short description for my project.
|
5
|
+
Home-page: https://github.com/Industry-Pays/OAFuncs
|
6
|
+
Author: Kun Liu
|
7
|
+
Author-email: liukun0312@stu.ouc.edu.cn
|
8
|
+
License: MIT
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Programming Language :: Python
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
16
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
18
|
+
Requires-Python: >=3.9.0
|
19
|
+
Description-Content-Type: text/markdown
|
20
|
+
License-File: LICENSE.txt
|
21
|
+
Requires-Dist: matplotlib
|
22
|
+
Requires-Dist: numpy
|
23
|
+
Requires-Dist: scipy
|
24
|
+
Requires-Dist: xarray
|
25
|
+
Requires-Dist: Cartopy
|
26
|
+
Requires-Dist: netCDF4
|
27
|
+
Requires-Dist: requests
|
28
|
+
Requires-Dist: bs4
|
29
|
+
Requires-Dist: rich
|
30
|
+
Requires-Dist: pathlib
|
31
|
+
Requires-Dist: pandas
|
32
|
+
|
33
|
+
|
34
|
+
# oafuncs
|
35
|
+
|
36
|
+
## Description
|
37
|
+
|
38
|
+
**Python Function**
|
39
|
+
|
40
|
+
```text
|
41
|
+
In the field of geoscience, some commonly used and universal operations!
|
42
|
+
|
43
|
+
Just for the convenience of daily use, some complex operations are integrated into general functions.
|
44
|
+
|
45
|
+
The code will be optimized and updated from time to time, with additions, deletions, or modifications…
|
46
|
+
|
47
|
+
Existing functions will not be completely removed, they might just have a different function name, or the parameter passing might have been optimized…
|
48
|
+
|
49
|
+
Note: If there are any requirements, you can email to liukun0312@stu.ouc.edu.cn. Within my capabilities, I can consider implementing them.
|
50
|
+
```
|
51
|
+
|
52
|
+
## PyPI
|
53
|
+
|
54
|
+
```html
|
55
|
+
https://pypi.org/project/oafuncs
|
56
|
+
```
|
57
|
+
|
58
|
+
## Github
|
59
|
+
|
60
|
+
```html
|
61
|
+
https://github.com/Industry-Pays/OAFuncs
|
62
|
+
```
|
63
|
+
|
64
|
+
## Example
|
65
|
+
|
66
|
+
```python
|
67
|
+
import oafuncs
|
68
|
+
|
69
|
+
# 查询当前所有可用函数
|
70
|
+
oafuncs.oa_help.query()
|
71
|
+
# 根据函数名获取使用方法
|
72
|
+
oafuncs.oa_help.use('query')
|
73
|
+
```
|
74
|
+
|
75
|
+
```shell
|
76
|
+
# 此小板块于2024/12/26更新,仅为示例,不代表最新情况
|
77
|
+
函数数量:
|
78
|
+
49
|
79
|
+
函数列表:
|
80
|
+
['MidpointNormalize', 'add_cartopy', 'add_gridlines', 'add_lonlat_unit', 'check_ncfile', 'choose_cmap', 'clear_folder', 'cmap2colors', 'convert_longitude', 'copy_file', 'create_cmap', 'create_cmap_rgbtxt', 'create_gif', 'download', 'download5doi', 'draw_time_range', 'extract5nc', 'fig_minus', 'file_size', 'find_file', 'get_time_list', 'get_ua', 'get_var', 'how_to_use', 'install_lib', 'interp_2d', 'link_file', 'make_folder', 'merge5nc', 'modify_var_attr', 'modify_var_value', 'nc_isel', 'plot_contourf', 'plot_contourf_cartopy', 'plot_contourf_lonlat', 'plot_quiver', 'query', 'remove', 'remove_empty_folder', 'rename_file', 'rename_var_or_dim', 'send', 'show', 'sign_in_love_ocean', 'sign_in_meteorological_home', 'sign_in_scientific_research', 'upgrade_lib', 'use', 'write2nc']
|
81
|
+
模块全路径:
|
82
|
+
oafuncs.oa_help.query
|
83
|
+
函数提示:
|
84
|
+
|
85
|
+
description: 查看oafuncs模块的函数列表
|
86
|
+
example: query()
|
87
|
+
```
|
88
|
+
|
89
|
+
## Structure
|
90
|
+
|
91
|
+
<img title="" src="./oafuncs/data_store/OAFuncs.png" alt="">
|
oafuncs-0.0.83/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# oafuncs
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
**Python Function**
|
6
|
+
|
7
|
+
```text
|
8
|
+
In the field of geoscience, some commonly used and universal operations!
|
9
|
+
|
10
|
+
Just for the convenience of daily use, some complex operations are integrated into general functions.
|
11
|
+
|
12
|
+
The code will be optimized and updated from time to time, with additions, deletions, or modifications…
|
13
|
+
|
14
|
+
Existing functions will not be completely removed, they might just have a different function name, or the parameter passing might have been optimized…
|
15
|
+
|
16
|
+
Note: If there are any requirements, you can email to liukun0312@stu.ouc.edu.cn. Within my capabilities, I can consider implementing them.
|
17
|
+
```
|
18
|
+
|
19
|
+
## PyPI
|
20
|
+
|
21
|
+
```html
|
22
|
+
https://pypi.org/project/oafuncs
|
23
|
+
```
|
24
|
+
|
25
|
+
## Github
|
26
|
+
|
27
|
+
```html
|
28
|
+
https://github.com/Industry-Pays/OAFuncs
|
29
|
+
```
|
30
|
+
|
31
|
+
## Example
|
32
|
+
|
33
|
+
```python
|
34
|
+
import oafuncs
|
35
|
+
|
36
|
+
# 查询当前所有可用函数
|
37
|
+
oafuncs.oa_help.query()
|
38
|
+
# 根据函数名获取使用方法
|
39
|
+
oafuncs.oa_help.use('query')
|
40
|
+
```
|
41
|
+
|
42
|
+
```shell
|
43
|
+
# 此小板块于2024/12/26更新,仅为示例,不代表最新情况
|
44
|
+
函数数量:
|
45
|
+
49
|
46
|
+
函数列表:
|
47
|
+
['MidpointNormalize', 'add_cartopy', 'add_gridlines', 'add_lonlat_unit', 'check_ncfile', 'choose_cmap', 'clear_folder', 'cmap2colors', 'convert_longitude', 'copy_file', 'create_cmap', 'create_cmap_rgbtxt', 'create_gif', 'download', 'download5doi', 'draw_time_range', 'extract5nc', 'fig_minus', 'file_size', 'find_file', 'get_time_list', 'get_ua', 'get_var', 'how_to_use', 'install_lib', 'interp_2d', 'link_file', 'make_folder', 'merge5nc', 'modify_var_attr', 'modify_var_value', 'nc_isel', 'plot_contourf', 'plot_contourf_cartopy', 'plot_contourf_lonlat', 'plot_quiver', 'query', 'remove', 'remove_empty_folder', 'rename_file', 'rename_var_or_dim', 'send', 'show', 'sign_in_love_ocean', 'sign_in_meteorological_home', 'sign_in_scientific_research', 'upgrade_lib', 'use', 'write2nc']
|
48
|
+
模块全路径:
|
49
|
+
oafuncs.oa_help.query
|
50
|
+
函数提示:
|
51
|
+
|
52
|
+
description: 查看oafuncs模块的函数列表
|
53
|
+
example: query()
|
54
|
+
```
|
55
|
+
|
56
|
+
## Structure
|
57
|
+
|
58
|
+
<img title="" src="./oafuncs/data_store/OAFuncs.png" alt="">
|
Binary file
|
@@ -100,6 +100,7 @@ def create_cmap_rgbtxt(rgbtxt_file,split_mark=','): # 根据RGB的txt文档制
|
|
100
100
|
return icmap
|
101
101
|
|
102
102
|
|
103
|
+
# ** 选择cmap
|
103
104
|
def choose_cmap(cmap_name=None, query=False):
|
104
105
|
"""
|
105
106
|
description: Choosing a colormap from the list of available colormaps or a custom colormap
|
@@ -1,31 +1,97 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
2
|
# coding=utf-8
|
3
|
-
|
3
|
+
"""
|
4
4
|
Author: Liu Kun && 16031215@qq.com
|
5
5
|
Date: 2024-09-17 17:12:47
|
6
6
|
LastEditors: Liu Kun && 16031215@qq.com
|
7
|
-
LastEditTime: 2024-
|
7
|
+
LastEditTime: 2024-12-13 19:11:08
|
8
8
|
FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_data.py
|
9
|
-
Description:
|
9
|
+
Description:
|
10
10
|
EditPlatform: vscode
|
11
11
|
ComputerInfo: XPS 15 9510
|
12
12
|
SystemInfo: Windows 11
|
13
13
|
Python Version: 3.11
|
14
|
-
|
15
|
-
|
14
|
+
"""
|
16
15
|
|
16
|
+
import itertools
|
17
17
|
import multiprocessing as mp
|
18
18
|
from concurrent.futures import ThreadPoolExecutor
|
19
19
|
|
20
20
|
import numpy as np
|
21
21
|
from scipy.interpolate import griddata
|
22
22
|
|
23
|
-
__all__ = [
|
23
|
+
__all__ = ["interp_2d"]
|
24
24
|
|
25
|
-
# ** 高维插值函数,插值最后两个维度
|
26
25
|
|
26
|
+
def interp_2d(target_x, target_y, origin_x, origin_y, data, method="linear", parallel=True):
|
27
|
+
"""
|
28
|
+
Perform 2D interpolation on the last two dimensions of a multi-dimensional array.
|
29
|
+
|
30
|
+
Parameters:
|
31
|
+
- target_x (array-like): 1D array of target grid's x-coordinates.
|
32
|
+
- target_y (array-like): 1D array of target grid's y-coordinates.
|
33
|
+
- origin_x (array-like): 1D array of original grid's x-coordinates.
|
34
|
+
- origin_y (array-like): 1D array of original grid's y-coordinates.
|
35
|
+
- data (numpy.ndarray): Multi-dimensional array where the last two dimensions correspond to the original grid.
|
36
|
+
- method (str, optional): Interpolation method, default is 'linear'. Other options include 'nearest', 'cubic', etc.
|
37
|
+
- parallel (bool, optional): Flag to enable parallel processing. Default is True.
|
38
|
+
|
39
|
+
Returns:
|
40
|
+
- interpolated_data (numpy.ndarray): Interpolated data with the same leading dimensions as the input data, but with the last two dimensions corresponding to the target grid.
|
41
|
+
|
42
|
+
Raises:
|
43
|
+
- ValueError: If the shape of the data does not match the shape of the origin_x or origin_y grids.
|
44
|
+
|
45
|
+
Usage:
|
46
|
+
- Interpolate a 2D array:
|
47
|
+
result = interp_2d(target_x, target_y, origin_x, origin_y, data_2d)
|
48
|
+
- Interpolate a 3D array (where the last two dimensions are spatial):
|
49
|
+
result = interp_2d(target_x, target_y, origin_x, origin_y, data_3d)
|
50
|
+
- Interpolate a 4D array (where the last two dimensions are spatial):
|
51
|
+
result = interp_2d(target_x, target_y, origin_x, origin_y, data_4d)
|
52
|
+
"""
|
53
|
+
|
54
|
+
def interp_single(data_slice, target_points, origin_points, method):
|
55
|
+
return griddata(origin_points, data_slice.ravel(), target_points, method=method).reshape(target_y.shape)
|
56
|
+
|
57
|
+
# 确保目标网格和初始网格都是二维的
|
58
|
+
if len(target_y.shape) == 1:
|
59
|
+
target_x, target_y = np.meshgrid(target_x, target_y)
|
60
|
+
if len(origin_y.shape) == 1:
|
61
|
+
origin_x, origin_y = np.meshgrid(origin_x, origin_y)
|
62
|
+
|
63
|
+
# 根据经纬度网格判断输入数据的形状是否匹配
|
64
|
+
if origin_x.shape != data.shape[-2:] or origin_y.shape != data.shape[-2:]:
|
65
|
+
raise ValueError("Shape of data does not match shape of origin_x or origin_y.")
|
66
|
+
|
67
|
+
# 创建网格和展平数据
|
68
|
+
target_points = np.column_stack((target_y.ravel(), target_x.ravel()))
|
69
|
+
origin_points = np.column_stack((origin_y.ravel(), origin_x.ravel()))
|
70
|
+
|
71
|
+
# 根据是否并行选择不同的执行方式
|
72
|
+
if parallel:
|
73
|
+
with ThreadPoolExecutor(max_workers=mp.cpu_count() - 2) as executor:
|
74
|
+
if len(data.shape) == 2:
|
75
|
+
interpolated_data = list(executor.map(interp_single, [data], [target_points], [origin_points], [method]))
|
76
|
+
elif len(data.shape) == 3:
|
77
|
+
interpolated_data = list(executor.map(interp_single, [data[i] for i in range(data.shape[0])], [target_points] * data.shape[0], [origin_points] * data.shape[0], [method] * data.shape[0]))
|
78
|
+
elif len(data.shape) == 4:
|
79
|
+
index_combinations = list(itertools.product(range(data.shape[0]), range(data.shape[1])))
|
80
|
+
interpolated_data = list(executor.map(interp_single, [data[i, j] for i, j in index_combinations], [target_points] * len(index_combinations), [origin_points] * len(index_combinations), [method] * len(index_combinations)))
|
81
|
+
interpolated_data = np.array(interpolated_data).reshape(data.shape[0], data.shape[1], *target_y.shape)
|
82
|
+
else:
|
83
|
+
if len(data.shape) == 2:
|
84
|
+
interpolated_data = interp_single(data, target_points, origin_points, method)
|
85
|
+
elif len(data.shape) == 3:
|
86
|
+
interpolated_data = np.stack([interp_single(data[i], target_points, origin_points, method) for i in range(data.shape[0])])
|
87
|
+
elif len(data.shape) == 4:
|
88
|
+
interpolated_data = np.stack([np.stack([interp_single(data[i, j], target_points, origin_points, method) for j in range(data.shape[1])]) for i in range(data.shape[0])])
|
89
|
+
|
90
|
+
return np.array(interpolated_data)
|
27
91
|
|
28
|
-
|
92
|
+
|
93
|
+
# ** 高维插值函数,插值最后两个维度
|
94
|
+
def interp_2d_20241213(target_x, target_y, origin_x, origin_y, data, method="linear"):
|
29
95
|
"""
|
30
96
|
高维插值函数,默认插值最后两个维度,传输数据前请确保数据的维度正确
|
31
97
|
参数:
|
@@ -52,7 +118,7 @@ def interp_2d(target_x, target_y, origin_x, origin_y, data, method='linear'):
|
|
52
118
|
|
53
119
|
if origin_x.shape != dims[-2:] or origin_y.shape != dims[-2:]:
|
54
120
|
print(origin_x.shape, dims[-2:])
|
55
|
-
raise ValueError(
|
121
|
+
raise ValueError("Shape of data does not match shape of origin_x or origin_y.")
|
56
122
|
|
57
123
|
# 将目标网格展平成一维数组
|
58
124
|
target_points = np.column_stack((np.ravel(target_y), np.ravel(target_x)))
|
@@ -69,7 +135,7 @@ def interp_2d(target_x, target_y, origin_x, origin_y, data, method='linear'):
|
|
69
135
|
for i in range(dims[0]):
|
70
136
|
dt = griddata(origin_points, np.ravel(data[i, :, :]), target_points, method=method)
|
71
137
|
interpolated_data.append(np.reshape(dt, target_y.shape))
|
72
|
-
print(f
|
138
|
+
print(f"Interpolating {i+1}/{dims[0]}...")
|
73
139
|
interpolated_data = np.array(interpolated_data)
|
74
140
|
elif len_dims == 4:
|
75
141
|
interpolated_data = []
|
@@ -78,8 +144,8 @@ def interp_2d(target_x, target_y, origin_x, origin_y, data, method='linear'):
|
|
78
144
|
for j in range(dims[1]):
|
79
145
|
dt = griddata(origin_points, np.ravel(data[i, j, :, :]), target_points, method=method)
|
80
146
|
interpolated_data[i].append(np.reshape(dt, target_y.shape))
|
81
|
-
print(f
|
82
|
-
print(
|
147
|
+
print(f"\rInterpolating {i*dims[1]+j+1}/{dims[0]*dims[1]}...", end="")
|
148
|
+
print("\n")
|
83
149
|
interpolated_data = np.array(interpolated_data)
|
84
150
|
|
85
151
|
return interpolated_data
|
@@ -87,8 +153,8 @@ def interp_2d(target_x, target_y, origin_x, origin_y, data, method='linear'):
|
|
87
153
|
|
88
154
|
# ** 高维插值函数,插值最后两个维度,使用多线程进行插值
|
89
155
|
# 在本地电脑上可以提速三倍左右,超算上暂时无法加速
|
90
|
-
def
|
91
|
-
|
156
|
+
def interp_2d_parallel_20241213(target_x, target_y, origin_x, origin_y, data, method="linear"):
|
157
|
+
"""
|
92
158
|
param {*} target_x 目标经度网格 1D 或 2D
|
93
159
|
param {*} target_y 目标纬度网格 1D 或 2D
|
94
160
|
param {*} origin_x 初始经度网格 1D 或 2D
|
@@ -98,22 +164,23 @@ def interp_2d_parallel(target_x, target_y, origin_x, origin_y, data, method='lin
|
|
98
164
|
return {*} 插值结果
|
99
165
|
description : 高维插值函数,默认插值最后两个维度,传输数据前请确保数据的维度正确
|
100
166
|
example : interpolated_data = interp_2d_parallel(target_x, target_y, origin_x, origin_y, data, method='linear')
|
101
|
-
|
102
|
-
|
167
|
+
"""
|
168
|
+
|
169
|
+
def interp_single2d(target_y, target_x, origin_y, origin_x, data, method="linear"):
|
103
170
|
target_points = np.column_stack((np.ravel(target_y), np.ravel(target_x)))
|
104
171
|
origin_points = np.column_stack((np.ravel(origin_y), np.ravel(origin_x)))
|
105
172
|
|
106
173
|
dt = griddata(origin_points, np.ravel(data[:, :]), target_points, method=method)
|
107
174
|
return np.reshape(dt, target_y.shape)
|
108
175
|
|
109
|
-
def interp_single3d(i, target_y, target_x, origin_y, origin_x, data, method=
|
176
|
+
def interp_single3d(i, target_y, target_x, origin_y, origin_x, data, method="linear"):
|
110
177
|
target_points = np.column_stack((np.ravel(target_y), np.ravel(target_x)))
|
111
178
|
origin_points = np.column_stack((np.ravel(origin_y), np.ravel(origin_x)))
|
112
179
|
|
113
180
|
dt = griddata(origin_points, np.ravel(data[i, :, :]), target_points, method=method)
|
114
181
|
return np.reshape(dt, target_y.shape)
|
115
182
|
|
116
|
-
def interp_single4d(i, j, target_y, target_x, origin_y, origin_x, data, method=
|
183
|
+
def interp_single4d(i, j, target_y, target_x, origin_y, origin_x, data, method="linear"):
|
117
184
|
target_points = np.column_stack((np.ravel(target_y), np.ravel(target_x)))
|
118
185
|
origin_points = np.column_stack((np.ravel(origin_y), np.ravel(origin_x)))
|
119
186
|
|
@@ -129,19 +196,31 @@ def interp_2d_parallel(target_x, target_y, origin_x, origin_y, data, method='lin
|
|
129
196
|
len_dims = len(dims)
|
130
197
|
|
131
198
|
if origin_x.shape != dims[-2:] or origin_y.shape != dims[-2:]:
|
132
|
-
raise ValueError(
|
199
|
+
raise ValueError("数据形状与 origin_x 或 origin_y 的形状不匹配.")
|
133
200
|
|
134
201
|
interpolated_data = []
|
135
202
|
|
136
203
|
# 使用多线程进行插值
|
137
|
-
with ThreadPoolExecutor(max_workers=mp.cpu_count()-2) as executor:
|
138
|
-
print(f
|
204
|
+
with ThreadPoolExecutor(max_workers=mp.cpu_count() - 2) as executor:
|
205
|
+
print(f"Using {mp.cpu_count()-2} threads...")
|
139
206
|
if len_dims == 2:
|
140
207
|
interpolated_data = list(executor.map(interp_single2d, [target_y], [target_x], [origin_y], [origin_x], [data], [method]))
|
141
208
|
elif len_dims == 3:
|
142
|
-
interpolated_data = list(executor.map(interp_single3d, [i for i in range(dims[0])], [target_y]*dims[0], [target_x]*dims[0], [origin_y]*dims[0], [origin_x]*dims[0], [data]*dims[0], [method]*dims[0]))
|
209
|
+
interpolated_data = list(executor.map(interp_single3d, [i for i in range(dims[0])], [target_y] * dims[0], [target_x] * dims[0], [origin_y] * dims[0], [origin_x] * dims[0], [data] * dims[0], [method] * dims[0]))
|
143
210
|
elif len_dims == 4:
|
144
|
-
interpolated_data = list(
|
211
|
+
interpolated_data = list(
|
212
|
+
executor.map(
|
213
|
+
interp_single4d,
|
214
|
+
[i for i in range(dims[0]) for j in range(dims[1])],
|
215
|
+
[j for i in range(dims[0]) for j in range(dims[1])],
|
216
|
+
[target_y] * dims[0] * dims[1],
|
217
|
+
[target_x] * dims[0] * dims[1],
|
218
|
+
[origin_y] * dims[0] * dims[1],
|
219
|
+
[origin_x] * dims[0] * dims[1],
|
220
|
+
[data] * dims[0] * dims[1],
|
221
|
+
[method] * dims[0] * dims[1],
|
222
|
+
)
|
223
|
+
)
|
145
224
|
interpolated_data = np.array(interpolated_data).reshape(dims[0], dims[1], target_y.shape[0], target_x.shape[1])
|
146
225
|
|
147
226
|
interpolated_data = np.array(interpolated_data)
|
@@ -149,7 +228,7 @@ def interp_2d_parallel(target_x, target_y, origin_x, origin_y, data, method='lin
|
|
149
228
|
return interpolated_data
|
150
229
|
|
151
230
|
|
152
|
-
if __name__ ==
|
231
|
+
if __name__ == "__main__":
|
153
232
|
import time
|
154
233
|
|
155
234
|
import matplotlib.pyplot as plt
|
@@ -169,15 +248,15 @@ if __name__ == '__main__':
|
|
169
248
|
data = np.random.rand(10, 10, 11, 11)
|
170
249
|
|
171
250
|
start = time.time()
|
172
|
-
interpolated_data = interp_2d(target_x, target_y, origin_x, origin_y, data)
|
173
|
-
print(f
|
251
|
+
interpolated_data = interp_2d(target_x, target_y, origin_x, origin_y, data, parallel=False)
|
252
|
+
print(f"Interpolation time: {time.time()-start:.2f}s")
|
174
253
|
|
175
254
|
print(interpolated_data.shape)
|
176
255
|
|
177
256
|
# 高维插值多线程
|
178
257
|
start = time.time()
|
179
|
-
interpolated_data =
|
180
|
-
print(f
|
258
|
+
interpolated_data = interp_2d(target_x, target_y, origin_x, origin_y, data)
|
259
|
+
print(f"Interpolation time: {time.time()-start:.2f}s")
|
181
260
|
|
182
261
|
print(interpolated_data.shape)
|
183
262
|
print(interpolated_data[0, 0, :, :].shape)
|
@@ -1,20 +1,21 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
2
|
# coding=utf-8
|
3
|
-
|
3
|
+
"""
|
4
4
|
Author: Liu Kun && 16031215@qq.com
|
5
5
|
Date: 2024-09-17 16:09:20
|
6
6
|
LastEditors: Liu Kun && 16031215@qq.com
|
7
|
-
LastEditTime: 2024-12-
|
7
|
+
LastEditTime: 2024-12-26 08:09:01
|
8
8
|
FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_down\\__init__.py
|
9
|
-
Description:
|
9
|
+
Description:
|
10
10
|
EditPlatform: vscode
|
11
11
|
ComputerInfo: XPS 15 9510
|
12
12
|
SystemInfo: Windows 11
|
13
13
|
Python Version: 3.11
|
14
|
-
|
14
|
+
"""
|
15
15
|
|
16
16
|
# from .love_ocean import sign as love_ocean
|
17
17
|
# from .meteorological_home import sign as meteorological_home
|
18
18
|
|
19
19
|
from .hycom_3hourly import *
|
20
20
|
from .literature import *
|
21
|
+
from .user_agent import *
|