oafuncs 0.0.81__py2.py3-none-any.whl → 0.0.83__py2.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/data_store/OAFuncs.png +0 -0
- oafuncs/oa_cmap.py +1 -0
- oafuncs/oa_data.py +107 -28
- oafuncs/oa_down/__init__.py +5 -4
- oafuncs/oa_down/hycom_3hourly.py +152 -35
- oafuncs/oa_down/user_agent.py +34 -0
- oafuncs/oa_draw.py +165 -103
- oafuncs/oa_file.py +66 -53
- oafuncs/oa_help.py +19 -16
- oafuncs/oa_nc.py +82 -114
- oafuncs-0.0.83.dist-info/METADATA +91 -0
- oafuncs-0.0.83.dist-info/RECORD +26 -0
- oafuncs/oa_down/test.py +0 -151
- oafuncs/oa_s/__init__.py +0 -23
- oafuncs/oa_s/oa_cmap.py +0 -163
- oafuncs/oa_s/oa_data.py +0 -187
- oafuncs/oa_s/oa_draw.py +0 -451
- oafuncs/oa_s/oa_file.py +0 -332
- oafuncs/oa_s/oa_help.py +0 -39
- oafuncs/oa_s/oa_nc.py +0 -410
- oafuncs/oa_s/oa_python.py +0 -107
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/__init__.py" +0 -26
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_cmap.py" +0 -163
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_data.py" +0 -187
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_down/__init__.py" +0 -20
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_down/hycom_3hourly.py" +0 -1176
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_down/literature.py" +0 -332
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_down/test_ua.py" +0 -151
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_draw.py" +0 -451
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_file.py" +0 -332
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_help.py" +0 -39
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_nc.py" +0 -410
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_python.py" +0 -107
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_sign/__init__.py" +0 -21
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_sign/meteorological.py" +0 -168
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_sign/ocean.py" +0 -158
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_sign/scientific.py" +0 -139
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_tool/__init__.py" +0 -18
- oafuncs - /321/205/320/231/320/277/321/206/320/254/320/274/oa_tool/email.py" +0 -114
- oafuncs-0.0.81.dist-info/METADATA +0 -918
- oafuncs-0.0.81.dist-info/RECORD +0 -51
- {oafuncs-0.0.81.dist-info → oafuncs-0.0.83.dist-info}/LICENSE.txt +0 -0
- {oafuncs-0.0.81.dist-info → oafuncs-0.0.83.dist-info}/WHEEL +0 -0
- {oafuncs-0.0.81.dist-info → oafuncs-0.0.83.dist-info}/top_level.txt +0 -0
@@ -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="">
|
@@ -0,0 +1,26 @@
|
|
1
|
+
oafuncs/__init__.py,sha256=glcIlhQ9xSK4WtL58dq7Od2S3JPqsuEyhUQ-VWO8hOc,1426
|
2
|
+
oafuncs/oa_cmap.py,sha256=rURQujDWzydNVtXOanDtChD248_bapubNsO2dX3Nb-E,6466
|
3
|
+
oafuncs/oa_data.py,sha256=DUKc--EyQfIcxAwy2Rv_oDMuE5uw9CVrt0bMAfVog98,12482
|
4
|
+
oafuncs/oa_draw.py,sha256=cZG4XfHEk2IoyBEQqkWat2CWbuyI7utFU9X4NGFEhuA,21250
|
5
|
+
oafuncs/oa_file.py,sha256=-AdRnFEtRTpIMXr5geYe5fEhyiMOFad5ethi_lF-Ogo,12277
|
6
|
+
oafuncs/oa_help.py,sha256=BFLoOyD5uVeOc8qQ3yAyzIR1q3JAj4GhqQfetd3KML4,1034
|
7
|
+
oafuncs/oa_nc.py,sha256=Gj0xLfqgQI3hNnr9SED1WFj2JU4GsJj2on_8EVdSk20,15595
|
8
|
+
oafuncs/oa_python.py,sha256=XPTP3o7zTFzfJR_YhsKfQksa3bSYwXsne9YxlJplCEA,3994
|
9
|
+
oafuncs/data_store/OAFuncs.png,sha256=C6_1718zWoEvs3QRSt8eWhRedDV4QIhQUKk3LWb1Z6Y,3298028
|
10
|
+
oafuncs/oa_down/User_Agent-list.txt,sha256=pazxSip8_lphEBOPHG902zmIBUg8sBKXgmqp_g6j_E4,661062
|
11
|
+
oafuncs/oa_down/__init__.py,sha256=pKPqxD0z09NEXWCemuemfgTct7Kcu3APPJqqB1FPXRM,565
|
12
|
+
oafuncs/oa_down/hycom_3hourly.py,sha256=wYOZrV5mZVSTfx6a5QLay8Jg2sL2x3sWKWmxwidRzMo,62928
|
13
|
+
oafuncs/oa_down/literature.py,sha256=dT3-7-beEzQ9mTP8LNV9Gf3q5Z1Pqqjc6FOS010HZeQ,17833
|
14
|
+
oafuncs/oa_down/test_ua.py,sha256=0IQq3NjqfNr7KkyjS_U-a4mYu-r-E7gzawwo4IfEa6Y,10851
|
15
|
+
oafuncs/oa_down/user_agent.py,sha256=NSJjB2LAqPKS0hErvN5FfwsQeb58XjlOc68emiAK66c,893
|
16
|
+
oafuncs/oa_sign/__init__.py,sha256=QKqTFrJDFK40C5uvk48GlRRbGFzO40rgkYwu6dYxatM,563
|
17
|
+
oafuncs/oa_sign/meteorological.py,sha256=mLbupsZSq427HTfVbZMvIlFzDHwSzQAbK3X19o8anFY,6525
|
18
|
+
oafuncs/oa_sign/ocean.py,sha256=xrW-rWD7xBWsB5PuCyEwQ1Q_RDKq2KCLz-LOONHgldU,5932
|
19
|
+
oafuncs/oa_sign/scientific.py,sha256=a4JxOBgm9vzNZKpJ_GQIQf7cokkraV5nh23HGbmTYKw,5064
|
20
|
+
oafuncs/oa_tool/__init__.py,sha256=IKOlqpWlb4cMDCtq2VKR_RTxQHDNqR_vfqqsOsp_lKQ,466
|
21
|
+
oafuncs/oa_tool/email.py,sha256=4lJxV_KUzhxgLYfVwYTqp0qxRugD7fvsZkXDe5WkUKo,3052
|
22
|
+
oafuncs-0.0.83.dist-info/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
|
23
|
+
oafuncs-0.0.83.dist-info/METADATA,sha256=e5ID-ZhjsWliu-gMd6gyWNw50CcQ-EkmRhDrXoQD8rc,3166
|
24
|
+
oafuncs-0.0.83.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
|
25
|
+
oafuncs-0.0.83.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
|
26
|
+
oafuncs-0.0.83.dist-info/RECORD,,
|
oafuncs/oa_down/test.py
DELETED
@@ -1,151 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python
|
2
|
-
# coding=utf-8
|
3
|
-
"""
|
4
|
-
Author: Liu Kun && 16031215@qq.com
|
5
|
-
Date: 2024-12-01 19:32:25
|
6
|
-
LastEditors: Liu Kun && 16031215@qq.com
|
7
|
-
LastEditTime: 2024-12-10 11:16:36
|
8
|
-
FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_down\\test.py
|
9
|
-
Description:
|
10
|
-
EditPlatform: vscode
|
11
|
-
ComputerInfo: XPS 15 9510
|
12
|
-
SystemInfo: Windows 11
|
13
|
-
Python Version: 3.12
|
14
|
-
"""
|
15
|
-
|
16
|
-
import os
|
17
|
-
import random
|
18
|
-
import re
|
19
|
-
|
20
|
-
|
21
|
-
def is_valid_user_agent(user_agent):
|
22
|
-
# 简单的正则表达式来检查User Agent的格式
|
23
|
-
# 这个正则表达式检查User Agent是否包含常见的浏览器信息格式
|
24
|
-
pattern = re.compile(
|
25
|
-
r"^(?:(?:Mozilla|Opera|Chrome|Safari|Edg|OPR)/[\d.]+)"
|
26
|
-
r"(?:\s(?:\(.*?\)))?"
|
27
|
-
r"(?:\s(?:Gecko|AppleWebKit|KHTML, like Gecko|Version|Edge|OPR)/[\d.]+)?"
|
28
|
-
r"(?:\s.*?(?:rv:|Version/|Ubuntu|Macintosh|Windows|X11|Linux|CrOS|FreeBSD|OpenBSD|NetBSD|iPhone|iPad|iPod|Android|BlackBerry|BB10|Mobile|Symbian|Windows Phone|IEMobile|Opera Mini|Opera Mobi|UCBrowser|MQQBrowser|baiduboxapp|baidubrowser|Safari|Firefox|MSIE|Trident|Edge|EdgA|Chrome|CriOS|Vivaldi|Sleipnir|Midori|ELinks|Lynx|w3m|Arora|Epiphany|Konqueror|Dillo|Netscape|SeaMonkey|K-Meleon|Camino|Iceape|Galeon|GranParadiso|Iceweasel|Firefox|Fennec|Conkeror|PaleMoon|Uzbl|QupZilla|Otter|Waterfox|Basilisk|Cyberfox|PaleMoon|GNU IceCat|GNU IceWeasel|IceCat|IceWeasel|Seamonkey|Iceape|Firefox|Epiphany|Web|Safari|Android|Mobile|BlackBerry|BB10|Tablet|Silk|Kindle|FxiOS|Focus|SamsungBrowser|browser|AppleWebKit|Puffin|DuckDuckGo|YaBrowser|Yandex|Amigo|NokiaBrowser|OviBrowser|OneBrowser|Chrome|Firefox|Safari|OPR|Coast|Mercury|Silk|Skyfire|IEMobile|Bolt|Jasmine|NativeHost|Crosswalk|TizenBrowser|SailfishBrowser|SamsungBrowser|Silk-Accelerated|UCBrowser|Quark|XiaoMi|OnePlus|Vivo|Oppo|Realme|Meizu|Lenovo|Huawei|ZTE|Alcatel|Sony|Nokia|LG|HTC|Asus|Acer|Motorola|Samsung)/[\d.]+)?$"
|
29
|
-
)
|
30
|
-
|
31
|
-
# 使用正则表达式匹配User Agent字符串
|
32
|
-
if pattern.match(user_agent):
|
33
|
-
return True
|
34
|
-
else:
|
35
|
-
return False
|
36
|
-
|
37
|
-
|
38
|
-
def get_ua():
|
39
|
-
current_dir = os.path.dirname(os.path.abspath(__file__))
|
40
|
-
ua_file_txt = os.path.join(current_dir, "User_Agent-list.txt")
|
41
|
-
|
42
|
-
with open(ua_file_txt, "r") as f:
|
43
|
-
ua_list = f.readlines()
|
44
|
-
# 去掉换行符和空行
|
45
|
-
ua_list = [line.strip() for line in ua_list if line.strip()]
|
46
|
-
|
47
|
-
return random.choice(ua_list)
|
48
|
-
|
49
|
-
|
50
|
-
def get_ua_org():
|
51
|
-
ua_list = [
|
52
|
-
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 OPR/26.0.1656.60",
|
53
|
-
"Opera/8.0 (Windows NT 5.1; U; en)",
|
54
|
-
"Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.50",
|
55
|
-
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.50",
|
56
|
-
"Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11",
|
57
|
-
"Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11",
|
58
|
-
"Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10",
|
59
|
-
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0",
|
60
|
-
"Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10",
|
61
|
-
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv,2.0.1) Gecko/20100101 Firefox/4.0.1",
|
62
|
-
"Mozilla/5.0 (Windows NT 6.1; rv,2.0.1) Gecko/20100101 Firefox/4.0.1",
|
63
|
-
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
|
64
|
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36",
|
65
|
-
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
|
66
|
-
"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
|
67
|
-
"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
|
68
|
-
"Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
|
69
|
-
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36",
|
70
|
-
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11",
|
71
|
-
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16",
|
72
|
-
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
|
73
|
-
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36",
|
74
|
-
"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko",
|
75
|
-
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)",
|
76
|
-
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 TaoBrowser/2.0 Safari/536.11",
|
77
|
-
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER",
|
78
|
-
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; LBBROWSER)",
|
79
|
-
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E; LBBROWSER)",
|
80
|
-
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; QQBrowser/7.0.3698.400)",
|
81
|
-
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)",
|
82
|
-
"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 SE 2.X MetaSr 1.0",
|
83
|
-
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SV1; QQDownload 732; .NET4.0C; .NET4.0E; SE 2.X MetaSr 1.0)",
|
84
|
-
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)",
|
85
|
-
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Maxthon/4.4.3.4000 Chrome/30.0.1599.101 Safari/537.36",
|
86
|
-
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
|
87
|
-
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 UBrowser/4.0.3214.0 Safari/537.36",
|
88
|
-
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4094.1 Safari/537.36",
|
89
|
-
"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
|
90
|
-
"Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
|
91
|
-
"Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5",
|
92
|
-
"Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
|
93
|
-
"Mozilla/5.0 (Linux; U; Android 2.2.1; zh-cn; HTC_Wildfire_A3333 Build/FRG83D) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
|
94
|
-
"Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
|
95
|
-
"MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
|
96
|
-
"Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10",
|
97
|
-
"Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13",
|
98
|
-
"Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+",
|
99
|
-
"Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0",
|
100
|
-
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;",
|
101
|
-
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
|
102
|
-
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)",
|
103
|
-
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
|
104
|
-
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
|
105
|
-
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)",
|
106
|
-
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)",
|
107
|
-
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)",
|
108
|
-
"Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
|
109
|
-
"Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124",
|
110
|
-
"Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)",
|
111
|
-
"UCWEB7.0.2.37/28/999",
|
112
|
-
"NOKIA5700/UCWEB7.0.2.37/28/999",
|
113
|
-
"Openwave/UCWEB7.0.2.37/28/999",
|
114
|
-
"Openwave/UCWEB7.0.2.37/28/999",
|
115
|
-
]
|
116
|
-
with open(newtxtfile, "w") as f:
|
117
|
-
for line in ua_list:
|
118
|
-
f.write(line + "\n")
|
119
|
-
# print(f'Using User-Agent: {ua}')
|
120
|
-
ua = random.choice(ua_list)
|
121
|
-
return ua
|
122
|
-
|
123
|
-
|
124
|
-
# get_ua_org()
|
125
|
-
|
126
|
-
if __name__ == "__main__":
|
127
|
-
txtfile = r"E:\Code\Python\My_Funcs\OAFuncs\oafuncs\oa_down\User_Agent-list.txt"
|
128
|
-
|
129
|
-
with open(txtfile, "r") as f:
|
130
|
-
lines = f.readlines()
|
131
|
-
# 去掉换行符和空行
|
132
|
-
lines = [line.strip() for line in lines if line.strip()]
|
133
|
-
""" new_line = []
|
134
|
-
for i in range(len(lines)):
|
135
|
-
if '/' in lines[i]:
|
136
|
-
new_line.append(lines[i])
|
137
|
-
else:
|
138
|
-
print(lines[i]) """
|
139
|
-
|
140
|
-
new_line = []
|
141
|
-
for line in lines:
|
142
|
-
if is_valid_user_agent(line):
|
143
|
-
# print(line)
|
144
|
-
new_line.append(line)
|
145
|
-
else:
|
146
|
-
print(f"Invalid User-Agent: {line}")
|
147
|
-
|
148
|
-
newtxtfile = r"E:\Code\Python\My_Funcs\OAFuncs\oafuncs\oa_down\ua_list_new.txt"
|
149
|
-
with open(newtxtfile, "w") as f:
|
150
|
-
for line in new_line:
|
151
|
-
f.write(line + "\n")
|
oafuncs/oa_s/__init__.py
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python
|
2
|
-
# coding=utf-8
|
3
|
-
"""
|
4
|
-
Author: Liu Kun && 16031215@qq.com
|
5
|
-
Date: 2024-09-17 16:09:20
|
6
|
-
LastEditors: Liu Kun && 16031215@qq.com
|
7
|
-
LastEditTime: 2024-12-13 10:47:40
|
8
|
-
FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_s\\__init__.py
|
9
|
-
Description:
|
10
|
-
EditPlatform: vscode
|
11
|
-
ComputerInfo: XPS 15 9510
|
12
|
-
SystemInfo: Windows 11
|
13
|
-
Python Version: 3.11
|
14
|
-
"""
|
15
|
-
|
16
|
-
# 会导致OAFuncs直接导入所有函数,不符合模块化设计
|
17
|
-
from .oa_cmap import *
|
18
|
-
from .oa_data import *
|
19
|
-
from .oa_draw import *
|
20
|
-
from .oa_file import *
|
21
|
-
from .oa_help import *
|
22
|
-
from .oa_nc import *
|
23
|
-
from .oa_python import *
|
oafuncs/oa_s/oa_cmap.py
DELETED
@@ -1,163 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python
|
2
|
-
# coding=utf-8
|
3
|
-
"""
|
4
|
-
Author: Liu Kun && 16031215@qq.com
|
5
|
-
Date: 2024-09-17 16:55:11
|
6
|
-
LastEditors: Liu Kun && 16031215@qq.com
|
7
|
-
LastEditTime: 2024-11-21 13:14:24
|
8
|
-
FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_cmap.py
|
9
|
-
Description:
|
10
|
-
EditPlatform: vscode
|
11
|
-
ComputerInfo: XPS 15 9510
|
12
|
-
SystemInfo: Windows 11
|
13
|
-
Python Version: 3.11
|
14
|
-
"""
|
15
|
-
|
16
|
-
import matplotlib as mpl
|
17
|
-
import matplotlib.pyplot as plt
|
18
|
-
import numpy as np
|
19
|
-
|
20
|
-
__all__ = ["show", "cmap2colors", "create_cmap", "create_cmap_rgbtxt", "choose_cmap"]
|
21
|
-
|
22
|
-
# ** 将cmap用填色图可视化(官网摘抄函数)
|
23
|
-
def show(colormaps: list):
|
24
|
-
"""
|
25
|
-
Helper function to plot data with associated colormap.
|
26
|
-
example:
|
27
|
-
cmap = ListedColormap(["darkorange", "gold", "lawngreen", "lightseagreen"])
|
28
|
-
show([cmap])
|
29
|
-
"""
|
30
|
-
np.random.seed(19680801)
|
31
|
-
data = np.random.randn(30, 30)
|
32
|
-
n = len(colormaps)
|
33
|
-
fig, axs = plt.subplots(1, n, figsize=(n * 2 + 2, 3), constrained_layout=True, squeeze=False)
|
34
|
-
for [ax, cmap] in zip(axs.flat, colormaps):
|
35
|
-
psm = ax.pcolormesh(data, cmap=cmap, rasterized=True, vmin=-4, vmax=4)
|
36
|
-
fig.colorbar(psm, ax=ax)
|
37
|
-
plt.show()
|
38
|
-
|
39
|
-
|
40
|
-
# ** 将cmap转为list,即多个颜色的列表
|
41
|
-
def cmap2colors(cmap, n=256):
|
42
|
-
"""
|
43
|
-
cmap : cmap名称
|
44
|
-
n : 提取颜色数量
|
45
|
-
return : 提取的颜色列表
|
46
|
-
example : out_colors = cmap2colors('viridis', 256)
|
47
|
-
"""
|
48
|
-
c_map = mpl.colormaps.get_cmap(cmap)
|
49
|
-
out_colors = [c_map(i) for i in np.linspace(0, 1, n)]
|
50
|
-
return out_colors
|
51
|
-
|
52
|
-
|
53
|
-
# ** 自制cmap,多色,可带位置
|
54
|
-
def create_cmap(colors: list, nodes=None, under=None, over=None): # 利用颜色快速配色
|
55
|
-
"""
|
56
|
-
func : 自制cmap,自动确定颜色位置(等比例)
|
57
|
-
description : colors可以是颜色名称,也可以是十六进制颜色代码
|
58
|
-
param {*} colors 颜色
|
59
|
-
param {*} nodes 颜色位置,默认不提供,等间距
|
60
|
-
return {*} cmap
|
61
|
-
example : cmap = create_cmap(['#C2B7F3','#B3BBF2','#B0CBF1','#ACDCF0','#A8EEED'])
|
62
|
-
cmap = create_cmap(['aliceblue','skyblue','deepskyblue'],[0.0,0.5,1.0])
|
63
|
-
"""
|
64
|
-
if nodes is None: # 采取自动分配比例
|
65
|
-
cmap_color = mpl.colors.LinearSegmentedColormap.from_list("mycmap", colors)
|
66
|
-
else: # 按照提供比例分配
|
67
|
-
cmap_color = mpl.colors.LinearSegmentedColormap.from_list("mycmap", list(zip(nodes, colors)))
|
68
|
-
if under is not None:
|
69
|
-
cmap_color.set_under(under)
|
70
|
-
if over is not None:
|
71
|
-
cmap_color.set_over(over)
|
72
|
-
return cmap_color
|
73
|
-
|
74
|
-
|
75
|
-
# ** 根据RGB的txt文档制作色卡(利用Grads调色盘)
|
76
|
-
def create_cmap_rgbtxt(rgbtxt_file,split_mark=','): # 根据RGB的txt文档制作色卡/根据rgb值制作
|
77
|
-
"""
|
78
|
-
func : 根据RGB的txt文档制作色卡
|
79
|
-
description : rgbtxt_file='E:/python/colorbar/test.txt'
|
80
|
-
param {*} rgbtxt_file txt文件路径
|
81
|
-
return {*} camp
|
82
|
-
example : cmap=create_cmap_rgbtxt(path,split_mark=',') #
|
83
|
-
|
84
|
-
txt example : 251,251,253
|
85
|
-
225,125,25
|
86
|
-
250,205,255
|
87
|
-
"""
|
88
|
-
with open(rgbtxt_file) as fid:
|
89
|
-
data = fid.readlines()
|
90
|
-
n = len(data)
|
91
|
-
rgb = np.zeros((n, 3))
|
92
|
-
for i in np.arange(n):
|
93
|
-
rgb[i][0] = data[i].split(split_mark)[0]
|
94
|
-
rgb[i][1] = data[i].split(split_mark)[1]
|
95
|
-
rgb[i][2] = data[i].split(split_mark)[2]
|
96
|
-
max_rgb = np.max(rgb)
|
97
|
-
if max_rgb > 2: # 如果rgb值大于2,则认为是0-255的值,需要归一化
|
98
|
-
rgb = rgb / 255.0
|
99
|
-
icmap = mpl.colors.ListedColormap(rgb, name="my_color")
|
100
|
-
return icmap
|
101
|
-
|
102
|
-
|
103
|
-
def choose_cmap(cmap_name=None, query=False):
|
104
|
-
"""
|
105
|
-
description: Choosing a colormap from the list of available colormaps or a custom colormap
|
106
|
-
param {*} cmap_name:
|
107
|
-
param {*} query:
|
108
|
-
return {*}
|
109
|
-
"""
|
110
|
-
|
111
|
-
my_cmap_dict = {
|
112
|
-
"diverging_1": create_cmap(["#4e00b3", "#0000FF", "#00c0ff", "#a1d3ff", "#DCDCDC", "#FFD39B", "#FF8247", "#FF0000", "#FF5F9E"]),
|
113
|
-
"cold_1": create_cmap(["#4e00b3", "#0000FF", "#00c0ff", "#a1d3ff", "#DCDCDC"]),
|
114
|
-
"warm_1": create_cmap(["#DCDCDC", "#FFD39B", "#FF8247", "#FF0000", "#FF5F9E"]),
|
115
|
-
# "land_1": create_custom(["#3E6436", "#678A59", "#91A176", "#B8A87D", "#D9CBB2"], under="#A6CEE3", over="#FFFFFF"), # 陆地颜色从深绿到浅棕,表示从植被到沙地的递减
|
116
|
-
# "ocean_1": create_custom(["#126697", "#2D88B3", "#4EA1C9", "#78B9D8", "#A6CEE3"], under="#8470FF", over="#3E6436"), # 海洋颜色从深蓝到浅蓝,表示从深海到浅海的递减
|
117
|
-
# "ocean_land_1": create_custom(
|
118
|
-
# [
|
119
|
-
# "#126697", # 深蓝(深海)
|
120
|
-
# "#2D88B3", # 蓝
|
121
|
-
# "#4EA1C9", # 蓝绿
|
122
|
-
# "#78B9D8", # 浅蓝(浅海)
|
123
|
-
# "#A6CEE3", # 浅蓝(近岸)
|
124
|
-
# "#AAAAAA", # 灰色(0值,海平面)
|
125
|
-
# "#D9CBB2", # 沙质土壤色(陆地开始)
|
126
|
-
# "#B8A87D", # 浅棕
|
127
|
-
# "#91A176", # 浅绿
|
128
|
-
# "#678A59", # 中绿
|
129
|
-
# "#3E6436", # 深绿(高山)
|
130
|
-
# ]
|
131
|
-
# ),
|
132
|
-
"colorful_1": create_cmap(["#6d00db", "#9800cb", "#F2003C", "#ff4500", "#ff7f00", "#FE28A2", "#FFC0CB", "#DDA0DD", "#40E0D0", "#1a66f2", "#00f7fb", "#8fff88", "#E3FF00"]),
|
133
|
-
}
|
134
|
-
if query:
|
135
|
-
for key, _ in my_cmap_dict.items():
|
136
|
-
print(key)
|
137
|
-
|
138
|
-
if cmap_name in my_cmap_dict:
|
139
|
-
return my_cmap_dict[cmap_name]
|
140
|
-
else:
|
141
|
-
try:
|
142
|
-
return mpl.colormaps.get_cmap(cmap_name)
|
143
|
-
except ValueError:
|
144
|
-
raise ValueError(f"Unknown cmap name: {cmap_name}")
|
145
|
-
|
146
|
-
|
147
|
-
if __name__ == "__main__":
|
148
|
-
# ** 测试自制cmap
|
149
|
-
colors = ["#C2B7F3", "#B3BBF2", "#B0CBF1", "#ACDCF0", "#A8EEED"]
|
150
|
-
nodes = [0.0, 0.2, 0.4, 0.6, 1.0]
|
151
|
-
c_map = create_cmap(colors, nodes)
|
152
|
-
show([c_map])
|
153
|
-
|
154
|
-
# ** 测试自制diverging型cmap
|
155
|
-
diverging_cmap = create_cmap(["#4e00b3", "#0000FF", "#00c0ff", "#a1d3ff", "#DCDCDC", "#FFD39B", "#FF8247", "#FF0000", "#FF5F9E"])
|
156
|
-
show([diverging_cmap])
|
157
|
-
|
158
|
-
# ** 测试根据RGB的txt文档制作色卡
|
159
|
-
file_path = "E:/python/colorbar/test.txt"
|
160
|
-
cmap_rgb = create_cmap_rgbtxt(file_path)
|
161
|
-
|
162
|
-
# ** 测试将cmap转为list
|
163
|
-
out_colors = cmap2colors("viridis", 256)
|
oafuncs/oa_s/oa_data.py
DELETED
@@ -1,187 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python
|
2
|
-
# coding=utf-8
|
3
|
-
'''
|
4
|
-
Author: Liu Kun && 16031215@qq.com
|
5
|
-
Date: 2024-09-17 17:12:47
|
6
|
-
LastEditors: Liu Kun && 16031215@qq.com
|
7
|
-
LastEditTime: 2024-11-21 13:13:20
|
8
|
-
FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_data.py
|
9
|
-
Description:
|
10
|
-
EditPlatform: vscode
|
11
|
-
ComputerInfo: XPS 15 9510
|
12
|
-
SystemInfo: Windows 11
|
13
|
-
Python Version: 3.11
|
14
|
-
'''
|
15
|
-
|
16
|
-
|
17
|
-
import multiprocessing as mp
|
18
|
-
from concurrent.futures import ThreadPoolExecutor
|
19
|
-
|
20
|
-
import numpy as np
|
21
|
-
from scipy.interpolate import griddata
|
22
|
-
|
23
|
-
__all__ = ['interp_2d', 'interp_2d_parallel']
|
24
|
-
|
25
|
-
# ** 高维插值函数,插值最后两个维度
|
26
|
-
|
27
|
-
|
28
|
-
def interp_2d(target_x, target_y, origin_x, origin_y, data, method='linear'):
|
29
|
-
"""
|
30
|
-
高维插值函数,默认插值最后两个维度,传输数据前请确保数据的维度正确
|
31
|
-
参数:
|
32
|
-
target_y (array-like): 目标经度网格 1D 或 2D
|
33
|
-
target_x (array-like): 目标纬度网格 1D 或 2D
|
34
|
-
origin_y (array-like): 初始经度网格 1D 或 2D
|
35
|
-
origin_x (array-like): 初始纬度网格 1D 或 2D
|
36
|
-
data (array-like): 数据 (*, lat, lon) 2D, 3D, 4D
|
37
|
-
method (str, optional): 插值方法,可选 'linear', 'nearest', 'cubic' 等,默认为 'linear'
|
38
|
-
返回:
|
39
|
-
array-like: 插值结果
|
40
|
-
"""
|
41
|
-
|
42
|
-
# 确保目标网格和初始网格都是二维的
|
43
|
-
if len(target_y.shape) == 1:
|
44
|
-
target_x, target_y = np.meshgrid(target_x, target_y)
|
45
|
-
if len(origin_y.shape) == 1:
|
46
|
-
origin_x, origin_y = np.meshgrid(origin_x, origin_y)
|
47
|
-
|
48
|
-
dims = data.shape
|
49
|
-
len_dims = len(dims)
|
50
|
-
# print(dims[-2:])
|
51
|
-
# 根据经纬度网格判断输入数据的形状是否匹配
|
52
|
-
|
53
|
-
if origin_x.shape != dims[-2:] or origin_y.shape != dims[-2:]:
|
54
|
-
print(origin_x.shape, dims[-2:])
|
55
|
-
raise ValueError('Shape of data does not match shape of origin_x or origin_y.')
|
56
|
-
|
57
|
-
# 将目标网格展平成一维数组
|
58
|
-
target_points = np.column_stack((np.ravel(target_y), np.ravel(target_x)))
|
59
|
-
|
60
|
-
# 将初始网格展平成一维数组
|
61
|
-
origin_points = np.column_stack((np.ravel(origin_y), np.ravel(origin_x)))
|
62
|
-
|
63
|
-
# 进行插值
|
64
|
-
if len_dims == 2:
|
65
|
-
interpolated_data = griddata(origin_points, np.ravel(data), target_points, method=method)
|
66
|
-
interpolated_data = np.reshape(interpolated_data, target_y.shape)
|
67
|
-
elif len_dims == 3:
|
68
|
-
interpolated_data = []
|
69
|
-
for i in range(dims[0]):
|
70
|
-
dt = griddata(origin_points, np.ravel(data[i, :, :]), target_points, method=method)
|
71
|
-
interpolated_data.append(np.reshape(dt, target_y.shape))
|
72
|
-
print(f'Interpolating {i+1}/{dims[0]}...')
|
73
|
-
interpolated_data = np.array(interpolated_data)
|
74
|
-
elif len_dims == 4:
|
75
|
-
interpolated_data = []
|
76
|
-
for i in range(dims[0]):
|
77
|
-
interpolated_data.append([])
|
78
|
-
for j in range(dims[1]):
|
79
|
-
dt = griddata(origin_points, np.ravel(data[i, j, :, :]), target_points, method=method)
|
80
|
-
interpolated_data[i].append(np.reshape(dt, target_y.shape))
|
81
|
-
print(f'\rInterpolating {i*dims[1]+j+1}/{dims[0]*dims[1]}...', end='')
|
82
|
-
print('\n')
|
83
|
-
interpolated_data = np.array(interpolated_data)
|
84
|
-
|
85
|
-
return interpolated_data
|
86
|
-
|
87
|
-
|
88
|
-
# ** 高维插值函数,插值最后两个维度,使用多线程进行插值
|
89
|
-
# 在本地电脑上可以提速三倍左右,超算上暂时无法加速
|
90
|
-
def interp_2d_parallel(target_x, target_y, origin_x, origin_y, data, method='linear'):
|
91
|
-
'''
|
92
|
-
param {*} target_x 目标经度网格 1D 或 2D
|
93
|
-
param {*} target_y 目标纬度网格 1D 或 2D
|
94
|
-
param {*} origin_x 初始经度网格 1D 或 2D
|
95
|
-
param {*} origin_y 初始纬度网格 1D 或 2D
|
96
|
-
param {*} data 数据 (*, lat, lon) 2D, 3D, 4D
|
97
|
-
param {*} method 插值方法,可选 'linear', 'nearest', 'cubic' 等,默认为 'linear'
|
98
|
-
return {*} 插值结果
|
99
|
-
description : 高维插值函数,默认插值最后两个维度,传输数据前请确保数据的维度正确
|
100
|
-
example : interpolated_data = interp_2d_parallel(target_x, target_y, origin_x, origin_y, data, method='linear')
|
101
|
-
'''
|
102
|
-
def interp_single2d(target_y, target_x, origin_y, origin_x, data, method='linear'):
|
103
|
-
target_points = np.column_stack((np.ravel(target_y), np.ravel(target_x)))
|
104
|
-
origin_points = np.column_stack((np.ravel(origin_y), np.ravel(origin_x)))
|
105
|
-
|
106
|
-
dt = griddata(origin_points, np.ravel(data[:, :]), target_points, method=method)
|
107
|
-
return np.reshape(dt, target_y.shape)
|
108
|
-
|
109
|
-
def interp_single3d(i, target_y, target_x, origin_y, origin_x, data, method='linear'):
|
110
|
-
target_points = np.column_stack((np.ravel(target_y), np.ravel(target_x)))
|
111
|
-
origin_points = np.column_stack((np.ravel(origin_y), np.ravel(origin_x)))
|
112
|
-
|
113
|
-
dt = griddata(origin_points, np.ravel(data[i, :, :]), target_points, method=method)
|
114
|
-
return np.reshape(dt, target_y.shape)
|
115
|
-
|
116
|
-
def interp_single4d(i, j, target_y, target_x, origin_y, origin_x, data, method='linear'):
|
117
|
-
target_points = np.column_stack((np.ravel(target_y), np.ravel(target_x)))
|
118
|
-
origin_points = np.column_stack((np.ravel(origin_y), np.ravel(origin_x)))
|
119
|
-
|
120
|
-
dt = griddata(origin_points, np.ravel(data[i, j, :, :]), target_points, method=method)
|
121
|
-
return np.reshape(dt, target_y.shape)
|
122
|
-
|
123
|
-
if len(target_y.shape) == 1:
|
124
|
-
target_x, target_y = np.meshgrid(target_x, target_y)
|
125
|
-
if len(origin_y.shape) == 1:
|
126
|
-
origin_x, origin_y = np.meshgrid(origin_x, origin_y)
|
127
|
-
|
128
|
-
dims = data.shape
|
129
|
-
len_dims = len(dims)
|
130
|
-
|
131
|
-
if origin_x.shape != dims[-2:] or origin_y.shape != dims[-2:]:
|
132
|
-
raise ValueError('数据形状与 origin_x 或 origin_y 的形状不匹配.')
|
133
|
-
|
134
|
-
interpolated_data = []
|
135
|
-
|
136
|
-
# 使用多线程进行插值
|
137
|
-
with ThreadPoolExecutor(max_workers=mp.cpu_count()-2) as executor:
|
138
|
-
print(f'Using {mp.cpu_count()-2} threads...')
|
139
|
-
if len_dims == 2:
|
140
|
-
interpolated_data = list(executor.map(interp_single2d, [target_y], [target_x], [origin_y], [origin_x], [data], [method]))
|
141
|
-
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]))
|
143
|
-
elif len_dims == 4:
|
144
|
-
interpolated_data = list(executor.map(interp_single4d, [i for i in range(dims[0]) for j in range(dims[1])], [j for i in range(dims[0]) for j in range(dims[1])], [target_y]*dims[0]*dims[1], [target_x]*dims[0]*dims[1], [origin_y]*dims[0]*dims[1], [origin_x]*dims[0]*dims[1], [data]*dims[0]*dims[1], [method]*dims[0]*dims[1]))
|
145
|
-
interpolated_data = np.array(interpolated_data).reshape(dims[0], dims[1], target_y.shape[0], target_x.shape[1])
|
146
|
-
|
147
|
-
interpolated_data = np.array(interpolated_data)
|
148
|
-
|
149
|
-
return interpolated_data
|
150
|
-
|
151
|
-
|
152
|
-
if __name__ == '__main__':
|
153
|
-
import time
|
154
|
-
|
155
|
-
import matplotlib.pyplot as plt
|
156
|
-
|
157
|
-
# 测试数据
|
158
|
-
origin_x = np.linspace(0, 10, 11)
|
159
|
-
origin_y = np.linspace(0, 10, 11)
|
160
|
-
target_x = np.linspace(0, 10, 101)
|
161
|
-
target_y = np.linspace(0, 10, 101)
|
162
|
-
data = np.random.rand(11, 11)
|
163
|
-
|
164
|
-
# 高维插值
|
165
|
-
origin_x = np.linspace(0, 10, 11)
|
166
|
-
origin_y = np.linspace(0, 10, 11)
|
167
|
-
target_x = np.linspace(0, 10, 101)
|
168
|
-
target_y = np.linspace(0, 10, 101)
|
169
|
-
data = np.random.rand(10, 10, 11, 11)
|
170
|
-
|
171
|
-
start = time.time()
|
172
|
-
interpolated_data = interp_2d(target_x, target_y, origin_x, origin_y, data)
|
173
|
-
print(f'Interpolation time: {time.time()-start:.2f}s')
|
174
|
-
|
175
|
-
print(interpolated_data.shape)
|
176
|
-
|
177
|
-
# 高维插值多线程
|
178
|
-
start = time.time()
|
179
|
-
interpolated_data = interp_2d_parallel(target_x, target_y, origin_x, origin_y, data)
|
180
|
-
print(f'Interpolation time: {time.time()-start:.2f}s')
|
181
|
-
|
182
|
-
print(interpolated_data.shape)
|
183
|
-
print(interpolated_data[0, 0, :, :].shape)
|
184
|
-
plt.figure()
|
185
|
-
plt.contourf(target_x, target_y, interpolated_data[0, 0, :, :])
|
186
|
-
plt.colorbar()
|
187
|
-
plt.show()
|