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,200 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# Copyright (c) 2022 NMC Developers.
|
|
4
|
+
# Distributed under the terms of the GPL V3 License.
|
|
5
|
+
# 将FMT格式数据直接解析为pyart的radar object格式
|
|
6
|
+
# Wenjian Zhu
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
from pyart.io.nexrad_archive import _find_range_params,_find_scans_to_interp,_interpolate_scan
|
|
12
|
+
from pyart.io.common import make_time_unit_str, _test_arguments, prepare_for_read
|
|
13
|
+
from pyart.config import FileMetadata, get_fillvalue
|
|
14
|
+
from pyart.core.radar import Radar
|
|
15
|
+
from cnrad_level2 import CNRADLevel2File
|
|
16
|
+
import warnings
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
mapping = {
|
|
20
|
+
"REF": "reflectivity",
|
|
21
|
+
"VEL": "velocity",
|
|
22
|
+
"SW": "spectrum_width",
|
|
23
|
+
"PHI": "differential_phase",
|
|
24
|
+
"ZDR": "differential_reflectivity",
|
|
25
|
+
"RHO": "cross_correlation_ratio",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
def read_cnrad_fmt(filename, field_names=None, additional_metadata=None,
|
|
29
|
+
file_field_names=False, exclude_fields=None,
|
|
30
|
+
include_fields=None, delay_field_loading=False,
|
|
31
|
+
station=None, scans=None,
|
|
32
|
+
linear_interp=True, **kwargs):
|
|
33
|
+
# test for non empty kwargs
|
|
34
|
+
_test_arguments(kwargs)
|
|
35
|
+
|
|
36
|
+
# create metadata retrieval object
|
|
37
|
+
filemetadata = FileMetadata('nexrad_archive', field_names,
|
|
38
|
+
additional_metadata, file_field_names,
|
|
39
|
+
exclude_fields, include_fields)
|
|
40
|
+
|
|
41
|
+
# open the file and retrieve scan information
|
|
42
|
+
nfile = CNRADLevel2File(prepare_for_read(filename))
|
|
43
|
+
scan_info = nfile.scan_info(scans)
|
|
44
|
+
|
|
45
|
+
# time
|
|
46
|
+
time = filemetadata('time')
|
|
47
|
+
time_start, _time = nfile.get_times(scans)
|
|
48
|
+
time['data'] = _time
|
|
49
|
+
time['units'] = make_time_unit_str(time_start)
|
|
50
|
+
|
|
51
|
+
# range
|
|
52
|
+
_range = filemetadata('range')
|
|
53
|
+
first_gate, gate_spacing, last_gate = _find_range_params(
|
|
54
|
+
scan_info, filemetadata)
|
|
55
|
+
_range['data'] = np.arange(first_gate, last_gate, gate_spacing, 'float32')
|
|
56
|
+
_range['meters_to_center_of_first_gate'] = float(first_gate)
|
|
57
|
+
_range['meters_between_gates'] = float(gate_spacing)
|
|
58
|
+
|
|
59
|
+
# metadata
|
|
60
|
+
metadata = filemetadata('metadata')
|
|
61
|
+
metadata['original_container'] = 'CINRAD_FMT'
|
|
62
|
+
vcp_pattern = nfile.get_vcp_pattern()
|
|
63
|
+
if vcp_pattern is not None:
|
|
64
|
+
metadata['vcp_pattern'] = vcp_pattern
|
|
65
|
+
if 'icao' in nfile.volume_header.keys():
|
|
66
|
+
metadata['instrument_name'] = nfile.volume_header['icao'].decode()
|
|
67
|
+
|
|
68
|
+
# scan_type
|
|
69
|
+
scan_type = 'ppi'
|
|
70
|
+
|
|
71
|
+
# latitude, longitude, altitude
|
|
72
|
+
latitude = filemetadata('latitude')
|
|
73
|
+
longitude = filemetadata('longitude')
|
|
74
|
+
altitude = filemetadata('altitude')
|
|
75
|
+
|
|
76
|
+
# if nfile._msg_type == '1' and station is not None:
|
|
77
|
+
# lat, lon, alt = get_nexrad_location(station)
|
|
78
|
+
# elif 'icao' in nfile.volume_header.keys() and nfile.volume_header['icao'].decode()[0] == 'T':
|
|
79
|
+
# lat, lon, alt = get_nexrad_location(
|
|
80
|
+
# nfile.volume_header['icao'].decode())
|
|
81
|
+
# else:
|
|
82
|
+
# lat, lon, alt = nfile.location()
|
|
83
|
+
|
|
84
|
+
lat, lon, alt = nfile.location()
|
|
85
|
+
|
|
86
|
+
latitude['data'] = np.array([lat], dtype='float64')
|
|
87
|
+
longitude['data'] = np.array([lon], dtype='float64')
|
|
88
|
+
altitude['data'] = np.array([alt], dtype='float64')
|
|
89
|
+
|
|
90
|
+
# sweep_number, sweep_mode, fixed_angle, sweep_start_ray_index
|
|
91
|
+
# sweep_end_ray_index
|
|
92
|
+
sweep_number = filemetadata('sweep_number')
|
|
93
|
+
sweep_mode = filemetadata('sweep_mode')
|
|
94
|
+
sweep_start_ray_index = filemetadata('sweep_start_ray_index')
|
|
95
|
+
sweep_end_ray_index = filemetadata('sweep_end_ray_index')
|
|
96
|
+
|
|
97
|
+
if scans is None:
|
|
98
|
+
nsweeps = int(nfile.nscans)
|
|
99
|
+
else:
|
|
100
|
+
nsweeps = len(scans)
|
|
101
|
+
sweep_number['data'] = np.arange(nsweeps, dtype='int32')
|
|
102
|
+
sweep_mode['data'] = np.array(
|
|
103
|
+
nsweeps * ['azimuth_surveillance'], dtype='S')
|
|
104
|
+
|
|
105
|
+
rays_per_scan = [s['nrays'] for s in scan_info]
|
|
106
|
+
sweep_end_ray_index['data'] = np.cumsum(rays_per_scan, dtype='int32') - 1
|
|
107
|
+
|
|
108
|
+
rays_per_scan.insert(0, 0)
|
|
109
|
+
sweep_start_ray_index['data'] = np.cumsum(
|
|
110
|
+
rays_per_scan[:-1], dtype='int32')
|
|
111
|
+
|
|
112
|
+
# azimuth, elevation, fixed_angle
|
|
113
|
+
azimuth = filemetadata('azimuth')
|
|
114
|
+
elevation = filemetadata('elevation')
|
|
115
|
+
fixed_angle = filemetadata('fixed_angle')
|
|
116
|
+
azimuth['data'] = nfile.get_azimuth_angles(scans)
|
|
117
|
+
elevation['data'] = nfile.get_elevation_angles(scans).astype('float32')
|
|
118
|
+
fixed_agl = []
|
|
119
|
+
for i in nfile.get_target_angles(scans):
|
|
120
|
+
if i > 180:
|
|
121
|
+
i = i - 360.
|
|
122
|
+
warnings.warn("Fixed_angle(s) greater than 180 degrees present."
|
|
123
|
+
+ " Assuming angle to be negative so subtrating 360",
|
|
124
|
+
UserWarning)
|
|
125
|
+
else:
|
|
126
|
+
i = i
|
|
127
|
+
fixed_agl.append(i)
|
|
128
|
+
fixed_angles = np.array(fixed_agl, dtype='float32')
|
|
129
|
+
fixed_angle['data'] = fixed_angles
|
|
130
|
+
|
|
131
|
+
# fields
|
|
132
|
+
max_ngates = len(_range['data'])
|
|
133
|
+
available_moments = set([m for scan in scan_info for m in scan['moments']])
|
|
134
|
+
interpolate = _find_scans_to_interp(
|
|
135
|
+
scan_info, first_gate, gate_spacing, filemetadata)
|
|
136
|
+
|
|
137
|
+
fields = {}
|
|
138
|
+
for moment in available_moments:
|
|
139
|
+
field_name = filemetadata.get_field_name(moment)
|
|
140
|
+
if field_name is None:
|
|
141
|
+
continue
|
|
142
|
+
dic = filemetadata(field_name)
|
|
143
|
+
dic['_FillValue'] = get_fillvalue()
|
|
144
|
+
if delay_field_loading and moment not in interpolate:
|
|
145
|
+
# dic = LazyLoadDict(dic)
|
|
146
|
+
# data_call = _NEXRADLevel2StagedField(
|
|
147
|
+
# nfile, moment, max_ngates, scans)
|
|
148
|
+
# dic.set_lazy('data', data_call)
|
|
149
|
+
pass
|
|
150
|
+
else:
|
|
151
|
+
mdata = nfile.get_data(moment, max_ngates, scans=scans)
|
|
152
|
+
if moment in interpolate:
|
|
153
|
+
interp_scans = interpolate[moment]
|
|
154
|
+
warnings.warn(
|
|
155
|
+
"Gate spacing is not constant, interpolating data in " +
|
|
156
|
+
"scans %s for moment %s." % (interp_scans, moment),
|
|
157
|
+
UserWarning)
|
|
158
|
+
for scan in interp_scans:
|
|
159
|
+
idx = scan_info[scan]['moments'].index(moment)
|
|
160
|
+
moment_ngates = scan_info[scan]['ngates'][idx]
|
|
161
|
+
start = sweep_start_ray_index['data'][scan]
|
|
162
|
+
end = sweep_end_ray_index['data'][scan]
|
|
163
|
+
if interpolate['multiplier'] == '4':
|
|
164
|
+
multiplier = '4'
|
|
165
|
+
else:
|
|
166
|
+
multiplier = '2'
|
|
167
|
+
_interpolate_scan(mdata, start, end, moment_ngates,
|
|
168
|
+
multiplier, linear_interp)
|
|
169
|
+
dic['data'] = mdata
|
|
170
|
+
fields[field_name] = dic
|
|
171
|
+
|
|
172
|
+
# instrument_parameters
|
|
173
|
+
nyquist_velocity = filemetadata('nyquist_velocity')
|
|
174
|
+
unambiguous_range = filemetadata('unambiguous_range')
|
|
175
|
+
nyquist_velocity['data'] = nfile.get_nyquist_vel(scans).astype('float32')
|
|
176
|
+
unambiguous_range['data'] = (
|
|
177
|
+
nfile.get_unambigous_range(scans).astype('float32'))
|
|
178
|
+
|
|
179
|
+
instrument_parameters = {'unambiguous_range': unambiguous_range,
|
|
180
|
+
'nyquist_velocity': nyquist_velocity, }
|
|
181
|
+
|
|
182
|
+
nfile.close()
|
|
183
|
+
return Radar(
|
|
184
|
+
time, _range, fields, metadata, scan_type,
|
|
185
|
+
latitude, longitude, altitude,
|
|
186
|
+
sweep_number, sweep_mode, fixed_angle, sweep_start_ray_index,
|
|
187
|
+
sweep_end_ray_index,
|
|
188
|
+
azimuth, elevation,
|
|
189
|
+
instrument_parameters=instrument_parameters)
|
|
190
|
+
|
|
191
|
+
if __name__ == "__main__":
|
|
192
|
+
pass
|
|
193
|
+
|
|
194
|
+
filepath = './testdata/FMT/'
|
|
195
|
+
filename = 'Z_RADR_I_Z9417_20210910154708_O_DOR_SAD_CAP_FMT.bin'
|
|
196
|
+
|
|
197
|
+
radar = read_cnrad_fmt(filepath + os.sep + filename)
|
|
198
|
+
|
|
199
|
+
print(list(radar.fields.keys()))
|
|
200
|
+
pass
|