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
@@ -1,3 +1,6 @@
1
+
2
+ # _*_ coding: utf-8 _*_
3
+
1
4
  '''
2
5
  读取新的雷达拼图数据
3
6
  朱文剑
@@ -148,7 +151,17 @@ def _unpack_structure(string, structure):
148
151
  return dict(zip([i[0] for i in structure], lst))
149
152
 
150
153
  def decode_mosaic(filepath,filename,minv=None,maxv = None):
154
+ """_summary_
155
+
156
+ Args:
157
+ filepath (_type_): 文件路径
158
+ filename (_type_): 文件名称
159
+ minv (_type_, optional): 最小值,小于该值设为缺省值. Defaults to None.
160
+ maxv (_type_, optional): 最大值,大于该值设为缺省值. Defaults to None.
151
161
 
162
+ Returns:
163
+ _type_: _description_
164
+ """
152
165
  if not os.path.exists(filepath+os.sep + filename):
153
166
  print(filepath+os.sep+filename + ' not exists!')
154
167
  return None,None
@@ -195,7 +208,7 @@ def decode_mosaic(filepath,filename,minv=None,maxv = None):
195
208
  lat_coord = ('lat', lat, {
196
209
  'long_name':'latitude', 'units':'degrees_north', '_CoordinateAxisType':'Lat'})
197
210
 
198
- if filename.find('REF')>=0:
211
+ if filename.find('_CREF_')>=0:
199
212
  # create xarray
200
213
  varattrs = {'long_name': 'Composite Refelectivity',
201
214
  'short_name': 'cref', 'units': 'dBZ',
@@ -203,6 +216,14 @@ def decode_mosaic(filepath,filename,minv=None,maxv = None):
203
216
  'minv':minv}
204
217
  data = xr.Dataset({'CREF':(['lat', 'lon'], data, varattrs)},
205
218
  coords={ 'lat':lat_coord, 'lon':lon_coord})
219
+ elif filename.find('_QREF_')>=0:
220
+ # create xarray
221
+ varattrs = {'long_name': ' Refelectivity',
222
+ 'short_name': 'qref', 'units': 'dBZ',
223
+ 'maxv':maxv,
224
+ 'minv':minv}
225
+ data = xr.Dataset({'QREF':(['lat', 'lon'], data, varattrs)},
226
+ coords={ 'lat':lat_coord, 'lon':lon_coord})
206
227
  elif filename.find('OHP')>=0:
207
228
  # create xarray
208
229
  varattrs = {'long_name': 'One hour precipitation',
@@ -211,10 +232,17 @@ def decode_mosaic(filepath,filename,minv=None,maxv = None):
211
232
  'minv':minv}
212
233
  data = xr.Dataset({'ohp':(['lat', 'lon'], data, varattrs)},
213
234
  coords={ 'lat':lat_coord, 'lon':lon_coord})
235
+ else:
236
+ varattrs = {'long_name': 'unknown data',
237
+ 'short_name': 'data', 'units': 'mm',
238
+ 'maxv':maxv,
239
+ 'minv':minv}
240
+ data = xr.Dataset({'data':(['lat', 'lon'], data, varattrs)},
241
+ coords={ 'lat':lat_coord, 'lon':lon_coord})
214
242
  # add attributes
215
243
  data.attrs['Conventions'] = "CF-1.6"
216
244
  data.attrs['Origin'] = 'cmadaas'
217
- data.attrs['author'] = 'ZWJ'
245
+ data.attrs['author'] = 'metradar'
218
246
 
219
247
 
220
248
  return data
@@ -0,0 +1,250 @@
1
+
2
+ # _*_ coding: utf-8 _*_
3
+
4
+ '''
5
+ 读取swan格点数据
6
+
7
+ '''
8
+
9
+ # %%
10
+ import numpy as np
11
+ import xarray as xr
12
+ import bz2
13
+ import os
14
+ from datetime import datetime, timedelta
15
+ from metradar.graph.draw_latlon_func import draw_latlon
16
+
17
+
18
+ # define head structure
19
+ head_dtype = [
20
+ ('ZonName', 'S12'),
21
+ ('DataName', 'S38'),
22
+ ('Flag', 'S8'),
23
+ ('Version', 'S8'),
24
+ ('year', 'i2'),
25
+ ('month', 'i2'),
26
+ ('day', 'i2'),
27
+ ('hour', 'i2'),
28
+ ('minute', 'i2'),
29
+ ('interval', 'i2'),
30
+ ('XNumGrids', 'i2'),
31
+ ('YNumGrids', 'i2'),
32
+ ('ZNumGrids', 'i2'),
33
+ ('RadarCount', 'i4'),
34
+ ('StartLon', 'f4'),
35
+ ('StartLat', 'f4'),
36
+ ('CenterLon', 'f4'),
37
+ ('CenterLat', 'f4'),
38
+ ('XReso', 'f4'),
39
+ ('YReso', 'f4'),
40
+ ('ZhighGrids', 'f4', 40),
41
+ ('RadarStationName', 'S20', 16),
42
+ ('RadarLongitude', 'f4', 20),
43
+ ('RadarLatitude', 'f4', 20),
44
+ ('RadarAltitude', 'f4', 20),
45
+ ('MosaicFlag', 'S1', 20),
46
+ ('m_iDataType', 'i2'),
47
+ ('m_iLevelDimension', 'i2'),
48
+ ('offset','f4'),
49
+ ('scale','f4'),
50
+ ('Reserved', 'S160')]
51
+
52
+
53
+ def decode_swan(filepath,filename,scale=None,varattrs={'long_name': 'mosaic composite reflectivity', 'short_name': 'QPF', 'units': 'mm'}
54
+ ,attach_forecast_period=False):
55
+
56
+ if not os.path.exists(filepath+os.sep+filename):
57
+ print(filepath + os.sep + filename + ' not exists!')
58
+ return None
59
+
60
+ fp = open(filepath + os.sep + filename, 'rb')
61
+
62
+ if filename.find('.bz2') > 0:
63
+
64
+ tmpbuf = fp.read()
65
+ byteArray = bz2.decompress(tmpbuf)
66
+ else:
67
+ byteArray = fp.read()
68
+
69
+ # read head information
70
+ head_info = np.frombuffer(byteArray[0:1024], dtype=head_dtype)
71
+ ind = 1024
72
+
73
+ # get coordinates
74
+ nlon = head_info['XNumGrids'][0].astype(np.int64)
75
+ nlat = head_info['YNumGrids'][0].astype(np.int64)
76
+ nlev = head_info['ZNumGrids'][0].astype(np.int64)
77
+ dlon = head_info['XReso'][0].astype(np.float32)
78
+ dlat = head_info['YReso'][0].astype(np.float32)
79
+ lat = head_info['StartLat'][0] - np.arange(nlat)*dlat - dlat/2.0
80
+ lon = head_info['StartLon'][0] + np.arange(nlon)*dlon - dlon/2.0
81
+ level = head_info['ZhighGrids'][0][0:nlev]
82
+ cur_scale = head_info['scale'][0].astype(np.float32)
83
+ cur_offset = head_info['offset'][0].astype(np.float32)
84
+
85
+ # retrieve data records
86
+ data_type = ['u1', 'u1', 'u2', 'i2']
87
+ data_type = data_type[head_info['m_iDataType'][0]]
88
+ data_len = (nlon * nlat * nlev)
89
+ data = np.frombuffer(
90
+ byteArray[ind:(ind + data_len*int(data_type[1]))],
91
+ dtype=data_type, count=data_len)
92
+
93
+ # convert data type
94
+ data.shape = (nlev, nlat, nlon)
95
+ data = data.astype(np.float32)
96
+ if not scale is None:
97
+ data = (data + scale[1]) * scale[0]
98
+ else:
99
+ data = data * cur_scale + cur_offset
100
+
101
+ # reverse latitude axis
102
+ # if len(data.shape) == 3:
103
+ # data = np.flip(data, 2)
104
+ # else:
105
+ data = np.flip(data, 1)
106
+ lat = lat[::-1]
107
+
108
+ # set time coordinates
109
+ init_time = datetime(
110
+ head_info['year'][0], head_info['month'][0],
111
+ head_info['day'][0], head_info['hour'][0], head_info['minute'][0])
112
+ if attach_forecast_period:
113
+ fhour = int(filename.split('.')[1])/60.0
114
+ else:
115
+ fhour = 0
116
+ fhour = np.array([fhour], dtype=np.float64)
117
+ time = init_time + timedelta(hours=fhour[0])
118
+ init_time = np.array([init_time], dtype='datetime64[ns]')
119
+ time = np.array([time], dtype='datetime64[ns]')
120
+
121
+ # define coordinates
122
+ time_coord = ('time', time)
123
+ lon_coord = ('lon', lon, {
124
+ 'long_name':'longitude', 'units':'degrees_east', '_CoordinateAxisType':'Lon'})
125
+ lat_coord = ('lat', lat, {
126
+ 'long_name':'latitude', 'units':'degrees_north', '_CoordinateAxisType':'Lat'})
127
+ level_coord = ('level', level, {
128
+ 'long_name':'height', 'units':'m'})
129
+
130
+ # create xarray
131
+ data = np.expand_dims(data, axis=0)
132
+ data = xr.Dataset({'data':(['time', 'level', 'lat', 'lon'], data, varattrs)},
133
+ coords={'time':time_coord, 'level':level_coord, 'lat':lat_coord, 'lon':lon_coord})
134
+
135
+ # add time coordinates
136
+ data.coords['forecast_reference_time'] = init_time[0]
137
+ data.coords['forecast_period'] = ('time', fhour, {
138
+ 'long_name':'forecast_period', 'units':'hour'})
139
+
140
+ # add attributes
141
+ data.attrs['Conventions'] = "CF-1.6"
142
+
143
+ return data
144
+
145
+
146
+
147
+ if __name__ == "__main__":
148
+ # pass
149
+
150
+ # %%
151
+ # testdata/SWAN/
152
+
153
+ # prod_type = 'MCR'
154
+ prod_type = 'MCC'
155
+ # prod_type = 'MKDP'
156
+ # prod_type = 'MZDR'
157
+ # prod_type = 'HCAMOSAIC'
158
+ # prod_type = 'TOP'
159
+ # prod_type = 'VIL'
160
+
161
+ timestr = '20230316113000'
162
+ filepath = '/home/wjzhu/OneDrive/PythonCode/MyWork/metradar/testdata/SWAN'
163
+
164
+ # filename = 'Z_OTHE_RADAMCR_20230316113000.bin.bz2'
165
+ # filename = 'Z_OTHE_RADAMOSAIC_20230316113000.bin.bz2'
166
+ # filename = 'Z_SWAN_RADAMCC_20230316113000.bin.bz2'
167
+ # filename = 'Z_SWAN_RADAMKDP_20230316113000.bin.bz2'
168
+ # filename = 'Z_SWAN_RADAMZDR_20230316113000.bin.bz2'
169
+ # filename = 'Z_SWAN_RADAMHCA_20230316114000.bin.bz2'
170
+ # filename = 'Z_SWAN_RADAMHCA_20220904110000.bin.bz2'
171
+
172
+ if prod_type == 'TDMOSAIC':
173
+ filename = 'Z_OTHE_RADAMOSAIC_' + timestr + '.bin.bz2'
174
+ elif prod_type == 'MCC':
175
+ filename = 'Z_SWAN_RADAMCC_' + timestr + '.bin.bz2'
176
+ elif prod_type == 'MKDP':
177
+ filename = 'Z_SWAN_RADAMKDP_' + timestr + '.bin.bz2'
178
+ elif prod_type == 'MZDR':
179
+ filename = 'Z_SWAN_RADAMZDR_' + timestr + '.bin.bz2'
180
+ elif prod_type == 'HCAMOSAIC':
181
+ filename = 'Z_SWAN_RADAMHCA_' + timestr + '.bin.bz2'
182
+ elif prod_type == 'MCR':
183
+ filename = 'Z_OTHE_RADAMCR_' + timestr + '.bin.bz2'
184
+ elif prod_type == 'TOP':
185
+ filename = 'Z_OTHE_RADAMTOP_' + timestr + '.bin.bz2'
186
+ elif prod_type == 'VIL':
187
+ filename = 'Z_OTHE_RADAMVIL_' + timestr + '.bin.bz2'
188
+
189
+
190
+ outpath = '/home/wjzhu/OneDrive/PythonCode/MyWork/metradar/pic/SWAN'
191
+ if not os.path.exists(outpath):
192
+ os.makedirs(outpath)
193
+ print('reading file: ',filepath + os.sep + filename)
194
+ if prod_type == 'MCR' or prod_type == 'TOP' or prod_type == 'VIL':
195
+ lev=0
196
+ else:
197
+ lev = 5
198
+ print('level index: ',lev)
199
+ data = decode_swan(filepath,filename,) # scale=[0.5,-64]
200
+ outname = filename + '_%.1fkm.png'%data.level[lev].values
201
+
202
+ slat = 24.5
203
+ nlat = 29.5
204
+ wlon = 103.5
205
+ elon = 109.5
206
+ # slat = float(data.lat.min().data)
207
+ # nlat = float(data.lat.max().data)
208
+ # wlon = float(data.lon.min().data)
209
+ # elon = float(data.lon.max().data)
210
+
211
+ newdata = data.data.sel(lat=slice(slat,nlat),lon=slice(wlon,elon))
212
+ # ttdata = newdata.isel(time=0,level=5)
213
+ # plt.show()
214
+ # %%
215
+ # newdata.isel(time=0,level=5).to_netcdf('/Users/wenjianzhu/Downloads/test.nc')
216
+ tstr = filename.split('_')[3].split('.')[0]
217
+
218
+ # CC的数据是从0-1,所以要处理一下
219
+
220
+ if filename.find('MCR') > 0 :
221
+ draw_latlon(newdata.data[0,lev,:,:],newdata.lat.data,newdata.lon.data,slat,nlat,wlon,elon,
222
+ outpath,outname,tstr,prefix_title='CR',dpi=800,units='dBZ',thred=0,)
223
+ if filename.find('TOP') > 0 :
224
+ draw_latlon(newdata.data[0,lev,:,:],newdata.lat.data,newdata.lon.data,slat,nlat,wlon,elon,
225
+ outpath,outname,tstr,prefix_title='ET',dpi=800,units='km',thred=2,)
226
+ if filename.find('VIL') > 0 :
227
+ draw_latlon(newdata.data[0,lev,:,:],newdata.lat.data,newdata.lon.data,slat,nlat,wlon,elon,
228
+ outpath,outname,tstr,prefix_title='VIL',dpi=800,units='kg/m2',thred=10,)
229
+ elif filename.find('MCC') > 0 :
230
+ draw_latlon(newdata.data[0,lev,:,:]* 100,newdata.lat.data,newdata.lon.data,slat,nlat,wlon,elon,
231
+ outpath,outname,tstr,prefix_title='CAPPI_CC_%.1fkm_'%data.level[lev].values,dpi=800,units='%',thred=0,)
232
+ elif filename.find('MKDP') > 0 :
233
+ draw_latlon(newdata.data[0,lev,:,:],newdata.lat.data,newdata.lon.data,slat,nlat,wlon,elon,
234
+ outpath,outname,tstr,prefix_title='CAPPI_KDP_%.1fkm_'%data.level[lev].values,dpi=800,units='deg/km',thred=-2)
235
+ elif filename.find('MZDR') > 0:
236
+ draw_latlon(newdata.data[0,lev,:,:],newdata.lat.data,newdata.lon.data,slat,nlat,wlon,elon,
237
+ outpath,outname,tstr,prefix_title='CAPPI_ZDR_%.1fkm_'%data.level[lev].values,dpi=800,units='dB',thred=-4,)
238
+ elif filename.find('RADAMOSAIC') > 0:
239
+ draw_latlon(newdata.data[0,lev,:,:],newdata.lat.data,newdata.lon.data,slat,nlat,wlon,elon,outpath,
240
+ outname,tstr,prefix_title='CAPPI_REF_%.1fkm_'%data.level[lev].values,dpi=800,units='dBZ',thred=2,)
241
+ elif filename.find('HCA') > 0:
242
+ draw_latlon(newdata.data[0,lev,:,:],newdata.lat.data,newdata.lon.data,slat,nlat,wlon,elon,outpath,
243
+ outname,tstr,prefix_title='CAPPI_HCA_%.1fkm_'%data.level[lev].values,dpi=800,units='cat',thred=0,)
244
+ pass
245
+
246
+ '''
247
+
248
+ HCA 空=0 地物回波=1 晴空回波=2 干雪=3 湿雪=4 冰晶=5 霰=6 大雨滴=7 小到中雨=8 大雨=9 冰雹=10
249
+
250
+ '''
@@ -1,4 +1,6 @@
1
1
 
2
+ # _*_ coding: utf-8 _*_
3
+
2
4
  '''
3
5
  记录rose产品的文件结构
4
6
 
@@ -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,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,32 @@
1
+
2
+ # _*_ coding: utf-8 _*_
3
+
4
+ '''
5
+ 快速绘制三维雷达组网拼图
6
+
7
+ '''
8
+
9
+ # %%
10
+ from metradar.graph.draw_comp_mosaic import draw_composite_operational
11
+ import os
12
+
13
+ from metradar.config import CONFIG
14
+
15
+ # 资源文件路径
16
+ RESOURCES_PATH = CONFIG.get('SETTING','RESOURCES_PATH')
17
+ COLOR_FILE=RESOURCES_PATH + '/gr2_colors/default_BR_PUP2.pal'
18
+
19
+ if __name__ == "__main__":
20
+
21
+
22
+ path = '/mnt/e/metradar_test/vpr/mosaic/20230731_daxing'
23
+ outpath = '/mnt/e/metradar_test/vpr/mosaic/20230731_daxing/mosac_pic'
24
+
25
+ print(os.listdir(path))
26
+ for file in os.listdir(path):
27
+ if not file.endswith('.nc'):
28
+ continue
29
+ draw_composite_operational(path + os.sep + file,outpath,colorfile=None)
30
+ pass
31
+
32
+