metradar 0.1.6__py3-none-any.whl → 0.1.8.2__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 (78) 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} +20 -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/make_vpr_aws/make_mosaic_20230731_daxing.ini +29 -0
  30. metradar/project/make_vpr_aws/make_mosaic_basefile.ini +29 -0
  31. metradar/project/nowcasting/__init__.py +9 -0
  32. metradar/project/nowcasting/nowcast_by_pysteps.py +214 -0
  33. metradar/{trans_nc_pgmb.py → project/nowcasting/trans_mosaic_pgmb.py} +19 -17
  34. metradar/project/qpe/Archive /346/250/241/345/274/217/350/257/264/346/230/216.txt" +2 -0
  35. metradar/project/qpe/__init__.py +9 -0
  36. metradar/project/qpe/archive_main_qpe_cfg.ini +91 -0
  37. metradar/project/qpe/do_s1.sh +6 -0
  38. metradar/project/qpe/do_s2.sh +6 -0
  39. metradar/project/qpe/do_s3.sh +6 -0
  40. metradar/project/qpe/do_s4.sh +6 -0
  41. metradar/project/qpe/do_s5.sh +6 -0
  42. metradar/project/qpe/exec_all.sh +11 -0
  43. metradar/project/qpe/get_rainrate_func.py +80 -0
  44. metradar/project/qpe/main_qpe_cfg.ini +85 -0
  45. metradar/project/qpe/s1_download_radar_region_cmadaas.py +123 -0
  46. metradar/project/qpe/s2_pre_process_single_radar.py +183 -0
  47. metradar/project/qpe/s3_trans_rainrate_to_qpe.py +499 -0
  48. metradar/project/qpe/s4_mosaic_qpe.py +523 -0
  49. metradar/project/qpe/s5_draw_qpe_mosaic.py +308 -0
  50. metradar/project/wind_retrieval/__init__.py +9 -0
  51. metradar/project/wind_retrieval/config_3dwind.ini +45 -0
  52. metradar/{main_pydda.py → project/wind_retrieval/main_pydda.py} +152 -149
  53. metradar/util/__init__.py +9 -0
  54. metradar/{comm_func.py → util/comm_func.py} +1 -41
  55. metradar/util/exceptions.py +50 -0
  56. metradar/util/geo_transforms_pyart.py +627 -0
  57. metradar/{get_tlogp_from_sharppy.py → util/get_tlogp_from_sharppy.py} +16 -5
  58. metradar/{parse_pal.py → util/parse_pal.py} +147 -147
  59. metradar/util/radar_common.py +16 -0
  60. metradar/{trans_new_mosaic_nc.py → util/trans_new_mosaic_nc.py} +1 -1
  61. metradar-0.1.8.2.dist-info/METADATA +90 -0
  62. metradar-0.1.8.2.dist-info/RECORD +69 -0
  63. {metradar-0.1.6.dist-info → metradar-0.1.8.2.dist-info}/WHEEL +1 -1
  64. metradar-0.1.8.2.dist-info/licenses/LICENSE +21 -0
  65. {metradar-0.1.6.dist-info → metradar-0.1.8.2.dist-info}/top_level.txt +0 -1
  66. cfg/config.py +0 -90
  67. metradar/grid.py +0 -281
  68. metradar/grid_data.py +0 -64
  69. metradar/oa_couhua.py +0 -166
  70. metradar/read_new_mosaic.py +0 -33
  71. metradar/retrieve_cmadaas.py +0 -3126
  72. metradar/retrieve_micaps_server.py +0 -2061
  73. metradar-0.1.6.dist-info/METADATA +0 -37
  74. metradar-0.1.6.dist-info/RECORD +0 -34
  75. /metradar/{pgmb_io.py → io/pgmb_io.py} +0 -0
  76. /metradar/{exceptions.py → project/make_vpr_aws/exceptions.py} +0 -0
  77. /metradar/{geo_transforms_pyart.py → project/make_vpr_aws/geo_transforms_pyart.py} +0 -0
  78. /metradar/{make_gif.py → util/make_gif.py} +0 -0
