metradar 0.1.0__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.
- metradar/__init__.py +7 -0
- metradar/cnrad_level2.py +1326 -0
- metradar/comm_func.py +135 -0
- metradar/construct_aws_refvpr_mainprog.py +515 -0
- metradar/construct_aws_refvpr_mainprog_cams.py +310 -0
- metradar/construct_aws_refvpr_mainprog_datan3d.py +386 -0
- metradar/construct_aws_refvpr_mainprog_swan.py +306 -0
- metradar/decode_fmt_pyart.py +200 -0
- metradar/decode_pup_rose.py +1993 -0
- metradar/draw_mosaic_new.py +421 -0
- metradar/draw_radar_aws_jilin_new.py +206 -0
- metradar/draw_radar_comp_func.py +1379 -0
- metradar/exceptions.py +50 -0
- metradar/geo_transforms_pyart.py +627 -0
- metradar/get_cross_section_from_pyart.py +354 -0
- metradar/get_tlogp_from_sharppy.py +93 -0
- metradar/grid.py +281 -0
- metradar/grid_data.py +64 -0
- metradar/main_pydda.py +653 -0
- metradar/make_gif.py +24 -0
- metradar/make_mosaic_mp_archive.py +538 -0
- metradar/mosaic_merge.py +64 -0
- metradar/mosaic_quickdraw.py +338 -0
- metradar/nowcast_by_pysteps.py +219 -0
- metradar/oa_couhua.py +166 -0
- metradar/oa_dig_func.py +955 -0
- metradar/parse_pal.py +148 -0
- metradar/pgmb_io.py +169 -0
- metradar/prepare_for_radar_draw.py +197 -0
- metradar/read_new_mosaic.py +33 -0
- metradar/read_new_mosaic_func.py +231 -0
- metradar/retrieve_cmadaas.py +3126 -0
- metradar/retrieve_micaps_server.py +2061 -0
- metradar/rose_structer.py +807 -0
- metradar/trans_nc_pgmb.py +62 -0
- metradar/trans_new_mosaic_nc.py +309 -0
- metradar/trans_polor2grid_func.py +203 -0
- metradar-0.1.0.dist-info/METADATA +12 -0
- metradar-0.1.0.dist-info/RECORD +41 -0
- metradar-0.1.0.dist-info/WHEEL +5 -0
- metradar-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
'''
|
|
2
|
+
读取新的雷达拼图数据
|
|
3
|
+
朱文剑
|
|
4
|
+
|
|
5
|
+
数据格式说明
|
|
6
|
+
|
|
7
|
+
//
|
|
8
|
+
/////////////////////////////////////////////////////////////////////
|
|
9
|
+
// 组网定量估测降水系统拼图产品文件规则
|
|
10
|
+
// 1. 文件里命名为:
|
|
11
|
+
// ACHN_XXX_20121012_090000_nn.bin
|
|
12
|
+
// 2. 文件格式:文件头 + 数据块
|
|
13
|
+
// 3. 数据从西北,往东南写
|
|
14
|
+
//***************************************
|
|
15
|
+
typedef struct tagMQPE_MosiacProductHeaderStructure
|
|
16
|
+
{
|
|
17
|
+
// 文件卷标,12字节(0-11),
|
|
18
|
+
char label[4]; //0-3 文件固定标识:MOC
|
|
19
|
+
char Version[4]; //4-7 文件格式版本代码,如: 1.0,1.1,etc
|
|
20
|
+
int FileBytes; //8-11 包含头信息在内的文件字节数,不超过2M
|
|
21
|
+
|
|
22
|
+
//产品描述, 84字节(12-95)
|
|
23
|
+
short MosaicID; //12-13 拼图产品编号
|
|
24
|
+
short coordinate; //14-15 坐标类型: 2=笛卡儿坐标,3=等经纬网格坐标
|
|
25
|
+
char varname[8]; //16-23 产品代码,如: ET,VIL,CR,CAP,OHP,OHPC
|
|
26
|
+
char description[64];//24-87 产品描述,如Composite Reflectivity mosaic
|
|
27
|
+
int BlockPos; //88-91 产品数据起始位置(字节顺序)
|
|
28
|
+
int BlockLen; //92-95 产品数据字节数
|
|
29
|
+
|
|
30
|
+
//数据时间, 28字节(96-123)
|
|
31
|
+
int TimeZone; //96-99 数据时钟,0=世界时,28800=北京时
|
|
32
|
+
short yr; //100-101 观测时间中的年份
|
|
33
|
+
short mon; //102-103 观测时间中的月份(1-12)
|
|
34
|
+
short day; //104-105 观测时间中的日期(1-31)
|
|
35
|
+
short hr; //106-107 观测时间中的小时(00-23)
|
|
36
|
+
short min; //108-109 观测时间中的分(00-59)
|
|
37
|
+
short sec; //110-111 观测时间中的秒(00-59)
|
|
38
|
+
int ObsSeconds; //112-115 观测时间的seconds
|
|
39
|
+
unsigned short ObsDates; //116-117 观测时间中的Julian dates
|
|
40
|
+
unsigned short GenDates; //118-119 产品处理时间的天数
|
|
41
|
+
int GenSeconds; //120-123 产品处理时间的描述
|
|
42
|
+
|
|
43
|
+
//数据区信息, 48字节(124-171)
|
|
44
|
+
int edge_s; //124-127 数据区的南边界,单位:1/1000度,放大1千倍
|
|
45
|
+
int edge_w; //128-131 数据区的西边界,单位:1/1000度,放大1千倍
|
|
46
|
+
int edge_n; //132-135 数据区的北边界,单位:1/1000度,放大1千倍
|
|
47
|
+
int edge_e; //136-139 数据区的东边界,单位:1/1000度,放大1千倍
|
|
48
|
+
int cx; //140-143 数据区中心坐标,单位:1/1000度,放大1千倍
|
|
49
|
+
int cy; //144-147 数据区中心坐标,单位:1/1000度,放大1千倍
|
|
50
|
+
int nX; //148-151 格点坐标为列数,
|
|
51
|
+
int nY; //152-155 格点坐标为行数,
|
|
52
|
+
int dx; //156-159 格点坐标为列分辨率,单位:1/10000度,放大1万倍
|
|
53
|
+
int dy; //160-163 格点坐标为行分辨率,单位:1/10000度,放大1万倍
|
|
54
|
+
short height; //164-165 雷达高度
|
|
55
|
+
short Compress; //166-167 数据压缩标识, 0=无,1=bz2,2=zip,3=lzw
|
|
56
|
+
int num_of_radars; //168-171有多少个雷达进行了拼图
|
|
57
|
+
|
|
58
|
+
int UnZipBytes; //数据段压缩前的字节数, //172-175
|
|
59
|
+
short scale; //176-177
|
|
60
|
+
short unUsed; //178-179
|
|
61
|
+
char RgnID[8]; //180-187
|
|
62
|
+
char units[8]; //180-187
|
|
63
|
+
char reserved[60];
|
|
64
|
+
}MOSAIC_PRODUCTHEADER;
|
|
65
|
+
|
|
66
|
+
-32768表示空白
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
'''
|
|
70
|
+
|
|
71
|
+
# %%
|
|
72
|
+
CODE1 = 'B'
|
|
73
|
+
CODE2 = 'H'
|
|
74
|
+
INT1 = 'B'
|
|
75
|
+
INT2 = 'H'
|
|
76
|
+
INT4 = 'I'
|
|
77
|
+
REAL4 = 'f'
|
|
78
|
+
REAL8 = 'd'
|
|
79
|
+
SINT1 = 'b'
|
|
80
|
+
SINT2 = 'h'
|
|
81
|
+
SINT4 = 'i'
|
|
82
|
+
|
|
83
|
+
MOSAIC_HEADER = (
|
|
84
|
+
('label', '4s'),
|
|
85
|
+
('Version', '4s'),
|
|
86
|
+
('FileBytes', INT4),
|
|
87
|
+
('MosaicID', INT2),
|
|
88
|
+
('coordinate', INT2),
|
|
89
|
+
('varname', '8s'),
|
|
90
|
+
('description', '64s'),
|
|
91
|
+
('BlockPos', INT4),
|
|
92
|
+
('BlockLen', INT4),
|
|
93
|
+
('TimeZone', INT4),
|
|
94
|
+
('year', INT2),
|
|
95
|
+
('month', INT2),
|
|
96
|
+
('day', INT2),
|
|
97
|
+
('hour', INT2),
|
|
98
|
+
('min', INT2),
|
|
99
|
+
('sec', INT2),
|
|
100
|
+
('ObsSeconds', INT4),
|
|
101
|
+
('ObsDates', INT2),
|
|
102
|
+
('GenDates', INT2),
|
|
103
|
+
('GenSeconds', INT4),
|
|
104
|
+
('edge_s', INT4),
|
|
105
|
+
('edge_w', INT4),
|
|
106
|
+
('edge_n', INT4),
|
|
107
|
+
('edge_e', INT4),
|
|
108
|
+
('cx', INT4),
|
|
109
|
+
('cy', INT4),
|
|
110
|
+
('nX', INT4),
|
|
111
|
+
('nY', INT4),
|
|
112
|
+
('dx', INT4),
|
|
113
|
+
('dy', INT4),
|
|
114
|
+
('height', INT2),
|
|
115
|
+
('Compress', INT2),
|
|
116
|
+
('num_of_radars', INT4),
|
|
117
|
+
('UnZipBytes', INT4),
|
|
118
|
+
('scale', INT2),
|
|
119
|
+
('unUsed', INT2),
|
|
120
|
+
('RgnID', '8s'),
|
|
121
|
+
('units', '8s'),
|
|
122
|
+
('reserved', '60s'),
|
|
123
|
+
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
import os
|
|
127
|
+
import numpy as np
|
|
128
|
+
import struct
|
|
129
|
+
import bz2
|
|
130
|
+
import xarray as xr
|
|
131
|
+
from datetime import datetime
|
|
132
|
+
|
|
133
|
+
def _structure_size(structure):
|
|
134
|
+
""" Find the size of a structure in bytes. """
|
|
135
|
+
return struct.calcsize('<' + ''.join([i[1] for i in structure]))
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _unpack_from_buf( buf, pos, structure):
|
|
139
|
+
""" Unpack a structure from a buffer. """
|
|
140
|
+
size = _structure_size(structure)
|
|
141
|
+
return _unpack_structure(buf[pos:pos + size], structure)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _unpack_structure(string, structure):
|
|
145
|
+
""" Unpack a structure from a string """
|
|
146
|
+
fmt = '<' + ''.join([i[1] for i in structure]) # little-endian
|
|
147
|
+
lst = struct.unpack(fmt, string)
|
|
148
|
+
return dict(zip([i[0] for i in structure], lst))
|
|
149
|
+
|
|
150
|
+
def decode_mosaic(filepath,filename,minv=None,maxv = None):
|
|
151
|
+
|
|
152
|
+
if not os.path.exists(filepath+os.sep + filename):
|
|
153
|
+
print(filepath+os.sep+filename + ' not exists!')
|
|
154
|
+
return None,None
|
|
155
|
+
try:
|
|
156
|
+
fin = open(filepath + os.sep + filename,'rb')
|
|
157
|
+
except:
|
|
158
|
+
return None,None
|
|
159
|
+
|
|
160
|
+
buf = fin.read()
|
|
161
|
+
fin.close()
|
|
162
|
+
pos = 0
|
|
163
|
+
if len(buf)==0:
|
|
164
|
+
return None
|
|
165
|
+
dic_gh = _unpack_from_buf(buf, pos, MOSAIC_HEADER)
|
|
166
|
+
pos +=_structure_size(MOSAIC_HEADER)
|
|
167
|
+
databuf = bz2.decompress(buf[pos:])
|
|
168
|
+
data = np.frombuffer(databuf, 'int16')
|
|
169
|
+
data = np.reshape(data,[dic_gh['nY'],dic_gh['nX']])
|
|
170
|
+
data=data.astype('float')
|
|
171
|
+
# data[data == -32768] = np.nan # 空白
|
|
172
|
+
# data[data == -1280] = np.nan # 有覆盖但无数据
|
|
173
|
+
data[data < -300] = np.nan
|
|
174
|
+
data = np.flipud(data)/dic_gh['scale']
|
|
175
|
+
if minv is None:
|
|
176
|
+
minv = np.nanmin(data)
|
|
177
|
+
if maxv is None:
|
|
178
|
+
maxv = np.nanmax(data)
|
|
179
|
+
data[data < int(minv)] = np.nan
|
|
180
|
+
data[data > int(maxv)] = np.nan
|
|
181
|
+
|
|
182
|
+
# set longitude and latitude coordinates
|
|
183
|
+
lat = dic_gh['edge_s']/1000 + np.arange(dic_gh['nY'])*dic_gh['dy']/10000
|
|
184
|
+
lon = dic_gh['edge_w']/1000 + np.arange(dic_gh['nX'])*dic_gh['dx']/10000
|
|
185
|
+
|
|
186
|
+
# set time coordinates
|
|
187
|
+
time = datetime(dic_gh['year'],dic_gh['month'],dic_gh['day'],dic_gh['hour'],dic_gh['min'],dic_gh['sec'])
|
|
188
|
+
time = np.array([time], dtype='datetime64[m]')
|
|
189
|
+
# data = np.expand_dims(data, axis=0)
|
|
190
|
+
|
|
191
|
+
# define coordinates
|
|
192
|
+
time_coord = ('time', time)
|
|
193
|
+
lon_coord = ('lon', lon, {
|
|
194
|
+
'long_name':'longitude', 'units':'degrees_east', '_CoordinateAxisType':'Lon'})
|
|
195
|
+
lat_coord = ('lat', lat, {
|
|
196
|
+
'long_name':'latitude', 'units':'degrees_north', '_CoordinateAxisType':'Lat'})
|
|
197
|
+
|
|
198
|
+
if filename.find('REF')>=0:
|
|
199
|
+
# create xarray
|
|
200
|
+
varattrs = {'long_name': 'Composite Refelectivity',
|
|
201
|
+
'short_name': 'cref', 'units': 'dBZ',
|
|
202
|
+
'maxv':maxv,
|
|
203
|
+
'minv':minv}
|
|
204
|
+
data = xr.Dataset({'CREF':(['lat', 'lon'], data, varattrs)},
|
|
205
|
+
coords={ 'lat':lat_coord, 'lon':lon_coord})
|
|
206
|
+
elif filename.find('OHP')>=0:
|
|
207
|
+
# create xarray
|
|
208
|
+
varattrs = {'long_name': 'One hour precipitation',
|
|
209
|
+
'short_name': 'ohp', 'units': 'mm',
|
|
210
|
+
'maxv':maxv,
|
|
211
|
+
'minv':minv}
|
|
212
|
+
data = xr.Dataset({'ohp':(['lat', 'lon'], data, varattrs)},
|
|
213
|
+
coords={ 'lat':lat_coord, 'lon':lon_coord})
|
|
214
|
+
# add attributes
|
|
215
|
+
data.attrs['Conventions'] = "CF-1.6"
|
|
216
|
+
data.attrs['Origin'] = 'cmadaas'
|
|
217
|
+
data.attrs['author'] = 'ZWJ'
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
return data
|
|
221
|
+
|
|
222
|
+
if __name__ == '__main__':
|
|
223
|
+
|
|
224
|
+
filepath = '/Users/wenjianzhu/Documents/'
|
|
225
|
+
filename = 'Z_RADA_C_BABJ_20240720033015_P_DOR_ACHN_CREF_20240720_032400.bin'
|
|
226
|
+
|
|
227
|
+
data = decode_mosaic(filepath,filename)
|
|
228
|
+
pass
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
# %%
|