oafuncs 0.0.92__py2.py3-none-any.whl → 0.0.94__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_data.py +22 -147
- oafuncs/oa_down/hycom_3hourly.py +92 -101
- oafuncs/oa_down/hycom_3hourly_20250129.py +1307 -0
- oafuncs/oa_down/literature.py +7 -7
- oafuncs/oa_file.py +6 -2
- oafuncs/oa_nc.py +46 -28
- {oafuncs-0.0.92.dist-info → oafuncs-0.0.94.dist-info}/METADATA +1 -1
- {oafuncs-0.0.92.dist-info → oafuncs-0.0.94.dist-info}/RECORD +11 -10
- {oafuncs-0.0.92.dist-info → oafuncs-0.0.94.dist-info}/LICENSE.txt +0 -0
- {oafuncs-0.0.92.dist-info → oafuncs-0.0.94.dist-info}/WHEEL +0 -0
- {oafuncs-0.0.92.dist-info → oafuncs-0.0.94.dist-info}/top_level.txt +0 -0
oafuncs/oa_down/literature.py
CHANGED
@@ -24,6 +24,7 @@ from rich import print
|
|
24
24
|
from rich.progress import track
|
25
25
|
from oafuncs.oa_down.user_agent import get_ua
|
26
26
|
from oafuncs.oa_file import remove
|
27
|
+
from oafuncs.oa_data import ensure_list
|
27
28
|
|
28
29
|
__all__ = ["download5doi"]
|
29
30
|
|
@@ -222,7 +223,7 @@ class _Downloader:
|
|
222
223
|
print("Try another URL...")
|
223
224
|
|
224
225
|
|
225
|
-
def
|
226
|
+
def _read_excel(file, col_name=r"DOI"):
|
226
227
|
df = pd.read_excel(file)
|
227
228
|
df_list = df[col_name].tolist()
|
228
229
|
# 去掉nan
|
@@ -230,7 +231,7 @@ def read_excel(file, col_name=r"DOI"):
|
|
230
231
|
return df_list
|
231
232
|
|
232
233
|
|
233
|
-
def
|
234
|
+
def _read_txt(file):
|
234
235
|
with open(file, "r") as f:
|
235
236
|
lines = f.readlines()
|
236
237
|
# 去掉换行符以及空行
|
@@ -268,13 +269,12 @@ def download5doi(store_path=None, doi_list=None, txt_file=None, excel_file=None,
|
|
268
269
|
store_path.mkdir(parents=True, exist_ok=True)
|
269
270
|
store_path = str(store_path)
|
270
271
|
|
271
|
-
|
272
|
-
|
273
|
-
doi_list = [doi_list]
|
272
|
+
if doi_list:
|
273
|
+
doi_list = ensure_list(doi_list)
|
274
274
|
if txt_file:
|
275
|
-
doi_list =
|
275
|
+
doi_list = _read_txt(txt_file)
|
276
276
|
if excel_file:
|
277
|
-
doi_list =
|
277
|
+
doi_list = _read_excel(excel_file, col_name)
|
278
278
|
remove(Path(store_path) / "wrong_record.txt")
|
279
279
|
print(f"Downloading {len(doi_list)} PDF files...")
|
280
280
|
for doi in track(doi_list, description="Downloading..."):
|
oafuncs/oa_file.py
CHANGED
@@ -226,8 +226,12 @@ def make_dir(directory):
|
|
226
226
|
make_dir(r"E:\Data\2024\09\17\var1")
|
227
227
|
"""
|
228
228
|
directory = str(directory)
|
229
|
-
os.
|
230
|
-
|
229
|
+
if os.path.exists(directory):
|
230
|
+
print(f"Directory already exists: {directory}")
|
231
|
+
return
|
232
|
+
else:
|
233
|
+
os.makedirs(directory, exist_ok=True)
|
234
|
+
print(f"Created directory: {directory}")
|
231
235
|
|
232
236
|
|
233
237
|
# ** 清空文件夹
|
oafuncs/oa_nc.py
CHANGED
@@ -199,6 +199,12 @@ def merge(file_list, var_name=None, dim_name=None, target_filename=None):
|
|
199
199
|
merge(file_list, var_name=['u', 'v'], dim_name='time', target_filename='merged.nc')
|
200
200
|
merge(file_list, var_name=None, dim_name='time', target_filename='merged.nc')
|
201
201
|
"""
|
202
|
+
# 看看保存文件是单纯文件名还是包含路径的,如果有路径,需要确保路径存在
|
203
|
+
if target_filename is None:
|
204
|
+
target_filename = "merged.nc"
|
205
|
+
if not os.path.exists(os.path.dirname(str(target_filename))):
|
206
|
+
os.makedirs(os.path.dirname(str(target_filename)))
|
207
|
+
|
202
208
|
if isinstance(file_list, str):
|
203
209
|
file_list = [file_list]
|
204
210
|
|
@@ -372,44 +378,56 @@ def rename(ncfile_path, old_name, new_name):
|
|
372
378
|
print(f"An error occurred: {e}")
|
373
379
|
|
374
380
|
|
375
|
-
def check(ncfile,
|
381
|
+
def check(ncfile: str, delete_switch: bool = False) -> bool:
|
376
382
|
"""
|
377
|
-
|
378
|
-
Check if the NetCDF file is corrupted using xarray.
|
383
|
+
Check if a NetCDF file is corrupted with enhanced error handling.
|
379
384
|
|
380
|
-
|
381
|
-
ncfile (str): The path to the NetCDF file.
|
382
|
-
if_delete (bool): Whether to delete the file if it is corrupted, default is False.
|
383
|
-
|
384
|
-
Returns:
|
385
|
-
bool: True if the file is not corrupted, False otherwise.
|
385
|
+
Handles HDF5 library errors gracefully without terminating program.
|
386
386
|
"""
|
387
|
+
is_valid = False
|
388
|
+
|
387
389
|
if not os.path.exists(ncfile):
|
390
|
+
print(f"File missing: {ncfile}")
|
388
391
|
return False
|
389
392
|
|
390
393
|
try:
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
+
# # 深度验证文件结构
|
395
|
+
# with nc.Dataset(ncfile, "r") as ds:
|
396
|
+
# # 显式检查文件结构完整性
|
397
|
+
# ds.sync() # 强制刷新缓冲区
|
398
|
+
# ds.close() # 显式关闭后重新打开验证
|
399
|
+
|
400
|
+
# 二次验证确保变量可访问
|
401
|
+
with nc.Dataset(ncfile, "r") as ds_verify:
|
402
|
+
if not ds_verify.variables:
|
403
|
+
print(f"Empty variables: {ncfile}")
|
394
404
|
else:
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
405
|
+
# 尝试访问元数据
|
406
|
+
_ = ds_verify.__dict__
|
407
|
+
# 抽样检查第一个变量
|
408
|
+
for var in ds_verify.variables.values():
|
409
|
+
_ = var.shape # 触发实际数据访问
|
410
|
+
break
|
411
|
+
is_valid = True
|
412
|
+
|
413
|
+
except Exception as e: # 捕获所有异常类型
|
414
|
+
print(f"HDF5 validation failed for {ncfile}: {str(e)}")
|
415
|
+
error_type = type(e).__name__
|
416
|
+
if "HDF5" in error_type or "h5" in error_type.lower():
|
417
|
+
print(f"Critical HDF5 structure error detected in {ncfile}")
|
418
|
+
|
419
|
+
# 安全删除流程
|
420
|
+
if not is_valid:
|
421
|
+
if delete_switch:
|
422
|
+
try:
|
423
|
+
os.remove(ncfile)
|
424
|
+
print(f"Removed corrupted: {ncfile}")
|
425
|
+
except Exception as del_error:
|
426
|
+
print(f"Delete failed: {ncfile} - {str(del_error)}")
|
411
427
|
return False
|
412
428
|
|
429
|
+
return True
|
430
|
+
|
413
431
|
|
414
432
|
def convert_longitude(ds, lon_name="longitude", convert=180):
|
415
433
|
"""
|
@@ -1,17 +1,18 @@
|
|
1
1
|
oafuncs/__init__.py,sha256=glcIlhQ9xSK4WtL58dq7Od2S3JPqsuEyhUQ-VWO8hOc,1426
|
2
2
|
oafuncs/oa_cmap.py,sha256=azVg9QR_IlG9lXCCXXVs1LS1kFci8yjxDmb_VA_TdTQ,7408
|
3
|
-
oafuncs/oa_data.py,sha256=
|
3
|
+
oafuncs/oa_data.py,sha256=40cZsixCaMDW2kg8kzh60bvD9PPPFn9ZXlQuPr7QhpQ,6563
|
4
4
|
oafuncs/oa_draw.py,sha256=QypQp4vJIrbAyFddEVxd9K9Q4d85PRYqYQi9xDUmSZw,11150
|
5
|
-
oafuncs/oa_file.py,sha256=
|
5
|
+
oafuncs/oa_file.py,sha256=EUL9osp7scZ3JTCwTUlKNfS1d_9xOsFrIkmFxzZAbdg,14233
|
6
6
|
oafuncs/oa_help.py,sha256=loyzTbjU_0VpSIBvAEUA_tqxG8MVsO0xFE_2hgQ3zMw,4188
|
7
|
-
oafuncs/oa_nc.py,sha256=
|
7
|
+
oafuncs/oa_nc.py,sha256=pdc3vEI-5uFYnyzXHAIHNlyeci4MJkeWgKJwjHJ3olI,18343
|
8
8
|
oafuncs/oa_python.py,sha256=Q-6UGGw_dJff7Ef8i87fsLPoGeHV5jBzfb-7HP4THR0,4018
|
9
9
|
oafuncs/data_store/OAFuncs.png,sha256=Cc0TDi9H5mWBporXYw9K0bUWC0oSsI-Qj3FGAXUtGKM,3332020
|
10
10
|
oafuncs/oa_down/User_Agent-list.txt,sha256=pazxSip8_lphEBOPHG902zmIBUg8sBKXgmqp_g6j_E4,661062
|
11
11
|
oafuncs/oa_down/__init__.py,sha256=kRX5eTUCbAiz3zTaQM1501paOYS_3fizDN4Pa0mtNUA,585
|
12
|
-
oafuncs/oa_down/hycom_3hourly.py,sha256=
|
12
|
+
oafuncs/oa_down/hycom_3hourly.py,sha256=9ge6l8xMB-VBzCd1Fr4pIDZfUY_PbrBkWyvur0V27bs,64941
|
13
|
+
oafuncs/oa_down/hycom_3hourly_20250129.py,sha256=zbUp5NNBMzDXEqSC0-Z9H_EoM6Fg-6tXymK0AXH9qRk,65553
|
13
14
|
oafuncs/oa_down/idm.py,sha256=XfYCNnQWADxOhhJd-T8sNYN0nGiRrAs7zbQcsB5-UmI,1668
|
14
|
-
oafuncs/oa_down/literature.py,sha256=
|
15
|
+
oafuncs/oa_down/literature.py,sha256=2bF9gSKQbzcci9LcKE81j8JEjIJwON7jbwQB3gDDA3E,11331
|
15
16
|
oafuncs/oa_down/test_ua.py,sha256=0IQq3NjqfNr7KkyjS_U-a4mYu-r-E7gzawwo4IfEa6Y,10851
|
16
17
|
oafuncs/oa_down/user_agent.py,sha256=TsPcAxFmMTYAEHRFjurI1bQBJfDhcA70MdHoUPwQmks,785
|
17
18
|
oafuncs/oa_sign/__init__.py,sha256=QKqTFrJDFK40C5uvk48GlRRbGFzO40rgkYwu6dYxatM,563
|
@@ -21,8 +22,8 @@ oafuncs/oa_sign/scientific.py,sha256=a4JxOBgm9vzNZKpJ_GQIQf7cokkraV5nh23HGbmTYKw
|
|
21
22
|
oafuncs/oa_tool/__init__.py,sha256=bNTy9abznDhg3k_Irx0YieXl37r-oDRMtTAxf57Stzs,487
|
22
23
|
oafuncs/oa_tool/email.py,sha256=4lJxV_KUzhxgLYfVwYTqp0qxRugD7fvsZkXDe5WkUKo,3052
|
23
24
|
oafuncs/oa_tool/parallel.py,sha256=kYbiIFDB7EoxasmXGSomaEDVUsg9Rfvdgbw93lBOY7o,3770
|
24
|
-
oafuncs-0.0.
|
25
|
-
oafuncs-0.0.
|
26
|
-
oafuncs-0.0.
|
27
|
-
oafuncs-0.0.
|
28
|
-
oafuncs-0.0.
|
25
|
+
oafuncs-0.0.94.dist-info/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
|
26
|
+
oafuncs-0.0.94.dist-info/METADATA,sha256=rKL0f-sli0TN2wL2WAU_-bA89eGzVu0aTyCK5K38RLU,3545
|
27
|
+
oafuncs-0.0.94.dist-info/WHEEL,sha256=9Hm2OB-j1QcCUq9Jguht7ayGIIZBRTdOXD1qg9cCgPM,109
|
28
|
+
oafuncs-0.0.94.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
|
29
|
+
oafuncs-0.0.94.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|