shancx 1.9.33.227__py3-none-any.whl → 1.9.33.229__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.
shancx/Read.py CHANGED
@@ -55,30 +55,9 @@ result = getGrib(input_Path)
55
55
  import pygrib
56
56
  import numpy as np
57
57
  import pandas as pd
58
- import gzip
59
- import tempfile
60
- def readGrib(filepath, target_param=None):
61
- filepath= filepath
62
- if filepath.endswith('.gz'):
63
- with gzip.open(filepath, 'rb') as f:
64
- with tempfile.NamedTemporaryFile(suffix='.grib2', delete=False) as tmp:
65
- tmp.write(f.read())
66
- filepath = tmp.name
58
+ def readGrib(file_path, target_param=None):
67
59
  try:
68
- with pygrib.open(filepath) as grbs:
69
- if target_param:
70
- try:
71
- grb = grbs.select(shortName=target_param)[0]
72
- except:
73
- try:
74
- grb = grbs.select(parameterName=target_param)[0]
75
- except:
76
- raise ValueError(f"未找到参数: {target_param}")
77
- else:
78
- grb = grbs[1]
79
- data = grb.values
80
- lats, lons = grb.latlons()
81
- #data2
60
+ with pygrib.open(file_path) as grbs:
82
61
  field_info = []
83
62
  for grb in grbs:
84
63
  field_info.append({
@@ -91,6 +70,18 @@ def readGrib(filepath, target_param=None):
91
70
  'units': getattr(grb, 'units', 'N/A'),
92
71
  'shape': grb.values.shape
93
72
  })
73
+ if target_param:
74
+ try:
75
+ grb = grbs.select(shortName=target_param)[0]
76
+ except:
77
+ try:
78
+ grb = grbs.select(parameterName=target_param)[0]
79
+ except:
80
+ raise ValueError(f"未找到参数: {target_param}")
81
+ else:
82
+ grb = grbs[1]
83
+ data = grb.values
84
+ lats, lons = grb.latlons()
94
85
  return {
95
86
  'data': data,
96
87
  'lats': lats,
@@ -99,8 +90,7 @@ def readGrib(filepath, target_param=None):
99
90
  'parameterName': grb.parameterName,
100
91
  'level': grb.level,
101
92
  'validDate': grb.validDate,
102
- 'units': grb.units,
103
- "field_info":field_info
93
+ 'units': grb.units
104
94
  }
105
95
  }
106
96
  except Exception as e:
shancx/npz.py CHANGED
@@ -1,14 +1,28 @@
1
1
  import numpy as np
2
2
  from pathlib import Path
3
+ import os
4
+ import uuid
5
+ import traceback
3
6
  def npzSave(output, data):
4
- output = output.replace('.npy', '.npz')
5
- output_path = Path(output).with_suffix('.npz')
6
- output_path.parent.mkdir(parents=True, exist_ok=True)
7
- np.savez_compressed(output_path, data=data)
8
- print(f"{output_path} done")
7
+ try:
8
+ output_path = Path(output)
9
+ if output_path.suffix in ['.npy', '.nc', '.h5', '.hdf5']:
10
+ output_path = output_path.with_suffix('.npz')
11
+ output_path.parent.mkdir(parents=True, exist_ok=True)
12
+ temp_filename = output_path.with_suffix(f'.tmp.{uuid.uuid4()}.npz')
13
+ np.savez_compressed(temp_filename, data=data)
14
+ os.replace(temp_filename, output_path)
15
+ print(f"{output_path} done")
16
+ except Exception as e:
17
+ print(traceback.format_exc())
18
+ if temp_filename and temp_filename.exists():
19
+ try:
20
+ os.remove(temp_filename)
21
+ print(f"⚠ Temporary files have been cleared: {temp_filename}")
22
+ except:
23
+ pass
9
24
  def npzLoad(output_path):
10
25
  return np.load(Path(output_path).with_suffix('.npz'))['data']
