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,123 @@
1
+ # _*_ coding: utf-8 _*_
2
+
3
+ """
4
+ 定时从天擎下载雷达基数据
5
+ @author: wenjianzhu
6
+ """
7
+
8
+ # %%
9
+ import urllib3
10
+ import json as js
11
+ import os
12
+ import configparser
13
+ from datetime import datetime,timedelta
14
+ import time
15
+ import hashlib
16
+ import uuid
17
+ from nmc_met_io.retrieve_cmadaas import cmadaas_radar_level2_by_timerange_and_id
18
+ #添加时间控制器
19
+ import sched
20
+ schedule = sched.scheduler(time.time, time.sleep)
21
+
22
+ # sub function for reading config file
23
+ def ConfigFetchError(Exception):
24
+ pass
25
+
26
+ def _get_config_from_rcfile(rcfile):
27
+ """
28
+ Get configure information from config_dk_met_io.ini file.
29
+ """
30
+
31
+ try:
32
+ config = configparser.ConfigParser()
33
+ config.read(rcfile,encoding='UTF-8')
34
+ except IOError as e:
35
+ raise ConfigFetchError(str(e))
36
+ except Exception as e:
37
+ raise ConfigFetchError(str(e))
38
+
39
+ return config
40
+
41
+
42
+ # 获取雷达基数据的代码如下:
43
+ def _download_radar_basedata(tstep,trange, staIds):
44
+
45
+ # 获取当前UTC时间,构建时间范围,用于获取数据
46
+ curtime = datetime.utcnow()
47
+ pretime = curtime + timedelta(minutes=-1*trange)
48
+ print("Search From: " + pretime.strftime("%Y-%m-%d %H:%M:%S") + " To: "+ curtime.strftime("%Y-%m-%d %H:%M:%S"))
49
+
50
+ time_range = "[" + pretime.strftime("%Y%m%d%H%M%S") + "," + curtime.strftime("%Y%m%d%H%M%S") + "]"
51
+
52
+ for rds in staIds:
53
+ #创建输出路径
54
+ cmadaas_radar_level2_by_timerange_and_id(radar_ids=rds,time_range=time_range,outpath=outpath)
55
+
56
+
57
+ print('Waiting for new data......')
58
+ schedule.enter(tstep, 0, _download_radar_basedata, (tstep, trange, staIds,))
59
+
60
+ # 递归删除文件夹中的过期文件
61
+ def loop_delete_data(filepath,pretime):
62
+ pass
63
+ if os.path.exists(filepath):
64
+
65
+ if os.path.isdir(filepath):
66
+ ff = os.listdir(filepath)
67
+ for f in ff:
68
+ if os.path.isdir(filepath + os.sep + f):
69
+ loop_delete_data(filepath + os.sep + f,pretime)
70
+ elif os.path.isfile(filepath + os.sep + f):
71
+ t = os.path.getctime(filepath + os.sep + f)
72
+ if t < pretime.timestamp():
73
+ os.remove(filepath + os.sep + f)
74
+ print(['Delete file:' + filepath + os.sep + f])
75
+
76
+ elif os.path.isfile(filepath):
77
+ t = os.path.getctime(filepath + os.sep + f)
78
+ if t < pretime.timestamp():
79
+ os.remove(filepath + os.sep + f)
80
+ print(['Delete file:' + filepath + os.sep + f])
81
+
82
+
83
+ def _delete_old_data(tstep):
84
+
85
+ print('delete expired data ...')
86
+ curtime = datetime.now()
87
+ pretime = curtime + timedelta(hours=-1 * int(data_save_hours))
88
+ loop_delete_data(outpath,pretime)
89
+
90
+ schedule.enter(tstep, 0, _delete_old_data, (tstep,))
91
+
92
+
93
+ if __name__=='__main__':
94
+ with open('current_pid_s1.txt','wt') as f:
95
+ f.write('current pid is: %s'%str(os.getpid()) + ' ,' + datetime.now().strftime('%Y-%m-%dT%H:%M:%S'))
96
+
97
+
98
+ config_file = '/home/wjzhu/OneDrive/PythonCode/MyWork/metradar/metradar/project/qpe/main_qpe_cfg.ini'
99
+
100
+
101
+ print(os.path.exists(config_file))
102
+ config = _get_config_from_rcfile(config_file)
103
+ staIds = config['RADAR_SITES']['RADARS'].split(',')
104
+
105
+ outpath = config['PATH_SETTING']['ROOT_PATH'] + os.sep + config['PATH_SETTING']['BASEDATA_PATH']
106
+
107
+ q_tstep = config['QUIRY_SETTING']['QUIRY_STEP']
108
+ q_trange = config['QUIRY_SETTING']['QUIRY_RANGE']
109
+ data_save_hours = config['DATA_SAVE_SETTING']['DATA_SAVE_HOURS']
110
+
111
+
112
+
113
+ # 增加数据下载任务
114
+ schedule.enter(0, 0, _download_radar_basedata, (int(q_tstep),int(q_trange),staIds,))
115
+
116
+ # 增加数据管理任务,定时删除旧文件
117
+ schedule.enter(0, 0, _delete_old_data, (60,))
118
+
119
+ # 增加程序自动重启任务,以解决可能存在的bug
120
+ schedule.run()
121
+
122
+
123
+ # %%
@@ -0,0 +1,183 @@
1
+ # _*_ coding: utf-8 _*_
2
+
3
+ '''
4
+ 定时扫描本地文件夹中的雷达基数据,并处理成单站qpe,用nc格式存储
5
+ '''
6
+
7
+ # %%
8
+ import os
9
+ from metradar.project.qpe.get_rainrate_func import get_rainrate
10
+ from datetime import datetime,timedelta
11
+ import sys
12
+ import configparser
13
+ import warnings
14
+ warnings.filterwarnings('ignore')
15
+ from multiprocessing import Pool,cpu_count,freeze_support
16
+ #添加时间控制器
17
+ import time
18
+ import sched
19
+ schedule = sched.scheduler(time.time, time.sleep)
20
+
21
+ BDEBUG=False
22
+ # sub function for reading config file
23
+ def ConfigFetchError(BaseException):
24
+ pass
25
+
26
+ def _get_config_from_rcfile(rcfile):
27
+ """
28
+ Get configure information from config_dk_met_io.ini file.
29
+ """
30
+ # print(os.getcwd())
31
+ print(rcfile)
32
+ try:
33
+ config = configparser.ConfigParser()
34
+ config.read(rcfile,encoding='UTF-8')
35
+ except IOError as e:
36
+ raise ConfigFetchError(str(e))
37
+ except Exception as e:
38
+ raise ConfigFetchError(str(e))
39
+
40
+ return config
41
+
42
+ def process_single(tstep=10):
43
+
44
+ if not os.path.exists(PATH_RR):
45
+ os.makedirs(PATH_RR)
46
+
47
+ pools = Pool(CPU_MAX)
48
+ print('共使用 %d 个逻辑CPU进行并行处理......'%CPU_MAX)
49
+ for rd in RADARS:
50
+
51
+ # 这里要改为递归查找文件,目录结构是ROOT_PATH ,年,月,日,站号
52
+
53
+ # 递归处理所有子文件夹中的文件
54
+ allfiles = []
55
+ allpaths = []
56
+ for root, dirs, files in os.walk(ROOT_PATH + os.sep + BASEDATA_PATH):
57
+ for file in files:
58
+ if file.endswith('.bz2'):
59
+ if file.find(rd) < 0:
60
+ continue
61
+ allfiles.append(file)
62
+ allpaths.append(root)
63
+
64
+ curoutpath = PATH_RR + os.sep + rd
65
+ if not os.path.exists(curoutpath):
66
+ os.makedirs(curoutpath)
67
+
68
+ allfiles = sorted(allfiles)
69
+
70
+ for ff in allfiles:
71
+ if ff.find('FMT.bin') < 0:
72
+ allfiles.remove(ff)
73
+ continue
74
+
75
+ bfiles_valid=0
76
+ for filename in allfiles:
77
+ #先判断该文件的qpe产品是否存在,如果已经存在就不重复处理,否则就处理
78
+ outname = filename.replace('.bz2','_rr.nc')
79
+ if not os.path.exists(curoutpath + os.sep + outname):
80
+ bfiles_valid += 1
81
+ if bfiles_valid > 0:
82
+ print('%s 站,共找到 %d 个待处理的新数据,正在处理,请耐心等待......'%(rd,bfiles_valid))
83
+ else:
84
+ print('%s 站,共找到 %d 个待处理的新数据'%(rd,bfiles_valid))
85
+
86
+ for nn in range(len(allfiles)):
87
+ #先判断该文件的qpe产品是否存在,如果已经存在就不重复处理,否则就处理
88
+
89
+ outname = allfiles[nn].replace('.bz2','_rr.nc')
90
+
91
+ if os.path.exists(curoutpath + os.sep + outname):
92
+ pass
93
+ # print(curoutpath + os.sep + outname + ' 已存在,不重复处理!')
94
+ else:
95
+ # print('正在处理 '+ filename)
96
+ pools.apply_async(get_rainrate,(allpaths[nn],allfiles[nn],curoutpath,outname,GRID_XNUM,GRID_YNUM,GRID_RESO))
97
+
98
+ pools.close()
99
+ pools.join()
100
+ if not BDEBUG:
101
+ print('Waiting for new data......')
102
+ schedule.enter(tstep, 0, process_single, (tstep,))
103
+
104
+
105
+ def _delete_old_data(tstep):
106
+
107
+ print('delete expired data ...')
108
+ curtime = datetime.now()
109
+ pretime = curtime + timedelta(hours=-1 * int(data_save_hours))
110
+ for rds in RADARS:
111
+ #查询过期数据
112
+ curpath = PATH_RR + os.sep + rds + os.sep
113
+ if not os.path.exists(curpath):
114
+ continue
115
+ ff = os.listdir(curpath)
116
+ for f in ff:
117
+ t = os.path.getctime(curpath + os.sep + f)
118
+
119
+ if t < pretime.timestamp():
120
+ os.remove(curpath + os.sep + f)
121
+ print(['Delete file:' + curpath + os.sep + f])
122
+
123
+
124
+ schedule.enter(tstep, 0, _delete_old_data, (tstep,))
125
+
126
+
127
+ if __name__ == '__main__':
128
+ freeze_support()
129
+ print('Usage: python s2_pre_process_single_radar.py inifile')
130
+ # 所有参数(包含脚本名)
131
+ all_args = sys.argv
132
+ # 实际参数(排除脚本名)
133
+ inifile = sys.argv[1:]
134
+
135
+
136
+ #如果未指定配置文件,则选用默认的配置
137
+ if len(inifile) ==0:
138
+ inifile = '/home/wjzhu/OneDrive/PythonCode/MyWork/metradar/metradar/project/qpe/main_qpe_cfg.ini'
139
+ else:
140
+ inifile = inifile[0]
141
+
142
+ config = _get_config_from_rcfile(inifile)
143
+ RUNMODE = int(config['COMMON']['RUN_MODE'])#X方向格点数
144
+ if RUNMODE == 0:
145
+ BDEBUG = False
146
+ else:
147
+ BDEBUG = True
148
+ ROOT_PATH = config['PATH_SETTING']['ROOT_PATH']
149
+ # BASEDATA_PATH = ROOT_PATH + os.sep + config['PATH_SETTING']['BASEDATA_PATH']
150
+ BASEDATA_PATH = config['PATH_SETTING']['BASEDATA_PATH']
151
+
152
+ RADARS = config['RADAR_SITES']['RADARS'].split(',')
153
+
154
+ PATH_RR = ROOT_PATH + os.sep + config['PATH_SETTING']['PATH_RR']
155
+
156
+ data_save_hours = config['DATA_SAVE_SETTING']['DATA_SAVE_HOURS']
157
+ #降水产品格点设置
158
+ GRID_XNUM = int(config['PARAMS']['GRID_XNUM'])#X方向格点数
159
+ GRID_YNUM = int(config['PARAMS']['GRID_YNUM']) #Y方向格点数
160
+ GRID_RESO = int(config['PARAMS']['GRID_RESO']) #网格分辨率,米
161
+ CPU_MAX = int(cpu_count() * float(config['PARAMS']['CPU_RATE']))
162
+
163
+ with open('current_pid_s2_%d.txt'%RUNMODE,'wt') as f:
164
+ f.write('current pid is: %s'%str(os.getpid()) + ' ,' + datetime.now().strftime('%Y-%m-%dT%H:%M:%S'))
165
+
166
+ # 重复的时间间隔
167
+ tstep = 10 # seconds
168
+
169
+ if not BDEBUG:
170
+ # 增加数据处理任务
171
+ schedule.enter(0, 0, process_single, (tstep,))
172
+
173
+ # 增加数据管理任务,定时删除旧文件
174
+ schedule.enter(0, 0, _delete_old_data, (60,))
175
+
176
+
177
+ schedule.run()
178
+ else:
179
+ process_single(tstep)
180
+
181
+
182
+
183
+ # %%