oafuncs 0.0.64__py2.py3-none-any.whl → 0.0.66__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/oa_down/hycom_3hourly.py +68 -55
- oafuncs/oa_tool/email.py +8 -4
- {oafuncs-0.0.64.dist-info → oafuncs-0.0.66.dist-info}/METADATA +1 -1
- {oafuncs-0.0.64.dist-info → oafuncs-0.0.66.dist-info}/RECORD +7 -7
- {oafuncs-0.0.64.dist-info → oafuncs-0.0.66.dist-info}/LICENSE.txt +0 -0
- {oafuncs-0.0.64.dist-info → oafuncs-0.0.66.dist-info}/WHEEL +0 -0
- {oafuncs-0.0.64.dist-info → oafuncs-0.0.66.dist-info}/top_level.txt +0 -0
oafuncs/oa_down/hycom_3hourly.py
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
Author: Liu Kun && 16031215@qq.com
|
5
5
|
Date: 2024-11-01 10:31:09
|
6
6
|
LastEditors: Liu Kun && 16031215@qq.com
|
7
|
-
LastEditTime: 2024-11-
|
7
|
+
LastEditTime: 2024-11-30 11:40:53
|
8
8
|
FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_down\\hycom_3hourly.py
|
9
9
|
Description:
|
10
10
|
EditPlatform: vscode
|
@@ -52,7 +52,7 @@ data_info['hourly']['dataset']['GLBy0.08']['version'] = {'93.0': {}}
|
|
52
52
|
# 在网页上提交超过范围的时间,会返回该数据集实际时间范围,从而纠正下面的时间范围
|
53
53
|
# 目前只纠正了GLBv0.08 93.0的时间范围,具体到小时了
|
54
54
|
# 其他数据集的时刻暂时默认为00起,21止
|
55
|
-
data_info['hourly']['dataset']['GLBv0.08']['version']['53.X']['time_range'] = {'time_start': '19940101', 'time_end': '
|
55
|
+
data_info['hourly']['dataset']['GLBv0.08']['version']['53.X']['time_range'] = {'time_start': '19940101', 'time_end': '20151231'}
|
56
56
|
data_info['hourly']['dataset']['GLBv0.08']['version']['56.3']['time_range'] = {'time_start': '20140701', 'time_end': '20160430'}
|
57
57
|
data_info['hourly']['dataset']['GLBv0.08']['version']['57.2']['time_range'] = {'time_start': '20160501', 'time_end': '20170131'}
|
58
58
|
data_info['hourly']['dataset']['GLBv0.08']['version']['92.8']['time_range'] = {'time_start': '20170201', 'time_end': '20170531'}
|
@@ -412,8 +412,11 @@ def ymdh_in_which_dataset_and_version(time_ymdh):
|
|
412
412
|
if have_data:
|
413
413
|
for d, v, trange in zip(d_list, v_list, trange_list):
|
414
414
|
print(f'[bold blue]{d} {v} {trange}')
|
415
|
+
return True
|
415
416
|
else:
|
416
|
-
raise ValueError(f'
|
417
|
+
# raise ValueError(f'{time_ymdh} is not in any dataset and version')
|
418
|
+
print(f'[bold red]{time_ymdh} is not in any dataset and version')
|
419
|
+
return False
|
417
420
|
|
418
421
|
|
419
422
|
def ymd_in_which_dataset_and_version(time_ymd):
|
@@ -439,8 +442,11 @@ def ymd_in_which_dataset_and_version(time_ymd):
|
|
439
442
|
if have_data:
|
440
443
|
for d, v, trange in zip(d_list, v_list, trange_list):
|
441
444
|
print(f'[bold blue]{d} {v} {trange}')
|
445
|
+
return True
|
442
446
|
else:
|
443
|
-
raise ValueError(f'[bold red]{time_ymd} is not in any dataset and version')
|
447
|
+
# raise ValueError(f'[bold red]{time_ymd} is not in any dataset and version')
|
448
|
+
print(f'[bold red]{time_ymd} is not in any dataset and version')
|
449
|
+
return False
|
444
450
|
|
445
451
|
|
446
452
|
def direct_choose_dataset_and_version(time_ymdh):
|
@@ -456,6 +462,7 @@ def direct_choose_dataset_and_version(time_ymdh):
|
|
456
462
|
if time_ymdh >= int(time_s) and time_ymdh <= int(time_e):
|
457
463
|
print(f'[bold purple]dataset: {dataset_name}, version: {version_name} is chosen')
|
458
464
|
return dataset_name, version_name
|
465
|
+
return None, None
|
459
466
|
|
460
467
|
|
461
468
|
def direct_choose_dataset_and_version_whole_day(time_ymd):
|
@@ -515,7 +522,7 @@ def clear_existing_file(file_full_path):
|
|
515
522
|
|
516
523
|
def check_existing_file(file_full_path):
|
517
524
|
if os.path.exists(file_full_path):
|
518
|
-
print(f'{file_full_path} exists')
|
525
|
+
print(f'[bold #FFA54F]{file_full_path} exists')
|
519
526
|
return True
|
520
527
|
else:
|
521
528
|
print(f'{file_full_path} does not exist')
|
@@ -620,6 +627,7 @@ def dlownload_file(target_url, store_path, file_name, check=False):
|
|
620
627
|
download_success = False
|
621
628
|
request_times = 0
|
622
629
|
filename = Path(store_path) / file_name
|
630
|
+
|
623
631
|
if check:
|
624
632
|
if check_existing_file(filename):
|
625
633
|
return
|
@@ -639,9 +647,10 @@ def dlownload_file(target_url, store_path, file_name, check=False):
|
|
639
647
|
with open(filename, 'wb') as f:
|
640
648
|
f.write(response.content)
|
641
649
|
# print(f'\r文件 {filename} 下载成功', end="")
|
642
|
-
print(f'[bold green]文件 {filename} 下载成功')
|
643
650
|
# query_ncfile_time(filename) # 这个函数在linux上目前会出问题
|
644
|
-
|
651
|
+
if os.path.exists(filename):
|
652
|
+
download_success = True
|
653
|
+
print(f'[bold green]文件 {filename} 下载成功')
|
645
654
|
|
646
655
|
except requests.exceptions.HTTPError as errh:
|
647
656
|
print(f"Http Error: {errh}")
|
@@ -671,20 +680,20 @@ def check_dataset_version_single_time(dataset_name, version_name, download_time)
|
|
671
680
|
if not check_hour_is_valid(download_time):
|
672
681
|
print('Please ensure the hour is 00, 03, 06, 09, 12, 15, 18, 21')
|
673
682
|
raise ValueError('The hour is invalid')
|
683
|
+
have_data = ymdh_in_which_dataset_and_version(download_time)
|
684
|
+
if not have_data:
|
685
|
+
return None, None
|
674
686
|
if dataset_name is None and version_name is None:
|
675
687
|
print('The dataset_name and version_name are None, so the dataset and version will be chosen according to the download_time.\nIf there is more than one dataset and version in the time range, the first one will be chosen.')
|
676
688
|
print('If you wanna choose the dataset and version by yourself, please set the dataset_name and version_name together.')
|
677
|
-
ymdh_in_which_dataset_and_version(download_time)
|
678
689
|
dataset_name, version_name = direct_choose_dataset_and_version(download_time)
|
679
690
|
elif dataset_name is None and version_name is not None:
|
680
691
|
print('Please ensure the dataset_name is not None')
|
681
692
|
print('If you do not add the dataset_name, both the dataset and version will be chosen according to the download_time.')
|
682
|
-
ymdh_in_which_dataset_and_version(download_time)
|
683
693
|
dataset_name, version_name = direct_choose_dataset_and_version(download_time)
|
684
694
|
elif dataset_name is not None and version_name is None:
|
685
695
|
print('Please ensure the version_name is not None')
|
686
696
|
print('If you do not add the version_name, both the dataset and version will be chosen according to the download_time.')
|
687
|
-
ymdh_in_which_dataset_and_version(download_time)
|
688
697
|
dataset_name, version_name = direct_choose_dataset_and_version(download_time)
|
689
698
|
else:
|
690
699
|
print('The dataset_name and version_name are both set by yourself.')
|
@@ -713,6 +722,8 @@ def get_submit_url_var(var, depth, level_num, lon_min, lon_max, lat_min, lat_max
|
|
713
722
|
def direct_download_single_time(var, lon_min=0, lon_max=359.92, lat_min=-80, lat_max=90, download_time='2024083100', depth=None, level_num=None, store_path=None, dataset_name=None, version_name=None, check=False):
|
714
723
|
download_time = str(download_time)
|
715
724
|
dataset_name, version_name = check_dataset_version_single_time(dataset_name, version_name, download_time)
|
725
|
+
if dataset_name is None and version_name is None:
|
726
|
+
return
|
716
727
|
|
717
728
|
if store_path is None:
|
718
729
|
store_path = str(Path.cwd())
|
@@ -754,20 +765,20 @@ def direct_download_single_time(var, lon_min=0, lon_max=359.92, lat_min=-80, lat
|
|
754
765
|
|
755
766
|
def check_dataset_version_whold_day(dataset_name, version_name, download_time):
|
756
767
|
download_time = str(download_time)
|
768
|
+
have_data = ymd_in_which_dataset_and_version(download_time)
|
769
|
+
if not have_data:
|
770
|
+
return None, None
|
757
771
|
if dataset_name is None and version_name is None:
|
758
772
|
print('The dataset_name and version_name are None, so the dataset and version will be chosen according to the download_time.\nIf there is more than one dataset and version in the time range, the first one will be chosen.')
|
759
773
|
print('If you wanna choose the dataset and version by yourself, please set the dataset_name and version_name together.')
|
760
|
-
ymd_in_which_dataset_and_version(download_time)
|
761
774
|
dataset_name, version_name = direct_choose_dataset_and_version_whole_day(download_time)
|
762
775
|
elif dataset_name is None and version_name is not None:
|
763
776
|
print('Please ensure the dataset_name is not None')
|
764
777
|
print('If you do not add the dataset_name, both the dataset and version will be chosen according to the download_time.')
|
765
|
-
ymd_in_which_dataset_and_version(download_time)
|
766
778
|
dataset_name, version_name = direct_choose_dataset_and_version_whole_day(download_time)
|
767
779
|
elif dataset_name is not None and version_name is None:
|
768
780
|
print('Please ensure the version_name is not None')
|
769
781
|
print('If you do not add the version_name, both the dataset and version will be chosen according to the download_time.')
|
770
|
-
ymd_in_which_dataset_and_version(download_time)
|
771
782
|
dataset_name, version_name = direct_choose_dataset_and_version_whole_day(download_time)
|
772
783
|
else:
|
773
784
|
print('The dataset_name and version_name are both set by yourself.')
|
@@ -778,6 +789,8 @@ def check_dataset_version_whold_day(dataset_name, version_name, download_time):
|
|
778
789
|
def direct_download_whole_day(var, lon_min=0, lon_max=359.92, lat_min=-80, lat_max=90, download_time='20240831', depth=None, level_num=None, store_path=None, dataset_name=None, version_name=None, check=False):
|
779
790
|
download_time = str(download_time)[:8]+'00'
|
780
791
|
dataset_name, version_name = check_dataset_version_whold_day(dataset_name, version_name, download_time[:8])
|
792
|
+
if dataset_name is None and version_name is None:
|
793
|
+
return
|
781
794
|
|
782
795
|
if store_path is None:
|
783
796
|
store_path = str(Path.cwd())
|
@@ -1145,67 +1158,67 @@ def how_to_use():
|
|
1145
1158
|
|
1146
1159
|
|
1147
1160
|
if __name__ == '__main__':
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1161
|
+
# help(hycom3h.download)
|
1162
|
+
time_s, time_e = '2018010100', '2024103121'
|
1163
|
+
merge_name = '2018_010300-020100'
|
1164
|
+
root_path = r'G:\Data\HYCOM\3hourly'
|
1165
|
+
location_dict = {'west': 105, 'east': 130, 'south': 15, 'north': 45}
|
1152
1166
|
download_dict = {
|
1153
1167
|
'water_u': {'simple_name': 'u', 'download': 1},
|
1154
1168
|
'water_v': {'simple_name': 'v', 'download': 1},
|
1155
1169
|
'surf_el': {'simple_name': 'ssh', 'download': 1},
|
1156
1170
|
'water_temp': {'simple_name': 'temp', 'download': 1},
|
1157
1171
|
'salinity': {'simple_name': 'salt', 'download': 1},
|
1172
|
+
'water_u_bottom': {'simple_name': 'u_b', 'download': 0},
|
1173
|
+
'water_v_bottom': {'simple_name': 'v_b', 'download': 0},
|
1174
|
+
'water_temp_bottom': {'simple_name': 'temp_b', 'download': 0},
|
1175
|
+
'salinity_bottom': {'simple_name': 'salt_b', 'download': 0},
|
1158
1176
|
}
|
1159
1177
|
|
1160
1178
|
var_list = []
|
1161
1179
|
for var_name in download_dict.keys():
|
1162
1180
|
if download_dict[var_name]['download'] == 1:
|
1163
|
-
var_list.append(
|
1181
|
+
var_list.append(var_name)
|
1164
1182
|
|
1165
1183
|
# set depth or level, only one can be True
|
1166
1184
|
# if you wanna download all depth or level, set both False
|
1167
|
-
|
1168
|
-
|
1169
|
-
num_workers =
|
1185
|
+
depth = None # or 0-4000 meters
|
1186
|
+
level = None # or 1-40 levels
|
1187
|
+
num_workers = 2
|
1188
|
+
|
1170
1189
|
check = True
|
1171
1190
|
|
1172
|
-
download_switch = True
|
1173
|
-
combine_switch =
|
1174
|
-
|
1175
|
-
single_var = True
|
1176
|
-
|
1177
|
-
def download_var(var):
|
1178
|
-
if set_depth:
|
1179
|
-
download(var=var, time_s=time_s, time_e=time_e, store_path=Path(root_path)/var, lon_min=location_dict[
|
1180
|
-
'west'], lon_max=location_dict['east'], lat_min=location_dict['south'], lat_max=location_dict['north'], depth=depth, num_workers=num_workers, check=check)
|
1181
|
-
elif set_level:
|
1182
|
-
download(var=var, time_s=time_s, time_e=time_e, store_path=Path(root_path)/var, lon_min=location_dict[
|
1183
|
-
'west'], lon_max=location_dict['east'], lat_min=location_dict['south'], lat_max=location_dict['north'], level=level, num_workers=num_workers, check=check)
|
1184
|
-
else:
|
1185
|
-
download(var=var, time_s=time_s, time_e=time_e, store_path=Path(root_path)/var, lon_min=location_dict[
|
1186
|
-
'west'], lon_max=location_dict['east'], lat_min=location_dict['south'], lat_max=location_dict['north'], num_workers=num_workers, check=check)
|
1191
|
+
download_switch, single_var = True, False
|
1192
|
+
combine_switch = True
|
1193
|
+
copy_switch, copy_dir = True, r'G:\Data\HYCOM\3hourly'
|
1187
1194
|
|
1188
1195
|
if download_switch:
|
1189
1196
|
if single_var:
|
1190
|
-
# single var
|
1191
1197
|
for var_name in var_list:
|
1192
|
-
|
1198
|
+
download(var=var_name, time_s=time_s, time_e=time_e, store_path=Path(root_path), lon_min=location_dict['west'], lon_max=location_dict['east'], lat_min=location_dict['south'], lat_max=location_dict['north'], num_workers=num_workers, check=check, depth=depth, level=level)
|
1193
1199
|
else:
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
""" if combine_switch:
|
1200
|
-
time_list = get_time_list(time_s, time_e, 3)
|
1201
|
-
for var_name in download_dict.keys():
|
1202
|
-
var = download_dict[var_name]['simple_name']
|
1203
|
-
if_download = download_dict[var_name]['download']
|
1204
|
-
if if_download == 0:
|
1205
|
-
continue
|
1200
|
+
download(var=var_list, time_s=time_s, time_e=time_e, store_path=Path(root_path), lon_min=location_dict['west'], lon_max=location_dict['east'], lat_min=location_dict['south'], lat_max=location_dict['north'], num_workers=num_workers, check=check, depth=depth, level=level)
|
1201
|
+
|
1202
|
+
""" if combine_switch or copy_switch:
|
1203
|
+
time_list = get_hour_list(time_s, time_e, 3)
|
1204
|
+
for var_name in var_list:
|
1206
1205
|
file_list = []
|
1207
|
-
|
1208
|
-
|
1209
|
-
Path(root_path)/
|
1210
|
-
|
1211
|
-
|
1206
|
+
if single_var:
|
1207
|
+
for time_str in time_list:
|
1208
|
+
file_list.append(Path(root_path)/f'HYCOM_{var_name}_{time_str}.nc')
|
1209
|
+
merge_path_name = Path(root_path)/f'HYCOM_{var_name}_{merge_name}.nc'
|
1210
|
+
else:
|
1211
|
+
# 如果混合,需要看情况获取文件列表
|
1212
|
+
fname = ''
|
1213
|
+
if var_name in ['water_u', 'water_v', 'water_u_bottom', 'water_v_bottom'] or var_name in ['u', 'v', 'u_b', 'v_b']:
|
1214
|
+
fname = 'uv3z'
|
1215
|
+
elif var_name in ['water_temp', 'salinity', 'water_temp_bottom', 'salinity_bottom'] or var_name in ['temp', 'salt', 'temp_b', 'salt_b']:
|
1216
|
+
fname = 'ts3z'
|
1217
|
+
elif var_name in ['surf_el'] or var_name in ['ssh']:
|
1218
|
+
fname = 'surf_el'
|
1219
|
+
for time_str in time_list:
|
1220
|
+
file_list.append(Path(root_path)/f'HYCOM_{fname}_{time_str}.nc')
|
1221
|
+
if combine_switch:
|
1222
|
+
merge5nc(file_list, var_name, 'time', merge_path_name)
|
1223
|
+
if copy_switch:
|
1224
|
+
copy_file(merge_path_name, copy_dir) """
|
oafuncs/oa_tool/email.py
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
Author: Liu Kun && 16031215@qq.com
|
5
5
|
Date: 2024-11-21 09:47:41
|
6
6
|
LastEditors: Liu Kun && 16031215@qq.com
|
7
|
-
LastEditTime: 2024-11-
|
8
|
-
FilePath: \\Python\\My_Funcs\\OAFuncs\\
|
7
|
+
LastEditTime: 2024-11-29 20:54:43
|
8
|
+
FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_tool\\email.py
|
9
9
|
Description:
|
10
10
|
EditPlatform: vscode
|
11
11
|
ComputerInfo: XPS 15 9510
|
@@ -88,7 +88,7 @@ def _send_message(title, content, msg_to):
|
|
88
88
|
print('发送内容为:\n{}\n\n'.format(content))
|
89
89
|
|
90
90
|
|
91
|
-
def send(title='Title', content=
|
91
|
+
def send(title='Title', content=None, send_to='16031215@qq.com'):
|
92
92
|
'''
|
93
93
|
Description: 发送邮件
|
94
94
|
|
@@ -103,7 +103,11 @@ def send(title='Title', content='Content', send_to='16031215@qq.com'):
|
|
103
103
|
Example:
|
104
104
|
send(title='Title', content='Content', '123@qq.com')
|
105
105
|
'''
|
106
|
-
|
106
|
+
if content is None:
|
107
|
+
# 避免发送空邮件,或有人误调用
|
108
|
+
return
|
109
|
+
else:
|
110
|
+
_send_message(title, content, send_to)
|
107
111
|
|
108
112
|
|
109
113
|
if __name__ == "__main__":
|
@@ -7,7 +7,7 @@ oafuncs/oa_help.py,sha256=ppNktmtNzs15R20MD1bM7yImlTQ_ngMwvoIglePOKXA,1000
|
|
7
7
|
oafuncs/oa_nc.py,sha256=ALAYfqDy5lbUNJsTU29j6ZWkM4wgqQU3p2Fxn5pkvsQ,12102
|
8
8
|
oafuncs/oa_python.py,sha256=XPTP3o7zTFzfJR_YhsKfQksa3bSYwXsne9YxlJplCEA,3994
|
9
9
|
oafuncs/oa_down/__init__.py,sha256=a6rgxHQi8spvlI-TaVEqnrDNhYsKm5_IQf7ckAZ8U4w,603
|
10
|
-
oafuncs/oa_down/hycom_3hourly.py,sha256=
|
10
|
+
oafuncs/oa_down/hycom_3hourly.py,sha256=AmU3F2-L1L5bKRG8sV3FbLOFTw6ePvmXhu51h60BKKo,65906
|
11
11
|
oafuncs/oa_down/hycom_3hourly_wholeday.py,sha256=bEl-hdSPJqN_9IaJIF-la0jEPw-sbCaKnciPirsWgP8,62598
|
12
12
|
oafuncs/oa_down/literature.py,sha256=dT3-7-beEzQ9mTP8LNV9Gf3q5Z1Pqqjc6FOS010HZeQ,17833
|
13
13
|
oafuncs/oa_down/refs_pdf.py,sha256=wr1sIYO2FUBJTn-K79NylbRUvCAFaee6_fQljxSI_Q8,17979
|
@@ -16,9 +16,9 @@ oafuncs/oa_sign/meteorological.py,sha256=mLbupsZSq427HTfVbZMvIlFzDHwSzQAbK3X19o8
|
|
16
16
|
oafuncs/oa_sign/ocean.py,sha256=xrW-rWD7xBWsB5PuCyEwQ1Q_RDKq2KCLz-LOONHgldU,5932
|
17
17
|
oafuncs/oa_sign/scientific.py,sha256=a4JxOBgm9vzNZKpJ_GQIQf7cokkraV5nh23HGbmTYKw,5064
|
18
18
|
oafuncs/oa_tool/__init__.py,sha256=IKOlqpWlb4cMDCtq2VKR_RTxQHDNqR_vfqqsOsp_lKQ,466
|
19
|
-
oafuncs/oa_tool/email.py,sha256=
|
20
|
-
oafuncs-0.0.
|
21
|
-
oafuncs-0.0.
|
22
|
-
oafuncs-0.0.
|
23
|
-
oafuncs-0.0.
|
24
|
-
oafuncs-0.0.
|
19
|
+
oafuncs/oa_tool/email.py,sha256=4lJxV_KUzhxgLYfVwYTqp0qxRugD7fvsZkXDe5WkUKo,3052
|
20
|
+
oafuncs-0.0.66.dist-info/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
|
21
|
+
oafuncs-0.0.66.dist-info/METADATA,sha256=n3T2-LjyuhY966ZAVTKOFuCHuKoVFu9RoPyk6YO9E6g,22378
|
22
|
+
oafuncs-0.0.66.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
|
23
|
+
oafuncs-0.0.66.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
|
24
|
+
oafuncs-0.0.66.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|