11
-
12
26
  """
13
27
  npzSave(output, data)
14
28
  npzLoad(output_path)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: shancx
3
- Version: 1.9.33.227
3
+ Version: 1.9.33.229
4
4
  Summary: A simple timer decorator
5
5
  Home-page: https://gitee.com/shancx
6
6
  Author: shancx
@@ -5,7 +5,7 @@ shancx/Lib.py,sha256=GUAspllSxk39mvj-F1Q8Ys0EcY_lQfZPRGPE7L3x4SE,977
5
5
  shancx/Path1.py,sha256=vX4A5RgdwVyIVVNZRocl18rOu1Z8YMLfDb0B92-0bE8,5334
6
6
  shancx/Point.py,sha256=gyIomOVbNoz6SOcAhhTS26NHBeJ0TOwB-ljNsBWN1ZE,1909
7
7
  shancx/QC.py,sha256=MFxbPMEwrnk5l0sTFMrx13wPlXJ5WI5TovzaiBoEr0E,9848
8
- shancx/Read.py,sha256=94FNUWiZn71X6ArZhyqhyORNcWJffC7Hz76BAtF9CJc,4577
8
+ shancx/Read.py,sha256=OCSiKbt_yIFFUWSDy6T83KlOYYMHOP628aXpatQCkjw,4197
9
9
  shancx/Resize.py,sha256=uwiOhD-aWPDLvIwOYEX-XXN_suOXv6hPDcaGyr4JLC4,4044
10
10
  shancx/ZR.py,sha256=5APchqVoI1G2MkrN9YJSWCwfLUygcSFIsUXSo9aq1Qg,341
11
11
  shancx/__init__.py,sha256=6sfiHElECqfy5eEEGqaCAw4YiKxgKfJ5IFFh9yvtewk,11442
@@ -17,7 +17,7 @@ shancx/geosProj.py,sha256=JMmtj3kV8rtFkKbmwvTKuDWlC8AkgLG8JvCPzkn8Dfs,2685
17
17
  shancx/getResponse.py,sha256=QmJfa4czGCOiKb8RuCLXKE7AAKVADAptNiwn7v1tfbM,1055
18
18
  shancx/info.py,sha256=0rk_L8Z5uj9RliaZrzT-CArH9ZObmdmcp-1RxAItL08,1122
19
19
  shancx/netdfJU.py,sha256=96KR9NMLr2Kcs_OOMpX7QPujdWUj0GCEUIZ7_4_pBxw,7741
20
- shancx/npz.py,sha256=ZydULlx1ZhgwxrdIrVDm9lGa8KY4q1MJ9dZo_wQriso,462
20
+ shancx/npz.py,sha256=AOE-_f9OItnJLTgH_6kQj5Fn4dOHtLJ6yWRRKk853gM,1045
21
21
  shancx/sendM.py,sha256=dcqGNPPy1n0NxrRgOrHZEpaGtLy15FS_lCYe6_TkvSs,3510
22
22
  shancx/wait.py,sha256=OgT9JmEgMH7d3ir3TEksx0_Kyl_S4bkOKl50jvVpdFA,8575
23
23
  shancx/3D/__init__.py,sha256=pDFvW1OOEW-ueXH50NJIYdWlySHZU6sr5htzHUSeROo,1000
@@ -87,7 +87,7 @@ shancx/Train/multiGpu.py,sha256=D_oZeiSc7VWktpnVDwrFOC1CYZSt9rxOKY5lngE5vFg,820
87
87
  shancx/Train/prepare.py,sha256=vL_8UOA66oZCBIwCICtihsGibivtNgaVJGulJxfNdn8,6793
88
88
  shancx/Train/renet50.py,sha256=wEhYk1X96WE5zuqHqVxWLJa-A5jDNkz4z6edORNufnA,6428
89
89
  shancx/tensBoard/__init__.py,sha256=ga2C5YyJITvvQA1ocpxna_KNFnNRJVwkTjLoIglLZUQ,993
90
- shancx-1.9.33.227.dist-info/METADATA,sha256=2IF7Rl9DDL9BPZypQ0PtDTid3CfYF7wOu9HjWhQO42Y,850
91
- shancx-1.9.33.227.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
92
- shancx-1.9.33.227.dist-info/top_level.txt,sha256=akfCS1vKWz3pNmEN_yN9ZiGp-60IQY5ET38mRx_i_-4,7
93
- shancx-1.9.33.227.dist-info/RECORD,,
90
+ shancx-1.9.33.229.dist-info/METADATA,sha256=bnZn5H1P1YztHINGA-DS0ObKNoJG9NCfKkmmP7iO2JA,850
91
+ shancx-1.9.33.229.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
92
+ shancx-1.9.33.229.dist-info/top_level.txt,sha256=akfCS1vKWz3pNmEN_yN9ZiGp-60IQY5ET38mRx_i_-4,7
93
+ shancx-1.9.33.229.dist-info/RECORD,,