@@ -0,0 +1,499 @@
1
+
2
+ # _*_ coding: utf-8 _*_
3
+
4
+
5
+ '''
6
+ 将雨强文件转换为定量降水产品
7
+
8
+ '''
9
+
10
+ import os
11
+ from datetime import datetime,timedelta
12
+ from typing import Dict
13
+ import numpy as np
14
+ import pyart
15
+ import configparser
16
+ import warnings
17
+ import scipy.interpolate
18
+ warnings.filterwarnings('ignore')
19
+ import pickle
20
+ from netCDF4 import Dataset
21
+ from threading import Thread
22
+ from multiprocessing import cpu_count
23
+ #添加时间控制器
24
+ import time
25
+ import sched
26
+ import sys
27
+ schedule = sched.scheduler(time.time, time.sleep)
28
+
29
+ from multiprocessing import Pool,cpu_count,freeze_support
30
+
31
+ BDEBUG = False
32
+ # sub function for reading config file
33
+ def ConfigFetchError(BaseException):
34
+ pass
35
+
36
+ def _get_config_from_rcfile(rcfile):
37
+ """
38
+ Get configure information from config_dk_met_io.ini file.
39
+ """
40
+
41
+ print(rcfile)
42
+ try:
43
+ config = configparser.ConfigParser()
44
+ config.read(rcfile,encoding='UTF-8')
45
+ except IOError as e:
46
+ raise ConfigFetchError(str(e))
47
+ except Exception as e:
48
+ raise ConfigFetchError(str(e))
49
+
50
+ return config
51
+
52
+ def get_datetime_from_filename1(filename):
53
+ timstr = filename[15:29]
54
+ fyear = int(timstr[0:4])
55
+ fmonth = int(timstr[4:6])
56
+ fday = int(timstr[6:8])
57
+ fhour = int(timstr[8:10])
58
+ fmin = int(timstr[10:12])
59
+ fsec = int(timstr[12:14])
60
+ ft = datetime(fyear,fmonth,fday,fhour,fmin,fsec)
61
+ return ft
62
+
63
+ class MyThread(Thread):
64
+
65
+ def __init__(self, fullfilepath):
66
+ Thread.__init__(self)
67
+ self.filepath = fullfilepath
68
+
69
+ def run(self):
70
+ self.result = pyart.io.read_grid(self.filepath)
71
+
72
+ def get_result(self):
73
+ return self.result
74
+
75
+ def do_single(params:Dict):
76
+ # 历史模式下,需要将所有文件都处理
77
+ curt = params['curt']
78
+ rd = params['rd']
79
+ acc_hours = params['acc_hours']
80
+ allfiles = params['allfiles']
81
+ curoutpath = params['curoutpath']
82
+ GRID_SHAPE = params['GRID_SHAPE']
83
+ GRID_LIMITS = params['GRID_LIMITS']
84
+ mosaic_lons = params['mosaic_lons']
85
+ mosaic_lats = params['mosaic_lats']
86
+ glons = params['glons']
87
+ glats = params['glats']
88
+ print(rd + ' 站当前最新的数据时间为: ' + curt.strftime('%Y-%m-%d %H:%M:%S'))
89
+ td = timedelta(hours=acc_hours)
90
+ pret = curt - td
91
+ files=[]
92
+ for ff in allfiles:
93
+ ft = get_datetime_from_filename1(ff)
94
+ if ft < pret or ft > curt:
95
+ continue
96
+ else:
97
+ files.append(ff)
98
+ # print(ff)
99
+
100
+ outrain = np.zeros([len(files),GRID_XNUM,GRID_YNUM],dtype=float)
101
+
102
+ # 定义时间戳列表
103
+ tlist = []
104
+ valid_filenum = 0
105
+ rad_lon = 0
106
+ rad_lat = 0
107
+ rad_alti = 0
108
+ rad_name = ''
109
+
110
+ for filename in files:
111
+ # print(filename)
112
+ try:
113
+ grid = pyart.io.read_grid(PATH_RR + os.sep + rd + os.sep + filename)
114
+ pass
115
+ except:
116
+ print(PATH_RR + os.sep + rd + os.sep + filename + '读取失败,暂不处理!')
117
+ try:
118
+ os.remove(PATH_RR + os.sep + rd + os.sep + filename)
119
+ print(PATH_RR + os.sep + rd + os.sep + filename + ' removed!')
120
+ except:
121
+ print('delete file failed! ' + filename)
122
+ pass
123
+ files.remove(filename)
124
+ continue
125
+ outrain[valid_filenum,:,:] = grid.fields['radar_estimated_rain_rate']['data'][0,:,:]
126
+ dateTime_p = datetime.strptime(grid.time['units'][14::],'%Y-%m-%dT%H:%M:%SZ')
127
+ tlist.append(dateTime_p)
128
+ rad_lon = grid.radar_longitude['data']
129
+ rad_lat = grid.radar_latitude['data']
130
+ rad_alti = grid.radar_altitude['data']
131
+ # rad_name = grid.metadata['instrument_name']
132
+ valid_filenum +=1
133
+
134
+ # 将最后一个文件的文件名中的时间作为当前站点qpe的时间时,不可以执行下一行
135
+ # tlist.append(curt) # 最后一个文件的权重由该文件的时间到当前规定的累积截止时间之间的差值
136
+ # print('%s 站,有效文件数为: %d ,本站处理结束!'%(rd,valid_filenum))
137
+ # print('%s 站共找到 %d 个有效文件'%(rd,valid_filenum))
138
+ outfilename = rd + '_' + curt.strftime('%Y%m%d_%H%M%S_') + '%02dhr.nc'%acc_hours
139
+
140
+ curn = rd + '_%02dhr'%acc_hours + curt.strftime('_%Y%m%d_%H%M%S')
141
+ bneed_process = True
142
+ if os.path.exists(curoutpath + os.sep + outfilename):
143
+ #如果目标文件已经存在,那么check它的源数据是否有更新,如果有更新,那么重新累加,如果没有,那么不累加,直接跳过
144
+
145
+ if os.path.exists(PATH_TMP + os.sep + curn ):
146
+ if os.path.getsize(PATH_TMP + os.sep + curn ) == 0:
147
+ raise ValueError(f"文件 {PATH_TMP + os.sep + curn } 为空")
148
+ try:
149
+ f = open(PATH_TMP + os.sep + curn,'rb')
150
+ dic_info = pickle.load(f)
151
+ f.close()
152
+ print()
153
+ except ValueError as e:
154
+ print(f"读取文件 {PATH_TMP + os.sep + curn } 时出错: {e}")
155
+ dic_info = None
156
+
157
+ if isinstance(dic_info,str):
158
+ if set(tlist) == set(dic_info):
159
+ print(curn + ' 源数据无变化,不重复处理!')
160
+ bneed_process = False
161
+ else:
162
+ pass
163
+ elif isinstance(dic_info,list):
164
+
165
+ if set(tlist) == set(dic_info):
166
+ print(curn + ' 源数据无变化,不重复处理!')
167
+ bneed_process = False
168
+ else:
169
+ pass
170
+
171
+ else:
172
+ pass
173
+ # 如果无需重复处理,就直接continue,进入下一站
174
+ if not bneed_process:
175
+ return True
176
+ f = open(PATH_TMP + os.sep + curn,'wb')
177
+ pickle.dump(tlist,f)
178
+ f.close()
179
+ #计算时间权重
180
+ dt = list(np.diff(tlist))
181
+
182
+ # 插入第一个文件的时间权重,限定一个范围,不要超过6分钟
183
+
184
+ dt.insert(0,min(timedelta(seconds = acc_hours * 3600 - round(np.sum([gk.seconds for gk in dt]))),timedelta(seconds=360)))
185
+
186
+ # print(dt)
187
+
188
+ acs = 0
189
+ wgts = []
190
+ for tt in dt:
191
+ acs += tt.seconds
192
+ wgts.append(tt.seconds / (1* 3600)) # 由于计算的是小时雨强,因此,这里算权重的时候只能按1小时来算,即3600秒
193
+ if acs > (acc_hours * 3600):
194
+ # print('累积时段和设置的不一样,设置的时段是 %d 小时,当前计算的是 %.1f 小时'%(acc_hours,acs/3600))
195
+ print('累积时段超过了设置的规定时段,设置的时段是 %d 小时,当前累积时长是 %.2f 小时'%(acc_hours,acs/3600))
196
+ # print(wgts)
197
+
198
+
199
+ # 累加降水
200
+ acc_rain = np.zeros([GRID_XNUM,GRID_YNUM],dtype=float)
201
+
202
+ for fn in np.arange(0,valid_filenum):
203
+ acc_rain += np.reshape(outrain[fn],[GRID_XNUM,GRID_YNUM])*wgts[fn]
204
+
205
+
206
+
207
+ # 将rain插值到大的网格上,方便下一步直接调用
208
+ nz, ny, nx = GRID_SHAPE
209
+ (z0, z1), (y0, y1), (x0, x1) = GRID_LIMITS
210
+ g_lons,g_lats = pyart.core.transforms.cartesian_to_geographic_aeqd(
211
+ np.linspace(x0, x1, nx),
212
+ np.linspace(y0, y1, ny),
213
+ rad_lon,
214
+ rad_lat)
215
+ mesh_lons,mesh_lats = np.meshgrid(g_lons,g_lats)
216
+ mosaic_grid = scipy.interpolate.griddata((mesh_lons.flatten(),mesh_lats.flatten()),acc_rain.flatten(),(glons,glats))
217
+
218
+ # %% 输出到nc格式
219
+ try:
220
+ ncfile = Dataset(curoutpath + os.sep + outfilename + '.lock', 'w', format='NETCDF4')
221
+ except:
222
+ if os.path.exists(curoutpath + os.sep + outfilename+ '.lock'):
223
+ try:
224
+ os.remove(curoutpath + os.sep + outfilename+ '.lock')
225
+ ncfile = Dataset(curoutpath + os.sep + outfilename+ '.lock', 'w', format='NETCDF4')
226
+ except:
227
+ print(curoutpath + os.sep + outfilename + '.lock' + ' 文件创建失败,删除成功,但无法再新建,跳过!')
228
+ return False
229
+ else:
230
+ print(curoutpath + os.sep + outfilename + '.lock' + ' 文件创建失败,程序跳过!')
231
+ return False
232
+
233
+ used_hours = (curt.timestamp() - get_datetime_from_filename1(files[0]).timestamp())/3600
234
+ used_hours = float('%.1f'%used_hours)
235
+
236
+ hreso = MOSAIC_RESO
237
+
238
+ # global
239
+ ncfile.description = 'SINGLE RADAR QPE MOSAIC'
240
+ ncfile.author = 'Zhu WenJian, kevin2075@163.com'
241
+ ncfile.reso = hreso
242
+ ncfile.sitenum = rd
243
+ ncfile.radlon = rad_lon
244
+ ncfile.radlat = rad_lat
245
+ ncfile.start_lat = START_LAT
246
+ ncfile.end_lat = END_LAT
247
+ ncfile.start_lon = START_LON
248
+ ncfile.end_lon = END_LON
249
+ ncfile.product_time = curt.strftime('%Y%m%d%H%M')
250
+ ncfile.last_update = datetime.utcnow().strftime('%Y%m%d%H%M')
251
+ ncfile.basefile_info = files
252
+ ncfile.used_hours = used_hours
253
+ ncfile.acc_hours = acc_hours
254
+
255
+ # dimensions
256
+ nlons = mosaic_lons
257
+ nlats = mosaic_lats
258
+
259
+ ncfile.createDimension('longitude', len(nlons))
260
+ ncfile.createDimension('latitude', len(nlats))
261
+
262
+ # variables
263
+ longitude = ncfile.createVariable('longitude', np.dtype('float32').char, ('longitude',))
264
+ longitude.units = 'degrees_east'
265
+ longitude.long_name = 'Longitude'
266
+ longitude.CoordinateAxisType = 'Lon'
267
+
268
+ latitude = ncfile.createVariable('latitude', np.dtype('float32').char, ('latitude',))
269
+ latitude.units = 'degrees_north'
270
+ latitude.long_name = 'Latitude'
271
+ latitude.CoordinateAxisType = 'Lat'
272
+
273
+ # H unsigned short
274
+ qpe_mosaic = ncfile.createVariable('qpe_mosaic', 'H', ('latitude', 'longitude'), zlib=True, least_significant_digit=1)
275
+ qpe_mosaic.unit_scale = 0.1
276
+ qpe_mosaic.long_name = "QPE MOSAIC SINGLE RADAR"
277
+ qpe_mosaic.units='mm'
278
+ # data
279
+ qpe_mosaic[:,:] = mosaic_grid * 10
280
+ longitude[:] = nlons
281
+ latitude[:] = nlats
282
+
283
+ ncfile.close()
284
+ os.rename(curoutpath + os.sep + outfilename + '.lock',curoutpath + os.sep + outfilename)
285
+ print(curoutpath + os.sep + outfilename + ' done!')
286
+ return 0
287
+
288
+
289
+ def sub_func(params:tuple):
290
+ acc_hours,rd = params
291
+ curfilepath = PATH_RR + os.sep + rd
292
+ curoutpath = PATH_QPE + os.sep + rd + os.sep
293
+
294
+ GRID_SHAPE = (1,GRID_XNUM, GRID_YNUM)
295
+ GRID_LIMITS = ((GRID_RESO, GRID_RESO), (-1000*(GRID_XNUM-1)/2, 1000*(GRID_XNUM-1)/2), (-1000*(GRID_XNUM-1)/2, 1000*(GRID_XNUM-1)/2))
296
+
297
+
298
+ mosaic_lats = np.arange(START_LAT,END_LAT+MOSAIC_RESO/2,MOSAIC_RESO)
299
+ mosaic_lons = np.arange(START_LON,END_LON+MOSAIC_RESO/2,MOSAIC_RESO)
300
+ glons,glats = np.meshgrid(mosaic_lons,mosaic_lats)
301
+
302
+ if not os.path.exists(curoutpath):
303
+
304
+ os.makedirs(curoutpath,exist_ok=True)
305
+
306
+ allfiles = os.listdir(curfilepath)
307
+ allfiles = sorted(allfiles)
308
+ if len(allfiles) == 0:
309
+ return False
310
+ for ff in allfiles:
311
+ if ff.find('.nc') < 0 or ff.find('.lock') > 0:
312
+ allfiles.remove(ff)
313
+
314
+ # print('%s 站共找到 %d 个文件.'%(rd,len(allfiles)))
315
+
316
+ # 开始累积降水
317
+ # 将最后一个文件的文件名中的时间作为当前站点qpe的时间
318
+ #设置当前截止时间
319
+
320
+ #实时模式下,用最新的即可
321
+ if RUNMODE ==0:
322
+ curttime = get_datetime_from_filename1(allfiles[-1])
323
+ params={}
324
+ params['curt'] = curttime
325
+ params['rd'] = rd
326
+ params['acc_hours'] = acc_hours
327
+ params['allfiles'] = allfiles
328
+ params['curoutpath'] = curoutpath
329
+ params['GRID_SHAPE'] = GRID_SHAPE
330
+ params['GRID_LIMITS'] = GRID_LIMITS
331
+ params['mosaic_lons'] = mosaic_lons
332
+ params['mosaic_lats'] = mosaic_lats
333
+ params['glons'] = glons
334
+ params['glats'] = glats
335
+
336
+ do_single(params)
337
+ #历史模式下,需要将所有文件都处理
338
+ else:
339
+ allpms=[]
340
+ freeze_support()
341
+ pools = Pool(CPU_MAX)
342
+ for f in allfiles:
343
+ curt = get_datetime_from_filename1(f)
344
+ params={}
345
+
346
+ params['curt'] = curt
347
+ params['rd'] = rd
348
+ params['acc_hours'] = acc_hours
349
+ params['allfiles'] = allfiles
350
+ params['curoutpath'] = curoutpath
351
+ params['GRID_SHAPE'] = GRID_SHAPE
352
+ params['GRID_LIMITS'] = GRID_LIMITS
353
+ params['mosaic_lons'] = mosaic_lons
354
+ params['mosaic_lats'] = mosaic_lats
355
+ params['glons'] = glons
356
+ params['glats'] = glats
357
+ # pools.apply_async(do_single,(params,))
358
+ allpms.append(params)
359
+ pools.map(do_single,allpms)
360
+ pools.close()
361
+ pools.join()
362
+
363
+ def get_qpe_from_rr(tstep=10):
364
+ #设置累积时段
365
+ # acc_hours = 3
366
+ # RADARS = ['Z9734','Z9731','Z9739','Z9746']
367
+ # PATH_RR = 'rain_rate'
368
+ # PATH_QPE = 'out_qpe'
369
+ #降水产品格点设置
370
+ # GRID_XNUM = 701 #X方向格点数
371
+ # GRID_YNUM = 701 #Y方向格点数
372
+ # GRID_RESO = 1000 #网格分辨率,米
373
+
374
+ # 用一个状态变量记录当前处理的数据相关信息,便于对比,减少重复计算量
375
+
376
+
377
+ if len(ACC_HOURS)==0:
378
+ print('累计时段为0小时,程序退出!')
379
+ return False
380
+
381
+ # 如果是实时模式
382
+ if RUNMODE == 0:
383
+ params=[]
384
+ for acc_hours in ACC_HOURS:
385
+ for rd in RADARS:
386
+ params.append((acc_hours,rd))
387
+
388
+ freeze_support()
389
+ print("CPUS = %d"%CPU_MAX)
390
+ print('正在启用%d个CPU进行并行计算,等待保存结果......'%CPU_MAX)
391
+ pool = Pool(CPU_MAX)
392
+ pool.map(sub_func,params)
393
+ else:
394
+ for acc_hours in ACC_HOURS:
395
+ for rd in RADARS:
396
+ sub_func((acc_hours,rd))
397
+
398
+
399
+ if not BDEBUG:
400
+ print('Waiting for new data......')
401
+ schedule.enter(tstep, 0, get_qpe_from_rr, (tstep,))
402
+ else:
403
+ pass
404
+
405
+ def _delete_old_data(tstep):
406
+
407
+ print('delete expired data ...')
408
+ curtime = datetime.now()
409
+ pretime = curtime + timedelta(hours=-1 * int(data_save_hours))
410
+ for rds in RADARS:
411
+ #查询过期数据
412
+ curpath = PATH_QPE + os.sep + rds + os.sep
413
+ if not os.path.exists(curpath):
414
+ continue
415
+ ff = os.listdir(curpath)
416
+ for f in ff:
417
+ t = os.path.getctime(curpath + os.sep + f)
418
+
419
+ if t < pretime.timestamp():
420
+ os.remove(curpath + os.sep + f)
421
+ print(['Delete file:' + curpath + os.sep + f])
422
+
423
+
424
+ schedule.enter(tstep, 0, _delete_old_data, (tstep,))
425
+
426
+ if __name__ == '__main__':
427
+
428
+ print('Usage: python s3_trans_rainrate_to_qpe.py inifile')
429
+ # 所有参数(包含脚本名)
430
+ all_args = sys.argv
431
+ # 实际参数(排除脚本名)
432
+ inifile = sys.argv[1:]
433
+
434
+
435
+ #如果未指定配置文件,则选用默认的配置
436
+ if len(inifile) ==0:
437
+ inifile = '/home/wjzhu/OneDrive/PythonCode/MyWork/metradar/metradar/project/qpe/main_qpe_cfg.ini'
438
+ else:
439
+ inifile = inifile[0]
440
+
441
+ config = _get_config_from_rcfile(inifile)
442
+ RUNMODE = int(config['COMMON']['RUN_MODE'])#X方向格点数
443
+ if RUNMODE == 0:
444
+ BDEBUG = False
445
+ else:
446
+ BDEBUG = True
447
+
448
+ ROOT_PATH = config['PATH_SETTING']['ROOT_PATH']
449
+ CPU_MAX = int(cpu_count() * float(config['PARAMS']['CPU_RATE']))
450
+ RADARS = config['RADAR_SITES']['RADARS'].split(',')
451
+
452
+ PATH_RR = ROOT_PATH + os.sep + config['PATH_SETTING']['PATH_RR']
453
+ PATH_QPE = ROOT_PATH + os.sep + config['PATH_SETTING']['PATH_QPE']
454
+ PATH_TMP = ROOT_PATH + os.sep + config['PATH_SETTING']['PATH_TMP']
455
+
456
+ if not os.path.exists(PATH_QPE):
457
+ try:
458
+ os.makedirs(PATH_QPE)
459
+ except:
460
+ print('创建目录失败:' + PATH_QPE)
461
+ if not os.path.exists(PATH_TMP):
462
+ try:
463
+ os.makedirs(PATH_TMP)
464
+ except:
465
+ print('创建目录失败:' + PATH_TMP)
466
+
467
+ #降水产品格点设置
468
+ GRID_XNUM = int(config['PARAMS']['GRID_XNUM'])#X方向格点数
469
+ GRID_YNUM = int(config['PARAMS']['GRID_YNUM']) #Y方向格点数
470
+ GRID_RESO = int(config['PARAMS']['GRID_RESO']) #网格分辨率,米
471
+
472
+ ACC_HOURS = [int(mm) for mm in config['PARAMS']['acc_hours'].split(',')]
473
+ data_save_hours = config['DATA_SAVE_SETTING']['DATA_SAVE_HOURS']
474
+
475
+
476
+ # 输出的大网格设置
477
+ MOSAIC_RESO = float(config['PARAMS']['MOSAIC_RESO']) #网格分辨率,度
478
+ START_LAT = float(config['PARAMS']['SOUTH_LAT']) #南纬
479
+ END_LAT = float(config['PARAMS']['NORTH_LAT']) #北纬
480
+ START_LON = float(config['PARAMS']['WEST_LON']) #西经
481
+ END_LON = float(config['PARAMS']['EAST_LON']) #东经
482
+
483
+ with open('current_pid_s3_%d.txt'%RUNMODE,'wt') as f:
484
+ f.write('current pid is: %s'%str(os.getpid()) + ' ,' + datetime.now().strftime('%Y-%m-%dT%H:%M:%S'))
485
+
486
+ # 重复的时间间隔
487
+ tstep = 10 # seconds
488
+
489
+ if not BDEBUG:
490
+ # 增加数据处理任务
491
+ schedule.enter(0, 0, get_qpe_from_rr, (tstep,))
492
+
493
+ # 增加数据管理任务,定时删除旧文件
494
+ schedule.enter(0, 0, _delete_old_data, (60,))
495
+
496
+ schedule.run()
497
+ else:
498
+ get_qpe_from_rr(10)
499
+ # get_qpe_from_rr(10,acc_hours,RADARS,PATH_RR,PATH_QPE,GRID_XNUM,GRID_YNUM,GRID_RESO)