shancx 1.8.92__py3-none-any.whl → 1.9.33.218__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.
Files changed (166) hide show
  1. shancx/3D/__init__.py +25 -0
  2. shancx/Algo/Class.py +11 -0
  3. shancx/Algo/CudaPrefetcher1.py +112 -0
  4. shancx/Algo/Fake_image.py +24 -0
  5. shancx/Algo/Hsml.py +391 -0
  6. shancx/Algo/L2Loss.py +10 -0
  7. shancx/Algo/MetricTracker.py +132 -0
  8. shancx/Algo/Normalize.py +66 -0
  9. shancx/Algo/OptimizerWScheduler.py +38 -0
  10. shancx/Algo/Rmageresize.py +79 -0
  11. shancx/Algo/Savemodel.py +33 -0
  12. shancx/Algo/SmoothL1_losses.py +27 -0
  13. shancx/Algo/Tqdm.py +62 -0
  14. shancx/Algo/__init__.py +121 -0
  15. shancx/Algo/checknan.py +28 -0
  16. shancx/Algo/iouJU.py +83 -0
  17. shancx/Algo/mask.py +25 -0
  18. shancx/Algo/psnr.py +9 -0
  19. shancx/Algo/ssim.py +70 -0
  20. shancx/Algo/structural_similarity.py +308 -0
  21. shancx/Algo/tool.py +704 -0
  22. shancx/Calmetrics/__init__.py +97 -0
  23. shancx/Calmetrics/calmetrics.py +14 -0
  24. shancx/Calmetrics/calmetricsmatrixLib.py +147 -0
  25. shancx/Calmetrics/rmseR2score.py +35 -0
  26. shancx/Clip/__init__.py +50 -0
  27. shancx/Cmd.py +126 -0
  28. shancx/Config_.py +26 -0
  29. shancx/Df/DataFrame.py +11 -2
  30. shancx/Df/__init__.py +17 -0
  31. shancx/Df/tool.py +0 -0
  32. shancx/Diffm/Psamples.py +18 -0
  33. shancx/Diffm/__init__.py +0 -0
  34. shancx/Diffm/test.py +207 -0
  35. shancx/Doc/__init__.py +214 -0
  36. shancx/E/__init__.py +178 -152
  37. shancx/Fillmiss/__init__.py +0 -0
  38. shancx/Fillmiss/imgidwJU.py +46 -0
  39. shancx/Fillmiss/imgidwLatLonJU.py +82 -0
  40. shancx/Gpu/__init__.py +55 -0
  41. shancx/H9/__init__.py +126 -0
  42. shancx/H9/ahi_read_hsd.py +877 -0
  43. shancx/H9/ahisearchtable.py +298 -0
  44. shancx/H9/geometry.py +2439 -0
  45. shancx/Hug/__init__.py +81 -0
  46. shancx/Inst.py +22 -0
  47. shancx/Lib.py +31 -0
  48. shancx/Mos/__init__.py +37 -0
  49. shancx/NN/__init__.py +235 -106
  50. shancx/Path1.py +161 -0
  51. shancx/Plot/GlobMap.py +276 -116
  52. shancx/Plot/__init__.py +491 -1
  53. shancx/Plot/draw_day_CR_PNG.py +4 -21
  54. shancx/Plot/exam.py +116 -0
  55. shancx/Plot/plotGlobal.py +325 -0
  56. shancx/{radar_nmc.py → Plot/radarNmc.py} +4 -34
  57. shancx/{subplots_single_china_map.py → Plot/single_china_map.py} +1 -1
  58. shancx/Point.py +46 -0
  59. shancx/QC.py +223 -0
  60. shancx/RdPzl/__init__.py +32 -0
  61. shancx/Read.py +72 -0
  62. shancx/Resize.py +79 -0
  63. shancx/SN/__init__.py +62 -123
  64. shancx/Time/GetTime.py +9 -3
  65. shancx/Time/__init__.py +66 -1
  66. shancx/Time/timeCycle.py +302 -0
  67. shancx/Time/tool.py +0 -0
  68. shancx/Train/__init__.py +74 -0
  69. shancx/Train/makelist.py +187 -0
  70. shancx/Train/multiGpu.py +27 -0
  71. shancx/Train/prepare.py +161 -0
  72. shancx/Train/renet50.py +157 -0
  73. shancx/ZR.py +12 -0
  74. shancx/__init__.py +333 -262
  75. shancx/args.py +27 -0
  76. shancx/bak.py +768 -0
  77. shancx/df2database.py +62 -2
  78. shancx/geosProj.py +80 -0
  79. shancx/info.py +38 -0
  80. shancx/netdfJU.py +231 -0
  81. shancx/sendM.py +59 -0
  82. shancx/tensBoard/__init__.py +28 -0
  83. shancx/wait.py +246 -0
  84. {shancx-1.8.92.dist-info → shancx-1.9.33.218.dist-info}/METADATA +15 -5
  85. shancx-1.9.33.218.dist-info/RECORD +91 -0
  86. {shancx-1.8.92.dist-info → shancx-1.9.33.218.dist-info}/WHEEL +1 -1
  87. my_timer_decorator/__init__.py +0 -10
  88. shancx/Dsalgor/__init__.py +0 -19
  89. shancx/E/DFGRRIB.py +0 -30
  90. shancx/EN/DFGRRIB.py +0 -30
  91. shancx/EN/__init__.py +0 -148
  92. shancx/FileRead.py +0 -44
  93. shancx/Gray2RGB.py +0 -86
  94. shancx/M/__init__.py +0 -137
  95. shancx/MN/__init__.py +0 -133
  96. shancx/N/__init__.py +0 -131
  97. shancx/Plot/draw_day_CR_PNGUS.py +0 -206
  98. shancx/Plot/draw_day_CR_SVG.py +0 -275
  99. shancx/Plot/draw_day_pre_PNGUS.py +0 -205
  100. shancx/Plot/glob_nation_map.py +0 -116
  101. shancx/Plot/radar_nmc.py +0 -61
  102. shancx/Plot/radar_nmc_china_map_compare1.py +0 -50
  103. shancx/Plot/radar_nmc_china_map_f.py +0 -121
  104. shancx/Plot/radar_nmc_us_map_f.py +0 -128
  105. shancx/Plot/subplots_compare_devlop.py +0 -36
  106. shancx/Plot/subplots_single_china_map.py +0 -45
  107. shancx/S/__init__.py +0 -138
  108. shancx/W/__init__.py +0 -132
  109. shancx/WN/__init__.py +0 -132
  110. shancx/code.py +0 -331
  111. shancx/draw_day_CR_PNG.py +0 -200
  112. shancx/draw_day_CR_PNGUS.py +0 -206
  113. shancx/draw_day_CR_SVG.py +0 -275
  114. shancx/draw_day_pre_PNGUS.py +0 -205
  115. shancx/makenetCDFN.py +0 -42
  116. shancx/mkIMGSCX.py +0 -92
  117. shancx/netCDF.py +0 -130
  118. shancx/radar_nmc_china_map_compare1.py +0 -50
  119. shancx/radar_nmc_china_map_f.py +0 -125
  120. shancx/radar_nmc_us_map_f.py +0 -67
  121. shancx/subplots_compare_devlop.py +0 -36
  122. shancx/tool.py +0 -18
  123. shancx/user/H8mess.py +0 -317
  124. shancx/user/__init__.py +0 -137
  125. shancx/user/cinradHJN.py +0 -496
  126. shancx/user/examMeso.py +0 -293
  127. shancx/user/hjnDAAS.py +0 -26
  128. shancx/user/hjnFTP.py +0 -81
  129. shancx/user/hjnGIS.py +0 -320
  130. shancx/user/hjnGPU.py +0 -21
  131. shancx/user/hjnIDW.py +0 -68
  132. shancx/user/hjnKDTree.py +0 -75
  133. shancx/user/hjnLAPSTransform.py +0 -47
  134. shancx/user/hjnMiscellaneous.py +0 -182
  135. shancx/user/hjnProj.py +0 -162
  136. shancx/user/inotify.py +0 -41
  137. shancx/user/matplotlibMess.py +0 -87
  138. shancx/user/mkNCHJN.py +0 -623
  139. shancx/user/newTypeRadar.py +0 -492
  140. shancx/user/test.py +0 -6
  141. shancx/user/tlogP.py +0 -129
  142. shancx/util_log.py +0 -33
  143. shancx/wtx/H8mess.py +0 -315
  144. shancx/wtx/__init__.py +0 -151
  145. shancx/wtx/cinradHJN.py +0 -496
  146. shancx/wtx/colormap.py +0 -64
  147. shancx/wtx/examMeso.py +0 -298
  148. shancx/wtx/hjnDAAS.py +0 -26
  149. shancx/wtx/hjnFTP.py +0 -81
  150. shancx/wtx/hjnGIS.py +0 -330
  151. shancx/wtx/hjnGPU.py +0 -21
  152. shancx/wtx/hjnIDW.py +0 -68
  153. shancx/wtx/hjnKDTree.py +0 -75
  154. shancx/wtx/hjnLAPSTransform.py +0 -47
  155. shancx/wtx/hjnLog.py +0 -78
  156. shancx/wtx/hjnMiscellaneous.py +0 -201
  157. shancx/wtx/hjnProj.py +0 -161
  158. shancx/wtx/inotify.py +0 -41
  159. shancx/wtx/matplotlibMess.py +0 -87
  160. shancx/wtx/mkNCHJN.py +0 -613
  161. shancx/wtx/newTypeRadar.py +0 -492
  162. shancx/wtx/test.py +0 -6
  163. shancx/wtx/tlogP.py +0 -129
  164. shancx-1.8.92.dist-info/RECORD +0 -99
  165. /shancx/{Dsalgor → Algo}/dsalgor.py +0 -0
  166. {shancx-1.8.92.dist-info → shancx-1.9.33.218.dist-info}/top_level.txt +0 -0
