metradar 0.1.5__py3-none-any.whl → 0.1.8__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 (75) hide show
  1. metradar/__init__.py +4 -2
  2. metradar/config.py +53 -0
  3. metradar/core/__init__.py +9 -0
  4. metradar/{get_cross_section_from_pyart.py → core/get_cross_section.py} +5 -157
  5. metradar/{mosaic_merge.py → core/mosaic_merge.py} +3 -1
  6. metradar/{oa_dig_func.py → core/oa_dig_func.py} +83 -333
  7. metradar/graph/__init__.py +9 -0
  8. metradar/{mosaic_quickdraw.py → graph/draw_comp_mosaic.py} +71 -68
  9. metradar/{draw_mosaic_new.py → graph/draw_latlon_func.py} +177 -173
  10. metradar/graph/draw_radar_aws.py +212 -0
  11. metradar/{draw_radar_comp_func.py → graph/draw_radar_comp_func.py} +319 -248
  12. metradar/graph/parse_pal.py +157 -0
  13. metradar/io/__init__.py +9 -0
  14. metradar/{cnrad_level2.py → io/cnrad_level2.py} +45 -2
  15. metradar/{decode_fmt_pyart.py → io/decode_fmt_pyart.py} +19 -3
  16. metradar/{decode_pup_rose.py → io/decode_pup_rose.py} +241 -684
  17. metradar/{read_new_mosaic_func.py → io/read_new_mosaic_func.py} +30 -2
  18. metradar/io/read_swan.py +250 -0
  19. metradar/{rose_structer.py → io/rose_structer.py} +2 -0
  20. metradar/project/__init__.py +9 -0
  21. metradar/project/make_mosaic/__init__.py +9 -0
  22. metradar/project/make_mosaic/batch_draw_mosaic.py +32 -0
  23. metradar/{make_mosaic_mp_archive.py → project/make_mosaic/make_mosaic_func.py} +144 -175
  24. metradar/project/make_mosaic/make_mosaic_mp.ini +29 -0
  25. metradar/project/make_mosaic/make_mosaic_mp.py +70 -0
  26. metradar/project/make_vpr_aws/__init__.py +9 -0
  27. metradar/project/make_vpr_aws/construct_aws_refvpr_mainprog.ini +39 -0
  28. metradar/project/make_vpr_aws/construct_aws_refvpr_mainprog.py +565 -0
  29. metradar/project/nowcasting/__init__.py +9 -0
  30. metradar/project/nowcasting/nowcast_by_pysteps.py +214 -0
  31. metradar/{trans_nc_pgmb.py → project/nowcasting/trans_mosaic_pgmb.py} +19 -17
  32. metradar/project/qpe/Archive /346/250/241/345/274/217/350/257/264/346/230/216.txt" +2 -0
  33. metradar/project/qpe/__init__.py +9 -0
  34. metradar/project/qpe/archive_main_qpe_cfg.ini +91 -0
  35. metradar/project/qpe/do_s1.sh +6 -0
  36. metradar/project/qpe/do_s2.sh +6 -0
  37. metradar/project/qpe/do_s3.sh +6 -0
  38. metradar/project/qpe/do_s4.sh +6 -0
  39. metradar/project/qpe/do_s5.sh +6 -0
  40. metradar/project/qpe/exec_all.sh +11 -0
  41. metradar/project/qpe/get_rainrate_func.py +80 -0
  42. metradar/project/qpe/main_qpe_cfg.ini +85 -0
  43. metradar/project/qpe/s1_download_radar_region_cmadaas.py +123 -0
  44. metradar/project/qpe/s2_pre_process_single_radar.py +183 -0
  45. metradar/project/qpe/s3_trans_rainrate_to_qpe.py +499 -0
  46. metradar/project/qpe/s4_mosaic_qpe.py +523 -0
  47. metradar/project/qpe/s5_draw_qpe_mosaic.py +308 -0
  48. metradar/project/wind_retrieval/__init__.py +9 -0
  49. metradar/project/wind_retrieval/config_3dwind.ini +45 -0
  50. metradar/{main_pydda.py → project/wind_retrieval/main_pydda.py} +152 -149
  51. metradar/util/__init__.py +9 -0
  52. metradar/{comm_func.py → util/comm_func.py} +1 -41
  53. metradar/util/exceptions.py +50 -0
  54. metradar/util/geo_transforms_pyart.py +627 -0
  55. metradar/{get_tlogp_from_sharppy.py → util/get_tlogp_from_sharppy.py} +16 -5
  56. metradar/{parse_pal.py → util/parse_pal.py} +147 -147
  57. metradar/util/radar_common.py +16 -0
  58. metradar/{trans_new_mosaic_nc.py → util/trans_new_mosaic_nc.py} +1 -1
  59. metradar-0.1.8.dist-info/METADATA +91 -0
  60. metradar-0.1.8.dist-info/RECORD +67 -0
  61. {metradar-0.1.5.dist-info → metradar-0.1.8.dist-info}/WHEEL +1 -1
  62. metradar-0.1.8.dist-info/licenses/LICENSE +21 -0
  63. metradar/grid.py +0 -281
  64. metradar/grid_data.py +0 -64
  65. metradar/oa_couhua.py +0 -166
  66. metradar/read_new_mosaic.py +0 -33
  67. metradar/retrieve_cmadaas.py +0 -3126
  68. metradar/retrieve_micaps_server.py +0 -2061
  69. metradar-0.1.5.dist-info/METADATA +0 -37
  70. metradar-0.1.5.dist-info/RECORD +0 -33
  71. /metradar/{pgmb_io.py → io/pgmb_io.py} +0 -0
  72. /metradar/{exceptions.py → project/make_vpr_aws/exceptions.py} +0 -0
  73. /metradar/{geo_transforms_pyart.py → project/make_vpr_aws/geo_transforms_pyart.py} +0 -0
  74. /metradar/{make_gif.py → util/make_gif.py} +0 -0
  75. {metradar-0.1.5.dist-info → metradar-0.1.8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,308 @@
1
+ # _*_ coding: utf-8 _*_
2
+
3
+
4
+ # 多进程绘图,提高历史模式下绘图效率
5
+
6
+ # %%绘图
7
+ import os
8
+ import numpy as np
9
+ import matplotlib.pyplot as plt
10
+ from matplotlib.transforms import offset_copy
11
+ from matplotlib.font_manager import FontProperties
12
+ import cartopy.crs as ccrs
13
+ import nmc_met_graphics.plot.mapview as nmc_draw
14
+ from netCDF4 import Dataset
15
+ import warnings
16
+
17
+ warnings.filterwarnings('ignore')
18
+
19
+ import matplotlib as mpl
20
+ from datetime import datetime,timedelta
21
+ from multiprocessing import Pool,Manager,freeze_support,cpu_count
22
+ import sys
23
+
24
+ from metradar.config import CONFIG
25
+
26
+ # 资源文件路径
27
+ RESOURCES_PATH = CONFIG.get('SETTING','RESOURCES_PATH')
28
+ FONT_FILE = RESOURCES_PATH + '/fonts/YaHeiConsolasHybrid_1.12.ttf'
29
+
30
+ BDEBUG = False
31
+
32
+ manager = Manager()
33
+ # 创建一个dict,装入每个qpe拼图的文件的名称和修改时间
34
+ shared_dict = manager.dict()
35
+
36
+ if not BDEBUG:
37
+ # linux : export MPLBACKEND=Agg
38
+ mpl.use('Agg')
39
+
40
+ import configparser
41
+ #添加时间控制器
42
+ import time
43
+ import sched
44
+ schedule = sched.scheduler(time.time, time.sleep)
45
+ # sub function for reading config file
46
+ def ConfigFetchError(Exception):
47
+ pass
48
+
49
+ def _get_config_from_rcfile(rcfile):
50
+ """
51
+ Get configure information from config_dk_met_io.ini file.
52
+ """
53
+
54
+ print(rcfile)
55
+ try:
56
+ config = configparser.ConfigParser()
57
+ config.read(rcfile,encoding='UTF-8')
58
+ except IOError as e:
59
+ raise ConfigFetchError(str(e))
60
+ except Exception as e:
61
+ raise ConfigFetchError(str(e))
62
+
63
+ return config
64
+
65
+ def get_datetime_from_filename1(filename):
66
+ timstr = filename[11:23]
67
+ fyear = int(timstr[0:4])
68
+ fmonth = int(timstr[4:6])
69
+ fday = int(timstr[6:8])
70
+ fhour = int(timstr[8:10])
71
+ fmin = int(timstr[10:12])
72
+ fsec = 0
73
+ ft = datetime(fyear,fmonth,fday,fhour,fmin,fsec).timestamp()
74
+ return ft
75
+
76
+ def draw_single(params: dict):
77
+ filename = params['filename']
78
+ pic_path = params['pic_path']
79
+ mosaic_path = params['mosaic_path']
80
+ acc_hours = params['acc_hours']
81
+ print('process file: ' + filename + ' acc_hours: ' + str(acc_hours))
82
+ if filename.find('%02dhr.nc'%acc_hours) < 0 or filename.find('.lock') > 0:
83
+ return -2
84
+ outname = filename.replace('.nc','.png')
85
+
86
+ if not BDEBUG:
87
+ pass
88
+ # 只要超过20分钟就不重新绘制
89
+ if (datetime.utcnow().timestamp() - get_datetime_from_filename1(filename)) > 20*60:
90
+ return -1
91
+
92
+ if os.path.exists(pic_path + os.sep + outname) and (datetime.utcnow().timestamp() - get_datetime_from_filename1(filename)) > 20*60 :
93
+ # print(pic_path + os.sep + outname + ' 已存在,且过时20分钟,不重新绘制!')
94
+ return -3
95
+
96
+ if not os.path.exists(mosaic_path + os.sep + filename):
97
+ print(mosaic_path + os.sep + filename + ' 文件不存在!')
98
+ return -4
99
+
100
+ try:
101
+ mosaic_file = Dataset(mosaic_path + os.sep + filename,'r')
102
+ except:
103
+ print(mosaic_path + os.sep + filename + ' 文件读取失败!')
104
+ return -5
105
+
106
+ # 检测临时状态
107
+ curt_file = datetime.fromtimestamp(os.path.getmtime(mosaic_path + os.sep + filename))
108
+ if filename in list(shared_dict.keys()):
109
+ if curt_file == shared_dict[filename]:
110
+ # 修改时间无变化,那么就不画图
111
+ print(filename + ' 无修改,不重复绘图!')
112
+ return 1
113
+
114
+ shared_dict[filename] = curt_file
115
+ mosaic_grid = mosaic_file.variables['qpe_mosaic'][:,:] * mosaic_file.variables['qpe_mosaic'].unit_scale
116
+ used_hours = mosaic_file.used_hours
117
+ used_sites = mosaic_file.used_sites
118
+ used_lons = mosaic_file.used_lons
119
+ used_lats = mosaic_file.used_lats
120
+ unused_sites = mosaic_file.unused_sites
121
+ unused_lons = mosaic_file.unused_lons
122
+ unused_lats = mosaic_file.unused_lats
123
+
124
+ #
125
+ #降水产品格点设置
126
+ START_LAT= mosaic_file.start_lat
127
+ END_LAT = mosaic_file.end_lat
128
+ START_LON= mosaic_file.start_lon
129
+ END_LON = mosaic_file.end_lon
130
+ GRID_RESO = mosaic_file.reso #网格分辨率,经纬度,度
131
+
132
+ mosaic_lats = np.arange(START_LAT,END_LAT+GRID_RESO/2,GRID_RESO)
133
+ mosaic_lons = np.arange(START_LON,END_LON+GRID_RESO/2,GRID_RESO)
134
+
135
+ m = nmc_draw.BaseMap(projection='PlateCarree',central_longitude=110.0,res='h')
136
+ fig =plt.figure(figsize=(8,8))
137
+ ax = plt.axes(projection=m.proj)
138
+ ax.set_extent([START_LON, END_LON, START_LAT, END_LAT])
139
+ mosaic_grid[mosaic_grid<0.5] = np.nan
140
+ projection = ccrs.PlateCarree()
141
+
142
+ # cmap = parse_cmap('pyart_NWSRef')
143
+ colors_1 = [[183,245,167],[120,215,110],[65,185,60],[50,140,45],[100,185,255],[0,5,255],[255,0,255]]
144
+ colors_2 = [[168,242,142],[65,185,60],[100,185,255],[0,5,255],[255,0,255],[128,0,64]]
145
+ levs_1 = [0,2.5,5,10,25,50,100,999]
146
+ levs_2 = [0,10,25,50,100,250,999]
147
+ if acc_hours < 3:
148
+ colors = np.array(colors_1)/255
149
+ levs = levs_1
150
+ else:
151
+ colors = np.array(colors_2)/255
152
+ levs = levs_2
153
+ cmap = mpl.colors.ListedColormap(colors, 'precipitation')
154
+ pm = m.contourf(mosaic_lons, mosaic_lats, mosaic_grid[:,:],ax=ax,colors =colors,levels=levs)
155
+ pm.set_clim(0,999)
156
+ nmc_draw.add_china_map_2cartopy(ax, name='county', edgecolor='darkgray', lw=0.5)
157
+ nmc_draw.add_china_map_2cartopy(ax, name='province', edgecolor='k', lw=1)
158
+
159
+ tt1 = datetime.strptime(mosaic_file.product_time, '%Y%m%d%H%M') + timedelta(hours=8)
160
+ tt2 = datetime.strptime(mosaic_file.last_update, '%Y%m%d%H%M') + timedelta(hours=8)
161
+ m.title(left_title = '%d hours Radar QPE(%s)'%(acc_hours,tt1.strftime('%Y%m%d%H%M')), ax=ax, font_size=13)
162
+ m.title(right_title = 'Last update:%s'%tt2.strftime('%Y%m%d%H%M'), ax=ax, font_size=13)
163
+ m.gridlines()
164
+ # m.cities()
165
+ if np.array(used_sites).size > 0:
166
+ ax.plot(used_lons, used_lats, marker='o', color='red', markersize=5, linewidth=0,
167
+ alpha=0.7, transform=ccrs.PlateCarree())
168
+ font = FontProperties(size=8, weight='bold')
169
+ geodetic_transform = ccrs.Geodetic()._as_mpl_transform(ax)
170
+ text_transform = offset_copy(geodetic_transform, units='dots', x=0,y=5)
171
+ if np.array(used_hours).size == 1:
172
+ ax.text(used_lons, used_lats, str(used_hours) + 'hr',verticalalignment='bottom', horizontalalignment='center',
173
+ transform=text_transform, fontproperties=font, color='black')
174
+ else:
175
+ for bbx in range(np.array(used_hours).size):
176
+ ax.text(used_lons[bbx], used_lats[bbx], str(used_hours[bbx]) + 'hr',verticalalignment='bottom', horizontalalignment='center',
177
+ transform=text_transform, fontproperties=font, color='black')
178
+
179
+
180
+ if np.array(unused_sites).size > 0:
181
+ ax.plot(unused_lons, unused_lats, marker='o', color='black', markersize=6, linewidth=0,
182
+ alpha=0.7, transform=ccrs.PlateCarree())
183
+ m.colorbar(pm)
184
+ plt.savefig( pic_path + os.sep + outname,dpi=150)
185
+ # 防止内存泄露
186
+ plt.close()
187
+ print(pic_path + os.sep + outname + ' done!')
188
+
189
+ return 0
190
+
191
+ def drawpic(tstep=10):
192
+
193
+ for acc_hours in ACC_HOURS:
194
+ pic_path = pic_path_ori + os.sep + '%02dhr'%acc_hours
195
+ if not os.path.exists(pic_path):
196
+ os.makedirs(pic_path)
197
+ mosaic_path = mosaic_path_ori + os.sep + '%02dhr'%acc_hours
198
+ if not os.path.exists(mosaic_path):
199
+ print(mosaic_path + ' 路径不存在!')
200
+ continue
201
+ files = os.listdir(mosaic_path)
202
+ files = sorted(files)
203
+ if len(files) == 0:
204
+ continue
205
+ all_pms =[]
206
+ for filename in files:
207
+ params = {}
208
+ params['filename'] = filename
209
+ params['pic_path'] = pic_path
210
+ params['mosaic_path'] = mosaic_path
211
+ params['acc_hours'] = acc_hours
212
+ all_pms.append(params)
213
+
214
+ # 构建多进程pool
215
+ freeze_support()
216
+ cores = CPU_MAX
217
+ if cores > len(files):
218
+ cores = len(files)
219
+ print('总共采用 %d 个核心,处理 %d 个文件'%(cores,len(files)))
220
+ pool = Pool(processes = cores)
221
+ pool.map(draw_single, all_pms)
222
+ pool.close()
223
+ pool.join()
224
+
225
+ if not BDEBUG: # 实时模式
226
+ print('Waiting for new data......')
227
+ schedule.enter(tstep, 0, drawpic, (tstep,))
228
+
229
+ def _delete_old_data(tstep):
230
+
231
+ print('delete expired data ...')
232
+ curtime = datetime.now()
233
+ pretime = curtime + timedelta(hours=-1*int(data_save_hours))
234
+
235
+ #查询过期数据
236
+
237
+ for acc_hours in ACC_HOURS:
238
+ curpath = pic_path_ori + os.sep + '%02dhr'%acc_hours
239
+ if not os.path.exists(curpath):
240
+ return False
241
+ ff = os.listdir(curpath)
242
+ for f in ff:
243
+ t = os.path.getctime(curpath + os.sep + f)
244
+ if t < pretime.timestamp():
245
+ os.remove(curpath + os.sep + f)
246
+ print(['Delete file:' + curpath + os.sep + f])
247
+
248
+ schedule.enter(tstep, 0, _delete_old_data, (tstep,))
249
+
250
+ if __name__ == '__main__':
251
+
252
+ print('Usage: python s5_draw_qpe_mosaic.py inifile')
253
+ # 所有参数(包含脚本名)
254
+ all_args = sys.argv
255
+ # 实际参数(排除脚本名)
256
+ inifile = sys.argv[1:]
257
+
258
+
259
+ #如果未指定配置文件,则选用默认的配置
260
+ if len(inifile) ==0:
261
+ inifile = '/home/wjzhu/OneDrive/PythonCode/MyWork/metradar/metradar/project/qpe/main_qpe_cfg.ini'
262
+ # inifile = 'archive_main_qpe_cfg.ini'
263
+ else:
264
+ inifile = inifile[0]
265
+
266
+ config = _get_config_from_rcfile(inifile)
267
+ RUNMODE = int(config['COMMON']['RUN_MODE'])#X方向格点数
268
+
269
+ if RUNMODE == 0:
270
+ BDEBUG = False
271
+ else:
272
+ BDEBUG = True
273
+
274
+ ROOT_PATH = config['PATH_SETTING']['ROOT_PATH']
275
+ ACC_HOURS = [int(mm) for mm in config['PARAMS']['acc_hours'].split(',')]
276
+ mosaic_path_ori = ROOT_PATH + os.sep + config['PATH_SETTING']['PATH_QPE_MOSAIC']
277
+ pic_path_ori = ROOT_PATH + os.sep + config['GRAPH']['PIC_PATH']
278
+ DPI = int(config['GRAPH']['PIC_DPI'])
279
+ data_save_hours = config['DATA_SAVE_SETTING']['DATA_SAVE_HOURS']
280
+ CPU_MAX = int(cpu_count() * float(config['PARAMS']['CPU_RATE']))
281
+
282
+
283
+ with open('current_pid_s5.txt','wt') as f:
284
+ f.write('current pid is: %s'%str(os.getpid()) + ' ,' + datetime.now().strftime('%Y-%m-%dT%H:%M:%S'))
285
+
286
+ import matplotlib as mpl
287
+ import shutil
288
+
289
+ # 获取 Matplotlib 字体目录
290
+ font_dir = mpl.get_data_path() + '/fonts/ttf/'
291
+ # 复制字体文件(需管理员权限)
292
+ shutil.copy(FONT_FILE, font_dir)
293
+ cache_dir = mpl.get_cachedir()
294
+ shutil.rmtree(cache_dir)
295
+
296
+ if not BDEBUG:
297
+ # 重复的时间间隔
298
+ tstep = 10 # seconds
299
+
300
+ # 增加数据处理任务
301
+ schedule.enter(0, 0, drawpic, (tstep,))
302
+
303
+ # 增加数据管理任务,定时删除旧文件
304
+ schedule.enter(0, 0, _delete_old_data, (60,))
305
+
306
+ schedule.run()
307
+ else:
308
+ drawpic(10)
@@ -0,0 +1,9 @@
1
+ """
2
+ metradar is a python package to read or retrieve radar data
3
+
4
+ """
5
+
6
+ __author__ = "The R & D Center for Weather Forecasting Technology in NMC, CMA"
7
+
8
+
9
+ __all__ = [s for s in dir() if not s.startswith('_')]
@@ -0,0 +1,45 @@
1
+ # 多雷达三维风场反演,配置文件
2
+ # utf-8编码,请勿直接用txt文本编辑
3
+ # 朱文剑,zhuwj@cma.gov.cn
4
+ [PATH_SETTINGS]
5
+ # testdata/basedata
6
+ RADAR_FILE_PATH=/mnt/e/metradar_test/wind_retrieve/basedata
7
+ OUT_PATH=/mnt/e/metradar_test/wind_retrieve/output/20200612054000
8
+ PIC_PATH=/mnt/e/metradar_test/wind_retrieve/pic/20200612054000
9
+ TLOG_PATH=/mnt/e/metradar_test/wind_retrieve/tlogp
10
+ TLOG_FILE=20061208.58238
11
+
12
+
13
+ [PARAM_SETTINGS]
14
+ # 拼图中心经纬度
15
+ CENTER_LON=119.4
16
+ CENTER_LAT=32.5
17
+
18
+ # X,Y,Z方向的范围边界设定,单位为公里km,如XLIM -50,50表示以拼图中心点西边50km到东边50km,总距离为100km
19
+ # 用,分割,请用英文输入法的逗号(半角)
20
+ # 建议用整数
21
+ XLIM=-50, 50
22
+ YLIM=-25, 75
23
+ ZLIM=1, 15
24
+
25
+ #X,Y,Z方向的分辨率,单位米
26
+ XRESO=1000
27
+ YRESO=1000
28
+ ZRESO=500
29
+
30
+ #参与拼图的雷达
31
+ RADAR_SITES=淮安, 南京, 泰州
32
+ # RADAR_SITES=HAJS, NJJS, TZJS
33
+ # yyyymmddHHMMSS,年月日时分秒
34
+ TIME_FILES=20200612054000
35
+
36
+ #垂直剖面分析的经度线和纬度线坐标,单位为度,最好精确到小数点后三位
37
+ ANA_LAT=32.787
38
+ ANA_LON=119.376
39
+
40
+ # 是否弹出图片显示窗口,matplotlib的,1或0
41
+ SHOW_PIC=0
42
+
43
+ # 是否保存图片 1或0
44
+ SAVE_PIC=1
45
+