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
shancx/Plot/__init__.py CHANGED
@@ -4,4 +4,494 @@
4
4
  # @Author : shancx
5
5
  # @File : __init__.py
6
6
  # @email : shanhe12@163.com
7
-
7
+ from shancx import crDir
8
+ import matplotlib.pyplot as plt
9
+ import datetime
10
+ def plotGrey(img,name="plotGrey", saveDir="plotGrey",cmap='gray', title='Image'):
11
+ now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
12
+ img = img.squeeze() # 去掉 batch 维度并转换为 numpy 数组
13
+ plt.imshow(img, cmap='gray')
14
+ plt.title(f"Image ")
15
+ plt.axis('off') # 不显示坐标轴
16
+ outpath = f'./{saveDir}/{name}_{now_str}.png' if name=="plotGrey" else f"./{saveDir}/{name}.png"
17
+ crDir(outpath)
18
+ plt.savefig(outpath)
19
+ plt.close()
20
+
21
+ import matplotlib.pyplot as plt
22
+ from shancx import crDir
23
+ import datetime
24
+ def plotMat(matrix,name='plotMat',saveDir="plotMat",title='Matrix Plot', xlabel='X-axis', ylabel='Y-axis', color_label='Value', cmap='viridis',aspect="equal"): #aspect='auto'
25
+ now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
26
+ plt.imshow(matrix, cmap=cmap, origin='upper', aspect=f'{aspect}')
27
+ plt.colorbar(label=color_label)
28
+ plt.title(title)
29
+ plt.xlabel(xlabel)
30
+ plt.ylabel(ylabel)
31
+ plt.tight_layout()
32
+ outpath = f'./{saveDir}/{name}_{now_str}.png' if name=="plotMat" else f"./{saveDir}/{name}.png"
33
+ crDir(outpath)
34
+ plt.savefig(outpath)
35
+ plt.close()
36
+
37
+ import matplotlib.pyplot as plt
38
+ from shancx import crDir
39
+ import datetime
40
+ def plotMatplus(matrix, name='plotMat', saveDir="plotMat", title='Matrix Plot',
41
+ xlabel='Longitude', ylabel='Latitude', color_label='Value',
42
+ cmap='viridis', extent=None):
43
+ """
44
+ extent: [lon_min, lon_max, lat_min, lat_max]
45
+ """
46
+ now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
47
+ plt.imshow(matrix, cmap=cmap, origin='upper', aspect='auto', extent=extent)
48
+ plt.colorbar(label=color_label)
49
+ plt.title(title)
50
+
51
+ # 添加度符号和方向标识
52
+ plt.xlabel(f'{xlabel} (°E)') # 东经
53
+ plt.ylabel(f'{ylabel} (°N)') # 北纬
54
+
55
+ plt.tight_layout()
56
+ outpath = f'./{saveDir}/{name}_{now_str}.png' if name=="plotMat" else f"./{saveDir}/{name}.png"
57
+ crDir(outpath)
58
+ plt.savefig(outpath)
59
+ plt.close()
60
+ """
61
+ latlon = [10.0, 37.0, 105.0, 125.0]
62
+ latmin, latmax, lonmin, lonmax = latlon
63
+ plotMatplus(data,extent=[lon_min, lon_max, lat_min, lat_max])
64
+ """
65
+
66
+ import datetime
67
+ from hjnwtx.colormap import cmp_hjnwtx
68
+ from shancx import crDir
69
+ import matplotlib.pyplot as plt
70
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
71
+ def plotRadar(array_dt,name="plotRadar", saveDir="plotRadar",ty="CR"):
72
+ now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
73
+ # array_dt[array_dt<=0] = np.nan
74
+ if len(array_dt.shape) == 2 and ty == "pre":
75
+ fig, ax = plt.subplots()
76
+ im = ax.imshow(array_dt, vmin=0, vmax=10, cmap=cmp_hjnwtx["pre_tqw"])
77
+ divider = make_axes_locatable(ax)
78
+ cax = divider.append_axes("right", size="5%", pad=0.05)
79
+ plt.colorbar(im, cax=cax)
80
+ fig.tight_layout()
81
+ outpath = f"./{saveDir}/{name}_pre_{now_str}.png" if name=="plotRadar" else f"./{saveDir}/{name}.png"
82
+ crDir(outpath)
83
+ plt.savefig(outpath)
84
+ plt.close()
85
+ else:
86
+ fig, ax = plt.subplots()
87
+ im = ax.imshow(array_dt, vmin=0, vmax=72, cmap=cmp_hjnwtx["radar_nmc"])
88
+ divider = make_axes_locatable(ax)
89
+ cax = divider.append_axes("right", size="5%", pad=0.05)
90
+ plt.colorbar(im, cax=cax)
91
+ fig.tight_layout()
92
+ outpath = f"./{saveDir}/{name}_CR_{now_str}.png" if name=="plotRadar" else f"./{saveDir}/{name}.png"
93
+ crDir(outpath)
94
+ plt.savefig(outpath)
95
+ plt.close()
96
+
97
+
98
+ import matplotlib.pyplot as plt
99
+ import numpy as np
100
+ import datetime
101
+ import os
102
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
103
+ from hjnwtx.colormap import cmp_hjnwtx
104
+ def plotA2b(a, b, name='plotA2b', saveDir="plotA2b", title='plotA2b Plot',class1 = "class",class2 = "class",ty="CR" ):
105
+ now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
106
+ cmap=cmp_hjnwtx["radar_nmc"] if ty == "CR" else 'summer'
107
+ sublen = a.shape[0]
108
+ fig, axes = plt.subplots(2, sublen, figsize=(20, 6))
109
+ for i in range(sublen):
110
+ im_a = axes[0, i].imshow(a[i], cmap=cmap)
111
+ axes[0, i].axis('off')
112
+ axes[0, i].set_title(f'{class1}[{i}]')
113
+ divider_a = make_axes_locatable(axes[0, i])
114
+ cax_a = divider_a.append_axes("right", size="5%", pad=0.1)
115
+ cbar_a = fig.colorbar(im_a, cax=cax_a)
116
+ cbar_a.ax.tick_params(labelsize=8)
117
+ for i in range(sublen):
118
+ im_b = axes[1, i].imshow(b[i], cmap=cmap)
119
+ axes[1, i].axis('off')
120
+ axes[1, i].set_title(f'{class2}[{i}]')
121
+ divider_b = make_axes_locatable(axes[1, i])
122
+ cax_b = divider_b.append_axes("right", size="5%", pad=0.1)
123
+ cbar_b = fig.colorbar(im_b, cax=cax_b)
124
+ cbar_b.ax.tick_params(labelsize=8)
125
+ plt.tight_layout()
126
+ plt.subplots_adjust(top=0.9, bottom=0.1, hspace=0.05, wspace=0.1)
127
+ outpath = f'./{saveDir}/{name}_{now_str}.png'
128
+ os.makedirs(os.path.dirname(outpath), exist_ok=True)
129
+ plt.savefig(outpath, bbox_inches='tight', pad_inches=0.05)
130
+ plt.close()
131
+
132
+ import matplotlib.pyplot as plt
133
+ import os
134
+ def plotScatter(df1,saveDir="plotScatter"):
135
+ now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
136
+ plt.figure(figsize=(10, 8))
137
+ plt.scatter(
138
+ df1["Lon"],
139
+ df1["Lat"],
140
+ s=25,
141
+ alpha=0.6,
142
+ edgecolor="black",
143
+ linewidth=0.5
144
+ )
145
+ plt.title("Scatter Plot of Latitude vs Longitude", fontsize=14)
146
+ plt.xlabel("Longitude", fontsize=12)
147
+ plt.ylabel("Latitude", fontsize=12)
148
+ plt.tight_layout()
149
+ os.makedirs(saveDir, exist_ok=True)
150
+ plt.savefig(f"./{saveDir}/plotScatter_{now_str}.png", dpi=300, bbox_inches="tight")
151
+ plt.close()
152
+
153
+ import matplotlib.pyplot as plt
154
+ import os
155
+ def plotScatter1(true,pre,saveDir="plotScatter"):
156
+ now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
157
+ plt.figure(figsize=(10, 8))
158
+ plt.scatter(
159
+ true,
160
+ pre,
161
+ s=25,
162
+ alpha=0.6,
163
+ edgecolor="black",
164
+ linewidth=0.5
165
+ )
166
+ plt.title("Scatter Plot of Ture Pre", fontsize=14)
167
+ plt.xlabel("Longitude", fontsize=12)
168
+ plt.ylabel("Latitude", fontsize=12)
169
+ plt.tight_layout()
170
+ os.makedirs(saveDir, exist_ok=True)
171
+ plt.savefig(f"./{saveDir}/plotScatter1_{now_str}.png", dpi=300, bbox_inches="tight")
172
+ plt.close()
173
+
174
+ import numpy as np
175
+ import matplotlib.pyplot as plt
176
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
177
+ from shancx import crDir
178
+ import os
179
+ def plotVal( epoch=0,*datasets, title=["input","prediction","truth"], saveDir="plotVal", cmap='summer'):
180
+ num_datasets = len(datasets)
181
+ title = title or [f"data{i}" for i in range(num_datasets)]
182
+ ncols = int(np.ceil(np.sqrt(num_datasets)))
183
+ nrows = int(np.ceil(num_datasets / ncols))
184
+ fig, axes = plt.subplots(nrows, ncols, figsize=(12, 8))
185
+ axes = axes.flatten()
186
+ for i, (data, t) in enumerate(zip(datasets, title)):
187
+ im = axes[i].matshow(data, cmap=cmap) #Paired viridis
188
+ divider = make_axes_locatable(axes[i])
189
+ cax = divider.append_axes("right", size="5%", pad=0.05)
190
+ fig.colorbar(im, cax=cax)
191
+ axes[i].set_title(t)
192
+ for j in range(i + 1, len(axes)):
193
+ fig.delaxes(axes[j])
194
+ fig.tight_layout()
195
+ os.makedirs(saveDir, exist_ok=True)
196
+ filename = f"{saveDir}/epoch_{epoch}.png"
197
+ plt.savefig(filename)
198
+ plt.close(fig)
199
+
200
+ """
201
+ if total >= 3:
202
+ break
203
+ if epoch % 2 == 0:
204
+ plotVal(epoch, inputs[0] --->example shape 为(256,256)
205
+ inputs,
206
+ pre,
207
+ targets
208
+ )
209
+ if epoch % 2 == 0:
210
+ plotVal(epoch,
211
+ data[0][0].detach().cpu().numpy().squeeze(), # 使用 detach()
212
+ output[0][0].detach().cpu().numpy().squeeze(), # 使用 detach()
213
+ label[0][0].detach().cpu().numpy().squeeze(), # 使用 detach()
214
+ title=["input", "prediction", "groundtruth"],
215
+ saveDir="plot_train_dir"
216
+ )
217
+ """
218
+ import numpy as np
219
+ import matplotlib.pyplot as plt
220
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
221
+ from shancx import crDir
222
+ import os
223
+
224
+ def plotValplus(epoch=0, *datasets, title=["input", "prediction", "truth"], saveDir="plotValplus", cmap='summer'):
225
+ num_datasets = len(datasets)
226
+ title = title or [f"data{i}" for i in range(num_datasets)]
227
+ ncols = int(np.ceil(np.sqrt(num_datasets)))
228
+ nrows = int(np.ceil(num_datasets / ncols))
229
+
230
+ fig, axes = plt.subplots(nrows, ncols, figsize=(12, 8))
231
+ axes = axes.flatten()
232
+
233
+ for i, (data, t) in enumerate(zip(datasets, title)):
234
+ # if np.isnan(data).any():
235
+ # print(f"Warning: NaN values found in dataset. Replacing NaN with 0.")
236
+ # data = np.nan_to_num(data, nan=0.0)
237
+ im = axes[i].matshow(data, cmap=cmap, vmin=np.nanmin(data), vmax=np.nanmax(data))
238
+ axes[i].set_xticks([])
239
+ axes[i].set_yticks([])
240
+ divider = make_axes_locatable(axes[i])
241
+ cax = divider.append_axes("right", size="5%", pad=0.05)
242
+ cbar = fig.colorbar(im, cax=cax, ticks=np.linspace(np.nanmin(data), np.nanmax(data), 15))
243
+ cbar.set_ticks(np.linspace(np.nanmin(data), np.nanmax(data), 15))
244
+ axes[i].set_title(t)
245
+ for j in range(i + 1, len(axes)):
246
+ fig.delaxes(axes[j])
247
+ fig.tight_layout()
248
+ os.makedirs(saveDir, exist_ok=True)
249
+ filename = f"{saveDir}/epoch_{epoch}.png"
250
+ plt.savefig(filename)
251
+ plt.close(fig)
252
+ """
253
+ if total >= 3:
254
+ break
255
+ if epoch % 2 == 0:
256
+ plotValplus(epoch,
257
+ data[0][0].detach().cpu().numpy().squeeze(), # 使用 detach()
258
+ output[0][0].detach().cpu().numpy().squeeze(), # 使用 detach()
259
+ label[0][0].detach().cpu().numpy().squeeze(), # 使用 detach()
260
+ title=["input", "prediction", "groundtruth"],
261
+ saveDir="plot_train_dir"
262
+ )
263
+ """
264
+
265
+
266
+ def plotValplus1(epoch=0, *datasets, title=["input", "prediction", "truth"], saveDir="plotValplus", cmap='summer'):
267
+ """
268
+ Main function to plot multiple datasets in a grid layout.
269
+ """
270
+ plt.ioff()
271
+ num_datasets = len(datasets)
272
+ title = title or [f"data{i}" for i in range(num_datasets)]
273
+ ncols = int(np.ceil(np.sqrt(num_datasets)))
274
+ nrows = int(np.ceil(num_datasets / ncols))
275
+ # Create subplots
276
+ fig, axes = plt.subplots(nrows, ncols, figsize=(12, 8))
277
+ axes = axes.flatten()
278
+ # Plot each dataset
279
+ for i, (data, t) in enumerate(zip(datasets, title)):
280
+ if i != 0:
281
+ vmin, vmax = 0, 70
282
+ cmap_used = cmp_hjnwtx["radar_nmc"]
283
+ plot_dataset(axes[i], data, t, cmap_used, vmin, vmax)
284
+ else:
285
+ # vmin, vmax = 150, 300
286
+ cmap_used = cmap #
287
+ plot_dataset(axes[i], data, t, cmap_used,np.min(data),np.max(data))
288
+ # Remove unused subplots
289
+ for j in range(i + 1, len(axes)):
290
+ fig.delaxes(axes[j])
291
+ # Adjust layout and save the figure
292
+ fig.tight_layout()
293
+ os.makedirs(saveDir, exist_ok=True)
294
+ filename = f"{saveDir}/epoch_{epoch}.png"
295
+ plt.savefig(filename)
296
+ plt.close(fig)
297
+
298
+ """
299
+ if total >= 3:
300
+ break
301
+ if epoch % 2 == 0:
302
+ plotValplus1(epoch,
303
+ data[0][0].detach().cpu().numpy().squeeze(), # 使用 detach()
304
+ output[0][0].detach().cpu().numpy().squeeze(), # 使用 detach()
305
+ label[0][0].detach().cpu().numpy().squeeze(), # 使用 detach()
306
+ title=["input", "prediction", "groundtruth"],
307
+ saveDir="plot_train_dir"
308
+ )
309
+ """
310
+
311
+ import numpy as np
312
+ import matplotlib
313
+ matplotlib.use("Agg")
314
+ import matplotlib.pyplot as plt
315
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
316
+ from hjnwtx.colormap import cmp_hjnwtx
317
+ from shancx import crDir
318
+ import os
319
+ def plot_dataset(ax, data, title, cmap, vmin, vmax): #Cited methods
320
+ """
321
+ Helper function to plot a single dataset on a given axis.
322
+ """
323
+ im = ax.matshow(data, cmap=cmap, vmin=vmin, vmax=vmax)
324
+ # Remove axis ticks
325
+ ax.set_xticks([])
326
+ ax.set_yticks([])
327
+ # Add colorbar
328
+ divider = make_axes_locatable(ax)
329
+ cax = divider.append_axes("right", size="5%", pad=0.05)
330
+ cbar = plt.colorbar(im, cax=cax, ticks=np.linspace(vmin, vmax, 15))
331
+ cbar.set_ticks(np.linspace(vmin, vmax, 15))
332
+ # Set title
333
+ ax.set_title(title)
334
+ return im
335
+
336
+ import matplotlib.pyplot as plt
337
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
338
+ import numpy as np
339
+ import os
340
+ import datetime
341
+ import pandas as pd
342
+ from multiprocessing import Pool
343
+ import argparse
344
+ from itertools import product
345
+ import glob
346
+ def calculate_colorbar_range(data):
347
+ vmin = int(np.nanmin(data))
348
+ vmax = int(np.nanmax(data))
349
+ return vmin, vmax
350
+ def plotgriddata(data, titles=None,name="temp", save_dir="plots",
351
+ cmap="viridis", vmin=None, vmax=None): #Cited methods
352
+ if not isinstance(data, np.ndarray) or data.ndim != 3:
353
+ raise ValueError("The input data must be a three-dimensional NumPy array [num_images, height, width]")
354
+ num_images = data.shape[0]
355
+ titles = titles or [f"Data {i}" for i in range(num_images)]
356
+ ncols = int(np.ceil(np.sqrt(num_images)))
357
+ nrows = int(np.ceil(num_images / ncols))
358
+ fig, axes = plt.subplots(nrows, ncols, figsize=(ncols * 3, nrows * 3))
359
+ axes = axes.ravel()
360
+ for i in range(num_images):
361
+ ax = axes[i]
362
+ im = ax.imshow(data[i], cmap=cmap)
363
+ ax.set_title(titles[i])
364
+ ax.axis('off')
365
+ divider = make_axes_locatable(ax)
366
+ cax = divider.append_axes("right", size="5%", pad=0.05)
367
+ cbar = plt.colorbar(im, cax=cax,
368
+ format='%.1f')
369
+ cbar.ax.tick_params(labelsize=6)
370
+ for j in range(num_images, len(axes)):
371
+ axes[j].axis('off')
372
+ plt.tight_layout()
373
+ os.makedirs(save_dir, exist_ok=True)
374
+ timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
375
+ filename = f"{name}_{timestamp}.png"
376
+ plt.savefig(os.path.join(save_dir, filename), dpi=300)
377
+ plt.close()
378
+ def plotDrawpic(basedata, save_dir="plotDrawpic_com", name="temp", cmap="summer"):
379
+ data_all = basedata[:,::2,::2]
380
+ if isinstance(name, str):
381
+ print("name str")
382
+ titles = [f"channel_{i+1} {name}" for i in range(basedata.shape[0])]
383
+ else:
384
+ titles = [f"{i}" for i in name.strftime("%Y%m%d%H%M%S")]
385
+ name = name.strftime("%Y%m%d%H%M%S")[0]
386
+ plotgriddata(
387
+ data=data_all,
388
+ titles=titles,
389
+ name=name,
390
+ save_dir=save_dir,
391
+ cmap=cmap
392
+ )
393
+
394
+ """
395
+ drawpic_com(Data_con, save_dir="plotDrawpic_com", name=timeList )
396
+ """
397
+ from hjnwtx.colormap import cmp_hjnwtx
398
+ import matplotlib.pyplot as plt
399
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
400
+ import numpy as np
401
+ import os
402
+ import datetime
403
+ def plot_grid_data(data, titles=None, saveDir="plots", name="temp", cmap="summer",radarnmc=1):
404
+ if not isinstance(data, np.ndarray) or data.ndim != 3:
405
+ raise ValueError("The input data must be a three-dimensional NumPy array [num_images, height, width]")
406
+ num_images = data.shape[0]
407
+ titles = titles or [f"Data {i}" for i in range(num_images)]
408
+ ncols = int(np.ceil(np.sqrt(num_images)))
409
+ nrows = int(np.ceil(num_images / ncols))
410
+ fig, axes = plt.subplots(nrows, ncols, figsize=(ncols * 4, nrows * 3))
411
+ if num_images == 1:
412
+ axes = np.array([[axes]])
413
+ elif axes.ndim == 1:
414
+ axes = axes.reshape(1, -1)
415
+ axes_flat = axes.ravel()
416
+ for i in range(num_images):
417
+ ax = axes_flat[i]
418
+ if i >= num_images - radarnmc:
419
+ im = ax.imshow(data[i], cmap=cmp_hjnwtx["radar_nmc"])
420
+ else:
421
+ im = ax.imshow(data[i], cmap=cmap)
422
+ ax.set_title(titles[i])
423
+ ax.axis('off')
424
+ divider = make_axes_locatable(ax)
425
+ cax = divider.append_axes("right", size="5%", pad=0.05)
426
+ plt.colorbar(im, cax=cax)
427
+ for j in range(num_images, len(axes_flat)):
428
+ axes_flat[j].axis('off')
429
+ plt.tight_layout()
430
+ os.makedirs(saveDir, exist_ok=True)
431
+ timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
432
+ filename = f"{name}_{timestamp}.png"
433
+ plt.savefig(os.path.join(saveDir, filename), dpi=300)
434
+ plt.close()
435
+
436
+ def plotTr(base_up, base_down, name="plotTr", saveDir="plotTr",cmap="summer",radarnmc=1):
437
+ data_all = np.concatenate([base_up, base_down], axis=0)
438
+ titles = [f"Pic_{i}" for i in range(base_up.shape[0])] + [f"Pic_{i+1}" for i in range(base_down.shape[0])]
439
+ plot_grid_data(
440
+ data=data_all,
441
+ titles=titles,
442
+ name=name,
443
+ saveDir=saveDir,
444
+ cmap=cmap,
445
+ radarnmc = radarnmc
446
+ )
447
+
448
+ """
449
+ if __name__ == "__main__":
450
+ base_up = np.random.rand(10, 50, 50) * 70
451
+ base_down = np.random.rand(1, 50, 50) * 70
452
+ plotTr(base_up, base_down, name="radar_plot",cmap="summer",radarnmc=1) # radar_mask.detach().cpu().numpy() tensor转numpy
453
+ """
454
+
455
+ import numpy as np
456
+ import matplotlib.pyplot as plt
457
+ import cartopy.crs as ccrs
458
+ import cartopy.feature as cfeature
459
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
460
+ def plotBorder(matrix,name='plotBorder',saveDir="plotBorder",extent=None,title='Matrix Plot', xlabel='X-axis', ylabel='Y-axis', color_label='Value', cmap='viridis'):
461
+ # 地理范围 (lat_min, lat_max, lon_min, lon_max) #[0,57,-132.0,-47] NA
462
+ if extent is None:
463
+ lat_min, lat_max = -3, 13
464
+ lon_min, lon_max = -0, 28
465
+ else:
466
+ lat_min, lat_max, lon_min, lon_max = extent
467
+ # 创建地图
468
+ now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
469
+ fig = plt.figure(figsize=(12, 8))
470
+ ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
471
+ ax.set_extent([lon_min, lon_max, lat_min, lat_max], crs=ccrs.PlateCarree())
472
+ im = ax.imshow(
473
+ matrix,
474
+ extent=[lon_min, lon_max, lat_min, lat_max],
475
+ origin='upper', # 卫星数据通常 origin='upper'
476
+ cmap='viridis', # 选择合适的 colormap
477
+ transform=ccrs.PlateCarree()
478
+ )
479
+ ax.add_feature(cfeature.COASTLINE, linewidth=0.5)
480
+ ax.add_feature(cfeature.BORDERS, linestyle=':', linewidth=0.5)
481
+ # 添加美国州边界(50m 分辨率)
482
+ states = cfeature.NaturalEarthFeature(
483
+ category='cultural',
484
+ name='admin_1_states_provinces_lines',
485
+ scale='50m',
486
+ facecolor='none'
487
+ )
488
+ ax.add_feature(states, edgecolor='red', linewidth=0.5)
489
+ divider = make_axes_locatable(ax)
490
+ cax = divider.append_axes("right", size="5%", pad=0.1, axes_class=plt.Axes)
491
+ cbar = plt.colorbar(im, cax=cax, label='Data Values')
492
+ ax.set_title('Sat data Boundaries', fontsize=14)
493
+ plt.tight_layout() # 优化布局
494
+ outpath = f'./{saveDir}/{name}_{now_str}.png' if name=="plotBorder" else f"./{saveDir}/{name}.png"
495
+ crDir(outpath)
496
+ plt.savefig(outpath)
497
+ plt.close()
@@ -29,7 +29,6 @@ import cartopy.io.shapereader as shpreader
29
29
  from shancx import crDir
