shancx 1.9.33.109__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 (65) hide show
  1. shancx/{Dsalgor → Algo}/__init__.py +37 -1
  2. shancx/Calmetrics/__init__.py +78 -9
  3. shancx/Calmetrics/calmetrics.py +14 -0
  4. shancx/Calmetrics/rmseR2score.py +14 -3
  5. shancx/{Command.py → Cmd.py} +20 -15
  6. shancx/Config_.py +26 -0
  7. shancx/Df/__init__.py +11 -0
  8. shancx/Df/tool.py +0 -1
  9. shancx/NN/__init__.py +200 -11
  10. shancx/{path.py → Path1.py} +2 -3
  11. shancx/Plot/__init__.py +129 -403
  12. shancx/Plot/draw_day_CR_PNG.py +4 -21
  13. shancx/Plot/exam.py +116 -0
  14. shancx/Plot/plotGlobal.py +325 -0
  15. shancx/Plot/radarNmc.py +1 -48
  16. shancx/Plot/single_china_map.py +1 -1
  17. shancx/Point.py +46 -0
  18. shancx/QC.py +223 -0
  19. shancx/Read.py +17 -10
  20. shancx/Resize.py +79 -0
  21. shancx/SN/__init__.py +8 -1
  22. shancx/Time/timeCycle.py +97 -23
  23. shancx/Train/makelist.py +161 -155
  24. shancx/__init__.py +79 -232
  25. shancx/bak.py +78 -53
  26. shancx/geosProj.py +2 -2
  27. shancx/wait.py +35 -1
  28. {shancx-1.9.33.109.dist-info → shancx-1.9.33.218.dist-info}/METADATA +12 -4
  29. shancx-1.9.33.218.dist-info/RECORD +91 -0
  30. {shancx-1.9.33.109.dist-info → shancx-1.9.33.218.dist-info}/WHEEL +1 -1
  31. shancx/Plot/Mip.py +0 -42
  32. shancx/Plot/border.py +0 -44
  33. shancx/Plot/draw_day_CR_PNGUS.py +0 -206
  34. shancx/Plot/draw_day_CR_SVG.py +0 -275
  35. shancx/Plot/draw_day_pre_PNGUS.py +0 -205
  36. shancx/Plot/radar_nmc_china_map_compare1.py +0 -50
  37. shancx/makenetCDFN.py +0 -42
  38. shancx-1.9.33.109.dist-info/RECORD +0 -91
  39. /shancx/{3DJU → 3D}/__init__.py +0 -0
  40. /shancx/{Dsalgor → Algo}/Class.py +0 -0
  41. /shancx/{Dsalgor → Algo}/CudaPrefetcher1.py +0 -0
  42. /shancx/{Dsalgor → Algo}/Fake_image.py +0 -0
  43. /shancx/{Dsalgor → Algo}/Hsml.py +0 -0
  44. /shancx/{Dsalgor → Algo}/L2Loss.py +0 -0
  45. /shancx/{Dsalgor → Algo}/MetricTracker.py +0 -0
  46. /shancx/{Dsalgor → Algo}/Normalize.py +0 -0
  47. /shancx/{Dsalgor → Algo}/OptimizerWScheduler.py +0 -0
  48. /shancx/{Dsalgor → Algo}/Rmageresize.py +0 -0
  49. /shancx/{Dsalgor → Algo}/Savemodel.py +0 -0
  50. /shancx/{Dsalgor → Algo}/SmoothL1_losses.py +0 -0
  51. /shancx/{Dsalgor → Algo}/Tqdm.py +0 -0
  52. /shancx/{Dsalgor → Algo}/checknan.py +0 -0
  53. /shancx/{Dsalgor → Algo}/dsalgor.py +0 -0
  54. /shancx/{Dsalgor → Algo}/iouJU.py +0 -0
  55. /shancx/{Dsalgor → Algo}/mask.py +0 -0
  56. /shancx/{Dsalgor → Algo}/psnr.py +0 -0
  57. /shancx/{Dsalgor → Algo}/ssim.py +0 -0
  58. /shancx/{Dsalgor → Algo}/structural_similarity.py +0 -0
  59. /shancx/{Dsalgor → Algo}/tool.py +0 -0
  60. /shancx/Calmetrics/{matrixLib.py → calmetricsmatrixLib.py} +0 -0
  61. /shancx/{Diffmodel → Diffm}/Psamples.py +0 -0
  62. /shancx/{Diffmodel → Diffm}/__init__.py +0 -0
  63. /shancx/{Diffmodel → Diffm}/test.py +0 -0
  64. /shancx/{Board → tensBoard}/__init__.py +0 -0
  65. {shancx-1.9.33.109.dist-info → shancx-1.9.33.218.dist-info}/top_level.txt +0 -0
