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/Path1.py ADDED
@@ -0,0 +1,161 @@
1
+
2
+
3
+ import os
4
+ from pathlib import Path
5
+ def curPath_():
6
+ current_file_path = os.path.abspath(__file__)
7
+ current_folder_path = os.path.dirname(current_file_path)
8
+ parent = Path(__file__).parent
9
+ return current_folder_path,parent
10
+
11
+ import sys
12
+ def curPath():
13
+ # 获取当前执行文件的绝对路径
14
+ current_file_path = os.path.abspath(sys.argv[0])
15
+ current_folder_path = os.path.dirname(current_file_path)
16
+ return current_folder_path
17
+
18
+ from pathlib import Path
19
+ def RootFilePaths(root_path=None):
20
+ root_dir = Path(f'{root_path}')
21
+ npy_files = list(root_dir.rglob('*.*'))
22
+ return npy_files
23
+ """
24
+ import gzip
25
+ with gzip.open(file_path=None, 'rt') as file:
26
+ first_line = file.readline()
27
+ """
28
+
29
+ """
30
+ CSV
31
+
32
+ import gzip
33
+ import csv
34
+ with gzip.open(file_path, 'rt') as file:
35
+ reader = csv.reader(file)
36
+ for row in reader:
37
+ print(row)
38
+
39
+ XML
40
+
41
+ import gzip
42
+ import xml.etree.ElementTree as ET
43
+ with gzip.open(file_path, 'rt') as file:
44
+ tree = ET.parse(file)
45
+ root = tree.getroot()
46
+ for child in root:
47
+ print(child.tag, child.attrib)
48
+
49
+ YAML
50
+
51
+ import gzip
52
+ import yaml
53
+ with gzip.open(file_path, 'rt') as file:
54
+ data = yaml.safe_load(file)
55
+ print(data)
56
+
57
+ TEXT
58
+
59
+ import gzip
60
+ with gzip.open(file_path, 'rt') as file:
61
+ for line in file:
62
+ print(line.strip())
63
+
64
+ """
65
+
66
+ """ model 2
67
+ import matplotlib.pyplot as plt
68
+ import datetime
69
+ import time
70
+ import os
71
+ import time
72
+ import shutil
73
+ from dateutil.relativedelta import relativedelta
74
+ import glob
75
+ import argparse
76
+ from multiprocessing import Pool
77
+ from itertools import product
78
+ import pandas as pd
79
+ import numpy as np
80
+ import copy
81
+ import traceback
82
+ from shancx.NN import _loggers
83
+ logger = _loggers()
84
+ from shancx import crDir,Mul_sub
85
+
86
+ base_source_dir = "/mnt/wtx_weather_forecast/CMA_DATA/NAFP/EC/C1D/2023/2023123120/"
87
+ base_source_dir = "/mnt/wtx_weather_forecast/CMA_DATA/NAFP/EC/C1D"
88
+ # 目标文件夹路径
89
+ target_dir = "/mnt/wtx_weather_forecast/scx/CMA_DATA/NAFP/EC/C1D/2023/2023123120/"
90
+ base_target_dir = "/mnt/wtx_weather_forecast/scx/CMA_DATA/NAFP/EC/C1D"
91
+
92
+ def map_data(conf):
93
+ UCT = conf[0]
94
+ # UCT = CST + relativedelta(hours=-8)
95
+ UCTstr = UCT.strftime("%Y%m%d%H%M")
96
+ # 文件名
97
+ file_name = "ECMFC1D_WIV_100"
98
+ source_dir = f"{base_source_dir}/{UCTstr[:4]}/{UCTstr[:10]}/*"
99
+ target_dir = f"{base_target_dir}/{UCTstr[:4]}/{UCTstr[:10]}"
100
+ crDir(target_dir)
101
+ source_fileL = [i for i in glob.glob(source_dir) if "ECMFC1D_WIV_100" in i ]
102
+ if not source_fileL:
103
+ return
104
+ source_file = source_fileL[0]
105
+ filename = os.path.basename(source_file)
106
+ target_file = f"{target_dir}/{filename}"
107
+ if os.path.exists(target_file):
108
+ print(f"目标文件已存在: {target_file}")
109
+ else:
110
+ try:
111
+ shutil.copy(source_file, target_dir)
112
+ print(f"文件已成功复制到: {target_file}")
113
+ logger.info(f"文件已成功复制到: {source_file} ---> {target_file}")
114
+ except Exception as e:
115
+ print(f"复制文件时出错: {traceback.format_exc()}")
116
+ logger.error(f"复制文件时出错: {traceback.format_exc()}")
117
+ def options():
118
+ parser = argparse.ArgumentParser(description='scx')
119
+ # parser.add_argument('--times', type=str, default='202406290000,202406300000')
120
+ parser.add_argument('--times', type=str, default='202407210000,202407220000')
121
+ parser.add_argument('--pac', type=str, default='100000')
122
+ # parser.add_argument('--combine', action='store_true', default=False)
123
+ parser.add_argument('--combine',action='store_true',default=False)
124
+ parser.add_argument('--isDebug',action='store_true',default=False)
125
+ parser.add_argument('--isDraw',action='store_true',default=False)
126
+ parser.add_argument('--freq', type=str, default="1H")
127
+ parser.add_argument('--tag',type=str, default=datetime.datetime.now().strftime("%Y%m%d%H%M"))
128
+ config= parser.parse_args()
129
+ print(config)
130
+ config.times = config.times.split(",")
131
+ config.pac = config.pac.split(",")
132
+ if len(config.times) == 1:
133
+ config.times = [config.times[0], config.times[0]]
134
+ config.times = [datetime.datetime.strptime(config.times[0], "%Y%m%d%H%M"),
135
+ datetime.datetime.strptime(config.times[1], "%Y%m%d%H%M")]
136
+ return config
137
+ if __name__ == '__main__':
138
+ cfg = options()
139
+ sUTC = cfg.times[0] + relativedelta(hours=-8)
140
+ eUTC = cfg.times[-1] + relativedelta(hours=-8)
141
+ sUTCstr = sUTC.strftime("%Y%m%d")
142
+ cfg = options()
143
+ # 假设 cfg.times[0] 和 cfg.times[-1] 是 datetime 对象
144
+ # 生成每天的时间序列
145
+ date_range = pd.date_range(start=sUTC.date(), end=eUTC.date(), freq="D")
146
+ # 生成每天 08:00 和 20:00 的时间点
147
+ timeList = []
148
+ for date in date_range:
149
+ timeList.append(date.replace(hour=8, minute=0, second=0, microsecond=0))
150
+ timeList.append(date.replace(hour=20, minute=0, second=0, microsecond=0))
151
+
152
+ # 过滤超出范围的时间点
153
+ timeList1 = [t for t in timeList if sUTC <= t <= eUTC]
154
+ logger.info(timeList1)
155
+ # for CST in timeList:
156
+ try:
157
+ Mul_sub(map_data,[timeList1],31)
158
+ except Exception as e:
159
+ print(traceback.format_exc())
160
+ """
161
+
shancx/Plot/GlobMap.py CHANGED
@@ -1,116 +1,276 @@
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)
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=None,cd="CHN",ty="CR",colorbarflag="add"):
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) == 2 and ty =="pre":
32
+ ax.imshow(array_dt, vmin=0, vmax=10, cmap=cmp_hjnwtx["pre_tqw"], transform=ccrs.PlateCarree(), extent=env)
33
+ if colorbarflag is not None :
34
+ plt.colorbar(ax.images[0], ax=ax, orientation='vertical',shrink=0.7)
35
+ plt.savefig(outpath)
36
+ else :
37
+ ax.imshow(array_dt, vmin=0, vmax=72, cmap=cmp_hjnwtx["radar_nmc"], transform=ccrs.PlateCarree(), extent=env)
38
+ if colorbarflag is not None :
39
+ plt.colorbar(ax.images[0], ax=ax, orientation='vertical',shrink=0.7)
40
+ plt.savefig(outpath)
41
+ plt.close(fig)
42
+
43
+ def add_glob_map(ax):
44
+ ax.add_feature(cfeature.COASTLINE, edgecolor='gray')
45
+ ax.add_feature(cfeature.BORDERS, linestyle=':', edgecolor='gray')
46
+ ax.add_feature(cfeature.LAKES, alpha=0.8)
47
+ # Adding state boundaries
48
+ if os.path.exists('/home/scx/ne_10m_admin_1_states_provinces.shp'):
49
+ states = '/home/scx/ne_10m_admin_1_states_provinces.shp'
50
+ else:
51
+ states = shpreader.natural_earth(resolution='10m', category='cultural', name='admin_1_states_provinces') # Automatically download
52
+ states_features = shpreader.Reader(states).geometries()
53
+ ax.add_geometries(states_features, ccrs.PlateCarree(), facecolor='none', edgecolor='gray', linestyle=':', linewidth=0.5, alpha=0.8)
54
+
55
+ def GlobLonLat(array_dt=None,Lon=None,Lat=None,cd="CHN",ty="CR",colorbarflag="add"): ### x_coords2 维度
56
+ if cd == "g":
57
+ env = [-179.617020, 179.632979,-85.098871,85.051128]
58
+ elif cd == "US":
59
+ env = [-132.0, -47.0, 0, 57.0]
60
+ elif cd == "CHN":
61
+ env = [73,134.99,12.21,54.2] #[73, 134.99, 12.21, 54.2]
62
+ else:
63
+ env = cd
64
+ now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
65
+ if array_dt is None :
66
+ array_dt = np.full([4200,6200],np.nan)
67
+ outpath = f"./radar_nmc/{str(cd)}_{now_str}.png"
68
+ crDir(outpath)
69
+
70
+ # Create figure and set the coordinate system
71
+ fig = plt.figure(figsize=(10, 8))
72
+ ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
73
+
74
+ # Set the extent for the United States
75
+ ax.set_extent(env, ccrs.PlateCarree()) # Adjust as needed
76
+
77
+ # Add the US map boundaries and features
78
+ add_glob_map(ax)
79
+
80
+ # Add data layers
81
+ if len(array_dt.shape) == 2 and ty =="pre":
82
+ ax.imshow(array_dt, vmin=0, vmax=10, cmap=cmp_hjnwtx["pre_tqw"], transform=ccrs.PlateCarree(), extent=env)
83
+ if colorbarflag is not None :
84
+ plt.colorbar(ax.images[0], ax=ax, orientation='vertical',shrink=0.7)
85
+ ax.scatter(list(Lon), list(Lat), s=0.5, c='red', marker='o', transform=ccrs.PlateCarree())
86
+ else :
87
+ ax.imshow(array_dt, vmin=0, vmax=72, cmap=cmp_hjnwtx["radar_nmc"], transform=ccrs.PlateCarree(), extent=env)
88
+ ax.scatter(list(Lon), list(Lat), s=0.5, c='red', marker='o', transform=ccrs.PlateCarree())
89
+ if colorbarflag is not None :
90
+ plt.colorbar(ax.images[0], ax=ax, orientation='vertical',shrink=0.7)
91
+ plt.tight_layout()
92
+ plt.savefig(outpath)
93
+ plt.close(fig)
94
+
95
+ def add_us_map(ax):
96
+ ax.add_feature(cfeature.COASTLINE, edgecolor='gray')
97
+ ax.add_feature(cfeature.BORDERS, linestyle=':', edgecolor='gray')
98
+ ax.add_feature(cfeature.LAKES, alpha=0.8)
99
+ # Adding state boundaries
100
+ if os.path.exists('/home/scx/ne_10m_admin_1_states_provinces.shp'):
101
+ states = '/home/scx/ne_10m_admin_1_states_provinces.shp'
102
+ else:
103
+ states = shpreader.natural_earth(resolution='10m', category='cultural', name='admin_1_states_provinces') # Automatically download
104
+ states_features = shpreader.Reader(states).geometries()
105
+ ax.add_geometries(states_features, ccrs.PlateCarree(), facecolor='none', edgecolor='gray', linestyle=':', linewidth=0.5, alpha=0.8)
106
+
107
+ # Example usage
108
+ # Assuming array_dt is your data array, pass it to drawUS
109
+ # array_dt = np.random.rand(3, 100, 100) # Example random data; replace with your actual data
110
+ # drawUS(array_dt)
111
+
112
+ def GlobLonLatPlus(array_dt=None,Lon=None,Lat=None,cd="CHN",ty="CR",name="temp",markcolor="red",outpath1=None): ### x_coords2 维度
113
+ if cd == "g":
114
+ env = [-179.617020, 179.632979,-85.098871,85.051128]
115
+ elif cd == "US":
116
+ env = [-132.0, -47.0, 0, 57.0]
117
+ elif cd == "CHN":
118
+ env = [73,134.99,12.21,54.2] #[73, 134.99, 12.21, 54.2]
119
+ else:
120
+ env = cd
121
+ now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
122
+ if array_dt is None :
123
+ array_dt = np.full([4200,6200],np.nan)
124
+ outpath = f"./radar_nmc/{str(cd)}_{now_str}_{name}.png"
125
+ if outpath1 is not None:
126
+ outpath = outpath1
127
+ crDir(outpath)
128
+ # Create figure and set the coordinate system
129
+ fig = plt.figure(figsize=(10, 8))
130
+ ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
131
+
132
+ # Set the extent for the United States
133
+ ax.set_extent(env, ccrs.PlateCarree()) # Adjust as needed
134
+
135
+ # Add the US map boundaries and features
136
+ add_glob_map(ax)
137
+
138
+ # Add data layers
139
+ if len(array_dt.shape) == 2 and ty =="pre":
140
+ ax.imshow(array_dt, vmin=0, vmax=10, cmap=cmp_hjnwtx["pre_tqw"], transform=ccrs.PlateCarree(), extent=env)
141
+ ax.scatter(list(Lon), list(Lat), s=0.5, c=f'{markcolor}', marker='o', transform=ccrs.PlateCarree())
142
+ plt.colorbar(ax.images[0], ax=ax, orientation='vertical',shrink=0.7)
143
+ plt.savefig(outpath)
144
+ else :
145
+ ax.imshow(array_dt, vmin=0, vmax=72, cmap=cmp_hjnwtx["radar_nmc"], transform=ccrs.PlateCarree(), extent=env)
146
+ ax.scatter(list(Lon), list(Lat), s=0.5, c=f'{markcolor}', marker='o', transform=ccrs.PlateCarree())
147
+ plt.colorbar(ax.images[0], ax=ax, orientation='vertical',shrink=0.7)
148
+ plt.savefig(outpath)
149
+ plt.close(fig)
150
+
151
+ def add_us_map(ax):
152
+ ax.add_feature(cfeature.COASTLINE, edgecolor='gray')
153
+ ax.add_feature(cfeature.BORDERS, linestyle=':', edgecolor='gray')
154
+ ax.add_feature(cfeature.LAKES, alpha=0.8)
155
+ # Adding state boundaries
156
+ if os.path.exists('/home/scx/ne_10m_admin_1_states_provinces.shp'):
157
+ states = '/home/scx/ne_10m_admin_1_states_provinces.shp'
158
+ else:
159
+ states = shpreader.natural_earth(resolution='10m', category='cultural', name='admin_1_states_provinces') # Automatically download
160
+ states_features = shpreader.Reader(states).geometries()
161
+ ax.add_geometries(states_features, ccrs.PlateCarree(), facecolor='none', edgecolor='gray', linestyle=':', linewidth=0.5, alpha=0.8)
162
+
163
+ # Example usage
164
+ # Assuming array_dt is your data array, pass it to drawUS
165
+ # array_dt = np.random.rand(3, 100, 100) # Example random data; replace with your actual data
166
+ # drawUS(array_dt)
167
+
168
+ import matplotlib.font_manager as fm
169
+ zh_font_path = '/mnt/wtx_weather_forecast/scx/fonts/truetype/simhei.ttf'
170
+ zh_font = fm.FontProperties(fname=zh_font_path)
171
+ def GlobLonLatPluss(array_dt,Lon,Lat,Lon1,Lat1,cd="CHN",ty="CR",name="temp",markcolor="red",outpath1=None): ### x_coords2 维度
172
+ if cd == "g":
173
+ env = [-179.617020, 179.632979,-85.098871,85.051128]
174
+ elif cd == "US":
175
+ env = [-132.0, -47.0, 0, 57.0]
176
+ elif cd == "CHN":
177
+ env = [73,134.99,12.21,54.2] #[73, 134.99, 12.21, 54.2]
178
+ else:
179
+ env = cd
180
+ now_str = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
181
+ outpath = f"./radar_nmc/{str(cd)}_{now_str}_{name}.png"
182
+ array_dt = np.where(array_dt>0,array_dt,np.nan)
183
+ if outpath1 is not None:
184
+ outpath = outpath1
185
+ crDir(outpath)
186
+ # Create figure and set the coordinate system
187
+ fig = plt.figure(figsize=(10, 8))
188
+ ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
189
+
190
+ # Set the extent for the United States
191
+ ax.set_extent(env, ccrs.PlateCarree()) # Adjust as needed
192
+
193
+ # Add the US map boundaries and features
194
+ add_glob_map(ax)
195
+ # Add data layers
196
+ if len(array_dt.shape) == 2 and ty =="pre":
197
+ ax.imshow(array_dt, vmin=0, vmax=10, cmap=cmp_hjnwtx["pre_tqw"], transform=ccrs.PlateCarree(), extent=env)
198
+ ax.scatter(list(Lon), list(Lat), s=0.5, c=f'{markcolor}', marker='o', transform=ccrs.PlateCarree())
199
+ else :
200
+ ax.imshow(array_dt, vmin=0, vmax=72, cmap=cmp_hjnwtx["radar_nmc"], transform=ccrs.PlateCarree(), extent=env)
201
+ sc1 = ax.scatter(list(Lon), list(Lat), s=2, c=f'blue', marker='o', transform=ccrs.PlateCarree(),edgecolor='black', linewidth=0.3,label="维天信相对彩云漏报 ")
202
+ sc2 = ax.scatter(list(Lon1), list(Lat1), s=2, c=f'red', marker='o', transform=ccrs.PlateCarree(),edgecolor='black', linewidth=0.3,label="共同漏报 ")
203
+ plt.colorbar(ax.images[0], ax=ax, orientation='vertical',shrink=0.8)
204
+ plt.title(f"{name}")
205
+ ax.legend(loc='upper left', fontsize='small', prop=zh_font) # 您可以根据需要调整字体大小和位置
206
+ plt.savefig(outpath)
207
+ plt.close(fig)
208
+
209
+ def add_us_map(ax):
210
+ ax.add_feature(cfeature.COASTLINE, edgecolor='gray')
211
+ ax.add_feature(cfeature.BORDERS, linestyle=':', edgecolor='gray')
212
+ ax.add_feature(cfeature.LAKES, alpha=0.8)
213
+ # Adding state boundaries
214
+ if os.path.exists('/home/scx/ne_10m_admin_1_states_provinces.shp'):
215
+ states = '/home/scx/ne_10m_admin_1_states_provinces.shp'
216
+ else:
217
+ states = shpreader.natural_earth(resolution='10m', category='cultural', name='admin_1_states_provinces') # Automatically download
218
+ states_features = shpreader.Reader(states).geometries()
219
+ ax.add_geometries(states_features, ccrs.PlateCarree(), facecolor='none', edgecolor='gray', linestyle=':', linewidth=0.5, alpha=0.8)
220
+
221
+ def globPng(d2,ty=None):
222
+ import numpy as np
223
+ import matplotlib.pyplot as plt
224
+ import cartopy.crs as ccrs
225
+ import cartopy.feature as cfeature
226
+ from hjnwtx.colormap import cmp_hjnwtx
227
+ from shancx.Time import UTCStr
228
+ CSTstr = UTCStr()
229
+ data = d2[::10,::10] # shape: (height, width)
230
+ lat_min, lat_max = -90, 90
231
+ lon_min, lon_max = -180, 180
232
+ fig = plt.figure(figsize=(15, 10))
233
+ ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
234
+ im = ax.imshow(data,
235
+ extent=[lon_min, lon_max, lat_min, lat_max],
236
+ cmap=cmp_hjnwtx["radar_nmc"],
237
+ transform=ccrs.PlateCarree())
238
+ if ty == "pre":
239
+ im = ax.imshow(data,
240
+ extent=[lon_min, lon_max, lat_min, lat_max],
241
+ vmin=0,
242
+ vmax=10,
243
+ cmap=cmp_hjnwtx["pre_tqw"],
244
+ transform=ccrs.PlateCarree())
245
+ ax.add_feature(cfeature.COASTLINE, linewidth=0.8, zorder=2)
246
+ ax.add_feature(cfeature.BORDERS, linestyle=':', linewidth=0.6, zorder=2)
247
+ ax.add_feature(cfeature.STATES, linestyle=':', linewidth=0.4, alpha=0.5, zorder=2)
248
+ ax_pos = ax.get_position()
249
+ # 设置色标与主图严格对齐
250
+ cax = fig.add_axes([
251
+ ax_pos.x1 + 0.01, # 主图右侧+0.01的间距
252
+ ax_pos.y0, # 与主图底部对齐
253
+ 0.02, # 色标宽度
254
+ ax_pos.height # 与主图同高度
255
+ ])
256
+
257
+ cbar = plt.colorbar(im, cax=cax)
258
+ cbar.set_label('Echo Intensity (dBZ)', fontsize=12, labelpad=10)
259
+ cbar.ax.tick_params(labelsize=10)
260
+ plt.subplots_adjust(
261
+ left=0.05,
262
+ right=0.85, # 减小right值以容纳色标
263
+ top=0.95,
264
+ bottom=0.125
265
+ )
266
+ ax.set_title('Global Radar',
267
+ fontsize=18,
268
+ pad=25,
269
+ weight='bold')
270
+ ax.set_xlabel('Longitude', fontsize=12, labelpad=10)
271
+ ax.set_ylabel('Latitude', fontsize=12, labelpad=15)
272
+ plt.savefig(f"global_radar_aligned_{CSTstr}.png",
273
+ dpi=300,
274
+ bbox_inches='tight',
275
+ facecolor='white')
276
+ plt.close()