30
30
 
31
31
  def add_china_map(ax):
32
- # 在地图上添加地形特征
33
32
  ax.add_feature(cfeature.COASTLINE, edgecolor='gray')
34
33
  ax.add_feature(cfeature.BORDERS, linestyle=':', edgecolor='gray')
35
34
  ax.add_feature(cfeature.LAKES, alpha=0.8)
@@ -38,28 +37,14 @@ def add_china_map(ax):
38
37
  provinces_features = shpreader.Reader(provinces).geometries()
39
38
  ax.add_geometries(provinces_features, ccrs.PlateCarree(), facecolor='none', edgecolor='gray', linestyle=':', linewidth=0.5, alpha=0.8)
40
39
 
41
-
42
40
  def draw_subplot(args):
43
41
  index, tp, vmax, vmin, cmap,time_index, name = args
44
- # print(time_index)
45
- # logger.info(f"Processing index: {index}")
46
- # logger.info(time_index)
47
42
  fig, ax = plt.subplots(figsize=(10, 10))
48
-
49
- # 创建绘图和设置坐标系
50
- # fig = plt.figure(figsize=(10, 8))
51
43
  ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
52
-
53
- # 设置图像显示的范围
54
- ax.set_extent([73, 135, 18, 54], ccrs.PlateCarree()) # 根据需要调整
55
-
56
- # 添加中国地图的边界和特征,包括省份轮廓
44
+ ax.set_extent([73, 135, 18, 54], ccrs.PlateCarree())
57
45
  add_china_map(ax)