shancx/Train/makelist.py CHANGED
@@ -1,181 +1,187 @@
1
1
 
2
-
2
+ def save_results(results, output_file, mode='w',title="input_path,tar_path"):
3
+ with open(output_file, mode) as f:
4
+ if mode == 'w':
5
+ f.write(f"{title}\n")
6
+ for result in results:
7
+ f.write(f"{result['input_path']},{result['tar_path']}\n")
8
+ """
9
+ output_file = "rmse_results.txt"
10
+ save_results([], output_file, mode='w')
11
+ result = {
12
+ 'input_path': input_path ,
13
+ 'tar_path': tar_path
14
+ }
15
+ save_results([result], output_file, mode='a')
16
+
17
+ df = pd.read_csv(csv_file, sep=" ",header=None)
18
+ sample_list = df.values.tolist()
19
+ self.paths = {
20
+ "input_path": [l[0] for l in self.sample_list],
21
+ "gt_path": [l[1] for l in self.sample_list]
22
+ }
23
+ """
3
24
  import os
4
25
  import numpy as np
5
26
  import pandas as pd
6
27
  import glob
7
28
  import datetime
8
- from hjnwtx.mkNCHJN import mkDir
9
- from shancx import Mul_sub_S
10
-
11
- # 将 getcheckdata 移到模块顶层
29
+ from shancx import Mul_sub_S,Mul_sub
30
+ from shancx import crDir
12
31
  def getcheckdata(conf):
13
- iph = conf[0]
32
+ satPath = conf[0]
14
33
  radar_dir_path = conf[1]
15
- maskTrainPathm = conf[2]
16
- sat_imin = conf[3]
34
+ sat_imin = conf[2]
17
35
  try:
18
- satdata = np.load(iph)
19
- radarpth = glob.glob(f"{radar_dir_path}/{sat_imin[:4]}/{sat_imin[:8]}/CR_{iph.split('/')[-1][5:-4]}*.npy")[0]
36
+ satdata = np.load(satPath)
37
+ radarpth = glob.glob(f"{radar_dir_path}/{sat_imin[:4]}/{sat_imin[:8]}/CR_{satPath.split('/')[-1][4:-4]}*.npy")[0]
20
38
  radardata = np.load(radarpth)
21
- maskpath = glob.glob(f"{maskTrainPathm}/{sat_imin[:4]}/{sat_imin[:8]}/mask_{iph.split('/')[-1][5:-4]}*.npy")[0]
22
- maskdata = np.load(maskpath)
23
- print(satdata.shape, radardata.shape, maskdata.shape)
24
- if radardata.shape != (1, 256, 256) or satdata.shape != (9, 256, 256) or maskdata.shape != (1, 256, 256):
25
- return None
26
- df = pd.DataFrame({'sat_path': [iph], 'radar_path': [radarpth], 'mask_path': [maskpath]})
39
+ if radardata.shape != satdata.shape :
40
+ return
41
+ df = pd.DataFrame({'sat_path': [satPath], 'radar_path': [radarpth] })
27
42
  return df
28
43
  except Exception as e:
29
- print(f"{iph} can not load succeed: {e}")
44
+ print(f"{satPath} can not load succeed: {e}")
30
45
  return None
