oafuncs 0.0.97.13__py3-none-any.whl → 0.0.97.15__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/cprogressbar.py +310 -75
- oafuncs/{oa_tool → _script}/email.py +26 -24
- oafuncs/_script/netcdf_merge.py +83 -330
- oafuncs/_script/netcdf_modify.py +106 -0
- oafuncs/_script/netcdf_write.py +125 -0
- oafuncs/{oa_tool → _script}/parallel.py +5 -3
- oafuncs/oa_cmap.py +59 -112
- oafuncs/oa_data.py +3 -24
- oafuncs/oa_date.py +47 -11
- oafuncs/oa_down/hycom_3hourly.py +4 -53
- oafuncs/oa_draw.py +11 -132
- oafuncs/oa_file.py +1 -23
- oafuncs/oa_nc.py +53 -281
- oafuncs/oa_python.py +77 -87
- oafuncs/oa_sign/meteorological.py +3 -3
- oafuncs/oa_tool.py +83 -0
- {oafuncs-0.0.97.13.dist-info → oafuncs-0.0.97.15.dist-info}/METADATA +1 -1
- {oafuncs-0.0.97.13.dist-info → oafuncs-0.0.97.15.dist-info}/RECORD +21 -20
- oafuncs/_script/auto_optimized_parallel_executor.py +0 -459
- oafuncs/oa_tool/__init__.py +0 -7
- {oafuncs-0.0.97.13.dist-info → oafuncs-0.0.97.15.dist-info}/WHEEL +0 -0
- {oafuncs-0.0.97.13.dist-info → oafuncs-0.0.97.15.dist-info}/licenses/LICENSE.txt +0 -0
- {oafuncs-0.0.97.13.dist-info → oafuncs-0.0.97.15.dist-info}/top_level.txt +0 -0
@@ -2,10 +2,10 @@
|
|
2
2
|
# coding=utf-8
|
3
3
|
"""
|
4
4
|
Author: Liu Kun && 16031215@qq.com
|
5
|
-
Date: 2025-
|
5
|
+
Date: 2025-04-04 20:19:23
|
6
6
|
LastEditors: Liu Kun && 16031215@qq.com
|
7
|
-
LastEditTime: 2025-
|
8
|
-
FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\
|
7
|
+
LastEditTime: 2025-04-04 20:19:23
|
8
|
+
FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\_script\\parallel.py
|
9
9
|
Description:
|
10
10
|
EditPlatform: vscode
|
11
11
|
ComputerInfo: XPS 15 9510
|
@@ -13,6 +13,8 @@ SystemInfo: Windows 11
|
|
13
13
|
Python Version: 3.12
|
14
14
|
"""
|
15
15
|
|
16
|
+
|
17
|
+
|
16
18
|
import contextlib
|
17
19
|
import logging
|
18
20
|
import multiprocessing as mp
|
oafuncs/oa_cmap.py
CHANGED
@@ -1,27 +1,15 @@
|
|
1
|
-
|
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
|
-
"""
|
1
|
+
from typing import List, Optional, Union
|
15
2
|
|
16
3
|
import matplotlib as mpl
|
17
4
|
import matplotlib.pyplot as plt
|
18
5
|
import numpy as np
|
19
6
|
from rich import print
|
20
7
|
|
21
|
-
__all__ = ["show", "to_color", "create", "
|
8
|
+
__all__ = ["show", "to_color", "create", "get"]
|
9
|
+
|
22
10
|
|
23
11
|
# ** 将cmap用填色图可视化(官网摘抄函数)
|
24
|
-
def show(colormaps):
|
12
|
+
def show(colormaps: Union[str, mpl.colors.Colormap, List[Union[str, mpl.colors.Colormap]]]) -> None:
|
25
13
|
"""
|
26
14
|
Description:
|
27
15
|
Helper function to plot data with associated colormap.
|
@@ -31,107 +19,84 @@ def show(colormaps):
|
|
31
19
|
cmap = ListedColormap(["darkorange", "gold", "lawngreen", "lightseagreen"])
|
32
20
|
show([cmap]); show("viridis"); show(["viridis", "cividis"])
|
33
21
|
"""
|
34
|
-
if
|
22
|
+
if not isinstance(colormaps, list):
|
35
23
|
colormaps = [colormaps]
|
36
24
|
np.random.seed(19680801)
|
37
25
|
data = np.random.randn(30, 30)
|
38
26
|
n = len(colormaps)
|
39
27
|
fig, axs = plt.subplots(1, n, figsize=(n * 2 + 2, 3), constrained_layout=True, squeeze=False)
|
40
|
-
for
|
28
|
+
for ax, cmap in zip(axs.flat, colormaps):
|
41
29
|
psm = ax.pcolormesh(data, cmap=cmap, rasterized=True, vmin=-4, vmax=4)
|
42
30
|
fig.colorbar(psm, ax=ax)
|
43
31
|
plt.show()
|
44
32
|
|
45
33
|
|
46
34
|
# ** 将cmap转为list,即多个颜色的列表
|
47
|
-
def to_color(
|
35
|
+
def to_color(cmap_name: str, n: int = 256) -> List[tuple]:
|
48
36
|
"""
|
49
37
|
Description:
|
50
38
|
Convert a colormap to a list of colors
|
51
39
|
Parameters:
|
52
|
-
|
53
|
-
n
|
40
|
+
cmap_name : str; the name of the colormap
|
41
|
+
n : int, optional; the number of colors
|
54
42
|
Return:
|
55
43
|
out_colors : list of colors
|
56
44
|
Example:
|
57
45
|
out_colors = to_color('viridis', 256)
|
58
46
|
"""
|
59
|
-
|
60
|
-
|
61
|
-
return out_colors
|
47
|
+
cmap = mpl.colormaps.get_cmap(cmap_name)
|
48
|
+
return [cmap(i) for i in np.linspace(0, 1, n)]
|
62
49
|
|
63
50
|
|
64
51
|
# ** 自制cmap,多色,可带位置
|
65
|
-
def create(
|
52
|
+
def create(color_list: Optional[List[Union[str, tuple]]] = None, rgb_file_path: Optional[str] = None, positions: Optional[List[float]] = None, under_color: Optional[Union[str, tuple]] = None, over_color: Optional[Union[str, tuple]] = None, delimiter: str = ",") -> mpl.colors.Colormap:
|
66
53
|
"""
|
67
54
|
Description:
|
68
|
-
Create a custom colormap
|
55
|
+
Create a custom colormap from a list of colors or an RGB txt document.
|
69
56
|
Parameters:
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
57
|
+
color_list : list of colors (optional, required if rgb_file_path is None)
|
58
|
+
rgb_file_path : str, the path of txt file (optional, required if color_list is None)
|
59
|
+
positions : list of positions (optional, for color_list)
|
60
|
+
under_color : color (optional)
|
61
|
+
over_color : color (optional)
|
62
|
+
delimiter : str, optional, default is ','; the delimiter of RGB values in txt file
|
74
63
|
Return:
|
75
64
|
cmap : colormap
|
76
65
|
Example:
|
77
|
-
cmap = create(['#C2B7F3','#B3BBF2','#B0CBF1','#ACDCF0','#A8EEED'])
|
78
|
-
cmap = create(['aliceblue','skyblue','deepskyblue'],[0.0,0.5,1.0])
|
66
|
+
cmap = create(color_list=['#C2B7F3','#B3BBF2','#B0CBF1','#ACDCF0','#A8EEED'])
|
67
|
+
cmap = create(color_list=['aliceblue','skyblue','deepskyblue'], positions=[0.0,0.5,1.0])
|
68
|
+
cmap = create(rgb_file_path='path/to/file.txt', delimiter=',')
|
79
69
|
"""
|
70
|
+
if rgb_file_path:
|
71
|
+
with open(rgb_file_path) as fid:
|
72
|
+
data = fid.readlines()
|
73
|
+
n = len(data)
|
74
|
+
rgb = np.zeros((n, 3))
|
75
|
+
for i in np.arange(n):
|
76
|
+
rgb[i][0] = data[i].split(delimiter)[0]
|
77
|
+
rgb[i][1] = data[i].split(delimiter)[1]
|
78
|
+
rgb[i][2] = data[i].split(delimiter)[2]
|
79
|
+
max_rgb = np.max(rgb)
|
80
|
+
if max_rgb > 2: # if the value is greater than 2, it is normalized to 0-1
|
81
|
+
rgb = rgb / 255.0
|
82
|
+
cmap_color = mpl.colors.ListedColormap(rgb, name="my_color")
|
83
|
+
elif color_list:
|
84
|
+
if positions is None: # 自动分配比例
|
85
|
+
cmap_color = mpl.colors.LinearSegmentedColormap.from_list("mycmap", color_list)
|
86
|
+
else: # 按提供比例分配
|
87
|
+
cmap_color = mpl.colors.LinearSegmentedColormap.from_list("mycmap", list(zip(positions, color_list)))
|
88
|
+
else:
|
89
|
+
raise ValueError("Either 'color_list' or 'rgb_file_path' must be provided.")
|
80
90
|
|
81
|
-
if
|
82
|
-
cmap_color
|
83
|
-
|
84
|
-
cmap_color
|
85
|
-
if under is not None:
|
86
|
-
cmap_color.set_under(under)
|
87
|
-
if over is not None:
|
88
|
-
cmap_color.set_over(over)
|
91
|
+
if under_color is not None:
|
92
|
+
cmap_color.set_under(under_color)
|
93
|
+
if over_color is not None:
|
94
|
+
cmap_color.set_over(over_color)
|
89
95
|
return cmap_color
|
90
96
|
|
91
97
|
|
92
|
-
# ** 根据RGB的txt文档制作色卡(利用Grads调色盘)
|
93
|
-
def create_rgbtxt(rgbtxt_file,split_mark=','): # 根据RGB的txt文档制作色卡/根据rgb值制作
|
94
|
-
"""
|
95
|
-
Description
|
96
|
-
-----------
|
97
|
-
Make a color card according to the RGB txt document, each line in the txt file is an RGB value, separated by commas, such as: 251,251,253
|
98
|
-
|
99
|
-
Parameters
|
100
|
-
----------
|
101
|
-
rgbtxt_file : str, the path of txt file
|
102
|
-
split_mark : str, optional, default is ','; the split mark of rgb value
|
103
|
-
|
104
|
-
Returns
|
105
|
-
-------
|
106
|
-
cmap : colormap
|
107
|
-
|
108
|
-
Example
|
109
|
-
-------
|
110
|
-
cmap=create_rgbtxt(path,split_mark=',')
|
111
|
-
|
112
|
-
txt example
|
113
|
-
-----------
|
114
|
-
251,251,253
|
115
|
-
225,125,25
|
116
|
-
250,205,255
|
117
|
-
"""
|
118
|
-
with open(rgbtxt_file) as fid:
|
119
|
-
data = fid.readlines()
|
120
|
-
n = len(data)
|
121
|
-
rgb = np.zeros((n, 3))
|
122
|
-
for i in np.arange(n):
|
123
|
-
rgb[i][0] = data[i].split(split_mark)[0]
|
124
|
-
rgb[i][1] = data[i].split(split_mark)[1]
|
125
|
-
rgb[i][2] = data[i].split(split_mark)[2]
|
126
|
-
max_rgb = np.max(rgb)
|
127
|
-
if max_rgb > 2: # if the value is greater than 2, it is normalized to 0-1
|
128
|
-
rgb = rgb / 255.0
|
129
|
-
my_cmap = mpl.colors.ListedColormap(rgb, name="my_color")
|
130
|
-
return my_cmap
|
131
|
-
|
132
|
-
|
133
98
|
# ** 选择cmap
|
134
|
-
def get(cmap_name=None, query=False):
|
99
|
+
def get(cmap_name: Optional[str] = None, query: bool = False) -> Optional[mpl.colors.Colormap]:
|
135
100
|
"""
|
136
101
|
Description:
|
137
102
|
Choosing a colormap from the list of available colormaps or a custom colormap
|
@@ -147,43 +112,26 @@ def get(cmap_name=None, query=False):
|
|
147
112
|
cmap = get('warm_1')
|
148
113
|
cmap = get('colorful_1')
|
149
114
|
"""
|
150
|
-
|
151
115
|
my_cmap_dict = {
|
152
116
|
"diverging_1": create(["#4e00b3", "#0000FF", "#00c0ff", "#a1d3ff", "#DCDCDC", "#FFD39B", "#FF8247", "#FF0000", "#FF5F9E"]),
|
153
117
|
"cool_1": create(["#4e00b3", "#0000FF", "#00c0ff", "#a1d3ff", "#DCDCDC"]),
|
154
118
|
"warm_1": create(["#DCDCDC", "#FFD39B", "#FF8247", "#FF0000", "#FF5F9E"]),
|
155
|
-
# "land_1": create_custom(["#3E6436", "#678A59", "#91A176", "#B8A87D", "#D9CBB2"], under="#A6CEE3", over="#FFFFFF"),
|
156
|
-
# "ocean_1": create_custom(["#126697", "#2D88B3", "#4EA1C9", "#78B9D8", "#A6CEE3"], under="#8470FF", over="#3E6436"),
|
157
|
-
# "ocean_land_1": create_custom(
|
158
|
-
# [
|
159
|
-
# "#126697", # 深蓝(深海)
|
160
|
-
# "#2D88B3", # 蓝
|
161
|
-
# "#4EA1C9", # 蓝绿
|
162
|
-
# "#78B9D8", # 浅蓝(浅海)
|
163
|
-
# "#A6CEE3", # 浅蓝(近岸)
|
164
|
-
# "#AAAAAA", # 灰色(0值,海平面)
|
165
|
-
# "#D9CBB2", # 沙质土壤色(陆地开始)
|
166
|
-
# "#B8A87D", # 浅棕
|
167
|
-
# "#91A176", # 浅绿
|
168
|
-
# "#678A59", # 中绿
|
169
|
-
# "#3E6436", # 深绿(高山)
|
170
|
-
# ]
|
171
|
-
# ),
|
172
119
|
"colorful_1": create(["#6d00db", "#9800cb", "#F2003C", "#ff4500", "#ff7f00", "#FE28A2", "#FFC0CB", "#DDA0DD", "#40E0D0", "#1a66f2", "#00f7fb", "#8fff88", "#E3FF00"]),
|
173
120
|
}
|
121
|
+
|
174
122
|
if query:
|
175
123
|
print("Available cmap names:")
|
176
|
-
print('-' * 20)
|
177
|
-
print('Defined by myself:')
|
178
|
-
for key, _ in my_cmap_dict.items():
|
179
|
-
print(key)
|
180
|
-
print('-' * 20)
|
181
|
-
print('Matplotlib built-in:')
|
182
|
-
print(mpl.colormaps())
|
183
124
|
print("-" * 20)
|
184
|
-
|
125
|
+
print("Defined by myself:")
|
126
|
+
print("\n".join(my_cmap_dict.keys()))
|
127
|
+
print("-" * 20)
|
128
|
+
print("Matplotlib built-in:")
|
129
|
+
print("\n".join(mpl.colormaps.keys()))
|
130
|
+
print("-" * 20)
|
131
|
+
return None
|
132
|
+
|
185
133
|
if cmap_name is None:
|
186
|
-
return
|
134
|
+
return None
|
187
135
|
|
188
136
|
if cmap_name in my_cmap_dict:
|
189
137
|
return my_cmap_dict[cmap_name]
|
@@ -191,9 +139,8 @@ def get(cmap_name=None, query=False):
|
|
191
139
|
try:
|
192
140
|
return mpl.colormaps.get_cmap(cmap_name)
|
193
141
|
except ValueError:
|
194
|
-
# raise ValueError(f"Unknown cmap name: {cmap_name}")
|
195
142
|
print(f"Unknown cmap name: {cmap_name}\nNow return 'rainbow' as default.")
|
196
|
-
return mpl.colormaps.get_cmap("rainbow")
|
143
|
+
return mpl.colormaps.get_cmap("rainbow") # 默认返回 'rainbow'
|
197
144
|
|
198
145
|
|
199
146
|
if __name__ == "__main__":
|
@@ -209,7 +156,7 @@ if __name__ == "__main__":
|
|
209
156
|
|
210
157
|
# ** 测试根据RGB的txt文档制作色卡
|
211
158
|
file_path = "E:/python/colorbar/test.txt"
|
212
|
-
cmap_rgb =
|
159
|
+
cmap_rgb = create(rgb_file_path=file_path)
|
213
160
|
|
214
161
|
# ** 测试将cmap转为list
|
215
162
|
out_colors = to_color("viridis", 256)
|
oafuncs/oa_data.py
CHANGED
@@ -17,14 +17,13 @@ import itertools
|
|
17
17
|
import multiprocessing as mp
|
18
18
|
from concurrent.futures import ThreadPoolExecutor
|
19
19
|
|
20
|
+
|
20
21
|
import numpy as np
|
21
22
|
import salem
|
22
23
|
import xarray as xr
|
23
|
-
from scipy.interpolate import griddata
|
24
|
-
from scipy.interpolate import interp1d
|
25
|
-
from typing import Iterable
|
24
|
+
from scipy.interpolate import griddata, interp1d
|
26
25
|
|
27
|
-
__all__ = ["interp_along_dim", "interp_2d", "ensure_list", "mask_shapefile"
|
26
|
+
__all__ = ["interp_along_dim", "interp_2d", "ensure_list", "mask_shapefile"]
|
28
27
|
|
29
28
|
|
30
29
|
def ensure_list(input_data):
|
@@ -255,26 +254,6 @@ def mask_shapefile(data: np.ndarray, lons: np.ndarray, lats: np.ndarray, shapefi
|
|
255
254
|
return None
|
256
255
|
|
257
256
|
|
258
|
-
def pbar(iterable: Iterable, prefix: str = "", color: str = "cyan", cmap: str = None, **kwargs) -> Iterable:
|
259
|
-
"""
|
260
|
-
快速创建进度条的封装函数
|
261
|
-
:param iterable: 可迭代对象
|
262
|
-
:param prefix: 进度条前缀
|
263
|
-
:param color: 基础颜色
|
264
|
-
:param cmap: 渐变色名称
|
265
|
-
:param kwargs: 其他ColorProgressBar支持的参数
|
266
|
-
|
267
|
-
example:
|
268
|
-
from oafuncs.oa_data import pbar
|
269
|
-
from time import sleep
|
270
|
-
for i in pbar(range(100), prefix="Processing", color="green", cmap="viridis"):
|
271
|
-
sleep(0.1)
|
272
|
-
"""
|
273
|
-
from ._script.cprogressbar import ColorProgressBar # 从progressbar.py导入类
|
274
|
-
|
275
|
-
return ColorProgressBar(iterable=iterable, prefix=prefix, color=color, cmap=cmap, **kwargs)
|
276
|
-
|
277
|
-
|
278
257
|
if __name__ == "__main__":
|
279
258
|
pass
|
280
259
|
""" import time
|
oafuncs/oa_date.py
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
Author: Liu Kun && 16031215@qq.com
|
5
5
|
Date: 2025-03-27 16:56:57
|
6
6
|
LastEditors: Liu Kun && 16031215@qq.com
|
7
|
-
LastEditTime: 2025-
|
7
|
+
LastEditTime: 2025-04-04 12:58:15
|
8
8
|
FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_date.py
|
9
9
|
Description:
|
10
10
|
EditPlatform: vscode
|
@@ -15,36 +15,37 @@ Python Version: 3.12
|
|
15
15
|
|
16
16
|
import calendar
|
17
17
|
import datetime
|
18
|
+
from typing import List, Optional
|
18
19
|
|
19
|
-
__all__ = ["
|
20
|
+
__all__ = ["month_days", "hour_range", "adjust_time", "timeit"]
|
20
21
|
|
21
22
|
|
22
|
-
def
|
23
|
+
def month_days(year: int, month: int) -> int:
|
23
24
|
return calendar.monthrange(year, month)[1]
|
24
25
|
|
25
26
|
|
26
|
-
def
|
27
|
+
def hour_range(start: str, end: str, interval: int = 6) -> List[str]:
|
27
28
|
"""
|
28
29
|
Generate a list of datetime strings with a specified interval in hours.
|
29
30
|
|
30
31
|
Args:
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
start (str): Start date in the format "%Y%m%d%H".
|
33
|
+
end (str): End date in the format "%Y%m%d%H".
|
34
|
+
interval (int): Interval in hours between each datetime.
|
34
35
|
|
35
36
|
Returns:
|
36
37
|
list: List of datetime strings in the format "%Y%m%d%H".
|
37
38
|
"""
|
38
|
-
date_s = datetime.datetime.strptime(
|
39
|
-
date_e = datetime.datetime.strptime(
|
39
|
+
date_s = datetime.datetime.strptime(start, "%Y%m%d%H")
|
40
|
+
date_e = datetime.datetime.strptime(end, "%Y%m%d%H")
|
40
41
|
date_list = []
|
41
42
|
while date_s <= date_e:
|
42
43
|
date_list.append(date_s.strftime("%Y%m%d%H"))
|
43
|
-
date_s += datetime.timedelta(hours=
|
44
|
+
date_s += datetime.timedelta(hours=interval)
|
44
45
|
return date_list
|
45
46
|
|
46
47
|
|
47
|
-
def adjust_time(initial_time, amount, time_unit="hours", output_format=None):
|
48
|
+
def adjust_time(initial_time: str, amount: int, time_unit: str = "hours", output_format: Optional[str] = None) -> str:
|
48
49
|
"""
|
49
50
|
Adjust a given initial time by adding a specified amount of time.
|
50
51
|
|
@@ -88,3 +89,38 @@ def adjust_time(initial_time, amount, time_unit="hours", output_format=None):
|
|
88
89
|
elif time_unit == "days":
|
89
90
|
default_format = "%Y%m%d"
|
90
91
|
return time_obj.strftime(default_format)
|
92
|
+
|
93
|
+
|
94
|
+
class timeit:
|
95
|
+
"""
|
96
|
+
A decorator to measure the execution time of a function.
|
97
|
+
|
98
|
+
Usage:
|
99
|
+
@timeit(log=True, print_time=True)
|
100
|
+
def my_function():
|
101
|
+
# Function code here
|
102
|
+
|
103
|
+
Args:
|
104
|
+
log (bool): Whether to log the execution time to a file. Defaults to False.
|
105
|
+
print_time (bool): Whether to print the execution time to the console. Defaults to True.
|
106
|
+
"""
|
107
|
+
|
108
|
+
def __init__(self, func, log: bool = False, print_time: bool = True):
|
109
|
+
self.func = func
|
110
|
+
self.log = log
|
111
|
+
self.print_time = print_time
|
112
|
+
|
113
|
+
def __call__(self, *args, **kwargs):
|
114
|
+
start_time = datetime.datetime.now()
|
115
|
+
result = self.func(*args, **kwargs)
|
116
|
+
end_time = datetime.datetime.now()
|
117
|
+
elapsed_time = (end_time - start_time).total_seconds()
|
118
|
+
|
119
|
+
if self.print_time:
|
120
|
+
print(f"Function '{self.func.__name__}' executed in {elapsed_time:.2f} seconds.")
|
121
|
+
|
122
|
+
if self.log:
|
123
|
+
with open("execution_time.log", "a") as log_file:
|
124
|
+
log_file.write(f"{datetime.datetime.now()} - Function '{self.func.__name__}' executed in {elapsed_time:.2f} seconds.\n")
|
125
|
+
|
126
|
+
return result
|
oafuncs/oa_down/hycom_3hourly.py
CHANGED
@@ -40,7 +40,7 @@ from oafuncs.oa_nc import modify as modify_nc
|
|
40
40
|
|
41
41
|
warnings.filterwarnings("ignore", category=RuntimeWarning, message="Engine '.*' loading failed:.*")
|
42
42
|
|
43
|
-
__all__ = ["draw_time_range", "download"
|
43
|
+
__all__ = ["draw_time_range", "download"]
|
44
44
|
|
45
45
|
|
46
46
|
def _get_initial_data():
|
@@ -278,7 +278,7 @@ def draw_time_range(pic_save_folder=None):
|
|
278
278
|
plt.close()
|
279
279
|
|
280
280
|
|
281
|
-
def
|
281
|
+
def _get_time_list(time_s, time_e, delta, interval_type="hour"):
|
282
282
|
"""
|
283
283
|
Description: get a list of time strings from time_s to time_e with a specified interval
|
284
284
|
Args:
|
@@ -1029,7 +1029,7 @@ def _download_hourly_func(var, time_s, time_e, lon_min=0, lon_max=359.92, lat_mi
|
|
1029
1029
|
_prepare_url_to_download(var, lon_min, lon_max, lat_min, lat_max, ymdh_time_s, None, depth, level, store_path, dataset_name, version_name, check)
|
1030
1030
|
elif int(ymdh_time_s) < int(ymdh_time_e):
|
1031
1031
|
print("Downloading a series of files...")
|
1032
|
-
time_list =
|
1032
|
+
time_list = _get_time_list(ymdh_time_s, ymdh_time_e, interval_hour, "hour")
|
1033
1033
|
with Progress() as progress:
|
1034
1034
|
task = progress.add_task(f"[cyan]{bar_desc}", total=len(time_list))
|
1035
1035
|
if ftimes == 1:
|
@@ -1048,7 +1048,7 @@ def _download_hourly_func(var, time_s, time_e, lon_min=0, lon_max=359.92, lat_mi
|
|
1048
1048
|
_done_callback(feature, progress, task, len(time_list), counter_lock)
|
1049
1049
|
else:
|
1050
1050
|
# new_time_list = get_time_list(ymdh_time_s, ymdh_time_e, 3 * ftimes, "hour")
|
1051
|
-
new_time_list =
|
1051
|
+
new_time_list = _get_time_list(ymdh_time_s, ymdh_time_e, interval_hour * ftimes, "hour")
|
1052
1052
|
total_num = len(new_time_list)
|
1053
1053
|
if num_workers is None or num_workers <= 1:
|
1054
1054
|
# 串行方式
|
@@ -1248,55 +1248,6 @@ def download(var, time_s, time_e=None, lon_min=0, lon_max=359.92, lat_min=-80, l
|
|
1248
1248
|
print("[bold #ecdbfe]=" * mark_len)
|
1249
1249
|
|
1250
1250
|
|
1251
|
-
def how_to_use():
|
1252
|
-
print("""
|
1253
|
-
# 1. Choose the dataset and version according to the time:
|
1254
|
-
# 1.1 Use function to query
|
1255
|
-
You can use the function check_time_in_dataset_and_version(time_input=20241101) to find the dataset and version according to the time.
|
1256
|
-
Then, you can see the dataset and version in the output.
|
1257
|
-
# 1.2 Draw a picture to see
|
1258
|
-
You can draw a picture to see the time range of each dataset and version.
|
1259
|
-
Using the function draw_time_range(pic_save_folder=None) to draw the picture.
|
1260
|
-
|
1261
|
-
# 2. Get the base url according to the dataset, version, var and year:
|
1262
|
-
# 2.1 Dataset and version were found in step 1
|
1263
|
-
# 2.2 Var: u, v, temp, salt, ssh, u_b, v_b, temp_b, salt_b
|
1264
|
-
# 2.3 Year: 1994-2024(current year)
|
1265
|
-
|
1266
|
-
# 3. Get the query_dict according to the var, lon_min, lon_max, lat_min, lat_max, depth, level_num, time_str_ymdh:
|
1267
|
-
# 3.1 Var: u, v, temp, salt, ssh, u_b, v_b, temp_b, salt_b
|
1268
|
-
# 3.2 Lon_min, lon_max, lat_min, lat_max: float
|
1269
|
-
# 3.3 Depth: 0-5000m, if you wanna get single depth data, you can set the depth
|
1270
|
-
# 3.4 Level_num: 1-40, if you wanna get single level data, you can set the level_num
|
1271
|
-
# 3.5 Time_str_ymdh: '2024110112', the hour normally is 00, 03, 06, 09, 12, 15, 18, 21, besides 1 hourly data
|
1272
|
-
# 3.6 Use the function to get the query_dict
|
1273
|
-
# 3.7 Note: If you wanna get the full depth or full level data, you can needn't set the depth or level_num
|
1274
|
-
|
1275
|
-
# 4. Get the submit url according to the dataset, version, var, year, query_dict:
|
1276
|
-
# 4.1 Use the function to get the submit url
|
1277
|
-
# 4.2 You can use the submit url to download the data
|
1278
|
-
|
1279
|
-
# 5. Download the data according to the submit url:
|
1280
|
-
# 5.1 Use the function to download the data
|
1281
|
-
# 5.2 You can download the data of single time or a series of time
|
1282
|
-
# 5.3 Note: If you wanna download a series of data, you can set the ymdh_time_s and ymdh_time_e different
|
1283
|
-
# 5.4 Note: The time resolution is 3 hours
|
1284
|
-
|
1285
|
-
# 6. Direct download the data:
|
1286
|
-
# 6.1 Use the function to direct download the data
|
1287
|
-
# 6.2 You can set the dataset_name and version_name by yourself
|
1288
|
-
# 6.3 Note: If you do not set the dataset_name and version_name, the dataset and version will be chosen according to the download_time
|
1289
|
-
# 6.4 Note: If you set the dataset_name and version_name, please ensure the dataset_name and version_name are correct
|
1290
|
-
# 6.5 Note: If you just set one of the dataset_name and version_name, both the dataset and version will be chosen according to the download_time
|
1291
|
-
|
1292
|
-
# 7. Simple use:
|
1293
|
-
# 7.1 You can use the function: download(var, ymdh_time_s, ymdh_time_e, lon_min=0, lon_max=359.92, lat_min=-80, lat_max=90, depth=None, level_num=None, store_path=None, dataset_name=None, version_name=None)
|
1294
|
-
# 7.2 You can download the data of single time or a series of time
|
1295
|
-
# 7.3 The parameters you must set are var, ymdh_time_s, ymdh_time_e
|
1296
|
-
# 7.4 Example: download('u', '2024110112', '2024110212', lon_min=0, lon_max=359.92, lat_min=-80, lat_max=90, depth=None, level_num=None, store_path=None, dataset_name=None, version_name=None)
|
1297
|
-
""")
|
1298
|
-
|
1299
|
-
|
1300
1251
|
if __name__ == "__main__":
|
1301
1252
|
download_dict = {
|
1302
1253
|
"water_u": {"simple_name": "u", "download": 1},
|