46
+ ax.imshow(tp, vmin=0, vmax=100, cmap=cmp_hjnwtx["radar_nmc"], transform=ccrs.PlateCarree(), extent=[73, 134.99, 12.21, 54.2], alpha=1)
58
47
 
59
- ax.imshow(tp, vmin=0, vmax=100, cmap=cmp_hjnwtx["radar_nmc"], transform=ccrs.PlateCarree(), extent=[73, 134.99, 12.21, 54.2], alpha=1)
60
-
61
-
62
- # ax.imshow(tp, vmax=vmax, vmin=vmin, cmap=cmap)
63
48
  ax.axis('off')
64
49
  # ax.text(0.5, 0.5, str(index), transform=ax.transAxes, color='white', fontsize=20, ha='center', va='center')
65
50
  ax.text(0.95, 0.95, f'{time_index}', transform=ax.transAxes, color='white', fontsize=20, ha='right', va='bottom')
@@ -70,9 +55,8 @@ def draw_subplot(args):
70
55
  plt.savefig(buf, format='png')
71
56
  buf.seek(0)
72
57
  plt.close(fig)
73
- return (index, buf) #返回两个数为元组
58
+ return (index, buf)
74
59
 
75
- # 修改读取部分
76
60
  def drawpic(tp, Count,timeList, name="temp"):