31
-
32
- def generateList(sat_dir_path, radar_dir_path, maskTrainPathm, savepath, split_time, timelist):
33
- """
34
- 生成训练、测试和验证数据集的文件列表,并保存为CSV文件。
35
-
36
- 参数:
37
- - sat_dir_path: 卫星数据路径
38
- - radar_dir_path: 雷达数据路径
39
- - maskTrainPathm: 掩码数据路径
40
- - savepath: 保存CSV文件的路径
41
- - split_time: 划分训练、测试和验证集的时间点列表
42
- - timelist: 要处理的时间范围列表
43
- """
44
- dataframes = {'train': [], 'test': [], 'valid': []}
45
-
46
- for sat_imin in timelist:
47
- print(f"Processing time: {sat_imin}")
48
- sat_imin_dt = datetime.datetime.strptime(sat_imin, '%Y%m%d%H%M')
49
- if sat_imin_dt < split_time[0]:
50
- split_name = 'train'
51
- elif split_time[0] <= sat_imin_dt < split_time[1]:
52
- split_name = 'test'
53
- else:
54
- split_name = 'valid'
55
-
56
- satpath = glob.glob(f"{sat_dir_path}/{sat_imin[:4]}/{sat_imin[:8]}/FY4B_{sat_imin}*.npy")
57
- satpath.sort()
58
- if satpath:
59
- data = Mul_sub_S(getcheckdata, [satpath,[radar_dir_path],[maskTrainPathm],[sat_imin]], 6)
60
- data = [i for i in data if i is not None ]
61
- if data :
62
- df = pd.concat(data)
63
- dataframes[split_name].append(df)
64
- else:
65
- continue
66
-
67
- train_df = pd.concat(dataframes['train']) if dataframes['train'] else pd.DataFrame()
68
- test_df = pd.concat(dataframes['test']) if dataframes['test'] else pd.DataFrame()
69
- valid_df = pd.concat(dataframes['valid']) if dataframes['valid'] else pd.DataFrame()
70
- mkDir(savepath)
71
- train_df.to_csv(f"{savepath}/df_train.csv", index=False, sep=',')
72
- test_df.to_csv(f"{savepath}/df_test.csv", index=False, sep=',')
73
- valid_df.to_csv(f"{savepath}/df_valid.csv", index=False, sep=',')
74
- print(f"train_df {len(train_df)} test_df {len(test_df)} valid_df {len(valid_df)}")
75
- print('complete!!!')
76
-
77
- if __name__ == "__main__":
78
- print()
79
- # 定义路径和参数
80
- # sat_dir_path = '/mnt/wtx_weather_forecast/scx/dataset/sample/sta2radar_N/AGRI_area_4KM'
81
- # radar_dir_path = '/mnt/wtx_weather_forecast/scx/dataset/sample/sta2radar_N/radar_selectArea_4KM_256'
82
- # maskTrainPathm = "/mnt/wtx_weather_forecast/scx/dataset/sample/sta2radar_N/mask_selectArea_4KM"
83
- # savepath = '/mnt/wtx_weather_forecast/scx/dataset/sample/datalist_vmask_mask_530T'
84
- # split_time = [datetime.datetime(2025, 2, 27),
85
- # datetime.datetime(2025, 2, 28),
86
- # datetime.datetime(2025, 3, 4)]
87
-
88
- # # 定义时间范围
89
- # start_time = datetime.datetime(2024,8,3)
90
- # end_time = datetime.datetime(2025, 3, 5)
91
- # timelist = pd.date_range(start=start_time, end=end_time, freq='30T').strftime('%Y%m%d%H%M').tolist()
92
-
93
- # # 调用方法 1.split_time 2. timelist 3. 路径
94
- # generate_data_list(sat_dir_path, radar_dir_path, maskTrainPathm, savepath, split_time, timelist)
95
-
96
-
46
+ def generateList(conf):
47
+ sat_dir_path, radar_dir_path, sat_imin= conf
48
+ satpath = glob.glob(f"{sat_dir_path}/{sat_imin[:4]}/{sat_imin[:8]}/SAT_{sat_imin}_*.npy")
49
+ satpath.sort()
50
+ if satpath:
51
+ datas = []
52
+ for path in satpath:
53
+ data = getcheckdata( (path,radar_dir_path,sat_imin))
54
+ datas.append(data)
55
+ datass = [i for i in datas if i is not None ]
56
+ if datass :
57
+ df = pd.concat(datass)
58
+ return df
59
+ else:
60
+ return None
61
+ import argparse
62
+ import datetime
63
+ import pandas as pd
64
+ def options():
65
+ parser = argparse.ArgumentParser(description='examdatabasedata')
66
+ parser.add_argument('--times', type=str, default='202502010000,202506220000')
67
+ parser.add_argument('--flag', type=str, default='val')
68
+ config= parser.parse_args()
69
+ print(config)
70
+ config.times = config.times.split(",")
71
+ if len(config.times) == 1:
72
+ config.times = [config.times[0], config.times[0]]
73
+ config.times = [datetime.datetime.strptime(config.times[0], "%Y%m%d%H%M"),
74
+ datetime.datetime.strptime(config.times[1], "%Y%m%d%H%M")]
75
+ return config
97
76
  """
77
+ if __name__ == '__main__':
78
+ cfg = options()
79
+ sUTC = cfg.times[0]
80
+ eUTC = cfg.times[-1]
81
+ flag = cfg.flag
82
+ sat_dir_path ="./"
83
+ radar_dir_path = f"./"
84
+ timelist = pd.date_range(sUTC, eUTC, t=f"{flag}")
85
+ timeListfliter = timelist[timelist.month.isin([1,4,7,10])&(timelist.day<=15)]
86
+ savepath = f'/mnt/wtx_weather_forecast/SAT/GOES18train_N/0624_1'
87
+ crDir(savepath)
88
+ # 调用方法 1.split_time 2. timelist 3. 路径
89
+ dataL = Mul_sub(generateList,[ [sat_dir_path]
90
+ , [radar_dir_path]
91
+ , timelist
92
+ ]
93
+ )
94
+ dataLs = [i for i in dataL if i is not None]
95
+ if flag =="trn":
96
+ train_df = pd.concat(dataLs)
97
+ crDir(savepath)
98
+ train_df.to_csv(f"{savepath}/df_train.csv", index=False, sep=',')
99
+ print(f"train_df {len(train_df)}")
100
+ print('complete!!!')
101
+ print(savepath)
102
+ if flag == "val":
103
+ valid_df = pd.concat(dataLs)
104
+ crDir(savepath)
105
+ valid_df.to_csv(f"{savepath}/df_valid.csv", index=False, sep=',')
106
+ print(f"valid_df {len(valid_df)}")
107
+ print('complete!!!')
108
+ print(savepath)
109
+
98
110
 
99
-
111
+ """
112
+ """
100
113
  import os
101
114
  import numpy as np
102
115
  import pandas as pd
103
116
  import glob
104
117
  import datetime
105
- from hjnwtx.mkNCHJN import mkDir
106
- from shancx import Mul_sub_S
107
- from shancx.Plot import plotRadar,plotMat
108
-
109
- # 将 getcheckdata 移到模块顶层
118
+ from shancx import Mul_sub_S,Mul_sub
119
+ from shancx import crDir
110
120
  def getcheckdata(conf):
111
- iph = conf[0]
112
- radar_dir_path = conf[1]
113
- maskTrainPathm = conf[2]
114
- sat_imin = conf[3]
121
+ inputPath = conf[0]
122
+ target_dir_path = conf[1]
123
+ imin = conf[2]
115
124
  try:
116
- satdata = np.load(iph)
117
- radarpth = glob.glob(f"{radar_dir_path}/{sat_imin[:4]}/{sat_imin[:8]}/CR_{iph.split('/')[-1][5:-4]}*.npy")[0]
118
- radardata = np.load(radarpth)
119
- maskpath = glob.glob(f"{maskTrainPathm}/{sat_imin[:4]}/{sat_imin[:8]}/mask_{iph.split('/')[-1][5:-4]}*.npy")[0]
120
- maskdata = np.load(maskpath)
121
- print(satdata.shape, radardata.shape, maskdata.shape)
122
- if radardata.shape != (1, 256, 256) or satdata.shape != (9, 256, 256) or maskdata.shape != (1, 256, 256):
123
- return None
124
- if np.mean(radardata) > 20 or np.mean(satdata) > 285 :
125
- plotMat(satdata[0],name=f"satdata_{sat_imin}")
126
- plotRadar(satdata[0],name=f"radar_{sat_imin}")
127
- return None
128
- df = pd.DataFrame({'sat_path': [iph], 'radar_path': [radarpth], 'mask_path': [maskpath]})
125
+ inputdata = np.load(inputPath)
126
+ targetpth = glob.glob(f"{target_dir_path}/{imin[:4]}/{imin[:8]}/analy_{inputPath.split('/')[-1][3:-4]}*.npy")[0]
127
+ targetdata = np.load(targetpth)
128
+ if inputdata.shape != targetdata.shape :
129
+ return
130
+ df = pd.DataFrame({'inputPath': [inputPath], 'targetpth': [targetpth] })
129
131
  return df
130
132
  except Exception as e:
131
- print(f"{iph} can not load succeed: {e}")
133
+ print(f"{inputPath} can not load succeed: {e}")
132
134
  return None
133
-
134
- def generateList(sat_dir_path, radar_dir_path, maskTrainPathm, savepath, timelist,flag):
135
- dataframes = {'train': [], 'test': [], 'valid': []}
136
- for sat_imin in timelist:
137
- split_name = flag
138
- satpath = glob.glob(f"{sat_dir_path}/{sat_imin[:4]}/{sat_imin[:8]}/FY4B_{sat_imin}*.npy")
139
- satpath.sort()
140
- if satpath:
141
- data = Mul_sub_S(getcheckdata, [satpath,[radar_dir_path],[maskTrainPathm],[sat_imin]], 6)
142
- data = [i for i in data if i is not None ]
143
- if data :
144
- df = pd.concat(data)
145
- dataframes[split_name].append(df)
146
- else:
147
- continue
148
- if flag =="train":
149
- train_df = pd.concat(dataframes['train']) if dataframes['train'] else pd.DataFrame()
150
- mkDir(savepath)
151
- train_df.to_csv(f"{savepath}/df_train.csv", index=False, sep=',')
152
- print(f"train_df {len(train_df)}")
153
- print('complete!!!')
154
- if flag == "valid":
155
- valid_df = pd.concat(dataframes['valid']) if dataframes['valid'] else pd.DataFrame()
156
- mkDir(savepath)
157
- valid_df.to_csv(f"{savepath}/df_valid.csv", index=False, sep=',')
158
- print(f"valid_df {len(valid_df)}")
159
- print('complete!!!')
160
-
161
- if __name__ == "__main__":
162
- print()
163
- # 定义路径和参数
164
- sat_dir_path = '/mnt/wtx_weather_forecast/scx/dataset/sample/sta2radar_N/AGRI_area_4KMQC2'
165
- radar_dir_path = '/mnt/wtx_weather_forecast/scx/dataset/sample/sta2radar_N/radar_selectArea_4KMQC2_256'
166
- maskTrainPathm = "/mnt/wtx_weather_forecast/scx/dataset/sample/sta2radar_N/mask_selectArea_4KMQC2"
167
- savepath = '/mnt/wtx_weather_forecast/scx/dataset/sample/datalist_vmask_filter'
168
- split_time = [datetime.datetime(2025, 2, 27),
169
- datetime.datetime(2025, 2, 28),
170
- datetime.datetime(2025, 3, 4)]
171
-
172
- # 定义时间范围
173
- start_time = datetime.datetime(2025,4,9)
174
- end_time = datetime.datetime(2025,4,14)
175
- flag = "train"
176
- timelist = pd.date_range(start=start_time, end=end_time, freq='30T').strftime('%Y%m%d%H%M').tolist()
177
-
135
+ def generateList(conf):
136
+ imin,input_dir_path, target_dir_path= conf
137
+ imin = imin.strftime("%Y%m%d%H%M")
138
+ targetpath = glob.glob(f"{input_dir_path}/{imin[:4]}/{imin[:8]}/EC_{imin}_*.npy")
139
+ targetpath.sort()
140
+ if targetpath:
141
+ datas = []
142
+ for path in targetpath:
143
+ data = getcheckdata( (path,target_dir_path,imin))
144
+ datas.append(data)
145
+ datass = [i for i in datas if i is not None ]
146
+ if datass :
147
+ df = pd.concat(datass)
148
+ return df
149
+ else:
150
+ return None
151
+ import argparse
152
+ import datetime
153
+ import pandas as pd
154
+ def options():
155
+ parser = argparse.ArgumentParser(description='examdatabasedata')
156
+ parser.add_argument('--times', type=str, default='202505210030,202505210130')
157
+ parser.add_argument('--flag', type=str, default='val')
158
+ parser.add_argument('--freq', type=str, default="1h")
159
+ config= parser.parse_args()
160
+ print(config)
161
+ config.times = config.times.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
+ sUTC = cfg.times[0]
170
+ eUTC = cfg.times[-1]
171
+ freq = cfg.freq
172
+ input_dir_path ="/mnt/wtx_weather_forecast/scx/smart_grid/train/clip_EC"
173
+ target_dir_path = f"/mnt/wtx_weather_forecast/scx/smart_grid/train/analy_1_256"
174
+ timelist = pd.date_range(sUTC, eUTC, freq=f"{freq}")
175
+ timeListfliter = timelist[timelist.month.isin([1,4,5,7,10])]
176
+ timeListfliter = list(timeListfliter)
177
+ savepath = f'/mnt/wtx_weather_forecast/SAT/downscale/0901'
178
+ crDir(savepath)
178
179
  # 调用方法 1.split_time 2. timelist 3. 路径
179
- generateList(sat_dir_path, radar_dir_path, maskTrainPathm, savepath, timelist,flag)
180
-
181
- """
180
+
181
+ dataL = Mul_sub(generateList,[ timeListfliter,[input_dir_path] , [target_dir_path]] )
182
+ dataLs = [i for i in dataL if i is not None]
183
+ pd.concat(dataLs).to_csv('train.txt', sep=' ', index=False)
184
+ a = pd.read_csv("./train.txt",sep=" ").values.tolist()
185
+ """
186
+
187
+