@@ -1,275 +0,0 @@
1
- import matplotlib.pyplot as plt
2
- import matplotlib
3
- matplotlib.use("svg")
4
- import datetime
5
- from hjnwtx.colormap import cmp_hjnwtx
6
- import time
7
- import os
8
- import time
9
- import shutil
10
-
11
- from dateutil.relativedelta import relativedelta
12
- import glob
13
- from config import logger
14
- import argparse
15
- import pandas as pd
16
- import re
17
- import netCDF4 as nc
18
- from multiprocessing import Pool
19
- from itertools import product
20
- import numpy as np
21
- import copy
22
- import traceback
23
-
24
-
25
- from multiprocessing import Process, Queue
26
-
27
- import io
28
- import cartopy.crs as ccrs
29
- import cartopy.feature as cfeature
30
- import cartopy.io.shapereader as shpreader
31
- from shancx import crDir
32
-
33
- import matplotlib.pyplot as plt
34
- import matplotlib.cbook as cbook
35
- import matplotlib.image as image
36
- import matplotlib.cm as cm
37
- import matplotlib.colors as colors
38
- import io
39
- import datetime
40
- import numpy as np
41
- from multiprocessing import Pool
42
- import cartopy.crs as ccrs
43
- import cartopy.feature as cfeature
44
- import cartopy.io.shapereader as shpreader
45
- import matplotlib.pyplot as plt
46
- import matplotlib.cm as cm
47
- import datetime
48
- import numpy as np
49
- from multiprocessing import Pool
50
- import io
51
- import os
52
- from shancx import crDir
53
-
54
- # Assuming these are defined somewhere else in your code
55
- # cmp_hjnwtx = {"radar_nmc": your_cmap_definition}
56
- # shpreader = your_shpreader_definition
57
- # cfeature = your_cfeature_definition
58
- # ccrs = your_ccrs_definition
59
-
60
-
61
- import matplotlib.pyplot as plt
62
- import datetime
63
- import os
64
- import io
65
- from multiprocessing import Pool
66
-
67
- # Assuming these are defined somewhere else in your code
68
- # cmp_hjnwtx = {"radar_nmc": your_cmap_definition}
69
- # shpreader = your_shpreader_definition
70
- # cfeature = your_cfeature_definition
71
- # ccrs = your_ccrs_definition
72
- import matplotlib.pyplot as plt
73
- import datetime
74
- import os
75
- import io
76
- from multiprocessing import Pool
77
-
78
-
79
- import matplotlib.pyplot as plt
80
- import datetime
81
- import os
82
- import io
83
- from multiprocessing import Pool
84
- import cairosvg # Install using pip if not already installed
85
-
86
-
87
- # Assuming these are defined somewhere else in your code
88
- # cmp_hjnwtx = {"radar_nmc": your_cmap_definition}
89
- # shpreader = your_shpreader_definition
90
- # cfeature = your_cfeature_definition
91
- # ccrs = your_ccrs_definition
92
- def add_china_map(ax):
93
- # Add terrain features on the map
94
- ax.add_feature(cfeature.COASTLINE, edgecolor='gray')
95
- ax.add_feature(cfeature.BORDERS, linestyle=':', edgecolor='gray')
96
- ax.add_feature(cfeature.LAKES, alpha=0.8)
97
-
98
- # Add province outlines
99
- provinces = shpreader.natural_earth(resolution='10m', category='cultural', name='admin_1_states_provinces')
100
- provinces_features = shpreader.Reader(provinces).geometries()
101
- ax.add_geometries(provinces_features, ccrs.PlateCarree(), facecolor='none', edgecolor='gray', linestyle=':', linewidth=0.5, alpha=0.8)
102
-
103
- def draw_subplot(args):
104
- index, tp, vmax, vmin, cmap, time_index, name = args
105
-
106
- fig, ax = plt.subplots(figsize=(10, 10), subplot_kw={'projection': ccrs.PlateCarree()})
107
-
108
- ax.set_extent([73, 135, 18, 54], ccrs.PlateCarree()) # Adjust as needed
109
-
110
- add_china_map(ax)
111
-
112
- # Plot the data
113
- img = ax.imshow(tp, vmin=vmin, vmax=vmax, cmap=cmap, extent=[73, 134.99, 12.21, 54.2], transform=ccrs.PlateCarree(), alpha=1)
114
-
115
- # Turn off axis
116
- ax.axis('off')
117
-
118
- # Add text annotations
119
- ax.text(0.95, 0.95, f'{time_index}', transform=ax.transAxes, color='white', fontsize=20, ha='right', va='bottom')
120
- ax.text(0.925, 0.925, f'{str(index)}', transform=ax.transAxes, color='white', fontsize=20, ha='right', va='top')
121
-
122
- fig.tight_layout()
123
-
124
- # Save the figure to a buffer as SVG
125
- buf = io.BytesIO()
126
- plt.savefig(buf, format='svg', bbox_inches='tight')
127
- buf.seek(0)
128
- plt.close(fig)
129
-
130
- return (index, buf)
131
-
132
- def drawpic(tp, Count, timeList, name="temp"):
133
- vmax = 70
134
- vmin = 0
135
- cmap = cmp_hjnwtx["radar_nmc"]
136
-
137
- # Create arguments list for multiprocessing
138
- args_list = [(index, tp[index, :, :], vmax, vmin, cmap, timeList[index], name) for index in range(2 * Count)]
139
-
140
- with Pool(31) as pool:
141
- results = pool.map(draw_subplot, args_list)
142
-
143
- # Convert SVG data to PNG using cairosvg
144
- png_buffers = []
145
- for result in results:
146
- svg_data = result[1].getvalue().decode('utf-8')
147
- png_bytes = cairosvg.svg2png(bytestring=svg_data.encode('utf-8'))
148
- png_buffers.append(io.BytesIO(png_bytes))
149
-
150
- # Create a grid of subplots
151
- combined_fig, axs = plt.subplots(2, Count, figsize=(10 * Count, 20))
152
-
153
- for i in range(2):
154
- for j in range(Count):
155
- index = i * Count + j
156
- ax = axs[i, j]
157
- # Use the PNG data directly for display
158
- png_buf = png_buffers[index]
159
- png_buf.seek(0)
160
- png_data = plt.imread(png_buf)
161
- ax.imshow(png_data, cmap=cmap) # Display PNG data
162
- ax.axis('off')
163
-
164
- # Save the combined figure as SVG
165
- now_str = datetime.datetime.now().strftime("%Y%m%d%H%M")
166
- outdir = f"./{timeList[0].strftime('%Y%m%d%H%M')}_CR"
167
- crDir(outdir)
168
- outpath = os.path.join(outdir, f"{name}_{now_str}.svg")
169
-
170
- plt.tight_layout()
171
- plt.savefig(outpath, format='svg', bbox_inches='tight')
172
- plt.close(combined_fig)
173
-
174
-
175
-
176
- BASE_TARGET_PATH = "/mnt/wtx_weather_forecast/WTX_DATA/RADA/MQPF"
177
-
178
-
179
- def get_mqpf_paths(UCTstr):
180
- year = UCTstr[:4]
181
- date = UCTstr[:8]
182
- mqpfPath_pattern = os.path.join(BASE_TARGET_PATH,year, date,f"MSP2_WTX_AIW_REF_L88_CHN_{UCTstr}_00000-00300-00006.nc")
183
- # mqpfPath_pattern = os.path.join(BASE_TARGET_PATH,year, date,f"MSP2_WTX_AIW_MQPF_L88_CHN_{UCTstr}_00000-00300-00006.nc")
184
-
185
- return mqpfPath_pattern
186
-
187
- def map_data(conf):
188
- CST = conf[0]
189
- UCT = CST + relativedelta(hours=-8)
190
- UCTstr = UCT.strftime("%Y%m%d%H%M")
191
- mqpfPath_pattern = get_mqpf_paths(UCTstr)
192
- mqpfPath_list = glob.glob(mqpfPath_pattern)
193
- if len(mqpfPath_list) == 0:
194
- data_loss = re.findall(r"(2024\d{8}?)",mqpfPath_pattern)
195
- print("data_loss",data_loss)
196
- print("data_loss_path",mqpfPath_pattern)
197
- tj_list.append(data_loss[0])
198
- return np.full((1, 4200, 6200), np.nan)
199
- else:
200
- try:
201
- with nc.Dataset(mqpfPath_list[0]) as dataNC:
202
- mqpf = dataNC.variables["CR"][:]
203
- mqpf = mqpf[:1]
204
- if mqpf.shape != (1, 4200, 6200):
205
- logger.info(mqpf.shape )
206
- logger.info(mqpfPath_list[0])
207
- print("mqpf shape error",mqpf.shape)
208
- mqpf = mqpf[:,:-1, :-1]
209
- if mqpf.shape != (1, 4200, 6200):
210
- return np.full((1, 4200, 6200), np.nan)
211
- else:
212
- return mqpf
213
- print("mqpf",UCTstr,mqpf.shape)
214
- tj_list1.append(mqpfPath_pattern)
215
- return mqpf
216
- except Exception as e:
217
- print(traceback.format_exc())
218
- return np.full((1, 4200, 6200), np.nan)
219
-
220
- def options():
221
- parser = argparse.ArgumentParser(description='draw CR')
222
- # parser.add_argument('--times', type=str, default='202406290000,202406300000')
223
- parser.add_argument('--times', type=str, default='202407220000,202407230000')
224
- parser.add_argument('--pac', type=str, default='100000')
225
- # parser.add_argument('--combine', action='store_true', default=False)
226
- parser.add_argument('--combine',action='store_true',default=False)
227
- parser.add_argument('--isDebug',action='store_true',default=False)
228
- parser.add_argument('--isDraw',action='store_true',default=False)
229
- parser.add_argument('--freq', type=str, default="1h")
230
- parser.add_argument('--tag',type=str, default=datetime.datetime.now().strftime("%Y%m%d%H%M"))
231
- config= parser.parse_args()
232
- print(config)
233
- config.times = config.times.split(",")
234
- config.pac = config.pac.split(",")
235
- if len(config.times) == 1:
236
- config.times = [config.times[0], config.times[0]]
237
- config.times = [datetime.datetime.strptime(config.times[0], "%Y%m%d%H%M"),
238
- datetime.datetime.strptime(config.times[1], "%Y%m%d%H%M")]
239
- return config
240
- if __name__ == '__main__':
241
- cfg = options()
242
- sCST = cfg.times[0]
243
- eCST = cfg.times[-1]
244
- sCSTstr = sCST.strftime("%Y%m%d")
245
- tj_list = []
246
- tj_list1= []
247
- start = datetime.datetime.now()
248
- timeList = pd.date_range(sCST,eCST,freq="360s",inclusive="left")
249
- # for CST in timeList:
250
- productList = product(timeList)
251
- with Pool(31) as p:
252
- Data = p.map(map_data,productList)
253
- end = datetime.datetime.now()
254
- print(start-end)
255
- Data_con = np.concatenate(Data,axis=0)
256
- loss_len = 240 - Data_con.shape[0]
257
- sCSTstr = sCST.strftime("%Y%m%d")
258
- eCSTstr = eCST.strftime("%Y%m%d")
259
- # Data_con1 = Data_con.filled()
260
- # np.save(f"data_{sCSTstr}_{eCSTstr}.npy",Data_con1)
261
- Data_con_120 = copy.copy(Data_con)
262
- drawpic(Data_con_120[:int(len(Data_con_120)/2)], int(len(Data_con_120)/4),timeList[:int(len(Data_con_120)/2)],name=f"temp120_{sCSTstr}_loss_{loss_len}_")
263
- print("done 120")
264
- end1 = datetime.datetime.now()
265
- print(end1-end)
266
- Data_con_240 = copy.copy(Data_con)
267
- print(Data_con_240[120:].shape)
268
- drawpic(Data_con_120[int(len(Data_con_120)/2):], int(len(Data_con_120)/4),timeList[int(len(Data_con_120)/2):],name=f"temp120_240_{sCSTstr}_{loss_len}_")
269
- print(datetime.datetime.now()-end1)
270
- print("done 120-240")
271
- logger.info("success")
272
-
273
-
274
- # "/mnt/wtx_weather_forecast/WTX_DATA/RADA/MQPF/2024/20240704/MSP2_WTX_AIW_REF_L88_CHN_202407040324_00000-00300-00006.nc"
275
-
@@ -1,205 +0,0 @@
1
- import matplotlib.pyplot as plt
2
- import datetime
3
- from hjnwtx.colormap import cmp_hjnwtx
4
- import time
5
- import os
6
- import time
7
- import shutil
8
-
9
- from dateutil.relativedelta import relativedelta
10
- import glob
11
- from config import logger
12
- import argparse
13
- import pandas as pd
14
- import re
15
- import netCDF4 as nc
16
- from multiprocessing import Pool
17
- from itertools import product
18
- import numpy as np
19
- import copy
20
- import traceback
21
-
22
-
23
- from multiprocessing import Process, Queue
24
-
25
- import io
26
- import cartopy.crs as ccrs
27
- import cartopy.feature as cfeature
28
- import cartopy.io.shapereader as shpreader
29
- from hjnwtx.mkNCHJN import mkDir
30
-
31
- shape_ = (1, 5701, 8501)
32
- def add_china_map(ax):
33
- # 在地图上添加地形特征
34
- ax.add_feature(cfeature.COASTLINE, edgecolor='gray')
35
- ax.add_feature(cfeature.BORDERS, linestyle=':', edgecolor='gray')
36
- ax.add_feature(cfeature.LAKES, alpha=0.8)
37
- # 添加省份轮廓
38
- provinces = shpreader.natural_earth(resolution='10m', category='cultural', name='admin_1_states_provinces')
39
- provinces_features = shpreader.Reader(provinces).geometries()
40
- ax.add_geometries(provinces_features, ccrs.PlateCarree(), facecolor='none', edgecolor='gray', linestyle=':', linewidth=0.5, alpha=0.8)
41
-
42
- def draw_subplot(args):
43
- env = [-132.0, -47.0, 0, 57.0]
44
- index, tp, vmax, vmin, cmap,time_index, name = args
45
- # print(time_index)
46
- # logger.info(f"Processing index: {index}")
47
- # logger.info(time_index)
48
- fig, ax = plt.subplots(figsize=(10, 10))
49
-
50
- # 创建绘图和设置坐标系
51
- # fig = plt.figure(figsize=(10, 8))
52
- ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
53
-
54
- # 设置图像显示的范围
55
- ax.set_extent(env, ccrs.PlateCarree()) # 根据需要调整
56
-
57
- # 添加中国地图的边界和特征,包括省份轮廓
58
- add_china_map(ax)
59
- tp = np.where(tp >= 0.1, tp, np.nan)
60
- ax.imshow(tp, vmin=0, vmax=10, cmap=cmp_hjnwtx["pre_tqw"], transform=ccrs.PlateCarree(), extent=env, alpha=1)
61
-
62
- # ax.imshow(tp, vmax=vmax, vmin=vmin, cmap=cmap)
63
- ax.axis('off')
64
- # ax.text(0.5, 0.5, str(index), transform=ax.transAxes, color='white', fontsize=20, ha='center', va='center')
65
- ax.text(0.95, 0.95, f'{time_index}', transform=ax.transAxes, color='white', fontsize=20, ha='right', va='bottom')
66
- ax.text(0.925, 0.925, f'{str(index)}', transform=ax.transAxes, color='white', fontsize=20, ha='right', va='top')
67
- fig.tight_layout()
68
-
69
- buf = io.BytesIO()
70
- plt.savefig(buf, format='png')
71
- buf.seek(0)
72
- plt.close(fig)
73
- return (index, buf) #返回两个数为元组
74
-
75
- # 修改读取部分
76
- def drawpic(tp, Count,timeList, name="temp"):
77
- vmax = 70
78
- vmin = 0
79
- cmap = cmp_hjnwtx["radar_nmc"]
80
- args_list = [ (index, tp[index, :, :], vmax, vmin, cmap,timeList[index], name) for index in range(2 * Count)]
81
-
82
- with Pool(31) as pool:
83
- results = pool.map(draw_subplot, args_list)
84
-
85
- buffers = [result[1] for result in results]
86
- combined_fig, axs = plt.subplots(2, Count, figsize=(10 * Count, 20))
87
- for i in range(2):
88
- for j in range(Count):
89
- index = i * Count + j
90
- ax = axs[i, j]
91
- ax.imshow(plt.imread(buffers[index]), cmap=cmap)
92
- ax.axis('off')
93
-
94
- now_str = datetime.datetime.now().strftime("%Y%m%d%H%M")
95
- plt.tight_layout()
96
- outpath = f"./{timeList[0].strftime('%Y%m%d%H%M')}_MQPF/{name}_{now_str}.png"
97
- mkDir(outpath)
98
- plt.savefig(outpath)
99
- plt.close(combined_fig)
100
-
101
-
102
-
103
- BASE_TARGET_PATH = "/mnt/wtx_weather_forecast/WTX_DATA/RADA/MQPF_GLB" #/mnt/wtx_weather_forecast/WTX_DATA/RADA/MQPF_PMSC
104
- # BASE_TARGET_PATH = "/mnt/wtx_weather_forecast/WTX_DATA/RADA/MQPF_PMSC" #/mnt/wtx_weather_forecast/WTX_DATA/RADA/MQPF_PMSC
105
-
106
- def get_mqpf_paths(UCTstr):
107
- year = UCTstr[:4]
108
- date = UCTstr[:8]
109
- mqpfPath_pattern = os.path.join(BASE_TARGET_PATH,year, date,f"MSP2_WTX_AIW_QPF_L88_NA_{UCTstr}_00000-00300-00006.nc") #MSP2_WTX_AIW_QPF_L88_NA_202410222254_00000-00300-00006.nc
110
- # mqpfPath_pattern = os.path.join(BASE_TARGET_PATH,year, date,f"MSP2_WTX_AIW_MQPF_L88_CHN_{UCTstr}_00000-00300-00006.nc")
111
-
112
- return mqpfPath_pattern
113
-
114
- def map_data(conf):
115
- CST = conf[0]
116
- UCT = CST + relativedelta(hours=-8)
117
- UCTstr = UCT.strftime("%Y%m%d%H%M")
118
- mqpfPath_pattern = get_mqpf_paths(UCTstr)
119
- mqpfPath_list = glob.glob(mqpfPath_pattern)
120
- if len(mqpfPath_list) == 0:
121
- data_loss = re.findall(r"(2024\d{8}?)",mqpfPath_pattern)
122
- print("data_loss",data_loss)
123
- print("data_loss_path",mqpfPath_pattern)
124
- tj_list.append(data_loss[0])
125
- return np.full(shape_, np.nan)
126
- else:
127
- try:
128
- with nc.Dataset(mqpfPath_list[0]) as dataNC:
129
- mqpf = dataNC.variables["MQPF"][:]
130
- mqpf = mqpf[:1]
131
- if mqpf.shape != shape_:
132
- logger.info(mqpf.shape )
133
- logger.info(mqpfPath_list[0])
134
- print("mqpf shape error",mqpf.shape)
135
- mqpf = mqpf[:,:-1, :-1]
136
- if mqpf.shape != shape_:
137
- return np.full(shape_, np.nan)
138
- else:
139
- return mqpf
140
- print("mqpf",UCTstr,mqpf.shape)
141
- tj_list1.append(mqpfPath_pattern)
142
- return mqpf
143
- except Exception as e:
144
- print(traceback.format_exc())
145
- return np.full(shape_, np.nan)
146
-
147
- def options():
148
- parser = argparse.ArgumentParser(description='plot radar')
149
- # parser.add_argument('--times', type=str, default='202406290000,202406300000')
150
- parser.add_argument('--times', type=str, default='202407310000,202408010000')
151
- parser.add_argument('--pac', type=str, default='100000')
152
- # parser.add_argument('--combine', action='store_true', default=False)
153
- parser.add_argument('--combine',action='store_true',default=False)
154
- parser.add_argument('--isDebug',action='store_true',default=False)
155
- parser.add_argument('--isDraw',action='store_true',default=False)
156
- parser.add_argument('--freq', type=str, default="1h")
157
- parser.add_argument('--tag',type=str, default=datetime.datetime.now().strftime("%Y%m%d%H%M"))
158
- config= parser.parse_args()
159
- print(config)
160
- config.times = config.times.split(",")
161
- config.pac = config.pac.split(",")
162
- if len(config.times) == 1:
163
- config.times = [config.times[0], config.times[0]]
164
- config.times = [datetime.datetime.strptime(config.times[0], "%Y%m%d%H%M"),
165
- datetime.datetime.strptime(config.times[1], "%Y%m%d%H%M")]
166
- return config
167
- if __name__ == '__main__':
168
- cfg = options()
169
- sCST = cfg.times[0]
170
- eCST = cfg.times[-1]
171
- sCSTstr = sCST.strftime("%Y%m%d")
172
- tj_list = []
173
- tj_list1= []
174
- start = datetime.datetime.now()
175
- logger.info(f"{sCST}")
176
- logger.info(f"{eCST}")
177
- logger.info(f"PNG")
178
- timeList = pd.date_range(sCST,eCST,freq="360s",inclusive="left")
179
- # for CST in timeList:
180
- productList = product(timeList)
181
- with Pool(31) as p:
182
- Data = p.map(map_data,productList)
183
- end = datetime.datetime.now()
184
- print(start-end)
185
- Data_con = np.concatenate(Data,axis=0)
186
- loss_len = 240 - Data_con.shape[0]
187
- sCSTstr = sCST.strftime("%Y%m%d")
188
- eCSTstr = eCST.strftime("%Y%m%d")
189
- # Data_con1 = Data_con.filled()
190
- # np.save(f"data_{sCSTstr}_{eCSTstr}.npy",Data_con1)
191
- Data_con_120 = copy.copy(Data_con)
192
- drawpic(Data_con_120[:int(len(Data_con_120)/2)], int(len(Data_con_120)/4),timeList[:int(len(Data_con_120)/2)],name=f"temp120_{sCSTstr}_loss_{loss_len}_")
193
- print("done 120")
194
- end1 = datetime.datetime.now()
195
- print(end1-end)
196
- Data_con_240 = copy.copy(Data_con)
197
- print(Data_con_240[120:].shape)
198
- drawpic(Data_con_120[int(len(Data_con_120)/2):], int(len(Data_con_120)/4),timeList[int(len(Data_con_120)/2):],name=f"temp120_240_{sCSTstr}_{loss_len}_")
199
- print(datetime.datetime.now()-end1)
200
- print("done 120-240")
201
- logger.info("success")
202
-
203
-
204
- # "/mnt/wtx_weather_forecast/WTX_DATA/RADA/MQPF/2024/20240704/MSP2_WTX_AIW_REF_L88_CHN_202407040324_00000-00300-00006.nc"
205
-
@@ -1,116 +0,0 @@
1
- import matplotlib.pyplot as plt
2
- import numpy as np
3
- import datetime
4
- from hjnwtx.colormap import cmp_hjnwtx # Assuming this is your custom colormap library
5
- import cartopy.crs as ccrs
6
- import cartopy.feature as cfeature
7
- import cartopy.io.shapereader as shpreader
8
- import os
9
- from shancx import crDir
10
-
11
- def Glob(array_dt,cd="CHN",ty="CR"):
12
- if cd == "g":
13
- env = [-179.617020, 179.632979,-85.098871,85.051128]
14
- elif cd == "US":
15
- env = [-132.0, -47.0, 0, 57.0]
16
- elif cd == "CHN":
17
- env = [73,134.99,12.21,54.2]
18
- else:
19
- env = cd
20
- now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
21
- outpath = f"./radar_nmc/{str(cd)}_{now_str}.png"
22
- crDir(outpath)
23
- # Create figure and set the coordinate system
24
- fig = plt.figure(figsize=(10, 8))
25
- ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
26
- # Set the extent for the United States
27
- ax.set_extent(env, ccrs.PlateCarree()) # Adjust as needed
28
- # Add the US map boundaries and features
29
- add_glob_map(ax)
30
- # Add data layers
31
- if len(array_dt.shape) == 3:
32
- for i, img_ch_nel in enumerate(array_dt):
33
- ax.imshow(img_ch_nel, vmin=50, vmax=500, cmap=cmp_hjnwtx["radar_nmc"], transform=ccrs.PlateCarree(), extent=env)
34
- plt.colorbar(ax.images[0], ax=ax, orientation='vertical')
35
- plt.savefig(f"{outpath}_layer_{i}.png")
36
- plt.clf() # Clear the figure to draw the next channel image
37
- elif len(array_dt.shape) == 2 and ty =="pre":
38
- ax.imshow(array_dt, vmin=0, vmax=10, cmap=cmp_hjnwtx["pre_tqw"], transform=ccrs.PlateCarree(), extent=env)
39
- plt.colorbar(ax.images[0], ax=ax, orientation='vertical')
40
- plt.savefig(outpath)
41
- else :
42
- ax.imshow(array_dt, vmin=0, vmax=72, cmap=cmp_hjnwtx["radar_nmc"], transform=ccrs.PlateCarree(), extent=env)
43
- plt.colorbar(ax.images[0], ax=ax, orientation='vertical')
44
- plt.savefig(outpath)
45
- plt.close(fig)
46
-
47
- def add_glob_map(ax):
48
- ax.add_feature(cfeature.COASTLINE, edgecolor='gray')
49
- ax.add_feature(cfeature.BORDERS, linestyle=':', edgecolor='gray')
50
- ax.add_feature(cfeature.LAKES, alpha=0.8)
51
- # Adding state boundaries
52
- if os.path.exists('/home/scx/ne_10m_admin_1_states_provinces.shp'):
53
- states = '/home/scx/ne_10m_admin_1_states_provinces.shp'
54
- else:
55
- states = shpreader.natural_earth(resolution='10m', category='cultural', name='admin_1_states_provinces') # Automatically download
56
- states_features = shpreader.Reader(states).geometries()
57
- ax.add_geometries(states_features, ccrs.PlateCarree(), facecolor='none', edgecolor='gray', linestyle=':', linewidth=0.5, alpha=0.8)
58
-
59
- def GlobLonLat(array_dt,Lon,Lat,cd="CHN",ty="CR"): ### x_coords2 维度
60
- if cd == "g":
61
- env = [-179.617020, 179.632979,-85.098871,85.051128]
62
- elif cd == "US":
63
- env = [-132.0, -47.0, 0, 57.0]
64
- elif cd == "CHN":
65
- env = [73,134.99,12.21,54.2] #[73, 134.99, 12.21, 54.2]
66
- else:
67
- env = cd
68
- now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
69
- outpath = f"./radar_nmc/{str(cd)}_{now_str}.png"
70
- crDir(outpath)
71
-
72
- # Create figure and set the coordinate system
73
- fig = plt.figure(figsize=(10, 8))
74
- ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
75
-
76
- # Set the extent for the United States
77
- ax.set_extent(env, ccrs.PlateCarree()) # Adjust as needed
78
-
79
- # Add the US map boundaries and features
80
- add_glob_map(ax)
81
-
82
- # Add data layers
83
- if len(array_dt.shape) == 3:
84
- for i, img_ch_nel in enumerate(array_dt):
85
- ax.imshow(img_ch_nel, vmin=50, vmax=500, cmap=cmp_hjnwtx["radar_nmc"], transform=ccrs.PlateCarree(), extent=env)
86
- plt.colorbar(ax.images[0], ax=ax, orientation='vertical')
87
- plt.savefig(f"{outpath}_layer_{i}.png")
88
- plt.close()
89
- elif len(array_dt.shape) == 2 and ty =="pre":
90
- ax.imshow(array_dt, vmin=0, vmax=10, cmap=cmp_hjnwtx["pre_tqw"], transform=ccrs.PlateCarree(), extent=env)
91
- plt.colorbar(ax.images[0], ax=ax, orientation='vertical')
92
- ax.scatter(list(Lon), list(Lat), s=0.5, c='red', marker='o', transform=ccrs.PlateCarree())
93
- plt.savefig(outpath)
94
- else :
95
- ax.imshow(array_dt, vmin=0, vmax=72, cmap=cmp_hjnwtx["radar_nmc"], transform=ccrs.PlateCarree(), extent=env)
96
- ax.scatter(list(Lon), list(Lat), s=0.5, c='red', marker='o', transform=ccrs.PlateCarree())
97
- plt.colorbar(ax.images[0], ax=ax, orientation='vertical')
98
- plt.savefig(outpath)
99
- plt.close(fig)
100
-
101
- def add_us_map(ax):
102
- ax.add_feature(cfeature.COASTLINE, edgecolor='gray')
103
- ax.add_feature(cfeature.BORDERS, linestyle=':', edgecolor='gray')
104
- ax.add_feature(cfeature.LAKES, alpha=0.8)
105
- # Adding state boundaries
106
- if os.path.exists('/home/scx/ne_10m_admin_1_states_provinces.shp'):
107
- states = '/home/scx/ne_10m_admin_1_states_provinces.shp'
108
- else:
109
- states = shpreader.natural_earth(resolution='10m', category='cultural', name='admin_1_states_provinces') # Automatically download
110
- states_features = shpreader.Reader(states).geometries()
111
- ax.add_geometries(states_features, ccrs.PlateCarree(), facecolor='none', edgecolor='gray', linestyle=':', linewidth=0.5, alpha=0.8)
112
-
113
- # Example usage
114
- # Assuming array_dt is your data array, pass it to drawUS
115
- # array_dt = np.random.rand(3, 100, 100) # Example random data; replace with your actual data
116
- # drawUS(array_dt)
shancx/Plot/radar_nmc.py DELETED
@@ -1,61 +0,0 @@
1
-
2
- import matplotlib.pyplot as plt
3
- import datetime
4
- from hjnwtx.colormap import cmp_hjnwtx
5
- import os
6
- import numpy as np
7
-
8
-
9
-
10
- from pathlib import Path
11
- def MDir(path):
12
- path_obj = Path(path)
13
- directory = path_obj.parent if path_obj.suffix else path_obj
14
- directory.mkdir(parents=True, exist_ok=True)
15
-
16
-
17
- def drawimg(array_dt,ty ="CR",temp = "temp"):
18
- now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
19
- if len(array_dt.shape)==3:
20
- for i , img_ch_nel in enumerate(array_dt):
21
- plt.imshow(img_ch_nel,vmin=0,vmax=10,cmap=cmp_hjnwtx["radar_nmc"])
22
- plt.colorbar()
23
- outpath = f"./radar_nmc/{temp}_{now_str}.png"
24
- MDir(outpath)
25
- plt.savefig(outpath)
26
- plt.close()
27
- if len(array_dt.shape)==2 and ty =="pre":
28
- plt.imshow(array_dt,vmin=0,vmax=10,cmap=cmp_hjnwtx["pre_tqw"])
29
- plt.colorbar()
30
- outpath = f"./radar_nmc/{temp}_{now_str}.png"
31
- MDir(outpath)
32
- plt.savefig(outpath)
33
- plt.close()
34
- else:
35
- plt.imshow(array_dt,vmin=0,vmax=72,cmap=cmp_hjnwtx["radar_nmc"])
36
- plt.colorbar()
37
- outpath = f"./radar_nmc/{temp}_{now_str}.png"
38
- MDir(outpath)
39
- plt.savefig(outpath)
40
- plt.close()
41
-
42
-
43
- def drawimg_coor(array_dt, temp="temp"):
44
- now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
45
- y_coords2, x_coords2 = np.where(array_dt > 0)
46
-
47
- def plot_and_save(image, path):
48
- plt.imshow(image, vmin=0, vmax=10, cmap=cmp_hjnwtx["radar_nmc"])
49
- for (x, y) in zip(x_coords2, y_coords2):
50
- plt.plot(x, y, 'ro', markersize=25) # Increase point size
51
- plt.text(x, y, f'{(image[y, x] * 6):.1f}', color='white', fontsize=12, ha='center', va='center') # Label the corresponding value
52
- plt.colorbar()
53
- MDir(path)
54
- plt.savefig(path)
55
- plt.close()
56
- if len(array_dt.shape) == 3:
57
- for i, img_ch_nel in enumerate(array_dt):
58
- plot_and_save(img_ch_nel, f"./radar_nmc/{temp}_{now_str}.png")
59
- elif len(array_dt.shape) == 2:
60
- plt.imshow(array_dt, vmin=0, vmax=100, cmap=cmp_hjnwtx["pre_tqw"])
61
- plot_and_save(array_dt, f"./radar_nmc/{temp}_{now_str}.png")