77
61
  vmax = 70
78
62
  vmin = 0
@@ -193,8 +177,7 @@ if __name__ == '__main__':
193
177
  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}_")
194
178
  print(datetime.datetime.now()-end1)
195
179
  print("done 120-240")
196
- logger.info("success")
197
-
180
+ logger.info("success")
198
181
 
199
182
  # "/mnt/wtx_weather_forecast/WTX_DATA/RADA/MQPF/2024/20240704/MSP2_WTX_AIW_REF_L88_CHN_202407040324_00000-00300-00006.nc"
200
183
 
shancx/Plot/exam.py ADDED
@@ -0,0 +1,116 @@
1
+ from matplotlib import pyplot as plt
2
+ import numpy as np
3
+ def drawHigh_new(TSV,F1V,ACCV,outpath):
4
+ TS_WTX = np.asarray(list(TSV.values()))
5
+ F1_WTX = np.asarray(list(F1V.values()))
6
+ ACC_WTX =np.asarray(list(ACCV.values()))
7
+ time = ['1h', '2h','3h']
8
+ TS_WTX = np.asarray(list(TSV.values()))
9
+ plt.figure(figsize=(6, 4))
10
+ inspect_flag = "TS"
11
+ plt.subplot(131)
12
+ bar_width = 0.3
13
+ plt.bar(time,[TS_WTX[0][0],TS_WTX[1][0],TS_WTX[2][0]], width=bar_width , label='WTX')
14
+ plt.xlabel('Time')
15
+ plt.ylabel(f'{inspect_flag}')
16
+ plt.title(f'{inspect_flag}')
17
+ plt.grid(axis="y")
18
+ inspect_flag = "F1"
19
+ TS_WTX = np.asarray(list(TSV.values()))
20
+ plt.subplot(132)
21
+ bar_width = 0.3
22
+ plt.bar(time,[F1_WTX[0][0],F1_WTX[1][0],F1_WTX[2][0]], width=bar_width , label='WTX')
23
+ plt.xlabel('Time')
24
+ plt.ylabel(f'{inspect_flag}')
25
+ plt.title(f'{inspect_flag}')
26
+ plt.grid(axis="y")
27
+ inspect_flag = "ACC"
28
+ TS_WTX = np.asarray(list(TSV.values()))
29
+ plt.subplot(133)
30
+ bar_width = 0.3
31
+ plt.bar(time,[ACC_WTX[0][0],ACC_WTX[1][0],F1_WTX[2][0]], width=bar_width , label='WTX')
32
+ plt.xlabel('Time')
33
+ plt.ylabel(f'{inspect_flag}')
34
+ plt.title(f'{inspect_flag}')
35
+ plt.grid(axis="y")
36
+ plt.tight_layout()
37
+ plt.savefig(outpath)
38
+ plt.close()
39
+
40
+ def drawLow_new(POV,FARV,outpath):
41
+ time = ['1h', '2h']
42
+ PO_WTX = np.asarray(list(POV.values()))
43
+ FAR_WTX = np.asarray(list(FARV.values()))
44
+ inspect_flag = "PO"
45
+ time = ['1h', '2h','3h']
46
+ plt.figure(figsize=(6, 4))
47
+ plt.subplot(121)
48
+ bar_width = 0.3
49
+ plt.bar(time,[PO_WTX[0][0],PO_WTX[1][0],PO_WTX[2][0]], width=bar_width , label='WTX')
50
+ plt.xlabel('Time')
51
+ plt.ylabel(f'{inspect_flag}')
52
+ plt.title(f'{inspect_flag}')
53
+ plt.grid(axis="y")
54
+ plt.tight_layout()
55
+ inspect_flag = "FAR"
56
+ plt.subplot(122)
57
+ bar_width = 0.3
58
+ plt.bar(time,[FAR_WTX[0][0],FAR_WTX[1][0],FAR_WTX[2][0]], width=bar_width , label='WTX')
59
+ plt.xlabel('Time')
60
+ plt.ylabel(f'{inspect_flag}')
61
+ plt.title(f'{inspect_flag}')
62
+ # plt.xticks(index + bar_width / 2, time)
63
+ plt.grid(axis="y")
64
+ plt.tight_layout()
65
+ plt.savefig(outpath)
66
+ plt.close()
67
+ """
68
+ POV = {}
69
+ for i in range(1,4):
70
+ F1hm =PO(df[f"PRE{i}_r"], df[f"PRE{i}_w"])
71
+ POV[i] = [np.round(F1hm, 3)]
72
+ POV
73
+ {1: [0.45], 2: [0.67], 3: [0.778]}
74
+ """
75
+
76
+ def drawLow(POV,FARV,outpath):
77
+ time = ['1h', '2h']
78
+ PO_CY = np.asarray(list(POV.values()))[:,0].astype(float)
79
+ PO_WTX = np.asarray(list(POV.values()))[:,1].astype(float)
80
+ FAR_CY = np.asarray(list(FARV.values()))[:,0].astype(float)
81
+ FAR_WTX = np.asarray(list(FARV.values()))[:,1].astype(float)
82
+ plt.figure(figsize=(8, 4))
83
+ bar_width = 0.35
84
+ index = np.arange(len(time))
85
+ x_pos = index + bar_width / 2 # 刻度标签位置
86
+ plt.subplot(121)
87
+ plt.bar(index, PO_CY, bar_width, label='CY')
88
+ plt.bar(index + bar_width, PO_WTX, bar_width, label='WTX')
89
+ plt.xlabel('Time')
90
+ plt.ylabel('PO')
91
+ plt.title('PO 对比')
92
+ plt.xticks(x_pos, time)
93
+ plt.legend()
94
+ plt.grid(axis="y")
95
+ plt.subplot(122)
96
+ plt.bar(index, FAR_CY, bar_width, label='CY')
97
+ plt.bar(index + bar_width, FAR_WTX, bar_width, label='WTX')
98
+ plt.xlabel('Time')
99
+ plt.ylabel('FAR')
100
+ plt.title('FAR 对比')
101
+ plt.xticks(x_pos, time)
102
+ plt.legend()
103
+ plt.grid(axis="y")
104
+ plt.tight_layout()
105
+ plt.savefig(outpath)
106
+ plt.close()
107
+ """
108
+ POV = {}
109
+ for i in range(1,3):
110
+ F1h =PO(df[f"PRE{i}_r"], df[f"PRE{i}_c"],thresholdF=thresholdF)
111
+ F1hm =PO(df[f"PRE{i}_r"], df[f"PRE{i}_w"])
112
+ POV[i] = [np.round(F1h, 3), np.round(F1hm, 3),f"{np.round((F1hm-F1h)/F1h*100,2)*-1}%"]
113
+ print(f"{i}h {np.round(F1h,3)} {np.round(F1hm,3)} {np.round((F1hm-F1h)/F1h*100,2)*-1}%")
114
+ POV CY WTX
115
+ {1: [0.778, 0.556, '28.57%'], 2: [1.0, 0.875, '12.5%']}
116
+ """